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
7481impl PartialEq for Object {
7482 #[inline]
7483 fn eq(&self, other: &Object) -> bool {
7484 Object::is(self.as_ref(), other.as_ref())
7485 }
7486}
7487
7488impl Eq for Object {}
7489
7490impl Default for Object<JsValue> {
7491 fn default() -> Self {
7492 Self::new()
7493 }
7494}
7495
7496// Proxy
7497#[wasm_bindgen]
7498extern "C" {
7499 #[wasm_bindgen(typescript_type = "ProxyConstructor")]
7500 #[derive(Clone, Debug)]
7501 pub type Proxy;
7502
7503 /// The [`Proxy`] object is used to define custom behavior for fundamental
7504 /// operations (e.g. property lookup, assignment, enumeration, function
7505 /// invocation, etc).
7506 ///
7507 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy)
7508 #[wasm_bindgen(constructor)]
7509 pub fn new(target: &JsValue, handler: &Object) -> Proxy;
7510
7511 /// The `Proxy.revocable()` method is used to create a revocable [`Proxy`]
7512 /// object.
7513 ///
7514 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy/revocable)
7515 #[wasm_bindgen(static_method_of = Proxy)]
7516 pub fn revocable(target: &JsValue, handler: &Object) -> Object;
7517}
7518
7519// RangeError
7520#[wasm_bindgen]
7521extern "C" {
7522 /// The `RangeError` object indicates an error when a value is not in the set
7523 /// or range of allowed values.
7524 ///
7525 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError)
7526 #[wasm_bindgen(extends = Error, extends = Object, typescript_type = "RangeError")]
7527 #[derive(Clone, Debug, PartialEq, Eq)]
7528 pub type RangeError;
7529
7530 /// The `RangeError` object indicates an error when a value is not in the set
7531 /// or range of allowed values.
7532 ///
7533 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError)
7534 #[wasm_bindgen(constructor)]
7535 pub fn new(message: &str) -> RangeError;
7536
7537 /// Creates a new `RangeError` with the given message and a typed
7538 /// [`ErrorOptions`] dictionary whose `cause` property indicates the
7539 /// original cause of the error.
7540 ///
7541 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError/RangeError)
7542 #[wasm_bindgen(constructor)]
7543 pub fn new_with_options(message: &str, options: &ErrorOptions) -> RangeError;
7544}
7545
7546// ReferenceError
7547#[wasm_bindgen]
7548extern "C" {
7549 /// The `ReferenceError` object represents an error when a non-existent
7550 /// variable is referenced.
7551 ///
7552 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError)
7553 #[wasm_bindgen(extends = Error, extends = Object, typescript_type = "ReferenceError")]
7554 #[derive(Clone, Debug, PartialEq, Eq)]
7555 pub type ReferenceError;
7556
7557 /// The `ReferenceError` object represents an error when a non-existent
7558 /// variable is referenced.
7559 ///
7560 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError)
7561 #[wasm_bindgen(constructor)]
7562 pub fn new(message: &str) -> ReferenceError;
7563
7564 /// Creates a new `ReferenceError` with the given message and a typed
7565 /// [`ErrorOptions`] dictionary whose `cause` property indicates the
7566 /// original cause of the error.
7567 ///
7568 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError/ReferenceError)
7569 #[wasm_bindgen(constructor)]
7570 pub fn new_with_options(message: &str, options: &ErrorOptions) -> ReferenceError;
7571}
7572
7573#[allow(non_snake_case)]
7574pub mod Reflect {
7575 use super::*;
7576
7577 // Reflect
7578 #[wasm_bindgen]
7579 extern "C" {
7580 /// The static `Reflect.apply()` method calls a target function with
7581 /// arguments as specified.
7582 ///
7583 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/apply)
7584 #[wasm_bindgen(js_namespace = Reflect, catch)]
7585 pub fn apply<T: JsFunction = fn() -> JsValue>(
7586 target: &Function<T>,
7587 this_argument: &JsValue,
7588 arguments_list: &Array,
7589 ) -> Result<<T as JsFunction>::Ret, JsValue>;
7590
7591 /// The static `Reflect.construct()` method acts like the new operator, but
7592 /// as a function. It is equivalent to calling `new target(...args)`. It
7593 /// gives also the added option to specify a different prototype.
7594 ///
7595 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/construct)
7596 #[cfg(not(js_sys_unstable_apis))]
7597 #[wasm_bindgen(js_namespace = Reflect, catch)]
7598 pub fn construct<T: JsFunction = fn() -> JsValue>(
7599 target: &Function<T>,
7600 arguments_list: &Array,
7601 ) -> Result<JsValue, JsValue>;
7602
7603 /// The static `Reflect.construct()` method acts like the new operator, but
7604 /// as a function. It is equivalent to calling `new target(...args)`. It
7605 /// gives also the added option to specify a different prototype.
7606 ///
7607 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/construct)
7608 #[cfg(js_sys_unstable_apis)]
7609 #[wasm_bindgen(js_namespace = Reflect, catch)]
7610 pub fn construct<T: JsFunction = fn() -> JsValue>(
7611 target: &Function<T>,
7612 arguments_list: &ArrayTuple, // DOTO: <A1, A2, A3, A4, A5, A6, A7, A8>,
7613 ) -> Result<JsValue, JsValue>;
7614
7615 /// The static `Reflect.construct()` method acts like the new operator, but
7616 /// as a function. It is equivalent to calling `new target(...args)`. It
7617 /// gives also the added option to specify a different prototype.
7618 ///
7619 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/construct)
7620 #[wasm_bindgen(js_namespace = Reflect, js_name = construct, catch)]
7621 pub fn construct_with_new_target(
7622 target: &Function,
7623 arguments_list: &Array,
7624 new_target: &Function,
7625 ) -> Result<JsValue, JsValue>;
7626
7627 /// The static `Reflect.defineProperty()` method is like
7628 /// `Object.defineProperty()` but returns a `Boolean`.
7629 ///
7630 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/defineProperty)
7631 #[cfg(not(js_sys_unstable_apis))]
7632 #[wasm_bindgen(js_namespace = Reflect, js_name = defineProperty, catch)]
7633 pub fn define_property<T>(
7634 target: &Object<T>,
7635 property_key: &JsValue,
7636 attributes: &Object,
7637 ) -> Result<bool, JsValue>;
7638
7639 /// The static `Reflect.defineProperty()` method is like
7640 /// `Object.defineProperty()` but returns a `Boolean`.
7641 ///
7642 /// The property key may be any JavaScript property-key representation
7643 /// (string, number, or symbol).
7644 ///
7645 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/defineProperty)
7646 #[cfg(js_sys_unstable_apis)]
7647 #[wasm_bindgen(
7648 js_namespace = Reflect,
7649 js_name = defineProperty,
7650 catch,
7651 experimental_generic_mono
7652 )]
7653 pub fn define_property<T, K: PropertyKey>(
7654 target: &Object<T>,
7655 property_key: K,
7656 attributes: &PropertyDescriptor<T>,
7657 ) -> Result<bool, JsValue>;
7658
7659 /// The static `Reflect.defineProperty()` method is like
7660 /// `Object.defineProperty()` but returns a `Boolean`.
7661 ///
7662 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/defineProperty)
7663 #[wasm_bindgen(js_namespace = Reflect, js_name = defineProperty, catch)]
7664 pub fn define_property_str<T>(
7665 target: &Object<T>,
7666 property_key: &JsString,
7667 attributes: &PropertyDescriptor<T>,
7668 ) -> Result<bool, JsValue>;
7669
7670 /// The static `Reflect.deleteProperty()` method allows to delete
7671 /// properties. It is like the `delete` operator as a function.
7672 ///
7673 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/deleteProperty)
7674 #[cfg(not(js_sys_unstable_apis))]
7675 #[wasm_bindgen(js_namespace = Reflect, js_name = deleteProperty, catch)]
7676 pub fn delete_property<T>(target: &Object<T>, key: &JsValue) -> Result<bool, JsValue>;
7677
7678 /// The static `Reflect.deleteProperty()` method allows to delete
7679 /// properties. It is like the `delete` operator as a function.
7680 ///
7681 /// The property key may be any JavaScript property-key representation
7682 /// (string, number, or symbol).
7683 ///
7684 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/deleteProperty)
7685 #[cfg(js_sys_unstable_apis)]
7686 #[wasm_bindgen(
7687 js_namespace = Reflect,
7688 js_name = deleteProperty,
7689 catch,
7690 experimental_generic_mono
7691 )]
7692 pub fn delete_property<T, K: PropertyKey>(
7693 target: &Object<T>,
7694 key: K,
7695 ) -> Result<bool, JsValue>;
7696
7697 /// The static `Reflect.deleteProperty()` method allows to delete
7698 /// properties. It is like the `delete` operator as a function.
7699 ///
7700 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/deleteProperty)
7701 #[wasm_bindgen(js_namespace = Reflect, js_name = deleteProperty, catch)]
7702 pub fn delete_property_str<T>(target: &Object<T>, key: &JsString) -> Result<bool, JsValue>;
7703
7704 /// The static `Reflect.get()` method works like getting a property from
7705 /// an object (`target[propertyKey]`) as a function.
7706 ///
7707 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/get)
7708 #[cfg(not(js_sys_unstable_apis))]
7709 #[wasm_bindgen(js_namespace = Reflect, catch)]
7710 pub fn get(target: &JsValue, key: &JsValue) -> Result<JsValue, JsValue>;
7711
7712 /// The static `Reflect.get()` method works like getting a property from
7713 /// an object (`target[propertyKey]`) as a function.
7714 ///
7715 /// The property key may be any JavaScript property-key representation
7716 /// (string, number, or symbol).
7717 ///
7718 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/get)
7719 #[cfg(js_sys_unstable_apis)]
7720 #[wasm_bindgen(js_namespace = Reflect, catch, experimental_generic_mono)]
7721 pub fn get<T, K: PropertyKey>(target: &Object<T>, key: K) -> Result<Option<T>, JsValue>;
7722
7723 /// The static `Reflect.get()` method works like getting a property from
7724 /// an object (`target[propertyKey]`) as a function.
7725 ///
7726 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/get)
7727 #[wasm_bindgen(js_namespace = Reflect, js_name = get, catch)]
7728 pub fn get_str<T>(target: &Object<T>, key: &JsString) -> Result<Option<T>, JsValue>;
7729
7730 /// The static `Reflect.get()` method works like getting a property from
7731 /// an object (`target[propertyKey]`) as a function.
7732 ///
7733 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/get)
7734 #[wasm_bindgen(js_namespace = Reflect, js_name = get, catch)]
7735 pub fn get_symbol<T>(target: &Object<T>, key: &Symbol) -> Result<JsValue, JsValue>;
7736
7737 /// The same as [`get`](fn.get.html)
7738 /// except the key is an `f64`, which is slightly faster.
7739 #[wasm_bindgen(js_namespace = Reflect, js_name = get, catch)]
7740 pub fn get_f64(target: &JsValue, key: f64) -> Result<JsValue, JsValue>;
7741
7742 /// The same as [`get`](fn.get.html)
7743 /// except the key is a `u32`, which is slightly faster.
7744 #[wasm_bindgen(js_namespace = Reflect, js_name = get, catch)]
7745 pub fn get_u32(target: &JsValue, key: u32) -> Result<JsValue, JsValue>;
7746
7747 /// The static `Reflect.getOwnPropertyDescriptor()` method is similar to
7748 /// `Object.getOwnPropertyDescriptor()`. It returns a property descriptor
7749 /// of the given property if it exists on the object, `undefined` otherwise.
7750 ///
7751 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getOwnPropertyDescriptor)
7752 #[cfg(not(js_sys_unstable_apis))]
7753 #[wasm_bindgen(js_namespace = Reflect, js_name = getOwnPropertyDescriptor, catch)]
7754 pub fn get_own_property_descriptor<T>(
7755 target: &Object<T>,
7756 property_key: &JsValue,
7757 ) -> Result<JsValue, JsValue>;
7758
7759 /// The static `Reflect.getOwnPropertyDescriptor()` method is similar to
7760 /// `Object.getOwnPropertyDescriptor()`. It returns a property descriptor
7761 /// of the given property if it exists on the object, `undefined` otherwise.
7762 ///
7763 /// The property key may be any JavaScript property-key representation
7764 /// (string, number, or symbol).
7765 ///
7766 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getOwnPropertyDescriptor)
7767 #[cfg(js_sys_unstable_apis)]
7768 #[wasm_bindgen(
7769 js_namespace = Reflect,
7770 js_name = getOwnPropertyDescriptor,
7771 catch,
7772 experimental_generic_mono
7773 )]
7774 pub fn get_own_property_descriptor<T, K: PropertyKey>(
7775 target: &Object<T>,
7776 property_key: K,
7777 ) -> Result<Option<PropertyDescriptor<T>>, JsValue>;
7778
7779 /// The static `Reflect.getOwnPropertyDescriptor()` method is similar to
7780 /// `Object.getOwnPropertyDescriptor()`. It returns a property descriptor
7781 /// of the given property if it exists on the object, `undefined` otherwise.
7782 ///
7783 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getOwnPropertyDescriptor)
7784 #[wasm_bindgen(js_namespace = Reflect, js_name = getOwnPropertyDescriptor, catch)]
7785 pub fn get_own_property_descriptor_str<T>(
7786 target: &Object<T>,
7787 property_key: &JsString,
7788 ) -> Result<PropertyDescriptor<T>, JsValue>;
7789
7790 /// The static `Reflect.getPrototypeOf()` method is almost the same
7791 /// method as `Object.getPrototypeOf()`. It returns the prototype
7792 /// (i.e. the value of the internal `[[Prototype]]` property) of
7793 /// the specified object.
7794 ///
7795 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getPrototypeOf)
7796 #[cfg(not(js_sys_unstable_apis))]
7797 #[wasm_bindgen(js_namespace = Reflect, js_name = getPrototypeOf, catch)]
7798 pub fn get_prototype_of(target: &JsValue) -> Result<Object, JsValue>;
7799
7800 /// The static `Reflect.getPrototypeOf()` method is almost the same
7801 /// method as `Object.getPrototypeOf()`. It returns the prototype
7802 /// (i.e. the value of the internal `[[Prototype]]` property) of
7803 /// the specified object.
7804 ///
7805 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getPrototypeOf)
7806 #[cfg(js_sys_unstable_apis)]
7807 #[wasm_bindgen(js_namespace = Reflect, js_name = getPrototypeOf, catch)]
7808 pub fn get_prototype_of(target: &Object) -> Result<Object, JsValue>;
7809
7810 /// The static `Reflect.has()` method works like the in operator as a
7811 /// function.
7812 ///
7813 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/has)
7814 #[cfg(not(js_sys_unstable_apis))]
7815 #[wasm_bindgen(js_namespace = Reflect, catch)]
7816 pub fn has(target: &JsValue, property_key: &JsValue) -> Result<bool, JsValue>;
7817
7818 /// The static `Reflect.has()` method works like the in operator as a
7819 /// function.
7820 ///
7821 /// The property key may be any JavaScript property-key representation
7822 /// (string, number, or symbol).
7823 ///
7824 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/has)
7825 #[cfg(js_sys_unstable_apis)]
7826 #[wasm_bindgen(js_namespace = Reflect, catch, experimental_generic_mono)]
7827 pub fn has<T, K: PropertyKey>(target: &Object<T>, property_key: K)
7828 -> Result<bool, JsValue>;
7829
7830 // Next major: deprecate
7831 /// The static `Reflect.has()` method works like the in operator as a
7832 /// function.
7833 ///
7834 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/has)
7835 #[wasm_bindgen(js_namespace = Reflect, js_name = has, catch)]
7836 pub fn has_str<T>(target: &Object<T>, property_key: &JsString) -> Result<bool, JsValue>;
7837
7838 /// The static `Reflect.has()` method works like the in operator as a
7839 /// function.
7840 ///
7841 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/has)
7842 #[wasm_bindgen(js_namespace = Reflect, js_name = has, catch)]
7843 pub fn has_symbol<T>(target: &Object<T>, property_key: &Symbol) -> Result<bool, JsValue>;
7844
7845 /// The static `Reflect.isExtensible()` method determines if an object is
7846 /// extensible (whether it can have new properties added to it). It is
7847 /// similar to `Object.isExtensible()`, but with some differences.
7848 ///
7849 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/isExtensible)
7850 #[wasm_bindgen(js_namespace = Reflect, js_name = isExtensible, catch)]
7851 pub fn is_extensible<T>(target: &Object<T>) -> Result<bool, JsValue>;
7852
7853 /// The static `Reflect.ownKeys()` method returns an array of the
7854 /// target object's own property keys.
7855 ///
7856 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/ownKeys)
7857 #[wasm_bindgen(js_namespace = Reflect, js_name = ownKeys, catch)]
7858 pub fn own_keys(target: &JsValue) -> Result<Array, JsValue>;
7859
7860 /// The static `Reflect.preventExtensions()` method prevents new
7861 /// properties from ever being added to an object (i.e. prevents
7862 /// future extensions to the object). It is similar to
7863 /// `Object.preventExtensions()`, but with some differences.
7864 ///
7865 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/preventExtensions)
7866 #[wasm_bindgen(js_namespace = Reflect, js_name = preventExtensions, catch)]
7867 pub fn prevent_extensions<T>(target: &Object<T>) -> Result<bool, JsValue>;
7868
7869 /// The static `Reflect.set()` method works like setting a
7870 /// property on an object.
7871 ///
7872 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
7873 #[cfg(not(js_sys_unstable_apis))]
7874 #[wasm_bindgen(js_namespace = Reflect, catch)]
7875 pub fn set(
7876 target: &JsValue,
7877 property_key: &JsValue,
7878 value: &JsValue,
7879 ) -> Result<bool, JsValue>;
7880
7881 /// The static `Reflect.set()` method works like setting a
7882 /// property on an object.
7883 ///
7884 /// The property key may be any JavaScript property-key representation
7885 /// (string, number, or symbol).
7886 ///
7887 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
7888 #[cfg(js_sys_unstable_apis)]
7889 #[wasm_bindgen(js_namespace = Reflect, catch, experimental_generic_mono)]
7890 pub fn set<T, K: PropertyKey>(
7891 target: &Object<T>,
7892 property_key: K,
7893 value: &T,
7894 ) -> Result<bool, JsValue>;
7895
7896 /// The static `Reflect.set()` method works like setting a
7897 /// property on an object.
7898 ///
7899 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
7900 #[cfg(js_sys_unstable_apis)]
7901 #[wasm_bindgen(js_namespace = Reflect, catch)]
7902 pub fn set_symbol<T>(
7903 target: &Object<T>,
7904 property_key: &Symbol,
7905 value: &JsValue,
7906 ) -> Result<bool, JsValue>;
7907
7908 // Next major: deprecate
7909 /// The static `Reflect.set()` method works like setting a
7910 /// property on an object.
7911 ///
7912 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
7913 #[wasm_bindgen(js_namespace = Reflect, js_name = set, catch)]
7914 pub fn set_str<T>(
7915 target: &Object<T>,
7916 property_key: &JsString,
7917 value: &T,
7918 ) -> Result<bool, JsValue>;
7919
7920 /// The same as [`set`](fn.set.html)
7921 /// except the key is an `f64`, which is slightly faster.
7922 #[wasm_bindgen(js_namespace = Reflect, js_name = set, catch)]
7923 pub fn set_f64(
7924 target: &JsValue,
7925 property_key: f64,
7926 value: &JsValue,
7927 ) -> Result<bool, JsValue>;
7928
7929 /// The same as [`set`](fn.set.html)
7930 /// except the key is a `u32`, which is slightly faster.
7931 #[wasm_bindgen(js_namespace = Reflect, js_name = set, catch)]
7932 pub fn set_u32(
7933 target: &JsValue,
7934 property_key: u32,
7935 value: &JsValue,
7936 ) -> Result<bool, JsValue>;
7937
7938 /// The static `Reflect.set()` method works like setting a
7939 /// property on an object.
7940 ///
7941 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
7942 #[wasm_bindgen(js_namespace = Reflect, js_name = set, catch)]
7943 pub fn set_with_receiver(
7944 target: &JsValue,
7945 property_key: &JsValue,
7946 value: &JsValue,
7947 receiver: &JsValue,
7948 ) -> Result<bool, JsValue>;
7949
7950 /// The static `Reflect.setPrototypeOf()` method is the same
7951 /// method as `Object.setPrototypeOf()`. It sets the prototype
7952 /// (i.e., the internal `[[Prototype]]` property) of a specified
7953 /// object to another object or to null.
7954 ///
7955 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/setPrototypeOf)
7956 #[wasm_bindgen(js_namespace = Reflect, js_name = setPrototypeOf, catch)]
7957 pub fn set_prototype_of<T>(
7958 target: &Object<T>,
7959 prototype: &JsValue,
7960 ) -> Result<bool, JsValue>;
7961 }
7962}
7963
7964// RegExp
7965#[wasm_bindgen]
7966extern "C" {
7967 #[wasm_bindgen(extends = Object, typescript_type = "RegExp")]
7968 #[derive(Clone, Debug, PartialEq, Eq)]
7969 pub type RegExp;
7970
7971 /// The `exec()` method executes a search for a match in a specified
7972 /// string. Returns a result array, or null.
7973 ///
7974 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec)
7975 #[cfg(not(js_sys_unstable_apis))]
7976 #[wasm_bindgen(method)]
7977 pub fn exec(this: &RegExp, text: &str) -> Option<Array<JsString>>;
7978
7979 /// The `exec()` method executes a search for a match in a specified
7980 /// string. Returns a result array, or null.
7981 ///
7982 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec)
7983 #[cfg(js_sys_unstable_apis)]
7984 #[wasm_bindgen(method)]
7985 pub fn exec(this: &RegExp, text: &str) -> Option<RegExpMatchArray>;
7986
7987 /// The flags property returns a string consisting of the flags of
7988 /// the current regular expression object.
7989 ///
7990 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/flags)
7991 #[wasm_bindgen(method, getter)]
7992 pub fn flags(this: &RegExp) -> JsString;
7993
7994 /// The global property indicates whether or not the "g" flag is
7995 /// used with the regular expression. global is a read-only
7996 /// property of an individual regular expression instance.
7997 ///
7998 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/global)
7999 #[wasm_bindgen(method, getter)]
8000 pub fn global(this: &RegExp) -> bool;
8001
8002 /// The ignoreCase property indicates whether or not the "i" flag
8003 /// is used with the regular expression. ignoreCase is a read-only
8004 /// property of an individual regular expression instance.
8005 ///
8006 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/ignoreCase)
8007 #[wasm_bindgen(method, getter, js_name = ignoreCase)]
8008 pub fn ignore_case(this: &RegExp) -> bool;
8009
8010 /// The non-standard input property is a static property of
8011 /// regular expressions that contains the string against which a
8012 /// regular expression is matched. RegExp.$_ is an alias for this
8013 /// property.
8014 ///
8015 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/input)
8016 #[wasm_bindgen(static_method_of = RegExp, getter)]
8017 pub fn input() -> JsString;
8018
8019 /// The lastIndex is a read/write integer property of regular expression
8020 /// instances that specifies the index at which to start the next match.
8021 ///
8022 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex)
8023 #[wasm_bindgen(structural, getter = lastIndex, method)]
8024 pub fn last_index(this: &RegExp) -> u32;
8025
8026 /// The lastIndex is a read/write integer property of regular expression
8027 /// instances that specifies the index at which to start the next match.
8028 ///
8029 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex)
8030 #[wasm_bindgen(structural, setter = lastIndex, method)]
8031 pub fn set_last_index(this: &RegExp, index: u32);
8032
8033 /// The non-standard lastMatch property is a static and read-only
8034 /// property of regular expressions that contains the last matched
8035 /// characters. `RegExp.$&` is an alias for this property.
8036 ///
8037 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastMatch)
8038 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = lastMatch)]
8039 pub fn last_match() -> JsString;
8040
8041 /// The non-standard lastParen property is a static and read-only
8042 /// property of regular expressions that contains the last
8043 /// parenthesized substring match, if any. `RegExp.$+` is an alias
8044 /// for this property.
8045 ///
8046 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastParen)
8047 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = lastParen)]
8048 pub fn last_paren() -> JsString;
8049
8050 /// The non-standard leftContext property is a static and
8051 /// read-only property of regular expressions that contains the
8052 /// substring preceding the most recent match. `RegExp.$`` is an
8053 /// alias for this property.
8054 ///
8055 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/leftContext)
8056 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = leftContext)]
8057 pub fn left_context() -> JsString;
8058
8059 /// The multiline property indicates whether or not the "m" flag
8060 /// is used with the regular expression. multiline is a read-only
8061 /// property of an individual regular expression instance.
8062 ///
8063 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/multiline)
8064 #[wasm_bindgen(method, getter)]
8065 pub fn multiline(this: &RegExp) -> bool;
8066
8067 /// The non-standard $1, $2, $3, $4, $5, $6, $7, $8, $9 properties
8068 /// are static and read-only properties of regular expressions
8069 /// that contain parenthesized substring matches.
8070 ///
8071 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/n)
8072 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$1")]
8073 pub fn n1() -> JsString;
8074 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$2")]
8075 pub fn n2() -> JsString;
8076 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$3")]
8077 pub fn n3() -> JsString;
8078 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$4")]
8079 pub fn n4() -> JsString;
8080 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$5")]
8081 pub fn n5() -> JsString;
8082 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$6")]
8083 pub fn n6() -> JsString;
8084 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$7")]
8085 pub fn n7() -> JsString;
8086 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$8")]
8087 pub fn n8() -> JsString;
8088 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$9")]
8089 pub fn n9() -> JsString;
8090
8091 /// The `RegExp` constructor creates a regular expression object for matching text with a pattern.
8092 ///
8093 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp)
8094 #[wasm_bindgen(constructor)]
8095 pub fn new(pattern: &str, flags: &str) -> RegExp;
8096 #[wasm_bindgen(constructor)]
8097 pub fn new_regexp(pattern: &RegExp, flags: &str) -> RegExp;
8098
8099 /// The non-standard rightContext property is a static and
8100 /// read-only property of regular expressions that contains the
8101 /// substring following the most recent match. `RegExp.$'` is an
8102 /// alias for this property.
8103 ///
8104 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/rightContext)
8105 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = rightContext)]
8106 pub fn right_context() -> JsString;
8107
8108 /// The source property returns a String containing the source
8109 /// text of the regexp object, and it doesn't contain the two
8110 /// forward slashes on both sides and any flags.
8111 ///
8112 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/source)
8113 #[wasm_bindgen(method, getter)]
8114 pub fn source(this: &RegExp) -> JsString;
8115
8116 /// The sticky property reflects whether or not the search is
8117 /// sticky (searches in strings only from the index indicated by
8118 /// the lastIndex property of this regular expression). sticky is
8119 /// a read-only property of an individual regular expression
8120 /// object.
8121 ///
8122 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/sticky)
8123 #[wasm_bindgen(method, getter)]
8124 pub fn sticky(this: &RegExp) -> bool;
8125
8126 /// The `test()` method executes a search for a match between a
8127 /// regular expression and a specified string. Returns true or
8128 /// false.
8129 ///
8130 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/test)
8131 #[wasm_bindgen(method)]
8132 pub fn test(this: &RegExp, text: &str) -> bool;
8133
8134 /// The `toString()` method returns a string representing the
8135 /// regular expression.
8136 ///
8137 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/toString)
8138 #[cfg(not(js_sys_unstable_apis))]
8139 #[wasm_bindgen(method, js_name = toString)]
8140 pub fn to_string(this: &RegExp) -> JsString;
8141
8142 /// The unicode property indicates whether or not the "u" flag is
8143 /// used with a regular expression. unicode is a read-only
8144 /// property of an individual regular expression instance.
8145 ///
8146 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/unicode)
8147 #[wasm_bindgen(method, getter)]
8148 pub fn unicode(this: &RegExp) -> bool;
8149}
8150
8151// RegExpMatchArray
8152#[wasm_bindgen]
8153extern "C" {
8154 /// The result array from `RegExp.exec()` or `String.matchAll()`.
8155 ///
8156 /// This is an array of strings with additional properties `index`, `input`, and `groups`.
8157 ///
8158 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec#return_value)
8159 #[wasm_bindgen(extends = Object, extends = Array, typescript_type = "RegExpMatchArray")]
8160 #[derive(Clone, Debug, PartialEq, Eq)]
8161 pub type RegExpMatchArray;
8162
8163 /// The 0-based index of the match in the string.
8164 #[wasm_bindgen(method, getter)]
8165 pub fn index(this: &RegExpMatchArray) -> u32;
8166
8167 /// The original string that was matched against.
8168 #[wasm_bindgen(method, getter)]
8169 pub fn input(this: &RegExpMatchArray) -> JsString;
8170
8171 /// An object of named capturing groups whose keys are the names and valuestype Array
8172 /// are the capturing groups, or `undefined` if no named capturing groups were defined.
8173 #[wasm_bindgen(method, getter)]
8174 pub fn groups(this: &RegExpMatchArray) -> Option<Object>;
8175
8176 /// The number of elements in the match array (full match + capture groups).
8177 #[wasm_bindgen(method, getter)]
8178 pub fn length(this: &RegExpMatchArray) -> u32;
8179
8180 /// Gets the matched string or capture group at the given index.
8181 /// Index 0 is the full match, indices 1+ are capture groups.
8182 #[wasm_bindgen(method, indexing_getter)]
8183 pub fn get(this: &RegExpMatchArray, index: u32) -> Option<JsString>;
8184}
8185
8186// Set
8187#[wasm_bindgen]
8188extern "C" {
8189 #[wasm_bindgen(extends = Object, typescript_type = "Set<any>")]
8190 #[derive(Clone, Debug, PartialEq, Eq)]
8191 pub type Set<T = JsValue>;
8192
8193 /// The [`Set`] object lets you store unique values of any type, whether
8194 /// primitive values or object references.
8195 ///
8196 /// **Note:** Consider using [`Set::new_typed`] to support typing.
8197 ///
8198 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
8199 #[cfg(not(js_sys_unstable_apis))]
8200 #[wasm_bindgen(constructor)]
8201 pub fn new(init: &JsValue) -> Set;
8202
8203 /// The [`Set`] object lets you store unique values of any type, whether
8204 /// primitive values or object references.
8205 ///
8206 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
8207 #[cfg(js_sys_unstable_apis)]
8208 #[wasm_bindgen(constructor)]
8209 pub fn new<T>() -> Set<T>;
8210
8211 // Next major: deprecate
8212 /// The [`Set`] object lets you store unique values of any type, whether
8213 /// primitive values or object references.
8214 ///
8215 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
8216 #[wasm_bindgen(constructor)]
8217 pub fn new_typed<T>() -> Set<T>;
8218
8219 /// The [`Set`] object lets you store unique values of any type, whether
8220 /// primitive values or object references.
8221 ///
8222 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
8223 #[wasm_bindgen(constructor, js_name = new)]
8224 pub fn new_empty<T>() -> Set<T>;
8225
8226 /// The [`Set`] object lets you store unique values of any type, whether
8227 /// primitive values or object references.
8228 ///
8229 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
8230 #[wasm_bindgen(constructor, js_name = new)]
8231 pub fn new_from_items<T>(items: &[T]) -> Set<T>;
8232
8233 /// The [`Set`] object lets you store unique values of any type, whether
8234 /// primitive values or object references.
8235 ///
8236 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
8237 #[wasm_bindgen(constructor, js_name = new, catch)]
8238 pub fn new_from_iterable<T, I: Iterable<Item = T>>(iterable: I) -> Result<Set<T>, JsValue>;
8239
8240 /// The `add()` method appends a new element with a specified value to the
8241 /// end of a [`Set`] object.
8242 ///
8243 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/add)
8244 #[wasm_bindgen(method)]
8245 pub fn add<T>(this: &Set<T>, value: &T) -> Set<T>;
8246
8247 /// The `clear()` method removes all elements from a [`Set`] object.
8248 ///
8249 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/clear)
8250 #[wasm_bindgen(method)]
8251 pub fn clear<T>(this: &Set<T>);
8252
8253 /// The `delete()` method removes the specified element from a [`Set`]
8254 /// object.
8255 ///
8256 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/delete)
8257 #[wasm_bindgen(method)]
8258 pub fn delete<T>(this: &Set<T>, value: &T) -> bool;
8259
8260 /// The `forEach()` method executes a provided function once for each value
8261 /// in the Set object, in insertion order.
8262 ///
8263 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/forEach)
8264 #[cfg(not(js_sys_unstable_apis))]
8265 #[wasm_bindgen(method, js_name = forEach)]
8266 pub fn for_each<T>(this: &Set<T>, callback: &mut dyn FnMut(T, T, Set<T>));
8267
8268 /// The `forEach()` method executes a provided function once for each value
8269 /// in the Set object, in insertion order.
8270 ///
8271 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/forEach)
8272 #[cfg(js_sys_unstable_apis)]
8273 #[wasm_bindgen(method, js_name = forEach)]
8274 pub fn for_each<T>(this: &Set<T>, callback: &mut dyn FnMut(T));
8275
8276 /// The `forEach()` method executes a provided function once for each value
8277 /// in the Set object, in insertion order.
8278 ///
8279 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/forEach)
8280 #[wasm_bindgen(method, js_name = forEach, catch)]
8281 pub fn try_for_each<T>(
8282 this: &Set<T>,
8283 callback: &mut dyn FnMut(T) -> Result<(), JsError>,
8284 ) -> Result<(), JsValue>;
8285
8286 /// The `has()` method returns a boolean indicating whether an element with
8287 /// the specified value exists in a [`Set`] object or not.
8288 ///
8289 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/has)
8290 #[wasm_bindgen(method)]
8291 pub fn has<T>(this: &Set<T>, value: &T) -> bool;
8292
8293 /// The size accessor property returns the number of elements in a [`Set`]
8294 /// object.
8295 ///
8296 /// [MDN documentation](https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Set/size)
8297 #[wasm_bindgen(method, getter)]
8298 pub fn size<T>(this: &Set<T>) -> u32;
8299
8300 /// The `union()` method returns a new set containing elements which are in
8301 /// either or both of this set and the given set.
8302 ///
8303 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/union)
8304 #[wasm_bindgen(method)]
8305 pub fn union<T>(this: &Set<T>, other: &Set<T>) -> Set<T>;
8306
8307 /// The `intersection()` method returns a new set containing elements which are
8308 /// in both this set and the given set.
8309 ///
8310 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/intersection)
8311 #[wasm_bindgen(method)]
8312 pub fn intersection<T>(this: &Set<T>, other: &Set<T>) -> Set<T>;
8313
8314 /// The `difference()` method returns a new set containing elements which are
8315 /// in this set but not in the given set.
8316 ///
8317 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/difference)
8318 #[wasm_bindgen(method)]
8319 pub fn difference<T>(this: &Set<T>, other: &Set<T>) -> Set<T>;
8320
8321 /// The `symmetricDifference()` method returns a new set containing elements
8322 /// which are in either this set or the given set, but not in both.
8323 ///
8324 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/symmetricDifference)
8325 #[wasm_bindgen(method, js_name = symmetricDifference)]
8326 pub fn symmetric_difference<T>(this: &Set<T>, other: &Set<T>) -> Set<T>;
8327
8328 /// The `isSubsetOf()` method returns a boolean indicating whether all elements
8329 /// of this set are in the given set.
8330 ///
8331 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/isSubsetOf)
8332 #[wasm_bindgen(method, js_name = isSubsetOf)]
8333 pub fn is_subset_of<T>(this: &Set<T>, other: &Set<T>) -> bool;
8334
8335 /// The `isSupersetOf()` method returns a boolean indicating whether all elements
8336 /// of the given set are in this set.
8337 ///
8338 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/isSupersetOf)
8339 #[wasm_bindgen(method, js_name = isSupersetOf)]
8340 pub fn is_superset_of<T>(this: &Set<T>, other: &Set<T>) -> bool;
8341
8342 /// The `isDisjointFrom()` method returns a boolean indicating whether this set
8343 /// has no elements in common with the given set.
8344 ///
8345 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/isDisjointFrom)
8346 #[wasm_bindgen(method, js_name = isDisjointFrom)]
8347 pub fn is_disjoint_from<T>(this: &Set<T>, other: &Set<T>) -> bool;
8348}
8349
8350impl Default for Set<JsValue> {
8351 fn default() -> Self {
8352 Self::new_typed()
8353 }
8354}
8355
8356impl<T> Iterable for Set<T> {
8357 type Item = T;
8358}
8359
8360// SetIterator
8361#[wasm_bindgen]
8362extern "C" {
8363 /// The `entries()` method returns a new Iterator object that contains an
8364 /// array of [value, value] for each element in the Set object, in insertion
8365 /// order. For Set objects there is no key like in Map objects. However, to
8366 /// keep the API similar to the Map object, each entry has the same value
8367 /// for its key and value here, so that an array [value, value] is returned.
8368 ///
8369 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/entries)
8370 #[cfg(not(js_sys_unstable_apis))]
8371 #[wasm_bindgen(method)]
8372 pub fn entries<T>(set: &Set<T>) -> Iterator;
8373
8374 /// The `entries()` method returns a new Iterator object that contains an
8375 /// array of [value, value] for each element in the Set object, in insertion
8376 /// order. For Set objects there is no key like in Map objects. However, to
8377 /// keep the API similar to the Map object, each entry has the same value
8378 /// for its key and value here, so that an array [value, value] is returned.
8379 ///
8380 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/entries)
8381 #[cfg(js_sys_unstable_apis)]
8382 #[wasm_bindgen(method, js_name = entries)]
8383 pub fn entries<T: JsGeneric>(set: &Set<T>) -> Iterator<ArrayTuple<(T, T)>>;
8384
8385 // Next major: deprecate
8386 /// The `entries()` method returns a new Iterator object that contains an
8387 /// array of [value, value] for each element in the Set object, in insertion
8388 /// order. For Set objects there is no key like in Map objects. However, to
8389 /// keep the API similar to the Map object, each entry has the same value
8390 /// for its key and value here, so that an array [value, value] is returned.
8391 ///
8392 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/entries)
8393 #[wasm_bindgen(method, js_name = entries)]
8394 pub fn entries_typed<T: JsGeneric>(set: &Set<T>) -> Iterator<ArrayTuple<(T, T)>>;
8395
8396 /// The `keys()` method is an alias for this method (for similarity with
8397 /// Map objects); it behaves exactly the same and returns values
8398 /// of Set elements.
8399 ///
8400 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/values)
8401 #[wasm_bindgen(method)]
8402 pub fn keys<T>(set: &Set<T>) -> Iterator<T>;
8403
8404 /// The `values()` method returns a new Iterator object that contains the
8405 /// values for each element in the Set object in insertion order.
8406 ///
8407 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/values)
8408 #[wasm_bindgen(method)]
8409 pub fn values<T>(set: &Set<T>) -> Iterator<T>;
8410}
8411
8412// SyntaxError
8413#[wasm_bindgen]
8414extern "C" {
8415 /// A `SyntaxError` is thrown when the JavaScript engine encounters tokens or
8416 /// token order that does not conform to the syntax of the language when
8417 /// parsing code.
8418 ///
8419 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError)
8420 #[wasm_bindgen(extends = Error, extends = Object, typescript_type = "SyntaxError")]
8421 #[derive(Clone, Debug, PartialEq, Eq)]
8422 pub type SyntaxError;
8423
8424 /// A `SyntaxError` is thrown when the JavaScript engine encounters tokens or
8425 /// token order that does not conform to the syntax of the language when
8426 /// parsing code.
8427 ///
8428 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError)
8429 #[wasm_bindgen(constructor)]
8430 pub fn new(message: &str) -> SyntaxError;
8431
8432 /// Creates a new `SyntaxError` with the given message and a typed
8433 /// [`ErrorOptions`] dictionary whose `cause` property indicates the
8434 /// original cause of the error.
8435 ///
8436 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError/SyntaxError)
8437 #[wasm_bindgen(constructor)]
8438 pub fn new_with_options(message: &str, options: &ErrorOptions) -> SyntaxError;
8439}
8440
8441// TypeError
8442#[wasm_bindgen]
8443extern "C" {
8444 /// The `TypeError` object represents an error when a value is not of the
8445 /// expected type.
8446 ///
8447 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError)
8448 #[wasm_bindgen(extends = Error, extends = Object, typescript_type = "TypeError")]
8449 #[derive(Clone, Debug, PartialEq, Eq)]
8450 pub type TypeError;
8451
8452 /// The `TypeError` object represents an error when a value is not of the
8453 /// expected type.
8454 ///
8455 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError)
8456 #[wasm_bindgen(constructor)]
8457 pub fn new(message: &str) -> TypeError;
8458
8459 /// Creates a new `TypeError` with the given message and a typed
8460 /// [`ErrorOptions`] dictionary whose `cause` property indicates the
8461 /// original cause of the error.
8462 ///
8463 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError/TypeError)
8464 #[wasm_bindgen(constructor)]
8465 pub fn new_with_options(message: &str, options: &ErrorOptions) -> TypeError;
8466}
8467
8468// URIError
8469#[wasm_bindgen]
8470extern "C" {
8471 /// The `URIError` object represents an error when a global URI handling
8472 /// function was used in a wrong way.
8473 ///
8474 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError)
8475 #[wasm_bindgen(extends = Error, extends = Object, js_name = URIError, typescript_type = "URIError")]
8476 #[derive(Clone, Debug, PartialEq, Eq)]
8477 pub type UriError;
8478
8479 /// The `URIError` object represents an error when a global URI handling
8480 /// function was used in a wrong way.
8481 ///
8482 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError)
8483 #[wasm_bindgen(constructor, js_class = "URIError")]
8484 pub fn new(message: &str) -> UriError;
8485
8486 /// Creates a new `URIError` with the given message and a typed
8487 /// [`ErrorOptions`] dictionary whose `cause` property indicates the
8488 /// original cause of the error.
8489 ///
8490 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError/URIError)
8491 #[wasm_bindgen(constructor, js_class = "URIError")]
8492 pub fn new_with_options(message: &str, options: &ErrorOptions) -> UriError;
8493}
8494
8495// WeakMap
8496#[wasm_bindgen]
8497extern "C" {
8498 #[wasm_bindgen(extends = Object, typescript_type = "WeakMap<object, any>")]
8499 #[derive(Clone, Debug, PartialEq, Eq)]
8500 pub type WeakMap<K = Object, V = JsValue>;
8501
8502 /// The [`WeakMap`] object is a collection of key/value pairs in which the
8503 /// keys are weakly referenced. The keys must be objects and the values can
8504 /// be arbitrary values.
8505 ///
8506 /// **Note:** Consider using [`WeakMap::new_typed`] to support typing.
8507 ///
8508 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap)
8509 #[cfg(not(js_sys_unstable_apis))]
8510 #[wasm_bindgen(constructor)]
8511 pub fn new() -> WeakMap;
8512
8513 /// The [`WeakMap`] object is a collection of key/value pairs in which the
8514 /// keys are weakly referenced. The keys must be objects and the values can
8515 /// be arbitrary values.
8516 ///
8517 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap)
8518 #[cfg(js_sys_unstable_apis)]
8519 #[wasm_bindgen(constructor)]
8520 pub fn new<K: JsGeneric = Object, V: JsGeneric = Object>() -> WeakMap<K, V>;
8521
8522 // Next major: deprecate
8523 /// The [`WeakMap`] object is a collection of key/value pairs in which the
8524 /// keys are weakly referenced. The keys must be objects and the values can
8525 /// be arbitrary values.
8526 ///
8527 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap)
8528 #[wasm_bindgen(constructor)]
8529 pub fn new_typed<K: JsGeneric = Object, V: JsGeneric = Object>() -> WeakMap<K, V>;
8530
8531 /// The `set()` method sets the value for the key in the [`WeakMap`] object.
8532 /// Returns the [`WeakMap`] object.
8533 ///
8534 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/set)
8535 #[wasm_bindgen(method, js_class = "WeakMap")]
8536 pub fn set<K, V>(this: &WeakMap<K, V>, key: &K, value: &V) -> WeakMap<K, V>;
8537
8538 /// The `get()` method returns a specified by key element
8539 /// from a [`WeakMap`] object. Returns `undefined` if the key is not found.
8540 ///
8541 /// **Note:** Consider using [`WeakMap::get_checked`] to get an `Option<V>` instead.
8542 ///
8543 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/get)
8544 #[cfg(not(js_sys_unstable_apis))]
8545 #[wasm_bindgen(method)]
8546 pub fn get<K, V>(this: &WeakMap<K, V>, key: &K) -> V;
8547
8548 /// The `get()` method returns a specified by key element
8549 /// from a [`WeakMap`] object. Returns `None` if the key is not found.
8550 ///
8551 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/get)
8552 #[cfg(js_sys_unstable_apis)]
8553 #[wasm_bindgen(method)]
8554 pub fn get<K, V>(this: &WeakMap<K, V>, key: &K) -> Option<V>;
8555
8556 /// The `get()` method returns a specified by key element
8557 /// from a [`WeakMap`] object. Returns `None` if the key is not found.
8558 ///
8559 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/get)
8560 #[wasm_bindgen(method, js_name = get)]
8561 pub fn get_checked<K, V>(this: &WeakMap<K, V>, key: &K) -> Option<V>;
8562
8563 /// The `has()` method returns a boolean indicating whether an element with
8564 /// the specified key exists in the [`WeakMap`] object or not.
8565 ///
8566 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/has)
8567 #[wasm_bindgen(method)]
8568 pub fn has<K, V>(this: &WeakMap<K, V>, key: &K) -> bool;
8569
8570 /// The `delete()` method removes the specified element from a [`WeakMap`]
8571 /// object.
8572 ///
8573 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/delete)
8574 #[wasm_bindgen(method)]
8575 pub fn delete<K, V>(this: &WeakMap<K, V>, key: &K) -> bool;
8576}
8577
8578impl Default for WeakMap {
8579 fn default() -> Self {
8580 Self::new()
8581 }
8582}
8583
8584// WeakSet
8585#[wasm_bindgen]
8586extern "C" {
8587 #[wasm_bindgen(extends = Object, typescript_type = "WeakSet<object>")]
8588 #[derive(Clone, Debug, PartialEq, Eq)]
8589 pub type WeakSet<T = Object>;
8590
8591 /// The `WeakSet` object lets you store weakly held objects in a collection.
8592 ///
8593 /// **Note:** Consider using [`WeakSet::new_typed`] for typed sets.
8594 ///
8595 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet)
8596 #[cfg(not(js_sys_unstable_apis))]
8597 #[wasm_bindgen(constructor)]
8598 pub fn new() -> WeakSet;
8599
8600 /// The `WeakSet` object lets you store weakly held objects in a collection.
8601 ///
8602 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet)
8603 #[cfg(js_sys_unstable_apis)]
8604 #[wasm_bindgen(constructor)]
8605 pub fn new<T = Object>() -> WeakSet<T>;
8606
8607 // Next major: deprecate
8608 /// The `WeakSet` object lets you store weakly held objects in a collection.
8609 ///
8610 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet)
8611 #[wasm_bindgen(constructor)]
8612 pub fn new_typed<T = Object>() -> WeakSet<T>;
8613
8614 /// The `has()` method returns a boolean indicating whether an object exists
8615 /// in a WeakSet or not.
8616 ///
8617 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet/has)
8618 #[wasm_bindgen(method)]
8619 pub fn has<T>(this: &WeakSet<T>, value: &T) -> bool;
8620
8621 /// The `add()` method appends a new object to the end of a WeakSet object.
8622 ///
8623 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet/add)
8624 #[wasm_bindgen(method)]
8625 pub fn add<T>(this: &WeakSet<T>, value: &T) -> WeakSet<T>;
8626
8627 /// The `delete()` method removes the specified element from a WeakSet
8628 /// object.
8629 ///
8630 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet/delete)
8631 #[wasm_bindgen(method)]
8632 pub fn delete<T>(this: &WeakSet<T>, value: &T) -> bool;
8633}
8634
8635impl Default for WeakSet {
8636 fn default() -> Self {
8637 Self::new()
8638 }
8639}
8640
8641// WeakRef
8642#[wasm_bindgen]
8643extern "C" {
8644 #[wasm_bindgen(extends = Object, typescript_type = "WeakRef<object>")]
8645 #[derive(Clone, Debug, PartialEq, Eq)]
8646 pub type WeakRef<T = Object>;
8647
8648 /// The `WeakRef` object contains a weak reference to an object. A weak
8649 /// reference to an object is a reference that does not prevent the object
8650 /// from being reclaimed by the garbage collector.
8651 ///
8652 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef)
8653 #[wasm_bindgen(constructor)]
8654 pub fn new<T = Object>(target: &T) -> WeakRef<T>;
8655
8656 /// Returns the `Object` this `WeakRef` points to, or `None` if the
8657 /// object has been garbage collected.
8658 ///
8659 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef/deref)
8660 #[wasm_bindgen(method)]
8661 pub fn deref<T>(this: &WeakRef<T>) -> Option<T>;
8662}
8663
8664#[cfg(js_sys_unstable_apis)]
8665#[allow(non_snake_case)]
8666pub mod Temporal;
8667
8668#[allow(non_snake_case)]
8669pub mod WebAssembly {
8670 use super::*;
8671
8672 // WebAssembly
8673 #[wasm_bindgen]
8674 extern "C" {
8675 /// The `WebAssembly.compile()` function compiles a `WebAssembly.Module`
8676 /// from WebAssembly binary code. This function is useful if it is
8677 /// necessary to a compile a module before it can be instantiated
8678 /// (otherwise, the `WebAssembly.instantiate()` function should be used).
8679 ///
8680 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compile)
8681 #[cfg(not(js_sys_unstable_apis))]
8682 #[wasm_bindgen(js_namespace = WebAssembly)]
8683 pub fn compile(buffer_source: &JsValue) -> Promise<JsValue>;
8684
8685 /// The `WebAssembly.compile()` function compiles a `WebAssembly.Module`
8686 /// from WebAssembly binary code. This function is useful if it is
8687 /// necessary to a compile a module before it can be instantiated
8688 /// (otherwise, the `WebAssembly.instantiate()` function should be used).
8689 ///
8690 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compile)
8691 #[cfg(js_sys_unstable_apis)]
8692 #[wasm_bindgen(js_namespace = WebAssembly)]
8693 pub fn compile(buffer_source: &JsValue) -> Promise<Module>;
8694
8695 /// The `WebAssembly.compileStreaming()` function compiles a
8696 /// `WebAssembly.Module` module directly from a streamed underlying
8697 /// source. This function is useful if it is necessary to a compile a
8698 /// module before it can be instantiated (otherwise, the
8699 /// `WebAssembly.instantiateStreaming()` function should be used).
8700 ///
8701 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compileStreaming)
8702 #[cfg(not(js_sys_unstable_apis))]
8703 #[wasm_bindgen(js_namespace = WebAssembly, js_name = compileStreaming)]
8704 pub fn compile_streaming(response: &Promise) -> Promise<JsValue>;
8705
8706 /// The `WebAssembly.compileStreaming()` function compiles a
8707 /// `WebAssembly.Module` module directly from a streamed underlying
8708 /// source. This function is useful if it is necessary to a compile a
8709 /// module before it can be instantiated (otherwise, the
8710 /// `WebAssembly.instantiateStreaming()` function should be used).
8711 ///
8712 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compileStreaming)
8713 #[cfg(js_sys_unstable_apis)]
8714 #[wasm_bindgen(js_namespace = WebAssembly, js_name = compileStreaming)]
8715 pub fn compile_streaming(response: &Promise) -> Promise<Module>;
8716
8717 /// The `WebAssembly.instantiate()` function allows you to compile and
8718 /// instantiate WebAssembly code.
8719 ///
8720 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate)
8721 #[cfg(not(js_sys_unstable_apis))]
8722 #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiate)]
8723 pub fn instantiate_buffer(buffer: &[u8], imports: &Object) -> Promise<JsValue>;
8724
8725 /// The `WebAssembly.instantiate()` function allows you to compile and
8726 /// instantiate WebAssembly code.
8727 ///
8728 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate)
8729 #[cfg(js_sys_unstable_apis)]
8730 #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiate)]
8731 pub fn instantiate_buffer(buffer: &[u8], imports: &Object) -> Promise<Instance>;
8732
8733 /// The `WebAssembly.instantiate()` function allows you to compile and
8734 /// instantiate WebAssembly code.
8735 ///
8736 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate)
8737 #[cfg(not(js_sys_unstable_apis))]
8738 #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiate)]
8739 pub fn instantiate_module(module: &Module, imports: &Object) -> Promise<JsValue>;
8740
8741 /// The `WebAssembly.instantiate()` function allows you to compile and
8742 /// instantiate WebAssembly code.
8743 ///
8744 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate)
8745 #[cfg(js_sys_unstable_apis)]
8746 #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiate)]
8747 pub fn instantiate_module(module: &Module, imports: &Object) -> Promise<Instance>;
8748
8749 /// The `WebAssembly.instantiateStreaming()` function compiles and
8750 /// instantiates a WebAssembly module directly from a streamed
8751 /// underlying source. This is the most efficient, optimized way to load
8752 /// Wasm code.
8753 ///
8754 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiateStreaming)
8755 #[cfg(not(js_sys_unstable_apis))]
8756 #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiateStreaming)]
8757 pub fn instantiate_streaming(response: &JsValue, imports: &Object) -> Promise<JsValue>;
8758
8759 /// The `WebAssembly.instantiateStreaming()` function compiles and
8760 /// instantiates a WebAssembly module directly from a streamed
8761 /// underlying source. This is the most efficient, optimized way to load
8762 /// Wasm code.
8763 ///
8764 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiateStreaming)
8765 #[cfg(js_sys_unstable_apis)]
8766 #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiateStreaming)]
8767 pub fn instantiate_streaming(response: &JsValue, imports: &Object) -> Promise<Instance>;
8768
8769 /// The `WebAssembly.validate()` function validates a given typed
8770 /// array of WebAssembly binary code, returning whether the bytes
8771 /// form a valid Wasm module (`true`) or not (`false`).
8772 ///
8773 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/validate)
8774 #[wasm_bindgen(js_namespace = WebAssembly, catch)]
8775 pub fn validate(buffer_source: &JsValue) -> Result<bool, JsValue>;
8776 }
8777
8778 // WebAssembly.CompileError
8779 #[wasm_bindgen]
8780 extern "C" {
8781 /// The `WebAssembly.CompileError()` constructor creates a new
8782 /// WebAssembly `CompileError` object, which indicates an error during
8783 /// WebAssembly decoding or validation.
8784 ///
8785 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/CompileError)
8786 #[wasm_bindgen(extends = Error, js_namespace = WebAssembly, typescript_type = "WebAssembly.CompileError")]
8787 #[derive(Clone, Debug, PartialEq, Eq)]
8788 pub type CompileError;
8789
8790 /// The `WebAssembly.CompileError()` constructor creates a new
8791 /// WebAssembly `CompileError` object, which indicates an error during
8792 /// WebAssembly decoding or validation.
8793 ///
8794 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/CompileError)
8795 #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
8796 pub fn new(message: &str) -> CompileError;
8797
8798 /// Creates a new `WebAssembly.CompileError` with the given message and
8799 /// a typed [`ErrorOptions`] dictionary whose `cause` property
8800 /// indicates the original cause of the error.
8801 ///
8802 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/CompileError/CompileError)
8803 #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
8804 pub fn new_with_options(message: &str, options: &ErrorOptions) -> CompileError;
8805 }
8806
8807 // WebAssembly.Instance
8808 #[wasm_bindgen]
8809 extern "C" {
8810 /// A `WebAssembly.Instance` object is a stateful, executable instance
8811 /// of a `WebAssembly.Module`. Instance objects contain all the exported
8812 /// WebAssembly functions that allow calling into WebAssembly code from
8813 /// JavaScript.
8814 ///
8815 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance)
8816 #[wasm_bindgen(extends = Object, js_namespace = WebAssembly, typescript_type = "WebAssembly.Instance")]
8817 #[derive(Clone, Debug, PartialEq, Eq)]
8818 pub type Instance;
8819
8820 /// The `WebAssembly.Instance()` constructor function can be called to
8821 /// synchronously instantiate a given `WebAssembly.Module`
8822 /// object. However, the primary way to get an `Instance` is through the
8823 /// asynchronous `WebAssembly.instantiateStreaming()` function.
8824 ///
8825 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance)
8826 #[wasm_bindgen(catch, constructor, js_namespace = WebAssembly)]
8827 pub fn new(module: &Module, imports: &Object) -> Result<Instance, JsValue>;
8828
8829 /// The `exports` readonly property of the `WebAssembly.Instance` object
8830 /// prototype returns an object containing as its members all the
8831 /// functions exported from the WebAssembly module instance, to allow
8832 /// them to be accessed and used by JavaScript.
8833 ///
8834 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance/exports)
8835 #[wasm_bindgen(getter, method, js_namespace = WebAssembly)]
8836 pub fn exports(this: &Instance) -> Object;
8837 }
8838
8839 // WebAssembly.LinkError
8840 #[wasm_bindgen]
8841 extern "C" {
8842 /// The `WebAssembly.LinkError()` constructor creates a new WebAssembly
8843 /// LinkError object, which indicates an error during module
8844 /// instantiation (besides traps from the start function).
8845 ///
8846 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/LinkError)
8847 #[wasm_bindgen(extends = Error, js_namespace = WebAssembly, typescript_type = "WebAssembly.LinkError")]
8848 #[derive(Clone, Debug, PartialEq, Eq)]
8849 pub type LinkError;
8850
8851 /// The `WebAssembly.LinkError()` constructor creates a new WebAssembly
8852 /// LinkError object, which indicates an error during module
8853 /// instantiation (besides traps from the start function).
8854 ///
8855 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/LinkError)
8856 #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
8857 pub fn new(message: &str) -> LinkError;
8858
8859 /// Creates a new `WebAssembly.LinkError` with the given message and a
8860 /// typed [`ErrorOptions`] dictionary whose `cause` property indicates
8861 /// the original cause of the error.
8862 ///
8863 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/LinkError/LinkError)
8864 #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
8865 pub fn new_with_options(message: &str, options: &ErrorOptions) -> LinkError;
8866 }
8867
8868 // WebAssembly.RuntimeError
8869 #[wasm_bindgen]
8870 extern "C" {
8871 /// The `WebAssembly.RuntimeError()` constructor creates a new WebAssembly
8872 /// `RuntimeError` object — the type that is thrown whenever WebAssembly
8873 /// specifies a trap.
8874 ///
8875 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/RuntimeError)
8876 #[wasm_bindgen(extends = Error, js_namespace = WebAssembly, typescript_type = "WebAssembly.RuntimeError")]
8877 #[derive(Clone, Debug, PartialEq, Eq)]
8878 pub type RuntimeError;
8879
8880 /// The `WebAssembly.RuntimeError()` constructor creates a new WebAssembly
8881 /// `RuntimeError` object — the type that is thrown whenever WebAssembly
8882 /// specifies a trap.
8883 ///
8884 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/RuntimeError)
8885 #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
8886 pub fn new(message: &str) -> RuntimeError;
8887
8888 /// Creates a new `WebAssembly.RuntimeError` with the given message
8889 /// and a typed [`ErrorOptions`] dictionary whose `cause` property
8890 /// indicates the original cause of the error.
8891 ///
8892 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/RuntimeError/RuntimeError)
8893 #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
8894 pub fn new_with_options(message: &str, options: &ErrorOptions) -> RuntimeError;
8895 }
8896
8897 // WebAssembly.Module
8898 #[wasm_bindgen]
8899 extern "C" {
8900 /// A `WebAssembly.Module` object contains stateless WebAssembly code
8901 /// that has already been compiled by the browser and can be
8902 /// efficiently shared with Workers, and instantiated multiple times.
8903 ///
8904 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module)
8905 #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Module")]
8906 #[derive(Clone, Debug, PartialEq, Eq)]
8907 pub type Module;
8908
8909 /// A `WebAssembly.Module` object contains stateless WebAssembly code
8910 /// that has already been compiled by the browser and can be
8911 /// efficiently shared with Workers, and instantiated multiple times.
8912 ///
8913 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module)
8914 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
8915 pub fn new(buffer_source: &JsValue) -> Result<Module, JsValue>;
8916
8917 /// The `WebAssembly.customSections()` function returns a copy of the
8918 /// contents of all custom sections in the given module with the given
8919 /// string name.
8920 ///
8921 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/customSections)
8922 #[wasm_bindgen(static_method_of = Module, js_namespace = WebAssembly, js_name = customSections)]
8923 pub fn custom_sections(module: &Module, sectionName: &str) -> Array;
8924
8925 /// The `WebAssembly.exports()` function returns an array containing
8926 /// descriptions of all the declared exports of the given `Module`.
8927 ///
8928 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/exports)
8929 #[wasm_bindgen(static_method_of = Module, js_namespace = WebAssembly)]
8930 pub fn exports(module: &Module) -> Array;
8931
8932 /// The `WebAssembly.imports()` function returns an array containing
8933 /// descriptions of all the declared imports of the given `Module`.
8934 ///
8935 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/imports)
8936 #[wasm_bindgen(static_method_of = Module, js_namespace = WebAssembly)]
8937 pub fn imports(module: &Module) -> Array;
8938 }
8939
8940 // WebAssembly.Table
8941 #[wasm_bindgen]
8942 extern "C" {
8943 /// The `WebAssembly.Table()` constructor creates a new `Table` object
8944 /// of the given size and element type.
8945 ///
8946 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table)
8947 #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Table")]
8948 #[derive(Clone, Debug, PartialEq, Eq)]
8949 pub type Table;
8950
8951 /// The `WebAssembly.Table()` constructor creates a new `Table` object
8952 /// of the given size and element type.
8953 ///
8954 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table)
8955 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
8956 pub fn new(table_descriptor: &Object) -> Result<Table, JsValue>;
8957
8958 /// The `WebAssembly.Table()` constructor creates a new `Table` object
8959 /// of the given size and element type.
8960 ///
8961 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table)
8962 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
8963 pub fn new_with_value(table_descriptor: &Object, value: JsValue) -> Result<Table, JsValue>;
8964
8965 /// The length prototype property of the `WebAssembly.Table` object
8966 /// returns the length of the table, i.e. the number of elements in the
8967 /// table.
8968 ///
8969 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/length)
8970 #[wasm_bindgen(method, getter, js_namespace = WebAssembly)]
8971 pub fn length(this: &Table) -> u32;
8972
8973 /// The `get()` prototype method of the `WebAssembly.Table()` object
8974 /// retrieves a function reference stored at a given index.
8975 ///
8976 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/get)
8977 #[wasm_bindgen(method, catch, js_namespace = WebAssembly)]
8978 pub fn get(this: &Table, index: u32) -> Result<Function, JsValue>;
8979
8980 /// The `get()` prototype method of the `WebAssembly.Table()` object
8981 /// retrieves a function reference stored at a given index.
8982 ///
8983 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/get)
8984 #[wasm_bindgen(method, catch, js_namespace = WebAssembly, js_name = get)]
8985 pub fn get_raw(this: &Table, index: u32) -> Result<JsValue, JsValue>;
8986
8987 /// The `grow()` prototype method of the `WebAssembly.Table` object
8988 /// increases the size of the `Table` instance by a specified number of
8989 /// elements.
8990 ///
8991 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/grow)
8992 #[wasm_bindgen(method, catch, js_namespace = WebAssembly)]
8993 pub fn grow(this: &Table, additional_capacity: u32) -> Result<u32, JsValue>;
8994
8995 /// The `grow()` prototype method of the `WebAssembly.Table` object
8996 /// increases the size of the `Table` instance by a specified number of
8997 /// elements.
8998 ///
8999 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/grow)
9000 #[wasm_bindgen(method, catch, js_namespace = WebAssembly, js_name = grow)]
9001 pub fn grow_with_value(
9002 this: &Table,
9003 additional_capacity: u32,
9004 value: JsValue,
9005 ) -> Result<u32, JsValue>;
9006
9007 /// The `set()` prototype method of the `WebAssembly.Table` object mutates a
9008 /// reference stored at a given index to a different value.
9009 ///
9010 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/set)
9011 #[wasm_bindgen(method, catch, js_namespace = WebAssembly)]
9012 pub fn set(this: &Table, index: u32, function: &Function) -> Result<(), JsValue>;
9013
9014 /// The `set()` prototype method of the `WebAssembly.Table` object mutates a
9015 /// reference stored at a given index to a different value.
9016 ///
9017 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/set)
9018 #[wasm_bindgen(method, catch, js_namespace = WebAssembly, js_name = set)]
9019 pub fn set_raw(this: &Table, index: u32, value: &JsValue) -> Result<(), JsValue>;
9020 }
9021
9022 // WebAssembly.Tag
9023 #[wasm_bindgen]
9024 extern "C" {
9025 /// The `WebAssembly.Tag()` constructor creates a new `Tag` object
9026 ///
9027 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Tag)
9028 #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Tag")]
9029 #[derive(Clone, Debug, PartialEq, Eq)]
9030 pub type Tag;
9031
9032 /// The `WebAssembly.Tag()` constructor creates a new `Tag` object
9033 ///
9034 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Tag)
9035 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
9036 pub fn new(tag_descriptor: &Object) -> Result<Tag, JsValue>;
9037 }
9038
9039 // WebAssembly.Exception
9040 #[wasm_bindgen]
9041 extern "C" {
9042 /// The `WebAssembly.Exception()` constructor creates a new `Exception` object
9043 ///
9044 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception)
9045 #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Exception")]
9046 #[derive(Clone, Debug, PartialEq, Eq)]
9047 pub type Exception;
9048
9049 /// The `WebAssembly.Exception()` constructor creates a new `Exception` object
9050 ///
9051 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception)
9052 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
9053 pub fn new(tag: &Tag, payload: &Array) -> Result<Exception, JsValue>;
9054
9055 /// The `WebAssembly.Exception()` constructor creates a new `Exception` object
9056 ///
9057 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception)
9058 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
9059 pub fn new_with_options(
9060 tag: &Tag,
9061 payload: &Array,
9062 options: &Object,
9063 ) -> Result<Exception, JsValue>;
9064
9065 /// The `is()` prototype method of the `WebAssembly.Exception` can be used to
9066 /// test if the Exception matches a given tag.
9067 ///
9068 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception/is)
9069 #[wasm_bindgen(method, js_namespace = WebAssembly)]
9070 pub fn is(this: &Exception, tag: &Tag) -> bool;
9071
9072 /// The `getArg()` prototype method of the `WebAssembly.Exception` can be used
9073 /// to get the value of a specified item in the exception's data arguments
9074 ///
9075 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception/getArg)
9076 #[wasm_bindgen(method, js_namespace = WebAssembly, js_name = getArg, catch)]
9077 pub fn get_arg(this: &Exception, tag: &Tag, index: u32) -> Result<JsValue, JsValue>;
9078 }
9079
9080 // WebAssembly.Global
9081 #[wasm_bindgen]
9082 extern "C" {
9083 /// The `WebAssembly.Global()` constructor creates a new `Global` object
9084 /// of the given type and value.
9085 ///
9086 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global)
9087 #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Global")]
9088 #[derive(Clone, Debug, PartialEq, Eq)]
9089 pub type Global;
9090
9091 /// The `WebAssembly.Global()` constructor creates a new `Global` object
9092 /// of the given type and value.
9093 ///
9094 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global)
9095 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
9096 pub fn new(global_descriptor: &Object, value: &JsValue) -> Result<Global, JsValue>;
9097
9098 /// The value prototype property of the `WebAssembly.Global` object
9099 /// returns the value of the global.
9100 ///
9101 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global)
9102 #[wasm_bindgen(method, getter, js_namespace = WebAssembly)]
9103 pub fn value(this: &Global) -> JsValue;
9104 #[wasm_bindgen(method, setter = value, js_namespace = WebAssembly)]
9105 pub fn set_value(this: &Global, value: &JsValue);
9106 }
9107
9108 // WebAssembly.Memory
9109 #[wasm_bindgen]
9110 extern "C" {
9111 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory)
9112 #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Memory")]
9113 #[derive(Clone, Debug, PartialEq, Eq)]
9114 pub type Memory;
9115
9116 /// The `WebAssembly.Memory()` constructor creates a new `Memory` object
9117 /// which is a resizable `ArrayBuffer` that holds the raw bytes of
9118 /// memory accessed by a WebAssembly `Instance`.
9119 ///
9120 /// A memory created by JavaScript or in WebAssembly code will be
9121 /// accessible and mutable from both JavaScript and WebAssembly.
9122 ///
9123 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory)
9124 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
9125 pub fn new(descriptor: &Object) -> Result<Memory, JsValue>;
9126
9127 /// An accessor property that returns the buffer contained in the
9128 /// memory.
9129 ///
9130 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory/buffer)
9131 #[wasm_bindgen(method, getter, js_namespace = WebAssembly)]
9132 pub fn buffer(this: &Memory) -> JsValue;
9133
9134 /// The `grow()` prototype method of the `Memory` object increases the
9135 /// size of the memory instance by a specified number of WebAssembly
9136 /// pages.
9137 ///
9138 /// Takes the number of pages to grow (64KiB in size) and returns the
9139 /// previous size of memory, in pages.
9140 ///
9141 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory/grow)
9142 #[wasm_bindgen(method, js_namespace = WebAssembly)]
9143 pub fn grow(this: &Memory, pages: u32) -> u32;
9144 }
9145
9146 // WebAssembly.Suspending / WebAssembly.promising (JSPI — JS Promise Integration)
9147 #[wasm_bindgen]
9148 extern "C" {
9149 /// A `WebAssembly.Suspending` object wraps a JavaScript async function
9150 /// so it can be used as a WebAssembly import under
9151 /// [JSPI (JS Promise Integration)][jspi].
9152 ///
9153 /// When WASM calls a `Suspending`-wrapped import that returns a
9154 /// `Promise`, the WASM fiber suspends until the promise settles; the
9155 /// resolved value is then returned to WASM as if the call had returned
9156 /// synchronously. The browser's event loop is **not** blocked.
9157 ///
9158 /// [jspi]: https://github.com/WebAssembly/js-promise-integration
9159 ///
9160 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Suspending)
9161 #[wasm_bindgen(
9162 js_namespace = WebAssembly,
9163 extends = Object,
9164 typescript_type = "WebAssembly.Suspending"
9165 )]
9166 #[derive(Clone, Debug, PartialEq, Eq)]
9167 pub type Suspending;
9168
9169 /// Wraps `func` (an async function) in a `WebAssembly.Suspending` object.
9170 ///
9171 /// Pass the returned object as a WASM import. Every call to that
9172 /// import from WASM will suspend the current fiber and resume it with
9173 /// the resolved value once `func`'s returned `Promise` settles.
9174 #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
9175 pub fn new(func: &Function) -> Suspending;
9176
9177 /// Wraps a WebAssembly exported `Function` so that calling it returns a
9178 /// `Promise` and enables JSPI suspension inside.
9179 ///
9180 /// Use `WebAssembly.promising` to obtain a "promising" wrapper around a
9181 /// raw WASM export; any JSPI suspensions that occur while the function
9182 /// executes will resolve the returned `Promise` when the fiber finishes.
9183 ///
9184 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/promising)
9185 #[wasm_bindgen(js_namespace = WebAssembly)]
9186 pub fn promising(func: &Function) -> Function;
9187 }
9188}
9189
9190/// The `JSON` object contains methods for parsing [JavaScript Object
9191/// Notation (JSON)](https://json.org/) and converting values to JSON. It
9192/// can't be called or constructed, and aside from its two method
9193/// properties, it has no interesting functionality of its own.
9194#[allow(non_snake_case)]
9195pub mod JSON {
9196 use super::*;
9197
9198 // JSON
9199 #[wasm_bindgen]
9200 extern "C" {
9201 /// The `JSON.parse()` method parses a JSON string, constructing the
9202 /// JavaScript value or object described by the string.
9203 ///
9204 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse)
9205 #[wasm_bindgen(catch, js_namespace = JSON)]
9206 pub fn parse(text: &str) -> Result<JsValue, JsValue>;
9207
9208 /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
9209 ///
9210 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
9211 #[wasm_bindgen(catch, js_namespace = JSON)]
9212 pub fn stringify(obj: &JsValue) -> Result<JsString, JsValue>;
9213
9214 /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
9215 ///
9216 /// The `replacer` argument is a function that alters the behavior of the stringification
9217 /// process, or an array of String and Number objects that serve as a whitelist
9218 /// for selecting/filtering the properties of the value object to be included
9219 /// in the JSON string. If this value is null or not provided, all properties
9220 /// of the object are included in the resulting JSON string.
9221 ///
9222 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
9223 #[cfg(not(js_sys_unstable_apis))]
9224 #[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
9225 pub fn stringify_with_replacer(
9226 obj: &JsValue,
9227 replacer: &JsValue,
9228 ) -> Result<JsString, JsValue>;
9229
9230 /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
9231 ///
9232 /// The `replacer` argument is a function that alters the behavior of the stringification
9233 /// process, or an array of String and Number objects that serve as a whitelist
9234 /// for selecting/filtering the properties of the value object to be included
9235 /// in the JSON string. If this value is null or not provided, all properties
9236 /// of the object are included in the resulting JSON string.
9237 ///
9238 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
9239 #[cfg(js_sys_unstable_apis)]
9240 #[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
9241 pub fn stringify_with_replacer<'a>(
9242 obj: &JsValue,
9243 replacer: &mut dyn FnMut(JsString, JsValue) -> Result<Option<JsValue>, JsError>,
9244 space: Option<u32>,
9245 ) -> Result<JsString, JsValue>;
9246
9247 // Next major: deprecate
9248 /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
9249 ///
9250 /// The `replacer` argument is a function that alters the behavior of the stringification
9251 /// process, or an array of String and Number objects that serve as a whitelist
9252 /// for selecting/filtering the properties of the value object to be included
9253 /// in the JSON string. If this value is null or not provided, all properties
9254 /// of the object are included in the resulting JSON string.
9255 ///
9256 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
9257 #[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
9258 pub fn stringify_with_replacer_func<'a>(
9259 obj: &JsValue,
9260 replacer: &mut dyn FnMut(JsString, JsValue) -> Result<Option<JsValue>, JsError>,
9261 space: Option<u32>,
9262 ) -> Result<JsString, JsValue>;
9263
9264 /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
9265 ///
9266 /// The `replacer` argument is a function that alters the behavior of the stringification
9267 /// process, or an array of String and Number objects that serve as a whitelist
9268 /// for selecting/filtering the properties of the value object to be included
9269 /// in the JSON string. If this value is null or not provided, all properties
9270 /// of the object are included in the resulting JSON string.
9271 ///
9272 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
9273 #[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
9274 pub fn stringify_with_replacer_list(
9275 obj: &JsValue,
9276 replacer: Vec<String>,
9277 space: Option<u32>,
9278 ) -> Result<JsString, JsValue>;
9279
9280 // Next major: deprecate
9281 /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
9282 ///
9283 /// The `replacer` argument is a function that alters the behavior of the stringification
9284 /// process, or an array of String and Number objects that serve as a whitelist
9285 /// for selecting/filtering the properties of the value object to be included
9286 /// in the JSON string. If this value is null or not provided, all properties
9287 /// of the object are included in the resulting JSON string.
9288 ///
9289 /// The `space` argument is a String or Number object that's used to insert white space into
9290 /// the output JSON string for readability purposes. If this is a Number, it
9291 /// indicates the number of space characters to use as white space; this number
9292 /// is capped at 10 (if it is greater, the value is just 10). Values less than
9293 /// 1 indicate that no space should be used. If this is a String, the string
9294 /// (or the first 10 characters of the string, if it's longer than that) is
9295 /// used as white space. If this parameter is not provided (or is null), no
9296 /// white space is used.
9297 ///
9298 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
9299 #[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
9300 pub fn stringify_with_replacer_and_space(
9301 obj: &JsValue,
9302 replacer: &JsValue,
9303 space: &JsValue,
9304 ) -> Result<JsString, JsValue>;
9305 }
9306}
9307// JsString
9308#[wasm_bindgen]
9309extern "C" {
9310 #[wasm_bindgen(js_name = String, extends = Object, is_type_of = JsValue::is_string, typescript_type = "string")]
9311 #[derive(Clone, PartialEq, Eq)]
9312 pub type JsString;
9313
9314 /// The length property of a String object indicates the length of a string,
9315 /// in UTF-16 code units.
9316 ///
9317 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/length)
9318 #[wasm_bindgen(method, getter)]
9319 pub fn length(this: &JsString) -> u32;
9320
9321 /// The 'at()' method returns a new string consisting of the single UTF-16
9322 /// code unit located at the specified offset into the string, counting from
9323 /// the end if it's negative.
9324 ///
9325 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/at)
9326 #[wasm_bindgen(method, js_class = "String")]
9327 pub fn at(this: &JsString, index: i32) -> Option<JsString>;
9328
9329 /// The String object's `charAt()` method returns a new string consisting of
9330 /// the single UTF-16 code unit located at the specified offset into the
9331 /// string.
9332 ///
9333 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charAt)
9334 #[wasm_bindgen(method, js_class = "String", js_name = charAt)]
9335 pub fn char_at(this: &JsString, index: u32) -> JsString;
9336
9337 /// The `charCodeAt()` method returns an integer between 0 and 65535
9338 /// representing the UTF-16 code unit at the given index (the UTF-16 code
9339 /// unit matches the Unicode code point for code points representable in a
9340 /// single UTF-16 code unit, but might also be the first code unit of a
9341 /// surrogate pair for code points not representable in a single UTF-16 code
9342 /// unit, e.g. Unicode code points > 0x10000). If you want the entire code
9343 /// point value, use `codePointAt()`.
9344 ///
9345 /// Returns `NaN` if index is out of range.
9346 ///
9347 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charCodeAt)
9348 #[wasm_bindgen(method, js_class = "String", js_name = charCodeAt)]
9349 pub fn char_code_at(this: &JsString, index: u32) -> f64;
9350
9351 /// The `codePointAt()` method returns a non-negative integer that is the
9352 /// Unicode code point value.
9353 ///
9354 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/codePointAt)
9355 #[cfg(not(js_sys_unstable_apis))]
9356 #[wasm_bindgen(method, js_class = "String", js_name = codePointAt)]
9357 pub fn code_point_at(this: &JsString, pos: u32) -> JsValue;
9358
9359 /// The `codePointAt()` method returns a non-negative integer that is the
9360 /// Unicode code point value.
9361 ///
9362 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/codePointAt)
9363 #[cfg(js_sys_unstable_apis)]
9364 #[wasm_bindgen(method, js_class = "String", js_name = codePointAt)]
9365 pub fn code_point_at(this: &JsString, pos: u32) -> Option<u32>;
9366
9367 // Next major: deprecate
9368 /// The `codePointAt()` method returns a non-negative integer that is the
9369 /// Unicode code point value.
9370 ///
9371 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/codePointAt)
9372 #[wasm_bindgen(method, js_class = "String", js_name = codePointAt)]
9373 pub fn try_code_point_at(this: &JsString, pos: u32) -> Option<u16>;
9374
9375 /// The `concat()` method concatenates the string arguments to the calling
9376 /// string and returns a new string.
9377 ///
9378 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/concat)
9379 #[cfg(not(js_sys_unstable_apis))]
9380 #[wasm_bindgen(method, js_class = "String")]
9381 pub fn concat(this: &JsString, string_2: &JsValue) -> JsString;
9382
9383 /// The `concat()` method concatenates the string arguments to the calling
9384 /// string and returns a new string.
9385 ///
9386 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/concat)
9387 #[cfg(js_sys_unstable_apis)]
9388 #[wasm_bindgen(method, js_class = "String")]
9389 pub fn concat(this: &JsString, string: &JsString) -> JsString;
9390
9391 /// The `concat()` method concatenates the string arguments to the calling
9392 /// string and returns a new string.
9393 ///
9394 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/concat)
9395 #[wasm_bindgen(method, js_class = "String")]
9396 pub fn concat_many(this: &JsString, strings: &[JsString]) -> JsString;
9397
9398 /// The `endsWith()` method determines whether a string ends with the characters of a
9399 /// specified string, returning true or false as appropriate.
9400 ///
9401 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith)
9402 #[cfg(not(js_sys_unstable_apis))]
9403 #[wasm_bindgen(method, js_class = "String", js_name = endsWith)]
9404 pub fn ends_with(this: &JsString, search_string: &str, length: i32) -> bool;
9405
9406 /// The `endsWith()` method determines whether a string ends with the characters of a
9407 /// specified string, returning true or false as appropriate.
9408 ///
9409 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith)
9410 #[cfg(js_sys_unstable_apis)]
9411 #[wasm_bindgen(method, js_class = "String", js_name = endsWith)]
9412 pub fn ends_with(this: &JsString, search_string: &str) -> bool;
9413
9414 /// The static `String.fromCharCode()` method returns a string created from
9415 /// the specified sequence of UTF-16 code units.
9416 ///
9417 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
9418 ///
9419 /// # Notes
9420 ///
9421 /// There are a few bindings to `from_char_code` in `js-sys`: `from_char_code1`, `from_char_code2`, etc...
9422 /// with different arities.
9423 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode, variadic)]
9424 pub fn from_char_code(char_codes: &[u16]) -> JsString;
9425
9426 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
9427 #[cfg(not(js_sys_unstable_apis))]
9428 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
9429 pub fn from_char_code1(a: u32) -> JsString;
9430
9431 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
9432 #[cfg(js_sys_unstable_apis)]
9433 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
9434 pub fn from_char_code1(a: u16) -> JsString;
9435
9436 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
9437 #[cfg(not(js_sys_unstable_apis))]
9438 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
9439 pub fn from_char_code2(a: u32, b: u32) -> JsString;
9440
9441 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
9442 #[cfg(js_sys_unstable_apis)]
9443 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
9444 pub fn from_char_code2(a: u16, b: u16) -> JsString;
9445
9446 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
9447 #[cfg(not(js_sys_unstable_apis))]
9448 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
9449 pub fn from_char_code3(a: u32, b: u32, c: u32) -> JsString;
9450
9451 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
9452 #[cfg(js_sys_unstable_apis)]
9453 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
9454 pub fn from_char_code3(a: u16, b: u16, c: u16) -> JsString;
9455
9456 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
9457 #[cfg(not(js_sys_unstable_apis))]
9458 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
9459 pub fn from_char_code4(a: u32, b: u32, c: u32, d: u32) -> JsString;
9460
9461 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
9462 #[cfg(js_sys_unstable_apis)]
9463 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
9464 pub fn from_char_code4(a: u16, b: u16, c: u16, d: u16) -> JsString;
9465
9466 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
9467 #[cfg(not(js_sys_unstable_apis))]
9468 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
9469 pub fn from_char_code5(a: u32, b: u32, c: u32, d: u32, e: u32) -> JsString;
9470
9471 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
9472 #[cfg(js_sys_unstable_apis)]
9473 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
9474 pub fn from_char_code5(a: u16, b: u16, c: u16, d: u16, e: u16) -> JsString;
9475
9476 /// The static `String.fromCodePoint()` method returns a string created by
9477 /// using the specified sequence of code points.
9478 ///
9479 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
9480 ///
9481 /// # Exceptions
9482 ///
9483 /// A RangeError is thrown if an invalid Unicode code point is given
9484 ///
9485 /// # Notes
9486 ///
9487 /// There are a few bindings to `from_code_point` in `js-sys`: `from_code_point1`, `from_code_point2`, etc...
9488 /// with different arities.
9489 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint, variadic)]
9490 pub fn from_code_point(code_points: &[u32]) -> Result<JsString, JsValue>;
9491
9492 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
9493 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
9494 pub fn from_code_point1(a: 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_point2(a: u32, b: 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_point3(a: u32, b: u32, c: 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_point4(a: u32, b: u32, c: u32, d: 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_point5(a: u32, b: u32, c: u32, d: u32, e: u32) -> Result<JsString, JsValue>;
9511
9512 /// The `includes()` method determines whether one string may be found
9513 /// within another string, returning true or false as appropriate.
9514 ///
9515 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes)
9516 #[wasm_bindgen(method, js_class = "String")]
9517 pub fn includes(this: &JsString, search_string: &str, position: i32) -> bool;
9518
9519 /// The `indexOf()` method returns the index within the calling String
9520 /// object of the first occurrence of the specified value, starting the
9521 /// search at fromIndex. Returns -1 if the value is not found.
9522 ///
9523 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf)
9524 #[wasm_bindgen(method, js_class = "String", js_name = indexOf)]
9525 pub fn index_of(this: &JsString, search_value: &str, from_index: i32) -> i32;
9526
9527 /// The `lastIndexOf()` method returns the index within the calling String
9528 /// object of the last occurrence of the specified value, searching
9529 /// backwards from fromIndex. Returns -1 if the value is not found.
9530 ///
9531 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/lastIndexOf)
9532 #[wasm_bindgen(method, js_class = "String", js_name = lastIndexOf)]
9533 pub fn last_index_of(this: &JsString, search_value: &str, from_index: i32) -> i32;
9534
9535 /// The `localeCompare()` method returns a number indicating whether
9536 /// a reference string comes before or after or is the same as
9537 /// the given string in sort order.
9538 ///
9539 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare)
9540 #[cfg(not(js_sys_unstable_apis))]
9541 #[wasm_bindgen(method, js_class = "String", js_name = localeCompare)]
9542 pub fn locale_compare(
9543 this: &JsString,
9544 compare_string: &str,
9545 locales: &Array,
9546 options: &Object,
9547 ) -> i32;
9548
9549 /// The `localeCompare()` method returns a number indicating whether
9550 /// a reference string comes before or after or is the same as
9551 /// the given string in sort order.
9552 ///
9553 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare)
9554 #[cfg(js_sys_unstable_apis)]
9555 #[wasm_bindgen(method, js_class = "String", js_name = localeCompare)]
9556 pub fn locale_compare(
9557 this: &JsString,
9558 compare_string: &str,
9559 locales: &[JsString],
9560 options: &Intl::CollatorOptions,
9561 ) -> i32;
9562
9563 /// The `match()` method retrieves the matches when matching a string against a regular expression.
9564 ///
9565 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match)
9566 #[wasm_bindgen(method, js_class = "String", js_name = match)]
9567 pub fn match_(this: &JsString, pattern: &RegExp) -> Option<Object>;
9568
9569 /// The `match_all()` method is similar to `match()`, but gives an iterator of `exec()` arrays, which preserve capture groups.
9570 ///
9571 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/matchAll)
9572 #[cfg(not(js_sys_unstable_apis))]
9573 #[wasm_bindgen(method, js_class = "String", js_name = matchAll)]
9574 pub fn match_all(this: &JsString, pattern: &RegExp) -> Iterator;
9575
9576 /// The `match_all()` method is similar to `match()`, but gives an iterator of `exec()` arrays, which preserve capture groups.
9577 ///
9578 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/matchAll)
9579 #[cfg(js_sys_unstable_apis)]
9580 #[wasm_bindgen(method, js_class = "String", js_name = matchAll)]
9581 pub fn match_all(this: &JsString, pattern: &RegExp) -> Iterator<RegExpMatchArray>;
9582
9583 /// The `normalize()` method returns the Unicode Normalization Form
9584 /// of a given string (if the value isn't a string, it will be converted to one first).
9585 ///
9586 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize)
9587 #[wasm_bindgen(method, js_class = "String")]
9588 pub fn normalize(this: &JsString, form: &str) -> JsString;
9589
9590 /// The `padEnd()` method pads the current string with a given string
9591 /// (repeated, if needed) so that the resulting string reaches a given
9592 /// length. The padding is applied from the end (right) of the current
9593 /// string.
9594 ///
9595 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padEnd)
9596 #[wasm_bindgen(method, js_class = "String", js_name = padEnd)]
9597 pub fn pad_end(this: &JsString, target_length: u32, pad_string: &str) -> JsString;
9598
9599 /// The `padStart()` method pads the current string with another string
9600 /// (repeated, if needed) so that the resulting string reaches the given
9601 /// length. The padding is applied from the start (left) of the current
9602 /// string.
9603 ///
9604 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padStart)
9605 #[wasm_bindgen(method, js_class = "String", js_name = padStart)]
9606 pub fn pad_start(this: &JsString, target_length: u32, pad_string: &str) -> JsString;
9607
9608 /// The `repeat()` method constructs and returns a new string which contains the specified
9609 /// number of copies of the string on which it was called, concatenated together.
9610 ///
9611 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat)
9612 #[wasm_bindgen(method, js_class = "String")]
9613 pub fn repeat(this: &JsString, count: i32) -> JsString;
9614
9615 /// The `replace()` method returns a new string with some or all matches of a pattern
9616 /// replaced by a replacement. The pattern can be a string or a RegExp, and
9617 /// the replacement can be a string or a function to be called for each match.
9618 ///
9619 /// Note: The original string will remain unchanged.
9620 ///
9621 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
9622 #[wasm_bindgen(method, js_class = "String")]
9623 pub fn replace(this: &JsString, pattern: &str, replacement: &str) -> JsString;
9624
9625 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
9626 #[cfg(not(js_sys_unstable_apis))]
9627 #[wasm_bindgen(method, js_class = "String", js_name = replace)]
9628 pub fn replace_with_function(
9629 this: &JsString,
9630 pattern: &str,
9631 replacement: &Function,
9632 ) -> JsString;
9633
9634 /// The replacer function signature is `(match, offset, string) -> replacement`
9635 /// for patterns without capture groups, or `(match, p1, p2, ..., pN, offset, string, groups) -> replacement`
9636 /// when capture groups are present.
9637 ///
9638 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
9639 #[cfg(js_sys_unstable_apis)]
9640 #[wasm_bindgen(method, js_class = "String", js_name = replace)]
9641 pub fn replace_with_function(
9642 this: &JsString,
9643 pattern: &str,
9644 replacement: &Function<fn(JsString) -> JsString>,
9645 ) -> JsString;
9646
9647 #[wasm_bindgen(method, js_class = "String", js_name = replace)]
9648 pub fn replace_by_pattern(this: &JsString, pattern: &RegExp, replacement: &str) -> JsString;
9649
9650 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
9651 #[cfg(not(js_sys_unstable_apis))]
9652 #[wasm_bindgen(method, js_class = "String", js_name = replace)]
9653 pub fn replace_by_pattern_with_function(
9654 this: &JsString,
9655 pattern: &RegExp,
9656 replacement: &Function,
9657 ) -> JsString;
9658
9659 /// The replacer function signature is `(match, offset, string) -> replacement`
9660 /// for patterns without capture groups, or `(match, p1, p2, ..., pN, offset, string, groups) -> replacement`
9661 /// when capture groups are present.
9662 ///
9663 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
9664 #[cfg(js_sys_unstable_apis)]
9665 #[wasm_bindgen(method, js_class = "String", js_name = replace)]
9666 pub fn replace_by_pattern_with_function(
9667 this: &JsString,
9668 pattern: &RegExp,
9669 replacement: &Function<fn(JsString) -> JsString>,
9670 ) -> JsString;
9671
9672 /// The `replace_all()` method returns a new string with all matches of a pattern
9673 /// replaced by a replacement. The pattern can be a string or a global RegExp, and
9674 /// the replacement can be a string or a function to be called for each match.
9675 ///
9676 /// Note: The original string will remain unchanged.
9677 ///
9678 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)
9679 #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
9680 pub fn replace_all(this: &JsString, pattern: &str, replacement: &str) -> JsString;
9681
9682 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)
9683 #[cfg(not(js_sys_unstable_apis))]
9684 #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
9685 pub fn replace_all_with_function(
9686 this: &JsString,
9687 pattern: &str,
9688 replacement: &Function,
9689 ) -> JsString;
9690
9691 /// The replacer function signature is `(match, offset, string) -> replacement`
9692 /// for patterns without capture groups, or `(match, p1, p2, ..., pN, offset, string, groups) -> replacement`
9693 /// when capture groups are present.
9694 ///
9695 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)
9696 #[cfg(js_sys_unstable_apis)]
9697 #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
9698 pub fn replace_all_with_function(
9699 this: &JsString,
9700 pattern: &str,
9701 replacement: &Function<fn(JsString) -> JsString>,
9702 ) -> JsString;
9703
9704 #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
9705 pub fn replace_all_by_pattern(this: &JsString, pattern: &RegExp, replacement: &str)
9706 -> JsString;
9707
9708 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)
9709 #[cfg(not(js_sys_unstable_apis))]
9710 #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
9711 pub fn replace_all_by_pattern_with_function(
9712 this: &JsString,
9713 pattern: &RegExp,
9714 replacement: &Function,
9715 ) -> JsString;
9716
9717 /// The replacer function signature is `(match, offset, string) -> replacement`
9718 /// for patterns without capture groups, or `(match, p1, p2, ..., pN, offset, string, groups) -> replacement`
9719 /// when capture groups are present.
9720 ///
9721 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)
9722 #[cfg(js_sys_unstable_apis)]
9723 #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
9724 pub fn replace_all_by_pattern_with_function(
9725 this: &JsString,
9726 pattern: &RegExp,
9727 replacement: &Function<fn(JsString) -> JsString>,
9728 ) -> JsString;
9729
9730 /// The `search()` method executes a search for a match between
9731 /// a regular expression and this String object.
9732 ///
9733 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/search)
9734 #[wasm_bindgen(method, js_class = "String")]
9735 pub fn search(this: &JsString, pattern: &RegExp) -> i32;
9736
9737 /// The `slice()` method extracts a section of a string and returns it as a
9738 /// new string, without modifying the original string.
9739 ///
9740 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice)
9741 #[wasm_bindgen(method, js_class = "String")]
9742 pub fn slice(this: &JsString, start: u32, end: u32) -> JsString;
9743
9744 /// The `split()` method splits a String object into an array of strings by separating the string
9745 /// into substrings, using a specified separator string to determine where to make each split.
9746 ///
9747 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)
9748 #[wasm_bindgen(method, js_class = "String")]
9749 pub fn split(this: &JsString, separator: &str) -> Array;
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", js_name = split)]
9753 pub fn split_limit(this: &JsString, separator: &str, limit: u32) -> 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_by_pattern(this: &JsString, pattern: &RegExp) -> 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_limit(this: &JsString, pattern: &RegExp, limit: u32) -> Array;
9762
9763 /// The `startsWith()` method determines whether a string begins with the
9764 /// characters of a specified string, returning true or false as
9765 /// appropriate.
9766 ///
9767 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith)
9768 #[wasm_bindgen(method, js_class = "String", js_name = startsWith)]
9769 pub fn starts_with(this: &JsString, search_string: &str, position: u32) -> bool;
9770
9771 /// The `substring()` method returns the part of the string between the
9772 /// start and end indexes, or to the end of the string.
9773 ///
9774 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring)
9775 #[wasm_bindgen(method, js_class = "String")]
9776 pub fn substring(this: &JsString, index_start: u32, index_end: u32) -> JsString;
9777
9778 /// The `substr()` method returns the part of a string between
9779 /// the start index and a number of characters after it.
9780 ///
9781 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr)
9782 #[wasm_bindgen(method, js_class = "String")]
9783 pub fn substr(this: &JsString, start: i32, length: i32) -> JsString;
9784
9785 /// The `toLocaleLowerCase()` method returns the calling string value converted to lower case,
9786 /// according to any locale-specific case mappings.
9787 ///
9788 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLocaleLowerCase)
9789 #[wasm_bindgen(method, js_class = "String", js_name = toLocaleLowerCase)]
9790 pub fn to_locale_lower_case(this: &JsString, locale: Option<&str>) -> JsString;
9791
9792 /// The `toLocaleUpperCase()` method returns the calling string value converted to upper case,
9793 /// according to any locale-specific case mappings.
9794 ///
9795 /// [MDN documentation](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/String/toLocaleUpperCase)
9796 #[wasm_bindgen(method, js_class = "String", js_name = toLocaleUpperCase)]
9797 pub fn to_locale_upper_case(this: &JsString, locale: Option<&str>) -> JsString;
9798
9799 /// The `toLowerCase()` method returns the calling string value
9800 /// converted to lower case.
9801 ///
9802 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLowerCase)
9803 #[wasm_bindgen(method, js_class = "String", js_name = toLowerCase)]
9804 pub fn to_lower_case(this: &JsString) -> JsString;
9805
9806 /// The `toString()` method returns a string representing the specified
9807 /// object.
9808 ///
9809 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toString)
9810 #[cfg(not(js_sys_unstable_apis))]
9811 #[wasm_bindgen(method, js_class = "String", js_name = toString)]
9812 pub fn to_string(this: &JsString) -> JsString;
9813
9814 /// The `toUpperCase()` method returns the calling string value converted to
9815 /// uppercase (the value will be converted to a string if it isn't one).
9816 ///
9817 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase)
9818 #[wasm_bindgen(method, js_class = "String", js_name = toUpperCase)]
9819 pub fn to_upper_case(this: &JsString) -> JsString;
9820
9821 /// The `trim()` method removes whitespace from both ends of a string.
9822 /// Whitespace in this context is all the whitespace characters (space, tab,
9823 /// no-break space, etc.) and all the line terminator characters (LF, CR,
9824 /// etc.).
9825 ///
9826 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trim)
9827 #[wasm_bindgen(method, js_class = "String")]
9828 pub fn trim(this: &JsString) -> JsString;
9829
9830 /// The `trimEnd()` method removes whitespace from the end of a string.
9831 /// `trimRight()` is an alias of this method.
9832 ///
9833 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimEnd)
9834 #[wasm_bindgen(method, js_class = "String", js_name = trimEnd)]
9835 pub fn trim_end(this: &JsString) -> JsString;
9836
9837 /// The `trimEnd()` method removes whitespace from the end of a string.
9838 /// `trimRight()` is an alias of this method.
9839 ///
9840 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimEnd)
9841 #[wasm_bindgen(method, js_class = "String", js_name = trimRight)]
9842 pub fn trim_right(this: &JsString) -> JsString;
9843
9844 /// The `trimStart()` method removes whitespace from the beginning of a
9845 /// string. `trimLeft()` is an alias of this method.
9846 ///
9847 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimStart)
9848 #[wasm_bindgen(method, js_class = "String", js_name = trimStart)]
9849 pub fn trim_start(this: &JsString) -> JsString;
9850
9851 /// The `trimStart()` method removes whitespace from the beginning of a
9852 /// string. `trimLeft()` is an alias of this method.
9853 ///
9854 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimStart)
9855 #[wasm_bindgen(method, js_class = "String", js_name = trimLeft)]
9856 pub fn trim_left(this: &JsString) -> JsString;
9857
9858 /// The `valueOf()` method returns the primitive value of a `String` object.
9859 ///
9860 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/valueOf)
9861 #[wasm_bindgen(method, js_class = "String", js_name = valueOf)]
9862 pub fn value_of(this: &JsString) -> JsString;
9863
9864 /// The static `raw()` method is a tag function of template literals,
9865 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9866 ///
9867 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9868 #[wasm_bindgen(catch, variadic, static_method_of = JsString, js_class = "String")]
9869 pub fn raw(call_site: &Object, substitutions: &Array) -> Result<JsString, JsValue>;
9870
9871 /// The static `raw()` method is a tag function of template literals,
9872 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9873 ///
9874 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9875 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9876 pub fn raw_0(call_site: &Object) -> Result<JsString, JsValue>;
9877
9878 /// The static `raw()` method is a tag function of template literals,
9879 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9880 ///
9881 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9882 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9883 pub fn raw_1(call_site: &Object, substitutions_1: &str) -> Result<JsString, JsValue>;
9884
9885 /// The static `raw()` method is a tag function of template literals,
9886 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9887 ///
9888 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9889 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9890 pub fn raw_2(
9891 call_site: &Object,
9892 substitutions1: &str,
9893 substitutions2: &str,
9894 ) -> Result<JsString, JsValue>;
9895
9896 /// The static `raw()` method is a tag function of template literals,
9897 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9898 ///
9899 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9900 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9901 pub fn raw_3(
9902 call_site: &Object,
9903 substitutions1: &str,
9904 substitutions2: &str,
9905 substitutions3: &str,
9906 ) -> Result<JsString, JsValue>;
9907
9908 /// The static `raw()` method is a tag function of template literals,
9909 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9910 ///
9911 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9912 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9913 pub fn raw_4(
9914 call_site: &Object,
9915 substitutions1: &str,
9916 substitutions2: &str,
9917 substitutions3: &str,
9918 substitutions4: &str,
9919 ) -> Result<JsString, JsValue>;
9920
9921 /// The static `raw()` method is a tag function of template literals,
9922 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9923 ///
9924 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9925 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9926 pub fn raw_5(
9927 call_site: &Object,
9928 substitutions1: &str,
9929 substitutions2: &str,
9930 substitutions3: &str,
9931 substitutions4: &str,
9932 substitutions5: &str,
9933 ) -> Result<JsString, JsValue>;
9934
9935 /// The static `raw()` method is a tag function of template literals,
9936 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9937 ///
9938 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9939 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9940 pub fn raw_6(
9941 call_site: &Object,
9942 substitutions1: &str,
9943 substitutions2: &str,
9944 substitutions3: &str,
9945 substitutions4: &str,
9946 substitutions5: &str,
9947 substitutions6: &str,
9948 ) -> Result<JsString, JsValue>;
9949
9950 /// The static `raw()` method is a tag function of template literals,
9951 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9952 ///
9953 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9954 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9955 pub fn raw_7(
9956 call_site: &Object,
9957 substitutions1: &str,
9958 substitutions2: &str,
9959 substitutions3: &str,
9960 substitutions4: &str,
9961 substitutions5: &str,
9962 substitutions6: &str,
9963 substitutions7: &str,
9964 ) -> Result<JsString, JsValue>;
9965}
9966
9967// These upcasts are non-castable due to the constraints on the function
9968// but the UpcastFrom covariance must still extend through closure types.
9969// (impl UpcastFrom really just means CovariantGeneric relation)
9970impl UpcastFrom<String> for JsString {}
9971impl UpcastFrom<JsString> for String {}
9972
9973impl UpcastFrom<&str> for JsString {}
9974impl UpcastFrom<JsString> for &str {}
9975
9976impl UpcastFrom<char> for JsString {}
9977impl UpcastFrom<JsString> for char {}
9978
9979impl wasm_bindgen::__rt::marker::JsStringLikeSealed for JsString {}
9980impl wasm_bindgen::__rt::marker::JsStringLikeSealed for &JsString {}
9981impl wasm_bindgen::JsStringLike for JsString {}
9982impl wasm_bindgen::JsStringLike for &JsString {}
9983
9984impl JsString {
9985 /// Returns the `JsString` value of this JS value if it's an instance of a
9986 /// string.
9987 ///
9988 /// If this JS value is not an instance of a string then this returns
9989 /// `None`.
9990 #[cfg(not(js_sys_unstable_apis))]
9991 #[deprecated(note = "recommended to use dyn_ref instead which is now equivalent")]
9992 pub fn try_from(val: &JsValue) -> Option<&JsString> {
9993 val.dyn_ref()
9994 }
9995
9996 /// Returns whether this string is a valid UTF-16 string.
9997 ///
9998 /// This is useful for learning whether `String::from(..)` will return a
9999 /// lossless representation of the JS string. If this string contains
10000 /// unpaired surrogates then `String::from` will succeed but it will be a
10001 /// lossy representation of the JS string because unpaired surrogates will
10002 /// become replacement characters.
10003 ///
10004 /// If this function returns `false` then to get a lossless representation
10005 /// of the string you'll need to manually use the `iter` method (or the
10006 /// `char_code_at` accessor) to view the raw character codes.
10007 ///
10008 /// For more information, see the documentation on [JS strings vs Rust
10009 /// strings][docs]
10010 ///
10011 /// [docs]: https://wasm-bindgen.github.io/wasm-bindgen/reference/types/str.html
10012 pub fn is_valid_utf16(&self) -> bool {
10013 core::char::decode_utf16(self.iter()).all(|i| i.is_ok())
10014 }
10015
10016 /// Returns an iterator over the `u16` character codes that make up this JS
10017 /// string.
10018 ///
10019 /// This method will call `char_code_at` for each code in this JS string,
10020 /// returning an iterator of the codes in sequence.
10021 pub fn iter(
10022 &self,
10023 ) -> impl ExactSizeIterator<Item = u16> + DoubleEndedIterator<Item = u16> + '_ {
10024 (0..self.length()).map(move |i| self.char_code_at(i) as u16)
10025 }
10026
10027 /// If this string consists of a single Unicode code point, then this method
10028 /// converts it into a Rust `char` without doing any allocations.
10029 ///
10030 /// If this JS value is not a valid UTF-8 or consists of more than a single
10031 /// codepoint, then this returns `None`.
10032 ///
10033 /// Note that a single Unicode code point might be represented as more than
10034 /// one code unit on the JavaScript side. For example, a JavaScript string
10035 /// `"\uD801\uDC37"` is actually a single Unicode code point U+10437 which
10036 /// corresponds to a character '𐐷'.
10037 pub fn as_char(&self) -> Option<char> {
10038 let len = self.length();
10039
10040 if len == 0 || len > 2 {
10041 return None;
10042 }
10043
10044 #[cfg(not(js_sys_unstable_apis))]
10045 let cp = self.code_point_at(0).as_f64().unwrap_throw() as u32;
10046 #[cfg(js_sys_unstable_apis)]
10047 let cp = self.code_point_at(0)?;
10048
10049 let c = core::char::from_u32(cp)?;
10050
10051 if c.len_utf16() as u32 == len {
10052 Some(c)
10053 } else {
10054 None
10055 }
10056 }
10057}
10058
10059impl PartialEq<str> for JsString {
10060 #[allow(clippy::cmp_owned)] // prevent infinite recursion
10061 fn eq(&self, other: &str) -> bool {
10062 String::from(self) == other
10063 }
10064}
10065
10066impl<'a> PartialEq<&'a str> for JsString {
10067 fn eq(&self, other: &&'a str) -> bool {
10068 <JsString as PartialEq<str>>::eq(self, other)
10069 }
10070}
10071
10072impl PartialEq<String> for JsString {
10073 fn eq(&self, other: &String) -> bool {
10074 <JsString as PartialEq<str>>::eq(self, other)
10075 }
10076}
10077
10078impl<'a> PartialEq<&'a String> for JsString {
10079 fn eq(&self, other: &&'a String) -> bool {
10080 <JsString as PartialEq<str>>::eq(self, other)
10081 }
10082}
10083
10084impl Default for JsString {
10085 fn default() -> Self {
10086 Self::from("")
10087 }
10088}
10089
10090impl<'a> From<&'a str> for JsString {
10091 fn from(s: &'a str) -> Self {
10092 JsString::unchecked_from_js(JsValue::from_str(s))
10093 }
10094}
10095
10096impl From<String> for JsString {
10097 fn from(s: String) -> Self {
10098 From::from(&*s)
10099 }
10100}
10101
10102impl From<char> for JsString {
10103 #[inline]
10104 fn from(c: char) -> Self {
10105 JsString::from_code_point1(c as u32).unwrap_throw()
10106 }
10107}
10108
10109impl<'a> From<&'a JsString> for String {
10110 fn from(s: &'a JsString) -> Self {
10111 s.obj.as_string().unwrap_throw()
10112 }
10113}
10114
10115impl From<JsString> for String {
10116 fn from(s: JsString) -> Self {
10117 From::from(&s)
10118 }
10119}
10120
10121impl fmt::Debug for JsString {
10122 #[inline]
10123 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10124 fmt::Debug::fmt(&String::from(self), f)
10125 }
10126}
10127
10128impl fmt::Display for JsString {
10129 #[inline]
10130 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10131 fmt::Display::fmt(&String::from(self), f)
10132 }
10133}
10134
10135impl str::FromStr for JsString {
10136 type Err = convert::Infallible;
10137 fn from_str(s: &str) -> Result<Self, Self::Err> {
10138 Ok(JsString::from(s))
10139 }
10140}
10141
10142// Symbol
10143#[wasm_bindgen]
10144extern "C" {
10145 #[wasm_bindgen(is_type_of = JsValue::is_symbol, typescript_type = "Symbol")]
10146 #[derive(Clone, Debug)]
10147 pub type Symbol;
10148
10149 /// The `Symbol.hasInstance` well-known symbol is used to determine
10150 /// if a constructor object recognizes an object as its instance.
10151 /// The `instanceof` operator's behavior can be customized by this symbol.
10152 ///
10153 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/hasInstance)
10154 #[wasm_bindgen(static_method_of = Symbol, getter, js_name = hasInstance)]
10155 pub fn has_instance() -> Symbol;
10156
10157 /// The `Symbol.isConcatSpreadable` well-known symbol is used to configure
10158 /// if an object should be flattened to its array elements when using the
10159 /// `Array.prototype.concat()` method.
10160 ///
10161 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/isConcatSpreadable)
10162 #[wasm_bindgen(static_method_of = Symbol, getter, js_name = isConcatSpreadable)]
10163 pub fn is_concat_spreadable() -> Symbol;
10164
10165 /// The `Symbol.asyncIterator` well-known symbol specifies the default AsyncIterator for an object.
10166 /// If this property is set on an object, it is an async iterable and can be used in a `for await...of` loop.
10167 ///
10168 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/asyncIterator)
10169 #[wasm_bindgen(static_method_of = Symbol, getter, js_name = asyncIterator)]
10170 pub fn async_iterator() -> Symbol;
10171
10172 /// The `Symbol.iterator` well-known symbol specifies the default iterator
10173 /// for an object. Used by `for...of`.
10174 ///
10175 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/iterator)
10176 #[wasm_bindgen(static_method_of = Symbol, getter)]
10177 pub fn iterator() -> Symbol;
10178
10179 /// The `Symbol.match` well-known symbol specifies the matching of a regular
10180 /// expression against a string. This function is called by the
10181 /// `String.prototype.match()` method.
10182 ///
10183 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/match)
10184 #[wasm_bindgen(static_method_of = Symbol, getter, js_name = match)]
10185 pub fn match_() -> Symbol;
10186
10187 /// The `Symbol.replace` well-known symbol specifies the method that
10188 /// replaces matched substrings of a string. This function is called by the
10189 /// `String.prototype.replace()` method.
10190 ///
10191 /// For more information, see `RegExp.prototype[@@replace]()` and
10192 /// `String.prototype.replace()`.
10193 ///
10194 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/replace)
10195 #[wasm_bindgen(static_method_of = Symbol, getter)]
10196 pub fn replace() -> Symbol;
10197
10198 /// The `Symbol.search` well-known symbol specifies the method that returns
10199 /// the index within a string that matches the regular expression. This
10200 /// function is called by the `String.prototype.search()` method.
10201 ///
10202 /// For more information, see `RegExp.prototype[@@search]()` and
10203 /// `String.prototype.search()`.
10204 ///
10205 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/search)
10206 #[wasm_bindgen(static_method_of = Symbol, getter)]
10207 pub fn search() -> Symbol;
10208
10209 /// The well-known symbol `Symbol.species` specifies a function-valued
10210 /// property that the constructor function uses to create derived objects.
10211 ///
10212 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/species)
10213 #[wasm_bindgen(static_method_of = Symbol, getter)]
10214 pub fn species() -> Symbol;
10215
10216 /// The `Symbol.split` well-known symbol specifies the method that splits a
10217 /// string at the indices that match a regular expression. This function is
10218 /// called by the `String.prototype.split()` method.
10219 ///
10220 /// For more information, see `RegExp.prototype[@@split]()` and
10221 /// `String.prototype.split()`.
10222 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/split)
10223 #[wasm_bindgen(static_method_of = Symbol, getter)]
10224 pub fn split() -> Symbol;
10225
10226 /// The `Symbol.toPrimitive` is a symbol that specifies a function valued
10227 /// property that is called to convert an object to a corresponding
10228 /// primitive value.
10229 ///
10230 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toPrimitive)
10231 #[wasm_bindgen(static_method_of = Symbol, getter, js_name = toPrimitive)]
10232 pub fn to_primitive() -> Symbol;
10233
10234 /// The `Symbol.toStringTag` well-known symbol is a string valued property
10235 /// that is used in the creation of the default string description of an
10236 /// object. It is accessed internally by the `Object.prototype.toString()`
10237 /// method.
10238 ///
10239 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toString)
10240 #[wasm_bindgen(static_method_of = Symbol, getter, js_name = toStringTag)]
10241 pub fn to_string_tag() -> Symbol;
10242
10243 /// The `Symbol.for(key)` method searches for existing symbols in a runtime-wide symbol registry with
10244 /// the given key and returns it if found.
10245 /// Otherwise a new symbol gets created in the global symbol registry with this key.
10246 ///
10247 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/for)
10248 #[wasm_bindgen(static_method_of = Symbol, js_name = for)]
10249 pub fn for_(key: &str) -> Symbol;
10250
10251 /// The `Symbol.keyFor(sym)` method retrieves a shared symbol key from the global symbol registry for the given symbol.
10252 ///
10253 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/keyFor)
10254 #[wasm_bindgen(static_method_of = Symbol, js_name = keyFor)]
10255 pub fn key_for(sym: &Symbol) -> JsValue;
10256
10257 // Next major: deprecate
10258 /// The `toString()` method returns a string representing the specified Symbol object.
10259 ///
10260 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toString)
10261 #[wasm_bindgen(method, js_name = toString)]
10262 pub fn to_string(this: &Symbol) -> JsString;
10263
10264 /// The `toString()` method returns a string representing the specified Symbol object.
10265 ///
10266 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toString)
10267 #[wasm_bindgen(method, js_name = toString)]
10268 pub fn to_js_string(this: &Symbol) -> JsString;
10269
10270 /// The `Symbol.unscopables` well-known symbol is used to specify an object
10271 /// value of whose own and inherited property names are excluded from the
10272 /// with environment bindings of the associated object.
10273 ///
10274 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/unscopables)
10275 #[wasm_bindgen(static_method_of = Symbol, getter)]
10276 pub fn unscopables() -> Symbol;
10277
10278 /// The `valueOf()` method returns the primitive value of a Symbol object.
10279 ///
10280 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/valueOf)
10281 #[wasm_bindgen(method, js_name = valueOf)]
10282 pub fn value_of(this: &Symbol) -> Symbol;
10283}
10284
10285mod primitive_union_sealed {
10286 /// Seal for the TypeScript primitive-union marker traits.
10287 pub trait Sealed {}
10288}
10289
10290macro_rules! impl_primitive_union_category {
10291 ($trait:path, bigint) => {
10292 impl $trait for i64 {}
10293 impl $trait for u64 {}
10294 impl $trait for i128 {}
10295 impl $trait for u128 {}
10296 impl $trait for BigInt {}
10297 impl $trait for &BigInt {}
10298 };
10299 ($trait:path, boolean) => {
10300 impl $trait for bool {}
10301 impl $trait for Boolean {}
10302 impl $trait for &Boolean {}
10303 };
10304 ($trait:path, number) => {
10305 impl $trait for i8 {}
10306 impl $trait for u8 {}
10307 impl $trait for i16 {}
10308 impl $trait for u16 {}
10309 impl $trait for i32 {}
10310 impl $trait for u32 {}
10311 impl $trait for isize {}
10312 impl $trait for usize {}
10313 impl $trait for f32 {}
10314 impl $trait for f64 {}
10315 impl $trait for Number {}
10316 impl $trait for &Number {}
10317 };
10318 // Mirrors the sealed `wasm_bindgen::JsStringLike` implementations. A
10319 // blanket `impl<T: JsStringLike>` would overlap with the concrete impls
10320 // below, since coherence cannot rule out a foreign trait being implemented
10321 // for `i32` and friends.
10322 ($trait:path, string) => {
10323 impl $trait for String {}
10324 impl $trait for &str {}
10325 impl $trait for JsString {}
10326 impl $trait for &JsString {}
10327 };
10328 ($trait:path, symbol) => {
10329 impl $trait for Symbol {}
10330 impl $trait for &Symbol {}
10331 };
10332}
10333
10334impl_primitive_union_category!(primitive_union_sealed::Sealed, bigint);
10335impl_primitive_union_category!(primitive_union_sealed::Sealed, boolean);
10336impl_primitive_union_category!(primitive_union_sealed::Sealed, number);
10337impl_primitive_union_category!(primitive_union_sealed::Sealed, string);
10338impl_primitive_union_category!(primitive_union_sealed::Sealed, symbol);
10339
10340macro_rules! primitive_union_category_doc {
10341 (bigint) => {
10342 "- `bigint`: `i64`, `u64`, `i128`, `u128`, [`BigInt`], and `&BigInt`\n"
10343 };
10344 (boolean) => {
10345 "- `boolean`: `bool`, [`Boolean`], and `&Boolean`\n"
10346 };
10347 (number) => {
10348 "- `number`: `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `isize`, `usize`, `f32`, `f64`, [`Number`], and `&Number`\n"
10349 };
10350 (string) => {
10351 "- `string`: `String`, `&str`, [`JsString`], and `&JsString` (the \
10352 [`JsStringLike`](wasm_bindgen::JsStringLike) types)\n"
10353 };
10354 (symbol) => {
10355 "- `symbol`: [`Symbol`] and `&Symbol`\n"
10356 };
10357}
10358
10359macro_rules! define_primitive_union_traits {
10360 ($(($(#[$attr:meta])* $name:ident, $typescript:literal, [$($supertrait:ident),*], [$($category:ident),+])),* $(,)?) => {
10361 $(
10362 $(#[$attr])*
10363 #[doc = concat!(
10364 "Marker for Rust parameter types represented by the TypeScript union `",
10365 $typescript,
10366 "`.\n\n",
10367 "Use this trait as a bound on an `experimental_generic_mono` ",
10368 "JavaScript import. Each monomorphisation retains its concrete ",
10369 "ABI representation; this marker only restricts which Rust types ",
10370 "may instantiate the parameter.\n\n",
10371 "The union's primitive categories use these Rust representations:\n\n",
10372 $(primitive_union_category_doc!($category),)+
10373 "\nThis trait is experimental and may change or be removed as ",
10374 "`experimental_generic_mono` evolves."
10375 )]
10376 pub trait $name: IntoWasmAbi + primitive_union_sealed::Sealed $(+ $supertrait)* {}
10377
10378 $(impl_primitive_union_category!($name, $category);)+
10379 )*
10380 };
10381}
10382
10383// The catalog covers every union of two or more of the primitive categories
10384// with a Rust-native ABI representation (`bigint`, `boolean`, `number`, and
10385// `string`). `symbol` crosses the boundary as an ordinary JS handle, so unions
10386// containing it are better expressed with a `&Symbol` overload; the one
10387// exception is `PropertyKey`, where `symbol` carries semantic identity.
10388define_primitive_union_traits! {
10389 (
10390 JsBigIntOrBooleanOrNumberOrStringLike,
10391 "bigint | boolean | number | string",
10392 [],
10393 [bigint, boolean, number, string]
10394 ),
10395 (
10396 JsBigIntOrBooleanOrNumberLike,
10397 "bigint | boolean | number",
10398 [JsBigIntOrBooleanOrNumberOrStringLike],
10399 [bigint, boolean, number]
10400 ),
10401 (
10402 JsBigIntOrBooleanOrStringLike,
10403 "bigint | boolean | string",
10404 [JsBigIntOrBooleanOrNumberOrStringLike],
10405 [bigint, boolean, string]
10406 ),
10407 (
10408 JsBigIntOrNumberOrStringLike,
10409 "bigint | number | string",
10410 [JsBigIntOrBooleanOrNumberOrStringLike],
10411 [bigint, number, string]
10412 ),
10413 (
10414 JsBooleanOrNumberOrStringLike,
10415 "boolean | number | string",
10416 [JsBigIntOrBooleanOrNumberOrStringLike],
10417 [boolean, number, string]
10418 ),
10419 (
10420 JsBigIntOrBooleanLike,
10421 "bigint | boolean",
10422 [JsBigIntOrBooleanOrNumberLike, JsBigIntOrBooleanOrStringLike],
10423 [bigint, boolean]
10424 ),
10425 (
10426 JsBigIntOrNumberLike,
10427 "bigint | number",
10428 [JsBigIntOrBooleanOrNumberLike, JsBigIntOrNumberOrStringLike],
10429 [bigint, number]
10430 ),
10431 (
10432 JsBigIntOrStringLike,
10433 "bigint | string",
10434 [JsBigIntOrBooleanOrStringLike, JsBigIntOrNumberOrStringLike],
10435 [bigint, string]
10436 ),
10437 (
10438 JsBooleanOrNumberLike,
10439 "boolean | number",
10440 [JsBigIntOrBooleanOrNumberLike, JsBooleanOrNumberOrStringLike],
10441 [boolean, number]
10442 ),
10443 (
10444 JsBooleanOrStringLike,
10445 "boolean | string",
10446 [JsBigIntOrBooleanOrStringLike, JsBooleanOrNumberOrStringLike],
10447 [boolean, string]
10448 ),
10449 (
10450 JsNumberOrStringLike,
10451 "number | string",
10452 [
10453 JsBigIntOrNumberOrStringLike,
10454 JsBooleanOrNumberOrStringLike,
10455 PropertyKey
10456 ],
10457 [number, string]
10458 ),
10459 (
10460 /// TypeScript's `PropertyKey`: the key types accepted by JavaScript
10461 /// property operations and by TypeScript's `Record`.
10462 ///
10463 PropertyKey,
10464 "number | string | symbol",
10465 [],
10466 [number, string, symbol]
10467 ),
10468}
10469
10470#[allow(non_snake_case)]
10471pub mod Intl {
10472 use super::*;
10473
10474 // Intl
10475 #[wasm_bindgen]
10476 extern "C" {
10477 /// The `Intl.getCanonicalLocales()` method returns an array containing
10478 /// the canonical locale names. Duplicates will be omitted and elements
10479 /// will be validated as structurally valid language tags.
10480 ///
10481 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/getCanonicalLocales)
10482 #[cfg(not(js_sys_unstable_apis))]
10483 #[wasm_bindgen(js_name = getCanonicalLocales, js_namespace = Intl)]
10484 pub fn get_canonical_locales(s: &JsValue) -> Array;
10485
10486 /// The `Intl.getCanonicalLocales()` method returns an array containing
10487 /// the canonical locale names. Duplicates will be omitted and elements
10488 /// will be validated as structurally valid language tags.
10489 ///
10490 /// Throws a `RangeError` if any of the strings are not valid locale identifiers.
10491 ///
10492 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/getCanonicalLocales)
10493 #[cfg(js_sys_unstable_apis)]
10494 #[wasm_bindgen(js_name = getCanonicalLocales, js_namespace = Intl, catch)]
10495 pub fn get_canonical_locales(s: &[JsString]) -> Result<Array<JsString>, JsValue>;
10496
10497 /// The `Intl.supportedValuesOf()` method returns an array containing the
10498 /// supported calendar, collation, currency, numbering system, or unit values
10499 /// supported by the implementation.
10500 ///
10501 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/supportedValuesOf)
10502 #[wasm_bindgen(js_name = supportedValuesOf, js_namespace = Intl)]
10503 pub fn supported_values_of(key: SupportedValuesKey) -> Array<JsString>;
10504 }
10505
10506 // Intl string enums
10507
10508 /// Key for `Intl.supportedValuesOf()`.
10509 #[wasm_bindgen]
10510 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10511 pub enum SupportedValuesKey {
10512 Calendar = "calendar",
10513 Collation = "collation",
10514 Currency = "currency",
10515 NumberingSystem = "numberingSystem",
10516 TimeZone = "timeZone",
10517 Unit = "unit",
10518 }
10519
10520 /// Locale matching algorithm for Intl constructors.
10521 #[wasm_bindgen]
10522 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10523 pub enum LocaleMatcher {
10524 Lookup = "lookup",
10525 BestFit = "best fit",
10526 }
10527
10528 /// Usage for `Intl.Collator`.
10529 #[wasm_bindgen]
10530 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10531 pub enum CollatorUsage {
10532 Sort = "sort",
10533 Search = "search",
10534 }
10535
10536 /// Sensitivity for `Intl.Collator`.
10537 #[wasm_bindgen]
10538 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10539 pub enum CollatorSensitivity {
10540 Base = "base",
10541 Accent = "accent",
10542 Case = "case",
10543 Variant = "variant",
10544 }
10545
10546 /// Case first option for `Intl.Collator`.
10547 #[wasm_bindgen]
10548 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10549 pub enum CollatorCaseFirst {
10550 Upper = "upper",
10551 Lower = "lower",
10552 False = "false",
10553 }
10554
10555 /// Style for `Intl.NumberFormat`.
10556 #[wasm_bindgen]
10557 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10558 pub enum NumberFormatStyle {
10559 Decimal = "decimal",
10560 Currency = "currency",
10561 Percent = "percent",
10562 Unit = "unit",
10563 }
10564
10565 /// Currency display for `Intl.NumberFormat`.
10566 #[wasm_bindgen]
10567 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10568 pub enum CurrencyDisplay {
10569 Code = "code",
10570 Symbol = "symbol",
10571 NarrowSymbol = "narrowSymbol",
10572 Name = "name",
10573 }
10574
10575 /// Currency sign for `Intl.NumberFormat`.
10576 #[wasm_bindgen]
10577 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10578 pub enum CurrencySign {
10579 Standard = "standard",
10580 Accounting = "accounting",
10581 }
10582
10583 /// Unit display for `Intl.NumberFormat`.
10584 #[wasm_bindgen]
10585 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10586 pub enum UnitDisplay {
10587 Short = "short",
10588 Narrow = "narrow",
10589 Long = "long",
10590 }
10591
10592 /// Notation for `Intl.NumberFormat`.
10593 #[wasm_bindgen]
10594 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10595 pub enum NumberFormatNotation {
10596 Standard = "standard",
10597 Scientific = "scientific",
10598 Engineering = "engineering",
10599 Compact = "compact",
10600 }
10601
10602 /// Compact display for `Intl.NumberFormat`.
10603 #[wasm_bindgen]
10604 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10605 pub enum CompactDisplay {
10606 Short = "short",
10607 Long = "long",
10608 }
10609
10610 /// Sign display for `Intl.NumberFormat`.
10611 #[wasm_bindgen]
10612 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10613 pub enum SignDisplay {
10614 Auto = "auto",
10615 Never = "never",
10616 Always = "always",
10617 ExceptZero = "exceptZero",
10618 }
10619
10620 /// Rounding mode for `Intl.NumberFormat`.
10621 #[wasm_bindgen]
10622 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10623 pub enum RoundingMode {
10624 Ceil = "ceil",
10625 Floor = "floor",
10626 Expand = "expand",
10627 Trunc = "trunc",
10628 HalfCeil = "halfCeil",
10629 HalfFloor = "halfFloor",
10630 HalfExpand = "halfExpand",
10631 HalfTrunc = "halfTrunc",
10632 HalfEven = "halfEven",
10633 }
10634
10635 /// Rounding priority for `Intl.NumberFormat`.
10636 #[wasm_bindgen]
10637 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10638 pub enum RoundingPriority {
10639 Auto = "auto",
10640 MorePrecision = "morePrecision",
10641 LessPrecision = "lessPrecision",
10642 }
10643
10644 /// Trailing zero display for `Intl.NumberFormat`.
10645 #[wasm_bindgen]
10646 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10647 pub enum TrailingZeroDisplay {
10648 Auto = "auto",
10649 StripIfInteger = "stripIfInteger",
10650 }
10651
10652 /// Use grouping option for `Intl.NumberFormat`.
10653 ///
10654 /// Determines whether to use grouping separators, such as thousands
10655 /// separators or thousand/lakh/crore separators.
10656 ///
10657 /// The default is `Min2` if notation is "compact", and `Auto` otherwise.
10658 ///
10659 /// Note: The string values `"true"` and `"false"` are accepted by JavaScript
10660 /// but are always converted to the default value. Use `True` and `False`
10661 /// variants for the boolean behavior.
10662 ///
10663 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#usegrouping)
10664 #[wasm_bindgen]
10665 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10666 pub enum UseGrouping {
10667 /// Display grouping separators even if the locale prefers otherwise.
10668 Always = "always",
10669 /// Display grouping separators based on the locale preference,
10670 /// which may also be dependent on the currency.
10671 Auto = "auto",
10672 /// Display grouping separators when there are at least 2 digits in a group.
10673 Min2 = "min2",
10674 /// Same as `Always`. Display grouping separators even if the locale prefers otherwise.
10675 True = "true",
10676 /// Display no grouping separators.
10677 False = "false",
10678 }
10679
10680 /// Date/time style for `Intl.DateTimeFormat`.
10681 #[wasm_bindgen]
10682 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10683 pub enum DateTimeStyle {
10684 Full = "full",
10685 Long = "long",
10686 Medium = "medium",
10687 Short = "short",
10688 }
10689
10690 /// Hour cycle for `Intl.DateTimeFormat`.
10691 #[wasm_bindgen]
10692 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10693 pub enum HourCycle {
10694 H11 = "h11",
10695 H12 = "h12",
10696 H23 = "h23",
10697 H24 = "h24",
10698 }
10699
10700 /// Weekday format for `Intl.DateTimeFormat`.
10701 #[wasm_bindgen]
10702 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10703 pub enum WeekdayFormat {
10704 Narrow = "narrow",
10705 Short = "short",
10706 Long = "long",
10707 }
10708
10709 /// Era format for `Intl.DateTimeFormat`.
10710 #[wasm_bindgen]
10711 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10712 pub enum EraFormat {
10713 Narrow = "narrow",
10714 Short = "short",
10715 Long = "long",
10716 }
10717
10718 /// Year format for `Intl.DateTimeFormat`.
10719 #[wasm_bindgen]
10720 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10721 pub enum YearFormat {
10722 Numeric = "numeric",
10723 TwoDigit = "2-digit",
10724 }
10725
10726 /// Month format for `Intl.DateTimeFormat`.
10727 #[wasm_bindgen]
10728 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10729 pub enum MonthFormat {
10730 #[wasm_bindgen]
10731 Numeric = "numeric",
10732 #[wasm_bindgen]
10733 TwoDigit = "2-digit",
10734 #[wasm_bindgen]
10735 Narrow = "narrow",
10736 #[wasm_bindgen]
10737 Short = "short",
10738 #[wasm_bindgen]
10739 Long = "long",
10740 }
10741
10742 /// Day format for `Intl.DateTimeFormat`.
10743 #[wasm_bindgen]
10744 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10745 pub enum DayFormat {
10746 #[wasm_bindgen]
10747 Numeric = "numeric",
10748 #[wasm_bindgen]
10749 TwoDigit = "2-digit",
10750 }
10751
10752 /// Hour/minute/second format for `Intl.DateTimeFormat`.
10753 #[wasm_bindgen]
10754 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10755 pub enum NumericFormat {
10756 #[wasm_bindgen]
10757 Numeric = "numeric",
10758 #[wasm_bindgen]
10759 TwoDigit = "2-digit",
10760 }
10761
10762 /// Time zone name format for `Intl.DateTimeFormat`.
10763 #[wasm_bindgen]
10764 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10765 pub enum TimeZoneNameFormat {
10766 Short = "short",
10767 Long = "long",
10768 ShortOffset = "shortOffset",
10769 LongOffset = "longOffset",
10770 ShortGeneric = "shortGeneric",
10771 LongGeneric = "longGeneric",
10772 }
10773
10774 /// Day period format for `Intl.DateTimeFormat`.
10775 #[wasm_bindgen]
10776 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10777 pub enum DayPeriodFormat {
10778 Narrow = "narrow",
10779 Short = "short",
10780 Long = "long",
10781 }
10782
10783 /// Part type for `DateTimeFormat.formatToParts()`.
10784 #[wasm_bindgen]
10785 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10786 pub enum DateTimeFormatPartType {
10787 Day = "day",
10788 DayPeriod = "dayPeriod",
10789 Era = "era",
10790 FractionalSecond = "fractionalSecond",
10791 Hour = "hour",
10792 Literal = "literal",
10793 Minute = "minute",
10794 Month = "month",
10795 RelatedYear = "relatedYear",
10796 Second = "second",
10797 TimeZoneName = "timeZoneName",
10798 Weekday = "weekday",
10799 Year = "year",
10800 YearName = "yearName",
10801 }
10802
10803 /// Part type for `NumberFormat.formatToParts()`.
10804 #[wasm_bindgen]
10805 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10806 pub enum NumberFormatPartType {
10807 Compact = "compact",
10808 Currency = "currency",
10809 Decimal = "decimal",
10810 ExponentInteger = "exponentInteger",
10811 ExponentMinusSign = "exponentMinusSign",
10812 ExponentSeparator = "exponentSeparator",
10813 Fraction = "fraction",
10814 Group = "group",
10815 Infinity = "infinity",
10816 Integer = "integer",
10817 Literal = "literal",
10818 MinusSign = "minusSign",
10819 Nan = "nan",
10820 PercentSign = "percentSign",
10821 PlusSign = "plusSign",
10822 Unit = "unit",
10823 Unknown = "unknown",
10824 }
10825
10826 /// Type for `Intl.PluralRules` (cardinal or ordinal).
10827 #[wasm_bindgen]
10828 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10829 pub enum PluralRulesType {
10830 Cardinal = "cardinal",
10831 Ordinal = "ordinal",
10832 }
10833
10834 /// Plural category returned by `PluralRules.select()`.
10835 #[wasm_bindgen]
10836 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10837 pub enum PluralCategory {
10838 Zero = "zero",
10839 One = "one",
10840 Two = "two",
10841 Few = "few",
10842 Many = "many",
10843 Other = "other",
10844 }
10845
10846 /// Numeric option for `Intl.RelativeTimeFormat`.
10847 #[wasm_bindgen]
10848 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10849 pub enum RelativeTimeFormatNumeric {
10850 Always = "always",
10851 Auto = "auto",
10852 }
10853
10854 /// Style for `Intl.RelativeTimeFormat`.
10855 #[wasm_bindgen]
10856 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10857 pub enum RelativeTimeFormatStyle {
10858 Long = "long",
10859 Short = "short",
10860 Narrow = "narrow",
10861 }
10862
10863 /// Unit for `RelativeTimeFormat.format()`.
10864 #[wasm_bindgen]
10865 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10866 pub enum RelativeTimeFormatUnit {
10867 Year = "year",
10868 Years = "years",
10869 Quarter = "quarter",
10870 Quarters = "quarters",
10871 Month = "month",
10872 Months = "months",
10873 Week = "week",
10874 Weeks = "weeks",
10875 Day = "day",
10876 Days = "days",
10877 Hour = "hour",
10878 Hours = "hours",
10879 Minute = "minute",
10880 Minutes = "minutes",
10881 Second = "second",
10882 Seconds = "seconds",
10883 }
10884
10885 /// Part type for `RelativeTimeFormat.formatToParts()`.
10886 #[wasm_bindgen]
10887 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10888 pub enum RelativeTimeFormatPartType {
10889 Literal = "literal",
10890 Integer = "integer",
10891 Decimal = "decimal",
10892 Fraction = "fraction",
10893 }
10894
10895 /// Source indicator for range format parts.
10896 ///
10897 /// Indicates which part of the range (start, end, or shared) a formatted
10898 /// part belongs to when using `formatRangeToParts()`.
10899 ///
10900 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatRangeToParts#description)
10901 #[wasm_bindgen]
10902 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10903 pub enum RangeSource {
10904 /// The part is from the start of the range.
10905 StartRange = "startRange",
10906 /// The part is from the end of the range.
10907 EndRange = "endRange",
10908 /// The part is shared between start and end (e.g., a separator or common element).
10909 Shared = "shared",
10910 }
10911
10912 /// Type for `Intl.ListFormat`.
10913 #[wasm_bindgen]
10914 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10915 pub enum ListFormatType {
10916 /// For lists of standalone items (default).
10917 Conjunction = "conjunction",
10918 /// For lists representing alternatives.
10919 Disjunction = "disjunction",
10920 /// For lists of values with units.
10921 Unit = "unit",
10922 }
10923
10924 /// Style for `Intl.ListFormat`.
10925 #[wasm_bindgen]
10926 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10927 pub enum ListFormatStyle {
10928 /// "A, B, and C" (default).
10929 Long = "long",
10930 /// "A, B, C".
10931 Short = "short",
10932 /// "A B C".
10933 Narrow = "narrow",
10934 }
10935
10936 /// Part type for `Intl.ListFormat.formatToParts()`.
10937 #[wasm_bindgen]
10938 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10939 pub enum ListFormatPartType {
10940 /// A value from the list.
10941 Element = "element",
10942 /// A linguistic construct (e.g., ", ", " and ").
10943 Literal = "literal",
10944 }
10945
10946 /// Type for `Intl.Segmenter`.
10947 #[wasm_bindgen]
10948 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10949 pub enum SegmenterGranularity {
10950 /// Segment by grapheme clusters (user-perceived characters).
10951 Grapheme = "grapheme",
10952 /// Segment by words.
10953 Word = "word",
10954 /// Segment by sentences.
10955 Sentence = "sentence",
10956 }
10957
10958 /// Type for `Intl.DisplayNames`.
10959 #[wasm_bindgen]
10960 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10961 pub enum DisplayNamesType {
10962 /// Language display names.
10963 Language = "language",
10964 /// Region display names.
10965 Region = "region",
10966 /// Script display names.
10967 Script = "script",
10968 /// Currency display names.
10969 Currency = "currency",
10970 /// Calendar display names.
10971 Calendar = "calendar",
10972 /// Date/time field display names.
10973 DateTimeField = "dateTimeField",
10974 }
10975
10976 /// Style for `Intl.DisplayNames`.
10977 #[wasm_bindgen]
10978 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10979 pub enum DisplayNamesStyle {
10980 /// Full display name (default).
10981 Long = "long",
10982 /// Abbreviated display name.
10983 Short = "short",
10984 /// Minimal display name.
10985 Narrow = "narrow",
10986 }
10987
10988 /// Fallback for `Intl.DisplayNames`.
10989 #[wasm_bindgen]
10990 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10991 pub enum DisplayNamesFallback {
10992 /// Return the input code if no display name is available (default).
10993 Code = "code",
10994 /// Return undefined if no display name is available.
10995 None = "none",
10996 }
10997
10998 /// Language display for `Intl.DisplayNames`.
10999 #[wasm_bindgen]
11000 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
11001 pub enum DisplayNamesLanguageDisplay {
11002 /// Use dialect names (e.g., "British English").
11003 Dialect = "dialect",
11004 /// Use standard names (e.g., "English (United Kingdom)").
11005 Standard = "standard",
11006 }
11007
11008 // Intl.RelativeTimeFormatOptions
11009 #[wasm_bindgen]
11010 extern "C" {
11011 /// Options for `Intl.RelativeTimeFormat` constructor.
11012 ///
11013 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/RelativeTimeFormat#options)
11014 #[wasm_bindgen(extends = Object)]
11015 #[derive(Clone, Debug)]
11016 pub type RelativeTimeFormatOptions;
11017
11018 #[wasm_bindgen(method, getter = localeMatcher)]
11019 pub fn get_locale_matcher(this: &RelativeTimeFormatOptions) -> Option<LocaleMatcher>;
11020 #[wasm_bindgen(method, setter = localeMatcher)]
11021 pub fn set_locale_matcher(this: &RelativeTimeFormatOptions, value: LocaleMatcher);
11022
11023 #[wasm_bindgen(method, getter = numeric)]
11024 pub fn get_numeric(this: &RelativeTimeFormatOptions) -> Option<RelativeTimeFormatNumeric>;
11025 #[wasm_bindgen(method, setter = numeric)]
11026 pub fn set_numeric(this: &RelativeTimeFormatOptions, value: RelativeTimeFormatNumeric);
11027
11028 #[wasm_bindgen(method, getter = style)]
11029 pub fn get_style(this: &RelativeTimeFormatOptions) -> Option<RelativeTimeFormatStyle>;
11030 #[wasm_bindgen(method, setter = style)]
11031 pub fn set_style(this: &RelativeTimeFormatOptions, value: RelativeTimeFormatStyle);
11032 }
11033
11034 impl RelativeTimeFormatOptions {
11035 pub fn new() -> RelativeTimeFormatOptions {
11036 JsCast::unchecked_into(Object::new())
11037 }
11038 }
11039
11040 impl Default for RelativeTimeFormatOptions {
11041 fn default() -> Self {
11042 RelativeTimeFormatOptions::new()
11043 }
11044 }
11045
11046 // Intl.ResolvedRelativeTimeFormatOptions
11047 #[wasm_bindgen]
11048 extern "C" {
11049 /// Resolved options returned by `Intl.RelativeTimeFormat.prototype.resolvedOptions()`.
11050 ///
11051 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/resolvedOptions)
11052 #[wasm_bindgen(extends = RelativeTimeFormatOptions)]
11053 #[derive(Clone, Debug)]
11054 pub type ResolvedRelativeTimeFormatOptions;
11055
11056 /// The resolved locale string.
11057 #[wasm_bindgen(method, getter = locale)]
11058 pub fn get_locale(this: &ResolvedRelativeTimeFormatOptions) -> JsString;
11059
11060 /// The numbering system used.
11061 #[wasm_bindgen(method, getter = numberingSystem)]
11062 pub fn get_numbering_system(this: &ResolvedRelativeTimeFormatOptions) -> JsString;
11063 }
11064
11065 // Intl.RelativeTimeFormatPart
11066 #[wasm_bindgen]
11067 extern "C" {
11068 /// A part of the formatted relative time returned by `formatToParts()`.
11069 ///
11070 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/formatToParts)
11071 #[wasm_bindgen(extends = Object)]
11072 #[derive(Clone, Debug)]
11073 pub type RelativeTimeFormatPart;
11074
11075 /// The type of this part.
11076 #[wasm_bindgen(method, getter = type)]
11077 pub fn type_(this: &RelativeTimeFormatPart) -> RelativeTimeFormatPartType;
11078
11079 /// The string value of this part.
11080 #[wasm_bindgen(method, getter = value)]
11081 pub fn value(this: &RelativeTimeFormatPart) -> JsString;
11082
11083 /// The unit used in this part (only for integer parts).
11084 #[wasm_bindgen(method, getter = unit)]
11085 pub fn unit(this: &RelativeTimeFormatPart) -> Option<JsString>;
11086 }
11087
11088 // Intl.LocaleMatcherOptions
11089 #[wasm_bindgen]
11090 extern "C" {
11091 /// Options for `supportedLocalesOf` methods.
11092 #[wasm_bindgen(extends = Object)]
11093 #[derive(Clone, Debug)]
11094 pub type LocaleMatcherOptions;
11095
11096 #[wasm_bindgen(method, getter = localeMatcher)]
11097 pub fn get_locale_matcher(this: &LocaleMatcherOptions) -> Option<LocaleMatcher>;
11098
11099 #[wasm_bindgen(method, setter = localeMatcher)]
11100 pub fn set_locale_matcher(this: &LocaleMatcherOptions, value: LocaleMatcher);
11101 }
11102
11103 impl LocaleMatcherOptions {
11104 pub fn new() -> LocaleMatcherOptions {
11105 JsCast::unchecked_into(Object::new())
11106 }
11107 }
11108
11109 impl Default for LocaleMatcherOptions {
11110 fn default() -> Self {
11111 LocaleMatcherOptions::new()
11112 }
11113 }
11114
11115 // Intl.Collator Options
11116 #[wasm_bindgen]
11117 extern "C" {
11118 /// Options for `Intl.Collator` and `String.prototype.localeCompare`.
11119 ///
11120 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Collator/Collator#options)
11121 #[wasm_bindgen(extends = Object)]
11122 #[derive(Clone, Debug)]
11123 pub type CollatorOptions;
11124
11125 #[wasm_bindgen(method, getter = localeMatcher)]
11126 pub fn get_locale_matcher(this: &CollatorOptions) -> Option<LocaleMatcher>;
11127 #[wasm_bindgen(method, setter = localeMatcher)]
11128 pub fn set_locale_matcher(this: &CollatorOptions, value: LocaleMatcher);
11129
11130 #[wasm_bindgen(method, getter = usage)]
11131 pub fn get_usage(this: &CollatorOptions) -> Option<CollatorUsage>;
11132 #[wasm_bindgen(method, setter = usage)]
11133 pub fn set_usage(this: &CollatorOptions, value: CollatorUsage);
11134
11135 #[wasm_bindgen(method, getter = sensitivity)]
11136 pub fn get_sensitivity(this: &CollatorOptions) -> Option<CollatorSensitivity>;
11137 #[wasm_bindgen(method, setter = sensitivity)]
11138 pub fn set_sensitivity(this: &CollatorOptions, value: CollatorSensitivity);
11139
11140 #[wasm_bindgen(method, getter = ignorePunctuation)]
11141 pub fn get_ignore_punctuation(this: &CollatorOptions) -> Option<bool>;
11142 #[wasm_bindgen(method, setter = ignorePunctuation)]
11143 pub fn set_ignore_punctuation(this: &CollatorOptions, value: bool);
11144
11145 #[wasm_bindgen(method, getter = numeric)]
11146 pub fn get_numeric(this: &CollatorOptions) -> Option<bool>;
11147 #[wasm_bindgen(method, setter = numeric)]
11148 pub fn set_numeric(this: &CollatorOptions, value: bool);
11149
11150 #[wasm_bindgen(method, getter = caseFirst)]
11151 pub fn get_case_first(this: &CollatorOptions) -> Option<CollatorCaseFirst>;
11152 #[wasm_bindgen(method, setter = caseFirst)]
11153 pub fn set_case_first(this: &CollatorOptions, value: CollatorCaseFirst);
11154 }
11155 impl CollatorOptions {
11156 pub fn new() -> CollatorOptions {
11157 JsCast::unchecked_into(Object::new())
11158 }
11159 }
11160 impl Default for CollatorOptions {
11161 fn default() -> Self {
11162 CollatorOptions::new()
11163 }
11164 }
11165
11166 // Intl.Collator ResolvedCollatorOptions
11167 #[wasm_bindgen]
11168 extern "C" {
11169 #[wasm_bindgen(extends = CollatorOptions)]
11170 #[derive(Clone, Debug)]
11171 pub type ResolvedCollatorOptions;
11172
11173 #[wasm_bindgen(method, getter = locale)]
11174 pub fn get_locale(this: &ResolvedCollatorOptions) -> JsString; // not Option, always present
11175 #[wasm_bindgen(method, getter = collation)]
11176 pub fn get_collation(this: &ResolvedCollatorOptions) -> JsString;
11177 }
11178
11179 // Intl.Collator
11180 #[wasm_bindgen]
11181 extern "C" {
11182 /// The `Intl.Collator` object is a constructor for collators, objects
11183 /// that enable language sensitive string comparison.
11184 ///
11185 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator)
11186 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.Collator")]
11187 #[derive(Clone, Debug)]
11188 pub type Collator;
11189
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 #[cfg(not(js_sys_unstable_apis))]
11195 #[wasm_bindgen(constructor, js_namespace = Intl)]
11196 pub fn new(locales: &Array, options: &Object) -> Collator;
11197
11198 /// The `Intl.Collator` object is a constructor for collators, objects
11199 /// that enable language sensitive string comparison.
11200 ///
11201 /// Throws a `RangeError` if locales contain invalid values.
11202 ///
11203 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator)
11204 #[cfg(js_sys_unstable_apis)]
11205 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
11206 pub fn new(locales: &[JsString], options: &CollatorOptions) -> Result<Collator, JsValue>;
11207
11208 /// The Intl.Collator.prototype.compare property returns a function that
11209 /// compares two strings according to the sort order of this Collator
11210 /// object.
11211 ///
11212 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/compare)
11213 #[cfg(not(js_sys_unstable_apis))]
11214 #[wasm_bindgen(method, getter, js_class = "Intl.Collator")]
11215 pub fn compare(this: &Collator) -> Function;
11216
11217 /// Compares two strings according to the sort order of this Collator.
11218 ///
11219 /// Returns a negative value if `a` comes before `b`, positive if `a` comes
11220 /// after `b`, and zero if they are equal.
11221 ///
11222 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Collator/compare)
11223 #[cfg(js_sys_unstable_apis)]
11224 #[wasm_bindgen(method, js_class = "Intl.Collator")]
11225 pub fn compare(this: &Collator, a: &str, b: &str) -> i32;
11226
11227 /// The `Intl.Collator.prototype.resolvedOptions()` method returns a new
11228 /// object with properties reflecting the locale and collation options
11229 /// computed during initialization of this Collator object.
11230 ///
11231 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/resolvedOptions)
11232 #[cfg(not(js_sys_unstable_apis))]
11233 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11234 pub fn resolved_options(this: &Collator) -> Object;
11235
11236 /// The `Intl.Collator.prototype.resolvedOptions()` method returns a new
11237 /// object with properties reflecting the locale and collation options
11238 /// computed during initialization of this Collator object.
11239 ///
11240 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/resolvedOptions)
11241 #[cfg(js_sys_unstable_apis)]
11242 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11243 pub fn resolved_options(this: &Collator) -> ResolvedCollatorOptions;
11244
11245 /// The `Intl.Collator.supportedLocalesOf()` method returns an array
11246 /// containing those of the provided locales that are supported in
11247 /// collation without having to fall back to the runtime's default
11248 /// locale.
11249 ///
11250 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/supportedLocalesOf)
11251 #[cfg(not(js_sys_unstable_apis))]
11252 #[wasm_bindgen(static_method_of = Collator, js_namespace = Intl, js_name = supportedLocalesOf)]
11253 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
11254
11255 /// The `Intl.Collator.supportedLocalesOf()` method returns an array
11256 /// containing those of the provided locales that are supported in
11257 /// collation without having to fall back to the runtime's default
11258 /// locale.
11259 ///
11260 /// Throws a `RangeError` if locales contain invalid values.
11261 ///
11262 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/supportedLocalesOf)
11263 #[cfg(js_sys_unstable_apis)]
11264 #[wasm_bindgen(static_method_of = Collator, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
11265 pub fn supported_locales_of(
11266 locales: &[JsString],
11267 options: &LocaleMatcherOptions,
11268 ) -> Result<Array<JsString>, JsValue>;
11269 }
11270
11271 #[cfg(not(js_sys_unstable_apis))]
11272 impl Default for Collator {
11273 fn default() -> Self {
11274 Self::new(
11275 &JsValue::UNDEFINED.unchecked_into(),
11276 &JsValue::UNDEFINED.unchecked_into(),
11277 )
11278 }
11279 }
11280
11281 #[cfg(js_sys_unstable_apis)]
11282 impl Default for Collator {
11283 fn default() -> Self {
11284 Self::new(&[], &Default::default()).unwrap()
11285 }
11286 }
11287
11288 // Intl.DateTimeFormatOptions
11289 #[wasm_bindgen]
11290 extern "C" {
11291 /// Options for `Intl.DateTimeFormat` constructor.
11292 ///
11293 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat#options)
11294 #[wasm_bindgen(extends = Object)]
11295 #[derive(Clone, Debug)]
11296 pub type DateTimeFormatOptions;
11297
11298 // Locale matching
11299 #[wasm_bindgen(method, getter = localeMatcher)]
11300 pub fn get_locale_matcher(this: &DateTimeFormatOptions) -> Option<LocaleMatcher>;
11301 #[wasm_bindgen(method, setter = localeMatcher)]
11302 pub fn set_locale_matcher(this: &DateTimeFormatOptions, value: LocaleMatcher);
11303
11304 // Calendar/numbering (free-form strings, no enum)
11305 #[wasm_bindgen(method, getter = calendar)]
11306 pub fn get_calendar(this: &DateTimeFormatOptions) -> Option<JsString>;
11307 #[wasm_bindgen(method, setter = calendar)]
11308 pub fn set_calendar(this: &DateTimeFormatOptions, value: &str);
11309
11310 #[wasm_bindgen(method, getter = numberingSystem)]
11311 pub fn get_numbering_system(this: &DateTimeFormatOptions) -> Option<JsString>;
11312 #[wasm_bindgen(method, setter = numberingSystem)]
11313 pub fn set_numbering_system(this: &DateTimeFormatOptions, value: &str);
11314
11315 // Timezone (free-form string)
11316 #[wasm_bindgen(method, getter = timeZone)]
11317 pub fn get_time_zone(this: &DateTimeFormatOptions) -> Option<JsString>;
11318 #[wasm_bindgen(method, setter = timeZone)]
11319 pub fn set_time_zone(this: &DateTimeFormatOptions, value: &str);
11320
11321 // Hour cycle
11322 #[wasm_bindgen(method, getter = hour12)]
11323 pub fn get_hour12(this: &DateTimeFormatOptions) -> Option<bool>;
11324 #[wasm_bindgen(method, setter = hour12)]
11325 pub fn set_hour12(this: &DateTimeFormatOptions, value: bool);
11326
11327 #[wasm_bindgen(method, getter = hourCycle)]
11328 pub fn get_hour_cycle(this: &DateTimeFormatOptions) -> Option<HourCycle>;
11329 #[wasm_bindgen(method, setter = hourCycle)]
11330 pub fn set_hour_cycle(this: &DateTimeFormatOptions, value: HourCycle);
11331
11332 // Style shortcuts
11333 #[wasm_bindgen(method, getter = dateStyle)]
11334 pub fn get_date_style(this: &DateTimeFormatOptions) -> Option<DateTimeStyle>;
11335 #[wasm_bindgen(method, setter = dateStyle)]
11336 pub fn set_date_style(this: &DateTimeFormatOptions, value: DateTimeStyle);
11337
11338 #[wasm_bindgen(method, getter = timeStyle)]
11339 pub fn get_time_style(this: &DateTimeFormatOptions) -> Option<DateTimeStyle>;
11340 #[wasm_bindgen(method, setter = timeStyle)]
11341 pub fn set_time_style(this: &DateTimeFormatOptions, value: DateTimeStyle);
11342
11343 // Component options
11344 #[wasm_bindgen(method, getter = weekday)]
11345 pub fn get_weekday(this: &DateTimeFormatOptions) -> Option<WeekdayFormat>;
11346 #[wasm_bindgen(method, setter = weekday)]
11347 pub fn set_weekday(this: &DateTimeFormatOptions, value: WeekdayFormat);
11348
11349 #[wasm_bindgen(method, getter = era)]
11350 pub fn get_era(this: &DateTimeFormatOptions) -> Option<EraFormat>;
11351 #[wasm_bindgen(method, setter = era)]
11352 pub fn set_era(this: &DateTimeFormatOptions, value: EraFormat);
11353
11354 #[wasm_bindgen(method, getter = year)]
11355 pub fn get_year(this: &DateTimeFormatOptions) -> Option<YearFormat>;
11356 #[wasm_bindgen(method, setter = year)]
11357 pub fn set_year(this: &DateTimeFormatOptions, value: YearFormat);
11358
11359 #[wasm_bindgen(method, getter = month)]
11360 pub fn get_month(this: &DateTimeFormatOptions) -> Option<MonthFormat>;
11361 #[wasm_bindgen(method, setter = month)]
11362 pub fn set_month(this: &DateTimeFormatOptions, value: MonthFormat);
11363
11364 #[wasm_bindgen(method, getter = day)]
11365 pub fn get_day(this: &DateTimeFormatOptions) -> Option<DayFormat>;
11366 #[wasm_bindgen(method, setter = day)]
11367 pub fn set_day(this: &DateTimeFormatOptions, value: DayFormat);
11368
11369 #[wasm_bindgen(method, getter = hour)]
11370 pub fn get_hour(this: &DateTimeFormatOptions) -> Option<NumericFormat>;
11371 #[wasm_bindgen(method, setter = hour)]
11372 pub fn set_hour(this: &DateTimeFormatOptions, value: NumericFormat);
11373
11374 #[wasm_bindgen(method, getter = minute)]
11375 pub fn get_minute(this: &DateTimeFormatOptions) -> Option<NumericFormat>;
11376 #[wasm_bindgen(method, setter = minute)]
11377 pub fn set_minute(this: &DateTimeFormatOptions, value: NumericFormat);
11378
11379 #[wasm_bindgen(method, getter = second)]
11380 pub fn get_second(this: &DateTimeFormatOptions) -> Option<NumericFormat>;
11381 #[wasm_bindgen(method, setter = second)]
11382 pub fn set_second(this: &DateTimeFormatOptions, value: NumericFormat);
11383
11384 #[wasm_bindgen(method, getter = fractionalSecondDigits)]
11385 pub fn get_fractional_second_digits(this: &DateTimeFormatOptions) -> Option<u8>;
11386 #[wasm_bindgen(method, setter = fractionalSecondDigits)]
11387 pub fn set_fractional_second_digits(this: &DateTimeFormatOptions, value: u8);
11388
11389 #[wasm_bindgen(method, getter = timeZoneName)]
11390 pub fn get_time_zone_name(this: &DateTimeFormatOptions) -> Option<TimeZoneNameFormat>;
11391 #[wasm_bindgen(method, setter = timeZoneName)]
11392 pub fn set_time_zone_name(this: &DateTimeFormatOptions, value: TimeZoneNameFormat);
11393
11394 #[wasm_bindgen(method, getter = dayPeriod)]
11395 pub fn get_day_period(this: &DateTimeFormatOptions) -> Option<DayPeriodFormat>;
11396 #[wasm_bindgen(method, setter = dayPeriod)]
11397 pub fn set_day_period(this: &DateTimeFormatOptions, value: DayPeriodFormat);
11398 }
11399
11400 impl DateTimeFormatOptions {
11401 pub fn new() -> DateTimeFormatOptions {
11402 JsCast::unchecked_into(Object::new())
11403 }
11404 }
11405
11406 impl Default for DateTimeFormatOptions {
11407 fn default() -> Self {
11408 DateTimeFormatOptions::new()
11409 }
11410 }
11411
11412 // Intl.ResolvedDateTimeFormatOptions
11413 #[wasm_bindgen]
11414 extern "C" {
11415 /// Resolved options returned by `Intl.DateTimeFormat.prototype.resolvedOptions()`.
11416 ///
11417 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/resolvedOptions)
11418 #[wasm_bindgen(extends = DateTimeFormatOptions)]
11419 #[derive(Clone, Debug)]
11420 pub type ResolvedDateTimeFormatOptions;
11421
11422 /// The resolved locale string.
11423 #[wasm_bindgen(method, getter = locale)]
11424 pub fn get_locale(this: &ResolvedDateTimeFormatOptions) -> JsString;
11425 }
11426
11427 // Intl.DateTimeFormatPart
11428 #[wasm_bindgen]
11429 extern "C" {
11430 /// A part of the formatted date returned by `formatToParts()`.
11431 ///
11432 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatToParts)
11433 #[wasm_bindgen(extends = Object)]
11434 #[derive(Clone, Debug)]
11435 pub type DateTimeFormatPart;
11436
11437 /// The type of the part (e.g., "day", "month", "year", "literal", etc.)
11438 #[wasm_bindgen(method, getter = type)]
11439 pub fn type_(this: &DateTimeFormatPart) -> DateTimeFormatPartType;
11440
11441 /// The value of the part.
11442 #[wasm_bindgen(method, getter)]
11443 pub fn value(this: &DateTimeFormatPart) -> JsString;
11444 }
11445
11446 // Intl.DateTimeRangeFormatPart
11447 #[wasm_bindgen]
11448 extern "C" {
11449 /// A part of the formatted date range returned by `formatRangeToParts()`.
11450 ///
11451 /// Extends `DateTimeFormatPart` with a `source` property indicating whether
11452 /// the part is from the start date, end date, or shared between them.
11453 ///
11454 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatRangeToParts)
11455 #[wasm_bindgen(extends = DateTimeFormatPart)]
11456 #[derive(Clone, Debug)]
11457 pub type DateTimeRangeFormatPart;
11458
11459 /// The source of the part: "startRange", "endRange", or "shared".
11460 #[wasm_bindgen(method, getter)]
11461 pub fn source(this: &DateTimeRangeFormatPart) -> RangeSource;
11462 }
11463
11464 // Intl.DateTimeFormat
11465 #[wasm_bindgen]
11466 extern "C" {
11467 /// The `Intl.DateTimeFormat` object is a constructor for objects
11468 /// that enable language-sensitive date and time formatting.
11469 ///
11470 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat)
11471 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.DateTimeFormat")]
11472 #[derive(Clone, Debug)]
11473 pub type DateTimeFormat;
11474
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 #[cfg(not(js_sys_unstable_apis))]
11480 #[wasm_bindgen(constructor, js_namespace = Intl)]
11481 pub fn new(locales: &Array, options: &Object) -> DateTimeFormat;
11482
11483 /// The `Intl.DateTimeFormat` object is a constructor for objects
11484 /// that enable language-sensitive date and time formatting.
11485 ///
11486 /// Throws a `RangeError` if locales contain invalid values.
11487 ///
11488 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat)
11489 #[cfg(js_sys_unstable_apis)]
11490 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
11491 pub fn new(
11492 locales: &[JsString],
11493 options: &DateTimeFormatOptions,
11494 ) -> Result<DateTimeFormat, JsValue>;
11495
11496 /// The Intl.DateTimeFormat.prototype.format property returns a getter function that
11497 /// formats a date according to the locale and formatting options of this
11498 /// Intl.DateTimeFormat object.
11499 ///
11500 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/format)
11501 #[cfg(not(js_sys_unstable_apis))]
11502 #[wasm_bindgen(method, getter, js_class = "Intl.DateTimeFormat")]
11503 pub fn format(this: &DateTimeFormat) -> Function;
11504
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/Intl/DateTimeFormat/format)
11509 #[cfg(js_sys_unstable_apis)]
11510 #[wasm_bindgen(method, js_class = "Intl.DateTimeFormat")]
11511 pub fn format(this: &DateTimeFormat, date: &Date) -> JsString;
11512
11513 /// The `Intl.DateTimeFormat.prototype.formatToParts()` method allows locale-aware
11514 /// formatting of strings produced by DateTimeFormat formatters.
11515 ///
11516 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/formatToParts)
11517 #[cfg(not(js_sys_unstable_apis))]
11518 #[wasm_bindgen(method, js_class = "Intl.DateTimeFormat", js_name = formatToParts)]
11519 pub fn format_to_parts(this: &DateTimeFormat, date: &Date) -> Array;
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(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<DateTimeFormatPart>;
11528
11529 /// The `Intl.DateTimeFormat.prototype.formatRange()` method formats a date range
11530 /// in the most concise way based on the locales and options provided when
11531 /// instantiating this `Intl.DateTimeFormat` object.
11532 ///
11533 /// Throws a `TypeError` if the dates are invalid.
11534 ///
11535 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatRange)
11536 #[wasm_bindgen(method, js_class = "Intl.DateTimeFormat", js_name = formatRange, catch)]
11537 pub fn format_range(
11538 this: &DateTimeFormat,
11539 start_date: &Date,
11540 end_date: &Date,
11541 ) -> Result<JsString, JsValue>;
11542
11543 /// The `Intl.DateTimeFormat.prototype.formatRangeToParts()` method returns an array
11544 /// of locale-specific tokens representing each part of the formatted date range
11545 /// produced by `Intl.DateTimeFormat` formatters.
11546 ///
11547 /// Throws a `TypeError` if the dates are invalid.
11548 ///
11549 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatRangeToParts)
11550 #[wasm_bindgen(method, js_class = "Intl.DateTimeFormat", js_name = formatRangeToParts, catch)]
11551 pub fn format_range_to_parts(
11552 this: &DateTimeFormat,
11553 start_date: &Date,
11554 end_date: &Date,
11555 ) -> Result<Array<DateTimeRangeFormatPart>, JsValue>;
11556
11557 /// The `Intl.DateTimeFormat.prototype.resolvedOptions()` method returns a new
11558 /// object with properties reflecting the locale and date and time formatting
11559 /// options computed during initialization of this DateTimeFormat object.
11560 ///
11561 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/resolvedOptions)
11562 #[cfg(not(js_sys_unstable_apis))]
11563 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11564 pub fn resolved_options(this: &DateTimeFormat) -> Object;
11565
11566 /// The `Intl.DateTimeFormat.prototype.resolvedOptions()` method returns a new
11567 /// object with properties reflecting the locale and date and time formatting
11568 /// options computed during initialization of this DateTimeFormat object.
11569 ///
11570 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/resolvedOptions)
11571 #[cfg(js_sys_unstable_apis)]
11572 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11573 pub fn resolved_options(this: &DateTimeFormat) -> ResolvedDateTimeFormatOptions;
11574
11575 /// The `Intl.DateTimeFormat.supportedLocalesOf()` method returns an array
11576 /// containing those of the provided locales that are supported in date
11577 /// and time formatting without having to fall back to the runtime's default
11578 /// locale.
11579 ///
11580 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/supportedLocalesOf)
11581 #[cfg(not(js_sys_unstable_apis))]
11582 #[wasm_bindgen(static_method_of = DateTimeFormat, js_namespace = Intl, js_name = supportedLocalesOf)]
11583 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
11584
11585 /// The `Intl.DateTimeFormat.supportedLocalesOf()` method returns an array
11586 /// containing those of the provided locales that are supported in date
11587 /// and time formatting without having to fall back to the runtime's default
11588 /// locale.
11589 ///
11590 /// Throws a `RangeError` if locales contain invalid values.
11591 ///
11592 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/supportedLocalesOf)
11593 #[cfg(js_sys_unstable_apis)]
11594 #[wasm_bindgen(static_method_of = DateTimeFormat, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
11595 pub fn supported_locales_of(
11596 locales: &[JsString],
11597 options: &LocaleMatcherOptions,
11598 ) -> Result<Array<JsString>, JsValue>;
11599 }
11600
11601 #[cfg(not(js_sys_unstable_apis))]
11602 impl Default for DateTimeFormat {
11603 fn default() -> Self {
11604 Self::new(
11605 &JsValue::UNDEFINED.unchecked_into(),
11606 &JsValue::UNDEFINED.unchecked_into(),
11607 )
11608 }
11609 }
11610
11611 #[cfg(js_sys_unstable_apis)]
11612 impl Default for DateTimeFormat {
11613 fn default() -> Self {
11614 Self::new(&[], &Default::default()).unwrap()
11615 }
11616 }
11617
11618 // Intl.NumberFormatOptions
11619 #[wasm_bindgen]
11620 extern "C" {
11621 /// Options for `Intl.NumberFormat` constructor.
11622 ///
11623 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#options)
11624 #[wasm_bindgen(extends = Object)]
11625 #[derive(Clone, Debug)]
11626 pub type NumberFormatOptions;
11627
11628 // Locale matching
11629 #[wasm_bindgen(method, getter = localeMatcher)]
11630 pub fn get_locale_matcher(this: &NumberFormatOptions) -> Option<LocaleMatcher>;
11631 #[wasm_bindgen(method, setter = localeMatcher)]
11632 pub fn set_locale_matcher(this: &NumberFormatOptions, value: LocaleMatcher);
11633
11634 // Numbering system (free-form string)
11635 #[wasm_bindgen(method, getter = numberingSystem)]
11636 pub fn get_numbering_system(this: &NumberFormatOptions) -> Option<JsString>;
11637 #[wasm_bindgen(method, setter = numberingSystem)]
11638 pub fn set_numbering_system(this: &NumberFormatOptions, value: &str);
11639
11640 // Style
11641 #[wasm_bindgen(method, getter = style)]
11642 pub fn get_style(this: &NumberFormatOptions) -> Option<NumberFormatStyle>;
11643 #[wasm_bindgen(method, setter = style)]
11644 pub fn set_style(this: &NumberFormatOptions, value: NumberFormatStyle);
11645
11646 // Currency options (currency code is free-form ISO 4217 string)
11647 #[wasm_bindgen(method, getter = currency)]
11648 pub fn get_currency(this: &NumberFormatOptions) -> Option<JsString>;
11649 #[wasm_bindgen(method, setter = currency)]
11650 pub fn set_currency(this: &NumberFormatOptions, value: &str);
11651
11652 #[wasm_bindgen(method, getter = currencyDisplay)]
11653 pub fn get_currency_display(this: &NumberFormatOptions) -> Option<CurrencyDisplay>;
11654 #[wasm_bindgen(method, setter = currencyDisplay)]
11655 pub fn set_currency_display(this: &NumberFormatOptions, value: CurrencyDisplay);
11656
11657 #[wasm_bindgen(method, getter = currencySign)]
11658 pub fn get_currency_sign(this: &NumberFormatOptions) -> Option<CurrencySign>;
11659 #[wasm_bindgen(method, setter = currencySign)]
11660 pub fn set_currency_sign(this: &NumberFormatOptions, value: CurrencySign);
11661
11662 // Unit options (unit name is free-form string)
11663 #[wasm_bindgen(method, getter = unit)]
11664 pub fn get_unit(this: &NumberFormatOptions) -> Option<JsString>;
11665 #[wasm_bindgen(method, setter = unit)]
11666 pub fn set_unit(this: &NumberFormatOptions, value: &str);
11667
11668 #[wasm_bindgen(method, getter = unitDisplay)]
11669 pub fn get_unit_display(this: &NumberFormatOptions) -> Option<UnitDisplay>;
11670 #[wasm_bindgen(method, setter = unitDisplay)]
11671 pub fn set_unit_display(this: &NumberFormatOptions, value: UnitDisplay);
11672
11673 // Notation
11674 #[wasm_bindgen(method, getter = notation)]
11675 pub fn get_notation(this: &NumberFormatOptions) -> Option<NumberFormatNotation>;
11676 #[wasm_bindgen(method, setter = notation)]
11677 pub fn set_notation(this: &NumberFormatOptions, value: NumberFormatNotation);
11678
11679 #[wasm_bindgen(method, getter = compactDisplay)]
11680 pub fn get_compact_display(this: &NumberFormatOptions) -> Option<CompactDisplay>;
11681 #[wasm_bindgen(method, setter = compactDisplay)]
11682 pub fn set_compact_display(this: &NumberFormatOptions, value: CompactDisplay);
11683
11684 // Sign display
11685 #[wasm_bindgen(method, getter = signDisplay)]
11686 pub fn get_sign_display(this: &NumberFormatOptions) -> Option<SignDisplay>;
11687 #[wasm_bindgen(method, setter = signDisplay)]
11688 pub fn set_sign_display(this: &NumberFormatOptions, value: SignDisplay);
11689
11690 // Digit options
11691 #[wasm_bindgen(method, getter = minimumIntegerDigits)]
11692 pub fn get_minimum_integer_digits(this: &NumberFormatOptions) -> Option<u8>;
11693 #[wasm_bindgen(method, setter = minimumIntegerDigits)]
11694 pub fn set_minimum_integer_digits(this: &NumberFormatOptions, value: u8);
11695
11696 #[wasm_bindgen(method, getter = minimumFractionDigits)]
11697 pub fn get_minimum_fraction_digits(this: &NumberFormatOptions) -> Option<u8>;
11698 #[wasm_bindgen(method, setter = minimumFractionDigits)]
11699 pub fn set_minimum_fraction_digits(this: &NumberFormatOptions, value: u8);
11700
11701 #[wasm_bindgen(method, getter = maximumFractionDigits)]
11702 pub fn get_maximum_fraction_digits(this: &NumberFormatOptions) -> Option<u8>;
11703 #[wasm_bindgen(method, setter = maximumFractionDigits)]
11704 pub fn set_maximum_fraction_digits(this: &NumberFormatOptions, value: u8);
11705
11706 #[wasm_bindgen(method, getter = minimumSignificantDigits)]
11707 pub fn get_minimum_significant_digits(this: &NumberFormatOptions) -> Option<u8>;
11708 #[wasm_bindgen(method, setter = minimumSignificantDigits)]
11709 pub fn set_minimum_significant_digits(this: &NumberFormatOptions, value: u8);
11710
11711 #[wasm_bindgen(method, getter = maximumSignificantDigits)]
11712 pub fn get_maximum_significant_digits(this: &NumberFormatOptions) -> Option<u8>;
11713 #[wasm_bindgen(method, setter = maximumSignificantDigits)]
11714 pub fn set_maximum_significant_digits(this: &NumberFormatOptions, value: u8);
11715
11716 // Grouping
11717 #[wasm_bindgen(method, getter = useGrouping)]
11718 pub fn get_use_grouping(this: &NumberFormatOptions) -> Option<UseGrouping>;
11719 #[wasm_bindgen(method, setter = useGrouping)]
11720 pub fn set_use_grouping(this: &NumberFormatOptions, value: UseGrouping);
11721
11722 // Rounding
11723 #[wasm_bindgen(method, getter = roundingMode)]
11724 pub fn get_rounding_mode(this: &NumberFormatOptions) -> Option<RoundingMode>;
11725 #[wasm_bindgen(method, setter = roundingMode)]
11726 pub fn set_rounding_mode(this: &NumberFormatOptions, value: RoundingMode);
11727
11728 #[wasm_bindgen(method, getter = roundingPriority)]
11729 pub fn get_rounding_priority(this: &NumberFormatOptions) -> Option<RoundingPriority>;
11730 #[wasm_bindgen(method, setter = roundingPriority)]
11731 pub fn set_rounding_priority(this: &NumberFormatOptions, value: RoundingPriority);
11732
11733 #[wasm_bindgen(method, getter = roundingIncrement)]
11734 pub fn get_rounding_increment(this: &NumberFormatOptions) -> Option<u32>;
11735 #[wasm_bindgen(method, setter = roundingIncrement)]
11736 pub fn set_rounding_increment(this: &NumberFormatOptions, value: u32);
11737
11738 #[wasm_bindgen(method, getter = trailingZeroDisplay)]
11739 pub fn get_trailing_zero_display(this: &NumberFormatOptions)
11740 -> Option<TrailingZeroDisplay>;
11741 #[wasm_bindgen(method, setter = trailingZeroDisplay)]
11742 pub fn set_trailing_zero_display(this: &NumberFormatOptions, value: TrailingZeroDisplay);
11743 }
11744
11745 impl NumberFormatOptions {
11746 pub fn new() -> NumberFormatOptions {
11747 JsCast::unchecked_into(Object::new())
11748 }
11749 }
11750
11751 impl Default for NumberFormatOptions {
11752 fn default() -> Self {
11753 NumberFormatOptions::new()
11754 }
11755 }
11756
11757 // Intl.ResolvedNumberFormatOptions
11758 #[wasm_bindgen]
11759 extern "C" {
11760 /// Resolved options returned by `Intl.NumberFormat.prototype.resolvedOptions()`.
11761 ///
11762 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/resolvedOptions)
11763 #[wasm_bindgen(extends = NumberFormatOptions)]
11764 #[derive(Clone, Debug)]
11765 pub type ResolvedNumberFormatOptions;
11766
11767 /// The resolved locale string.
11768 #[wasm_bindgen(method, getter = locale)]
11769 pub fn get_locale(this: &ResolvedNumberFormatOptions) -> JsString;
11770 }
11771
11772 // Intl.NumberFormatPart
11773 #[wasm_bindgen]
11774 extern "C" {
11775 /// A part of the formatted number returned by `formatToParts()`.
11776 ///
11777 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatToParts)
11778 #[wasm_bindgen(extends = Object)]
11779 #[derive(Clone, Debug)]
11780 pub type NumberFormatPart;
11781
11782 /// The type of the part (e.g., "integer", "decimal", "fraction", "currency", etc.)
11783 #[wasm_bindgen(method, getter = type)]
11784 pub fn type_(this: &NumberFormatPart) -> NumberFormatPartType;
11785
11786 /// The value of the part.
11787 #[wasm_bindgen(method, getter)]
11788 pub fn value(this: &NumberFormatPart) -> JsString;
11789 }
11790
11791 // Intl.NumberRangeFormatPart
11792 #[wasm_bindgen]
11793 extern "C" {
11794 /// A part of the formatted number range returned by `formatRangeToParts()`.
11795 ///
11796 /// Extends `NumberFormatPart` with a `source` property indicating whether
11797 /// the part is from the start number, end number, or shared between them.
11798 ///
11799 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatRangeToParts)
11800 #[wasm_bindgen(extends = NumberFormatPart)]
11801 #[derive(Clone, Debug)]
11802 pub type NumberRangeFormatPart;
11803
11804 /// The source of the part: "startRange", "endRange", or "shared".
11805 #[wasm_bindgen(method, getter)]
11806 pub fn source(this: &NumberRangeFormatPart) -> RangeSource;
11807 }
11808
11809 // Intl.NumberFormat
11810 #[wasm_bindgen]
11811 extern "C" {
11812 /// The `Intl.NumberFormat` object is a constructor for objects
11813 /// that enable language sensitive number formatting.
11814 ///
11815 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat)
11816 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.NumberFormat")]
11817 #[derive(Clone, Debug)]
11818 pub type NumberFormat;
11819
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 #[cfg(not(js_sys_unstable_apis))]
11825 #[wasm_bindgen(constructor, js_namespace = Intl)]
11826 pub fn new(locales: &Array, options: &Object) -> NumberFormat;
11827
11828 /// The `Intl.NumberFormat` object is a constructor for objects
11829 /// that enable language sensitive number formatting.
11830 ///
11831 /// Throws a `RangeError` if locales contain invalid values.
11832 ///
11833 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat)
11834 #[cfg(js_sys_unstable_apis)]
11835 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
11836 pub fn new(
11837 locales: &[JsString],
11838 options: &NumberFormatOptions,
11839 ) -> Result<NumberFormat, JsValue>;
11840
11841 /// The Intl.NumberFormat.prototype.format property returns a getter function that
11842 /// formats a number according to the locale and formatting options of this
11843 /// NumberFormat object.
11844 ///
11845 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/format)
11846 #[cfg(not(js_sys_unstable_apis))]
11847 #[wasm_bindgen(method, getter, js_class = "Intl.NumberFormat")]
11848 pub fn format(this: &NumberFormat) -> Function;
11849
11850 /// Formats a number according to the locale and formatting options of this
11851 /// `Intl.NumberFormat` object.
11852 ///
11853 /// Accepts numeric strings for BigInt/arbitrary precision (e.g., `"123n"` → `"123"`,
11854 /// or use E notation: `"1000000E-6"` → `"1"`).
11855 ///
11856 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/format)
11857 #[cfg(js_sys_unstable_apis)]
11858 #[wasm_bindgen(method, js_class = "Intl.NumberFormat")]
11859 pub fn format(this: &NumberFormat, value: &JsString) -> JsString;
11860
11861 /// The `Intl.Numberformat.prototype.formatToParts()` method allows locale-aware
11862 /// formatting of strings produced by NumberTimeFormat formatters.
11863 ///
11864 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/formatToParts)
11865 #[cfg(not(js_sys_unstable_apis))]
11866 #[wasm_bindgen(method, js_class = "Intl.NumberFormat", js_name = formatToParts)]
11867 pub fn format_to_parts(this: &NumberFormat, number: f64) -> Array;
11868
11869 /// The `Intl.NumberFormat.prototype.formatToParts()` method allows locale-aware
11870 /// formatting of strings produced by `Intl.NumberFormat` formatters.
11871 ///
11872 /// Accepts numeric strings for BigInt/arbitrary precision (e.g., `"123n"` → `"123"`,
11873 /// or use E notation: `"1000000E-6"` → `"1"`).
11874 ///
11875 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatToParts)
11876 #[cfg(js_sys_unstable_apis)]
11877 #[wasm_bindgen(method, js_class = "Intl.NumberFormat", js_name = formatToParts)]
11878 pub fn format_to_parts(this: &NumberFormat, value: &JsString) -> Array<NumberFormatPart>;
11879
11880 /// Formats a range of numbers according to the locale and formatting options
11881 /// of this `Intl.NumberFormat` object.
11882 ///
11883 /// Accepts numeric strings for BigInt/arbitrary precision (e.g., `"123n"` → `"123"`,
11884 /// or use E notation: `"1000000E-6"` → `"1"`).
11885 ///
11886 /// Throws a `TypeError` if the values are invalid.
11887 ///
11888 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatRange)
11889 #[wasm_bindgen(method, js_class = "Intl.NumberFormat", js_name = formatRange, catch)]
11890 pub fn format_range(
11891 this: &NumberFormat,
11892 start: &JsString,
11893 end: &JsString,
11894 ) -> Result<JsString, JsValue>;
11895
11896 /// Returns an array of locale-specific tokens representing each part of
11897 /// the formatted number range.
11898 ///
11899 /// Accepts numeric strings for BigInt/arbitrary precision (e.g., `"123n"` → `"123"`,
11900 /// or use E notation: `"1000000E-6"` → `"1"`).
11901 ///
11902 /// Throws a `TypeError` if the values are invalid.
11903 ///
11904 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatRangeToParts)
11905 #[wasm_bindgen(method, js_class = "Intl.NumberFormat", js_name = formatRangeToParts, catch)]
11906 pub fn format_range_to_parts(
11907 this: &NumberFormat,
11908 start: &JsString,
11909 end: &JsString,
11910 ) -> Result<Array<NumberRangeFormatPart>, JsValue>;
11911
11912 /// The `Intl.NumberFormat.prototype.resolvedOptions()` method returns a new
11913 /// object with properties reflecting the locale and number formatting
11914 /// options computed during initialization of this NumberFormat object.
11915 ///
11916 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/resolvedOptions)
11917 #[cfg(not(js_sys_unstable_apis))]
11918 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11919 pub fn resolved_options(this: &NumberFormat) -> Object;
11920
11921 /// The `Intl.NumberFormat.prototype.resolvedOptions()` method returns a new
11922 /// object with properties reflecting the locale and number formatting
11923 /// options computed during initialization of this NumberFormat object.
11924 ///
11925 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/resolvedOptions)
11926 #[cfg(js_sys_unstable_apis)]
11927 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11928 pub fn resolved_options(this: &NumberFormat) -> ResolvedNumberFormatOptions;
11929
11930 /// The `Intl.NumberFormat.supportedLocalesOf()` method returns an array
11931 /// containing those of the provided locales that are supported in number
11932 /// formatting without having to fall back to the runtime's default locale.
11933 ///
11934 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/supportedLocalesOf)
11935 #[cfg(not(js_sys_unstable_apis))]
11936 #[wasm_bindgen(static_method_of = NumberFormat, js_namespace = Intl, js_name = supportedLocalesOf)]
11937 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
11938
11939 /// The `Intl.NumberFormat.supportedLocalesOf()` method returns an array
11940 /// containing those of the provided locales that are supported in number
11941 /// formatting without having to fall back to the runtime's default locale.
11942 ///
11943 /// Throws a `RangeError` if locales contain invalid values.
11944 ///
11945 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/supportedLocalesOf)
11946 #[cfg(js_sys_unstable_apis)]
11947 #[wasm_bindgen(static_method_of = NumberFormat, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
11948 pub fn supported_locales_of(
11949 locales: &[JsString],
11950 options: &LocaleMatcherOptions,
11951 ) -> Result<Array<JsString>, JsValue>;
11952 }
11953
11954 #[cfg(not(js_sys_unstable_apis))]
11955 impl Default for NumberFormat {
11956 fn default() -> Self {
11957 Self::new(
11958 &JsValue::UNDEFINED.unchecked_into(),
11959 &JsValue::UNDEFINED.unchecked_into(),
11960 )
11961 }
11962 }
11963
11964 #[cfg(js_sys_unstable_apis)]
11965 impl Default for NumberFormat {
11966 fn default() -> Self {
11967 Self::new(&[], &Default::default()).unwrap()
11968 }
11969 }
11970
11971 // Intl.PluralRulesOptions
11972 #[wasm_bindgen]
11973 extern "C" {
11974 /// Options for `Intl.PluralRules` constructor.
11975 ///
11976 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules/PluralRules#options)
11977 #[wasm_bindgen(extends = Object)]
11978 #[derive(Clone, Debug)]
11979 pub type PluralRulesOptions;
11980
11981 #[wasm_bindgen(method, getter = localeMatcher)]
11982 pub fn get_locale_matcher(this: &PluralRulesOptions) -> Option<LocaleMatcher>;
11983 #[wasm_bindgen(method, setter = localeMatcher)]
11984 pub fn set_locale_matcher(this: &PluralRulesOptions, value: LocaleMatcher);
11985
11986 #[wasm_bindgen(method, getter = type)]
11987 pub fn get_type(this: &PluralRulesOptions) -> Option<PluralRulesType>;
11988 #[wasm_bindgen(method, setter = type)]
11989 pub fn set_type(this: &PluralRulesOptions, value: PluralRulesType);
11990
11991 #[wasm_bindgen(method, getter = minimumIntegerDigits)]
11992 pub fn get_minimum_integer_digits(this: &PluralRulesOptions) -> Option<u8>;
11993 #[wasm_bindgen(method, setter = minimumIntegerDigits)]
11994 pub fn set_minimum_integer_digits(this: &PluralRulesOptions, value: u8);
11995
11996 #[wasm_bindgen(method, getter = minimumFractionDigits)]
11997 pub fn get_minimum_fraction_digits(this: &PluralRulesOptions) -> Option<u8>;
11998 #[wasm_bindgen(method, setter = minimumFractionDigits)]
11999 pub fn set_minimum_fraction_digits(this: &PluralRulesOptions, value: u8);
12000
12001 #[wasm_bindgen(method, getter = maximumFractionDigits)]
12002 pub fn get_maximum_fraction_digits(this: &PluralRulesOptions) -> Option<u8>;
12003 #[wasm_bindgen(method, setter = maximumFractionDigits)]
12004 pub fn set_maximum_fraction_digits(this: &PluralRulesOptions, value: u8);
12005
12006 #[wasm_bindgen(method, getter = minimumSignificantDigits)]
12007 pub fn get_minimum_significant_digits(this: &PluralRulesOptions) -> Option<u8>;
12008 #[wasm_bindgen(method, setter = minimumSignificantDigits)]
12009 pub fn set_minimum_significant_digits(this: &PluralRulesOptions, value: u8);
12010
12011 #[wasm_bindgen(method, getter = maximumSignificantDigits)]
12012 pub fn get_maximum_significant_digits(this: &PluralRulesOptions) -> Option<u8>;
12013 #[wasm_bindgen(method, setter = maximumSignificantDigits)]
12014 pub fn set_maximum_significant_digits(this: &PluralRulesOptions, value: u8);
12015
12016 #[wasm_bindgen(method, getter = roundingPriority)]
12017 pub fn get_rounding_priority(this: &PluralRulesOptions) -> Option<RoundingPriority>;
12018 #[wasm_bindgen(method, setter = roundingPriority)]
12019 pub fn set_rounding_priority(this: &PluralRulesOptions, value: RoundingPriority);
12020
12021 #[wasm_bindgen(method, getter = roundingIncrement)]
12022 pub fn get_rounding_increment(this: &PluralRulesOptions) -> Option<u32>;
12023 #[wasm_bindgen(method, setter = roundingIncrement)]
12024 pub fn set_rounding_increment(this: &PluralRulesOptions, value: u32);
12025
12026 #[wasm_bindgen(method, getter = roundingMode)]
12027 pub fn get_rounding_mode(this: &PluralRulesOptions) -> Option<RoundingMode>;
12028 #[wasm_bindgen(method, setter = roundingMode)]
12029 pub fn set_rounding_mode(this: &PluralRulesOptions, value: RoundingMode);
12030
12031 #[wasm_bindgen(method, getter = trailingZeroDisplay)]
12032 pub fn get_trailing_zero_display(this: &PluralRulesOptions) -> Option<TrailingZeroDisplay>;
12033 #[wasm_bindgen(method, setter = trailingZeroDisplay)]
12034 pub fn set_trailing_zero_display(this: &PluralRulesOptions, value: TrailingZeroDisplay);
12035 }
12036
12037 impl PluralRulesOptions {
12038 pub fn new() -> PluralRulesOptions {
12039 JsCast::unchecked_into(Object::new())
12040 }
12041 }
12042
12043 impl Default for PluralRulesOptions {
12044 fn default() -> Self {
12045 PluralRulesOptions::new()
12046 }
12047 }
12048
12049 // Intl.ResolvedPluralRulesOptions
12050 #[wasm_bindgen]
12051 extern "C" {
12052 /// Resolved options returned by `Intl.PluralRules.prototype.resolvedOptions()`.
12053 ///
12054 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules/resolvedOptions)
12055 #[wasm_bindgen(extends = PluralRulesOptions)]
12056 #[derive(Clone, Debug)]
12057 pub type ResolvedPluralRulesOptions;
12058
12059 /// The resolved locale string.
12060 #[wasm_bindgen(method, getter = locale)]
12061 pub fn get_locale(this: &ResolvedPluralRulesOptions) -> JsString;
12062
12063 /// The plural categories used by the locale.
12064 #[wasm_bindgen(method, getter = pluralCategories)]
12065 pub fn get_plural_categories(this: &ResolvedPluralRulesOptions) -> Array<JsString>;
12066 }
12067
12068 // Intl.PluralRules
12069 #[wasm_bindgen]
12070 extern "C" {
12071 /// The `Intl.PluralRules` object is a constructor for objects
12072 /// that enable plural sensitive formatting and plural language rules.
12073 ///
12074 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules)
12075 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.PluralRules")]
12076 #[derive(Clone, Debug)]
12077 pub type PluralRules;
12078
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 #[cfg(not(js_sys_unstable_apis))]
12084 #[wasm_bindgen(constructor, js_namespace = Intl)]
12085 pub fn new(locales: &Array, options: &Object) -> PluralRules;
12086
12087 /// The `Intl.PluralRules` object is a constructor for objects
12088 /// that enable plural sensitive formatting and plural language rules.
12089 ///
12090 /// Throws a `RangeError` if locales contain invalid values.
12091 ///
12092 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules)
12093 #[cfg(js_sys_unstable_apis)]
12094 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
12095 pub fn new(
12096 locales: &[JsString],
12097 options: &PluralRulesOptions,
12098 ) -> Result<PluralRules, JsValue>;
12099
12100 /// The `Intl.PluralRules.prototype.resolvedOptions()` method returns a new
12101 /// object with properties reflecting the locale and plural formatting
12102 /// options computed during initialization of this PluralRules object.
12103 ///
12104 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/resolvedOptions)
12105 #[cfg(not(js_sys_unstable_apis))]
12106 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
12107 pub fn resolved_options(this: &PluralRules) -> Object;
12108
12109 /// The `Intl.PluralRules.prototype.resolvedOptions()` method returns a new
12110 /// object with properties reflecting the locale and plural formatting
12111 /// options computed during initialization of this PluralRules object.
12112 ///
12113 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/resolvedOptions)
12114 #[cfg(js_sys_unstable_apis)]
12115 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
12116 pub fn resolved_options(this: &PluralRules) -> ResolvedPluralRulesOptions;
12117
12118 /// The `Intl.PluralRules.prototype.select()` method returns a String indicating
12119 /// which plural rule to use for locale-aware formatting.
12120 ///
12121 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/select)
12122 #[cfg(not(js_sys_unstable_apis))]
12123 #[wasm_bindgen(method, js_namespace = Intl)]
12124 pub fn select(this: &PluralRules, number: f64) -> JsString;
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(js_sys_unstable_apis)]
12131 #[wasm_bindgen(method, js_namespace = Intl)]
12132 pub fn select(this: &PluralRules, number: f64) -> PluralCategory;
12133
12134 /// The `Intl.PluralRules.prototype.selectRange()` method returns a string indicating
12135 /// which plural rule to use for locale-aware formatting of a range of numbers.
12136 ///
12137 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules/selectRange)
12138 #[cfg(not(js_sys_unstable_apis))]
12139 #[wasm_bindgen(method, js_namespace = Intl, js_name = selectRange)]
12140 pub fn select_range(this: &PluralRules, start: f64, end: f64) -> JsString;
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(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) -> PluralCategory;
12149
12150 /// The `Intl.PluralRules.supportedLocalesOf()` method returns an array
12151 /// containing those of the provided locales that are supported in plural
12152 /// formatting without having to fall back to the runtime's default locale.
12153 ///
12154 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/supportedLocalesOf)
12155 #[cfg(not(js_sys_unstable_apis))]
12156 #[wasm_bindgen(static_method_of = PluralRules, js_namespace = Intl, js_name = supportedLocalesOf)]
12157 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
12158
12159 /// The `Intl.PluralRules.supportedLocalesOf()` method returns an array
12160 /// containing those of the provided locales that are supported in plural
12161 /// formatting without having to fall back to the runtime's default locale.
12162 ///
12163 /// Throws a `RangeError` if locales contain invalid values.
12164 ///
12165 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/supportedLocalesOf)
12166 #[cfg(js_sys_unstable_apis)]
12167 #[wasm_bindgen(static_method_of = PluralRules, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
12168 pub fn supported_locales_of(
12169 locales: &[JsString],
12170 options: &LocaleMatcherOptions,
12171 ) -> Result<Array<JsString>, JsValue>;
12172 }
12173
12174 #[cfg(not(js_sys_unstable_apis))]
12175 impl Default for PluralRules {
12176 fn default() -> Self {
12177 Self::new(
12178 &JsValue::UNDEFINED.unchecked_into(),
12179 &JsValue::UNDEFINED.unchecked_into(),
12180 )
12181 }
12182 }
12183
12184 #[cfg(js_sys_unstable_apis)]
12185 impl Default for PluralRules {
12186 fn default() -> Self {
12187 Self::new(&[], &Default::default()).unwrap()
12188 }
12189 }
12190
12191 // Intl.RelativeTimeFormat
12192 #[wasm_bindgen]
12193 extern "C" {
12194 /// The `Intl.RelativeTimeFormat` object is a constructor for objects
12195 /// that enable language-sensitive relative time formatting.
12196 ///
12197 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat)
12198 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.RelativeTimeFormat")]
12199 #[derive(Clone, Debug)]
12200 pub type RelativeTimeFormat;
12201
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 #[cfg(not(js_sys_unstable_apis))]
12207 #[wasm_bindgen(constructor, js_namespace = Intl)]
12208 pub fn new(locales: &Array, options: &Object) -> RelativeTimeFormat;
12209
12210 /// The `Intl.RelativeTimeFormat` object is a constructor for objects
12211 /// that enable language-sensitive relative time formatting.
12212 ///
12213 /// Throws a `RangeError` if locales contain invalid values.
12214 ///
12215 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat)
12216 #[cfg(js_sys_unstable_apis)]
12217 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
12218 pub fn new(locales: &[JsString]) -> Result<RelativeTimeFormat, JsValue>;
12219
12220 /// The `Intl.RelativeTimeFormat` object is a constructor for objects
12221 /// that enable language-sensitive relative time formatting.
12222 ///
12223 /// Throws a `RangeError` if locales or options contain invalid values.
12224 ///
12225 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat)
12226 #[cfg(js_sys_unstable_apis)]
12227 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
12228 pub fn new_with_options(
12229 locales: &[JsString],
12230 options: &RelativeTimeFormatOptions,
12231 ) -> Result<RelativeTimeFormat, JsValue>;
12232
12233 /// The `Intl.RelativeTimeFormat.prototype.format` method formats a `value` and `unit`
12234 /// according to the locale and formatting options of this Intl.RelativeTimeFormat object.
12235 ///
12236 /// Throws a `RangeError` if unit is invalid.
12237 ///
12238 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/format)
12239 #[cfg(not(js_sys_unstable_apis))]
12240 #[wasm_bindgen(method, js_class = "Intl.RelativeTimeFormat")]
12241 pub fn format(this: &RelativeTimeFormat, value: f64, unit: &str) -> JsString;
12242
12243 /// The `Intl.RelativeTimeFormat.prototype.format` method formats a `value` and `unit`
12244 /// according to the locale and formatting options of this Intl.RelativeTimeFormat object.
12245 ///
12246 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/format)
12247 #[cfg(js_sys_unstable_apis)]
12248 #[wasm_bindgen(method, js_class = "Intl.RelativeTimeFormat")]
12249 pub fn format(
12250 this: &RelativeTimeFormat,
12251 value: f64,
12252 unit: RelativeTimeFormatUnit,
12253 ) -> JsString;
12254
12255 /// The `Intl.RelativeTimeFormat.prototype.formatToParts()` method returns an array of
12256 /// objects representing the relative time format in parts that can be used for custom locale-aware formatting.
12257 ///
12258 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/formatToParts)
12259 #[cfg(not(js_sys_unstable_apis))]
12260 #[wasm_bindgen(method, js_class = "Intl.RelativeTimeFormat", js_name = formatToParts)]
12261 pub fn format_to_parts(this: &RelativeTimeFormat, value: f64, unit: &str) -> Array;
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(js_sys_unstable_apis)]
12268 #[wasm_bindgen(method, js_class = "Intl.RelativeTimeFormat", js_name = formatToParts)]
12269 pub fn format_to_parts(
12270 this: &RelativeTimeFormat,
12271 value: f64,
12272 unit: RelativeTimeFormatUnit,
12273 ) -> Array<RelativeTimeFormatPart>;
12274
12275 /// The `Intl.RelativeTimeFormat.prototype.resolvedOptions()` method returns a new
12276 /// object with properties reflecting the locale and relative time formatting
12277 /// options computed during initialization of this RelativeTimeFormat object.
12278 ///
12279 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/resolvedOptions)
12280 #[cfg(not(js_sys_unstable_apis))]
12281 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
12282 pub fn resolved_options(this: &RelativeTimeFormat) -> Object;
12283
12284 /// The `Intl.RelativeTimeFormat.prototype.resolvedOptions()` method returns a new
12285 /// object with properties reflecting the locale and relative time formatting
12286 /// options computed during initialization of this RelativeTimeFormat object.
12287 ///
12288 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/resolvedOptions)
12289 #[cfg(js_sys_unstable_apis)]
12290 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
12291 pub fn resolved_options(this: &RelativeTimeFormat) -> ResolvedRelativeTimeFormatOptions;
12292
12293 /// The `Intl.RelativeTimeFormat.supportedLocalesOf()` method returns an array
12294 /// containing those of the provided locales that are supported in date and time
12295 /// formatting without having to fall back to the runtime's default locale.
12296 ///
12297 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RelativeTimeFormat/supportedLocalesOf)
12298 #[cfg(not(js_sys_unstable_apis))]
12299 #[wasm_bindgen(static_method_of = RelativeTimeFormat, js_namespace = Intl, js_name = supportedLocalesOf)]
12300 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
12301
12302 /// The `Intl.RelativeTimeFormat.supportedLocalesOf()` method returns an array
12303 /// containing those of the provided locales that are supported in date and time
12304 /// formatting without having to fall back to the runtime's default locale.
12305 ///
12306 /// Throws a `RangeError` if locales contain invalid values.
12307 ///
12308 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RelativeTimeFormat/supportedLocalesOf)
12309 #[cfg(js_sys_unstable_apis)]
12310 #[wasm_bindgen(static_method_of = RelativeTimeFormat, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
12311 pub fn supported_locales_of(
12312 locales: &[JsString],
12313 options: &LocaleMatcherOptions,
12314 ) -> Result<Array<JsString>, JsValue>;
12315 }
12316
12317 #[cfg(not(js_sys_unstable_apis))]
12318 impl Default for RelativeTimeFormat {
12319 fn default() -> Self {
12320 Self::new(
12321 &JsValue::UNDEFINED.unchecked_into(),
12322 &JsValue::UNDEFINED.unchecked_into(),
12323 )
12324 }
12325 }
12326
12327 #[cfg(js_sys_unstable_apis)]
12328 impl Default for RelativeTimeFormat {
12329 fn default() -> Self {
12330 Self::new(&[]).unwrap()
12331 }
12332 }
12333
12334 // Intl.ListFormatOptions
12335 #[wasm_bindgen]
12336 extern "C" {
12337 /// Options for `Intl.ListFormat` constructor.
12338 ///
12339 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/ListFormat#options)
12340 #[wasm_bindgen(extends = Object)]
12341 #[derive(Clone, Debug)]
12342 pub type ListFormatOptions;
12343
12344 #[wasm_bindgen(method, getter = localeMatcher)]
12345 pub fn get_locale_matcher(this: &ListFormatOptions) -> Option<LocaleMatcher>;
12346 #[wasm_bindgen(method, setter = localeMatcher)]
12347 pub fn set_locale_matcher(this: &ListFormatOptions, value: LocaleMatcher);
12348
12349 #[wasm_bindgen(method, getter = type)]
12350 pub fn get_type(this: &ListFormatOptions) -> Option<ListFormatType>;
12351 #[wasm_bindgen(method, setter = type)]
12352 pub fn set_type(this: &ListFormatOptions, value: ListFormatType);
12353
12354 #[wasm_bindgen(method, getter = style)]
12355 pub fn get_style(this: &ListFormatOptions) -> Option<ListFormatStyle>;
12356 #[wasm_bindgen(method, setter = style)]
12357 pub fn set_style(this: &ListFormatOptions, value: ListFormatStyle);
12358 }
12359
12360 impl ListFormatOptions {
12361 pub fn new() -> ListFormatOptions {
12362 JsCast::unchecked_into(Object::new())
12363 }
12364 }
12365
12366 impl Default for ListFormatOptions {
12367 fn default() -> Self {
12368 ListFormatOptions::new()
12369 }
12370 }
12371
12372 // Intl.ResolvedListFormatOptions
12373 #[wasm_bindgen]
12374 extern "C" {
12375 /// Resolved options returned by `Intl.ListFormat.prototype.resolvedOptions()`.
12376 ///
12377 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/resolvedOptions)
12378 #[wasm_bindgen(extends = ListFormatOptions)]
12379 #[derive(Clone, Debug)]
12380 pub type ResolvedListFormatOptions;
12381
12382 /// The resolved locale string.
12383 #[wasm_bindgen(method, getter = locale)]
12384 pub fn get_locale(this: &ResolvedListFormatOptions) -> JsString;
12385 }
12386
12387 // Intl.ListFormatPart
12388 #[wasm_bindgen]
12389 extern "C" {
12390 /// A part of the formatted list returned by `formatToParts()`.
12391 ///
12392 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/formatToParts)
12393 #[wasm_bindgen(extends = Object)]
12394 #[derive(Clone, Debug)]
12395 pub type ListFormatPart;
12396
12397 /// The type of the part ("element" or "literal").
12398 #[wasm_bindgen(method, getter = type)]
12399 pub fn type_(this: &ListFormatPart) -> ListFormatPartType;
12400
12401 /// The value of the part.
12402 #[wasm_bindgen(method, getter)]
12403 pub fn value(this: &ListFormatPart) -> JsString;
12404 }
12405
12406 // Intl.ListFormat
12407 #[wasm_bindgen]
12408 extern "C" {
12409 /// The `Intl.ListFormat` object enables language-sensitive list formatting.
12410 ///
12411 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat)
12412 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.ListFormat")]
12413 #[derive(Clone, Debug)]
12414 pub type ListFormat;
12415
12416 /// Creates a new `Intl.ListFormat` object.
12417 ///
12418 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/ListFormat)
12419 #[cfg(not(js_sys_unstable_apis))]
12420 #[wasm_bindgen(constructor, js_namespace = Intl)]
12421 pub fn new(locales: &Array, options: &Object) -> ListFormat;
12422
12423 /// Creates a new `Intl.ListFormat` object.
12424 ///
12425 /// Throws a `RangeError` if locales or options contain invalid values.
12426 ///
12427 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/ListFormat)
12428 #[cfg(js_sys_unstable_apis)]
12429 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
12430 pub fn new(
12431 locales: &[JsString],
12432 options: &ListFormatOptions,
12433 ) -> Result<ListFormat, JsValue>;
12434
12435 /// Formats a list of strings according to the locale and options.
12436 ///
12437 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/format)
12438 #[cfg(not(js_sys_unstable_apis))]
12439 #[wasm_bindgen(method, js_class = "Intl.ListFormat")]
12440 pub fn format(this: &ListFormat, list: &Array) -> JsString;
12441
12442 /// Formats a list of strings according to the locale and options.
12443 ///
12444 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/format)
12445 #[cfg(js_sys_unstable_apis)]
12446 #[wasm_bindgen(method, js_class = "Intl.ListFormat")]
12447 pub fn format(this: &ListFormat, list: &[JsString]) -> JsString;
12448
12449 /// Returns an array of objects representing the list in parts.
12450 ///
12451 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/formatToParts)
12452 #[cfg(not(js_sys_unstable_apis))]
12453 #[wasm_bindgen(method, js_class = "Intl.ListFormat", js_name = formatToParts)]
12454 pub fn format_to_parts(this: &ListFormat, list: &Array) -> Array;
12455
12456 /// Returns an array of objects representing the list in parts.
12457 ///
12458 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/formatToParts)
12459 #[cfg(js_sys_unstable_apis)]
12460 #[wasm_bindgen(method, js_class = "Intl.ListFormat", js_name = formatToParts)]
12461 pub fn format_to_parts(this: &ListFormat, list: &[JsString]) -> Array<ListFormatPart>;
12462
12463 /// Returns an object with properties reflecting the options used.
12464 ///
12465 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/resolvedOptions)
12466 #[cfg(not(js_sys_unstable_apis))]
12467 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
12468 pub fn resolved_options(this: &ListFormat) -> Object;
12469
12470 /// Returns an object with properties reflecting the options used.
12471 ///
12472 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/resolvedOptions)
12473 #[cfg(js_sys_unstable_apis)]
12474 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
12475 pub fn resolved_options(this: &ListFormat) -> ResolvedListFormatOptions;
12476
12477 /// Returns an array of supported locales.
12478 ///
12479 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/supportedLocalesOf)
12480 #[cfg(not(js_sys_unstable_apis))]
12481 #[wasm_bindgen(static_method_of = ListFormat, js_namespace = Intl, js_name = supportedLocalesOf)]
12482 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
12483
12484 /// Returns an array of supported locales.
12485 ///
12486 /// Throws a `RangeError` if locales contain invalid values.
12487 ///
12488 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/supportedLocalesOf)
12489 #[cfg(js_sys_unstable_apis)]
12490 #[wasm_bindgen(static_method_of = ListFormat, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
12491 pub fn supported_locales_of(
12492 locales: &[JsString],
12493 options: &LocaleMatcherOptions,
12494 ) -> Result<Array<JsString>, JsValue>;
12495 }
12496
12497 #[cfg(not(js_sys_unstable_apis))]
12498 impl Default for ListFormat {
12499 fn default() -> Self {
12500 Self::new(
12501 &JsValue::UNDEFINED.unchecked_into(),
12502 &JsValue::UNDEFINED.unchecked_into(),
12503 )
12504 }
12505 }
12506
12507 #[cfg(js_sys_unstable_apis)]
12508 impl Default for ListFormat {
12509 fn default() -> Self {
12510 Self::new(&[], &Default::default()).unwrap()
12511 }
12512 }
12513
12514 // Intl.SegmenterOptions
12515 #[wasm_bindgen]
12516 extern "C" {
12517 /// Options for `Intl.Segmenter` constructor.
12518 ///
12519 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/Segmenter#options)
12520 #[wasm_bindgen(extends = Object)]
12521 #[derive(Clone, Debug)]
12522 pub type SegmenterOptions;
12523
12524 #[wasm_bindgen(method, getter = localeMatcher)]
12525 pub fn get_locale_matcher(this: &SegmenterOptions) -> Option<LocaleMatcher>;
12526 #[wasm_bindgen(method, setter = localeMatcher)]
12527 pub fn set_locale_matcher(this: &SegmenterOptions, value: LocaleMatcher);
12528
12529 #[wasm_bindgen(method, getter = granularity)]
12530 pub fn get_granularity(this: &SegmenterOptions) -> Option<SegmenterGranularity>;
12531 #[wasm_bindgen(method, setter = granularity)]
12532 pub fn set_granularity(this: &SegmenterOptions, value: SegmenterGranularity);
12533 }
12534
12535 impl SegmenterOptions {
12536 pub fn new() -> SegmenterOptions {
12537 JsCast::unchecked_into(Object::new())
12538 }
12539 }
12540
12541 impl Default for SegmenterOptions {
12542 fn default() -> Self {
12543 SegmenterOptions::new()
12544 }
12545 }
12546
12547 // Intl.ResolvedSegmenterOptions
12548 #[wasm_bindgen]
12549 extern "C" {
12550 /// Resolved options returned by `Intl.Segmenter.prototype.resolvedOptions()`.
12551 ///
12552 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/resolvedOptions)
12553 #[wasm_bindgen(extends = SegmenterOptions)]
12554 #[derive(Clone, Debug)]
12555 pub type ResolvedSegmenterOptions;
12556
12557 /// The resolved locale string.
12558 #[wasm_bindgen(method, getter = locale)]
12559 pub fn get_locale(this: &ResolvedSegmenterOptions) -> JsString;
12560 }
12561
12562 // Intl.SegmentData
12563 #[wasm_bindgen]
12564 extern "C" {
12565 /// Data about a segment returned by the Segments iterator.
12566 ///
12567 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/segment/Segments#segment_data)
12568 #[wasm_bindgen(extends = Object)]
12569 #[derive(Clone, Debug)]
12570 pub type SegmentData;
12571
12572 /// The segment string.
12573 #[wasm_bindgen(method, getter)]
12574 pub fn segment(this: &SegmentData) -> JsString;
12575
12576 /// The index of the segment in the original string.
12577 #[wasm_bindgen(method, getter)]
12578 pub fn index(this: &SegmentData) -> u32;
12579
12580 /// The original input string.
12581 #[wasm_bindgen(method, getter)]
12582 pub fn input(this: &SegmentData) -> JsString;
12583
12584 /// Whether the segment is word-like (only for word granularity).
12585 #[wasm_bindgen(method, getter = isWordLike)]
12586 pub fn is_word_like(this: &SegmentData) -> Option<bool>;
12587 }
12588
12589 // Intl.Segments
12590 #[wasm_bindgen]
12591 extern "C" {
12592 /// The Segments object is an iterable collection of segments of a string.
12593 ///
12594 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/segment/Segments)
12595 #[wasm_bindgen(extends = Object)]
12596 #[derive(Clone, Debug)]
12597 pub type Segments;
12598
12599 /// Returns segment data for the segment containing the character at the given index.
12600 ///
12601 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/segment/Segments/containing)
12602 #[wasm_bindgen(method)]
12603 pub fn containing(this: &Segments, index: u32) -> Option<SegmentData>;
12604 }
12605
12606 // Intl.Segmenter
12607 #[wasm_bindgen]
12608 extern "C" {
12609 /// The `Intl.Segmenter` object enables locale-sensitive text segmentation.
12610 ///
12611 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter)
12612 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.Segmenter")]
12613 #[derive(Clone, Debug)]
12614 pub type Segmenter;
12615
12616 /// Creates a new `Intl.Segmenter` object.
12617 ///
12618 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/Segmenter)
12619 #[cfg(not(js_sys_unstable_apis))]
12620 #[wasm_bindgen(constructor, js_namespace = Intl)]
12621 pub fn new(locales: &Array, options: &Object) -> Segmenter;
12622
12623 /// Creates a new `Intl.Segmenter` object.
12624 ///
12625 /// Throws a `RangeError` if locales or options contain invalid values.
12626 ///
12627 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/Segmenter)
12628 #[cfg(js_sys_unstable_apis)]
12629 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
12630 pub fn new(locales: &[JsString], options: &SegmenterOptions) -> Result<Segmenter, JsValue>;
12631
12632 /// Returns a Segments object containing the segments of the input string.
12633 ///
12634 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/segment)
12635 #[wasm_bindgen(method, js_class = "Intl.Segmenter")]
12636 pub fn segment(this: &Segmenter, input: &str) -> Segments;
12637
12638 /// Returns an object with properties reflecting the options used.
12639 ///
12640 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/resolvedOptions)
12641 #[cfg(not(js_sys_unstable_apis))]
12642 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
12643 pub fn resolved_options(this: &Segmenter) -> Object;
12644
12645 /// Returns an object with properties reflecting the options used.
12646 ///
12647 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/resolvedOptions)
12648 #[cfg(js_sys_unstable_apis)]
12649 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
12650 pub fn resolved_options(this: &Segmenter) -> ResolvedSegmenterOptions;
12651
12652 /// Returns an array of supported locales.
12653 ///
12654 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/supportedLocalesOf)
12655 #[cfg(not(js_sys_unstable_apis))]
12656 #[wasm_bindgen(static_method_of = Segmenter, js_namespace = Intl, js_name = supportedLocalesOf)]
12657 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
12658
12659 /// Returns an array of supported locales.
12660 ///
12661 /// Throws a `RangeError` if locales contain invalid values.
12662 ///
12663 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/supportedLocalesOf)
12664 #[cfg(js_sys_unstable_apis)]
12665 #[wasm_bindgen(static_method_of = Segmenter, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
12666 pub fn supported_locales_of(
12667 locales: &[JsString],
12668 options: &LocaleMatcherOptions,
12669 ) -> Result<Array<JsString>, JsValue>;
12670 }
12671
12672 #[cfg(not(js_sys_unstable_apis))]
12673 impl Default for Segmenter {
12674 fn default() -> Self {
12675 Self::new(
12676 &JsValue::UNDEFINED.unchecked_into(),
12677 &JsValue::UNDEFINED.unchecked_into(),
12678 )
12679 }
12680 }
12681
12682 #[cfg(js_sys_unstable_apis)]
12683 impl Default for Segmenter {
12684 fn default() -> Self {
12685 Self::new(&[], &Default::default()).unwrap()
12686 }
12687 }
12688
12689 // Intl.DisplayNamesOptions
12690 #[wasm_bindgen]
12691 extern "C" {
12692 /// Options for `Intl.DisplayNames` constructor.
12693 ///
12694 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/DisplayNames#options)
12695 #[wasm_bindgen(extends = Object)]
12696 #[derive(Clone, Debug)]
12697 pub type DisplayNamesOptions;
12698
12699 #[wasm_bindgen(method, getter = localeMatcher)]
12700 pub fn get_locale_matcher(this: &DisplayNamesOptions) -> Option<LocaleMatcher>;
12701 #[wasm_bindgen(method, setter = localeMatcher)]
12702 pub fn set_locale_matcher(this: &DisplayNamesOptions, value: LocaleMatcher);
12703
12704 #[wasm_bindgen(method, getter = type)]
12705 pub fn get_type(this: &DisplayNamesOptions) -> Option<DisplayNamesType>;
12706 #[wasm_bindgen(method, setter = type)]
12707 pub fn set_type(this: &DisplayNamesOptions, value: DisplayNamesType);
12708
12709 #[wasm_bindgen(method, getter = style)]
12710 pub fn get_style(this: &DisplayNamesOptions) -> Option<DisplayNamesStyle>;
12711 #[wasm_bindgen(method, setter = style)]
12712 pub fn set_style(this: &DisplayNamesOptions, value: DisplayNamesStyle);
12713
12714 #[wasm_bindgen(method, getter = fallback)]
12715 pub fn get_fallback(this: &DisplayNamesOptions) -> Option<DisplayNamesFallback>;
12716 #[wasm_bindgen(method, setter = fallback)]
12717 pub fn set_fallback(this: &DisplayNamesOptions, value: DisplayNamesFallback);
12718
12719 #[wasm_bindgen(method, getter = languageDisplay)]
12720 pub fn get_language_display(
12721 this: &DisplayNamesOptions,
12722 ) -> Option<DisplayNamesLanguageDisplay>;
12723 #[wasm_bindgen(method, setter = languageDisplay)]
12724 pub fn set_language_display(this: &DisplayNamesOptions, value: DisplayNamesLanguageDisplay);
12725 }
12726
12727 impl DisplayNamesOptions {
12728 pub fn new() -> DisplayNamesOptions {
12729 JsCast::unchecked_into(Object::new())
12730 }
12731 }
12732
12733 impl Default for DisplayNamesOptions {
12734 fn default() -> Self {
12735 DisplayNamesOptions::new()
12736 }
12737 }
12738
12739 // Intl.ResolvedDisplayNamesOptions
12740 #[wasm_bindgen]
12741 extern "C" {
12742 /// Resolved options returned by `Intl.DisplayNames.prototype.resolvedOptions()`.
12743 ///
12744 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/resolvedOptions)
12745 #[wasm_bindgen(extends = DisplayNamesOptions)]
12746 #[derive(Clone, Debug)]
12747 pub type ResolvedDisplayNamesOptions;
12748
12749 /// The resolved locale string.
12750 #[wasm_bindgen(method, getter = locale)]
12751 pub fn get_locale(this: &ResolvedDisplayNamesOptions) -> JsString;
12752 }
12753
12754 // Intl.DisplayNames
12755 #[wasm_bindgen]
12756 extern "C" {
12757 /// The `Intl.DisplayNames` object enables the consistent translation of
12758 /// language, region, and script display names.
12759 ///
12760 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames)
12761 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.DisplayNames")]
12762 #[derive(Clone, Debug)]
12763 pub type DisplayNames;
12764
12765 /// Creates a new `Intl.DisplayNames` object.
12766 ///
12767 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/DisplayNames)
12768 #[cfg(not(js_sys_unstable_apis))]
12769 #[wasm_bindgen(constructor, js_namespace = Intl)]
12770 pub fn new(locales: &Array, options: &Object) -> DisplayNames;
12771
12772 /// Creates a new `Intl.DisplayNames` object.
12773 ///
12774 /// Throws a `RangeError` if locales or options contain invalid values.
12775 ///
12776 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/DisplayNames)
12777 #[cfg(js_sys_unstable_apis)]
12778 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
12779 pub fn new(
12780 locales: &[JsString],
12781 options: &DisplayNamesOptions,
12782 ) -> Result<DisplayNames, JsValue>;
12783
12784 /// Returns the display name for the given code.
12785 ///
12786 /// Returns `undefined` if fallback is "none" and no name is available.
12787 ///
12788 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/of)
12789 #[wasm_bindgen(method, js_class = "Intl.DisplayNames")]
12790 pub fn of(this: &DisplayNames, code: &str) -> Option<JsString>;
12791
12792 /// Returns an object with properties reflecting the options used.
12793 ///
12794 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/resolvedOptions)
12795 #[cfg(not(js_sys_unstable_apis))]
12796 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
12797 pub fn resolved_options(this: &DisplayNames) -> Object;
12798
12799 /// Returns an object with properties reflecting the options used.
12800 ///
12801 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/resolvedOptions)
12802 #[cfg(js_sys_unstable_apis)]
12803 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
12804 pub fn resolved_options(this: &DisplayNames) -> ResolvedDisplayNamesOptions;
12805
12806 /// Returns an array of supported locales.
12807 ///
12808 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/supportedLocalesOf)
12809 #[cfg(not(js_sys_unstable_apis))]
12810 #[wasm_bindgen(static_method_of = DisplayNames, js_namespace = Intl, js_name = supportedLocalesOf)]
12811 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
12812
12813 /// Returns an array of supported locales.
12814 ///
12815 /// Throws a `RangeError` if locales contain invalid values.
12816 ///
12817 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/supportedLocalesOf)
12818 #[cfg(js_sys_unstable_apis)]
12819 #[wasm_bindgen(static_method_of = DisplayNames, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
12820 pub fn supported_locales_of(
12821 locales: &[JsString],
12822 options: &LocaleMatcherOptions,
12823 ) -> Result<Array<JsString>, JsValue>;
12824 }
12825
12826 // Intl.Locale
12827 #[wasm_bindgen]
12828 extern "C" {
12829 /// The `Intl.Locale` object is a standard built-in property of the Intl object
12830 /// that represents a Unicode locale identifier.
12831 ///
12832 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale)
12833 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.Locale")]
12834 #[derive(Clone, Debug)]
12835 pub type Locale;
12836
12837 /// Creates a new `Intl.Locale` object.
12838 ///
12839 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/Locale)
12840 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
12841 pub fn new(tag: &str) -> Result<Locale, JsValue>;
12842
12843 /// Creates a new `Intl.Locale` object with options.
12844 ///
12845 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/Locale)
12846 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
12847 pub fn new_with_options(tag: &str, options: &Object) -> Result<Locale, JsValue>;
12848
12849 /// The base name of the locale (language + region + script).
12850 ///
12851 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/baseName)
12852 #[wasm_bindgen(method, getter = baseName)]
12853 pub fn base_name(this: &Locale) -> JsString;
12854
12855 /// The calendar type for the locale.
12856 ///
12857 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/calendar)
12858 #[wasm_bindgen(method, getter)]
12859 pub fn calendar(this: &Locale) -> Option<JsString>;
12860
12861 /// The case first sorting option.
12862 ///
12863 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/caseFirst)
12864 #[wasm_bindgen(method, getter = caseFirst)]
12865 pub fn case_first(this: &Locale) -> Option<JsString>;
12866
12867 /// The collation type for the locale.
12868 ///
12869 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/collation)
12870 #[wasm_bindgen(method, getter)]
12871 pub fn collation(this: &Locale) -> Option<JsString>;
12872
12873 /// The hour cycle for the locale.
12874 ///
12875 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/hourCycle)
12876 #[wasm_bindgen(method, getter = hourCycle)]
12877 pub fn hour_cycle(this: &Locale) -> Option<JsString>;
12878
12879 /// The language code for the locale.
12880 ///
12881 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/language)
12882 #[wasm_bindgen(method, getter)]
12883 pub fn language(this: &Locale) -> JsString;
12884
12885 /// The numbering system for the locale.
12886 ///
12887 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/numberingSystem)
12888 #[wasm_bindgen(method, getter = numberingSystem)]
12889 pub fn numbering_system(this: &Locale) -> Option<JsString>;
12890
12891 /// Whether the locale uses numeric collation.
12892 ///
12893 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/numeric)
12894 #[wasm_bindgen(method, getter)]
12895 pub fn numeric(this: &Locale) -> bool;
12896
12897 /// The region code for the locale.
12898 ///
12899 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/region)
12900 #[wasm_bindgen(method, getter)]
12901 pub fn region(this: &Locale) -> Option<JsString>;
12902
12903 /// The script code for the locale.
12904 ///
12905 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/script)
12906 #[wasm_bindgen(method, getter)]
12907 pub fn script(this: &Locale) -> Option<JsString>;
12908
12909 /// Returns an array of available calendars for the locale.
12910 ///
12911 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getCalendars)
12912 #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getCalendars)]
12913 pub fn get_calendars(this: &Locale) -> Array<JsString>;
12914
12915 /// Returns an array of available collations for the locale.
12916 ///
12917 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getCollations)
12918 #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getCollations)]
12919 pub fn get_collations(this: &Locale) -> Array<JsString>;
12920
12921 /// Returns an array of available hour cycles for the locale.
12922 ///
12923 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getHourCycles)
12924 #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getHourCycles)]
12925 pub fn get_hour_cycles(this: &Locale) -> Array<JsString>;
12926
12927 /// Returns an array of available numbering systems for the locale.
12928 ///
12929 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getNumberingSystems)
12930 #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getNumberingSystems)]
12931 pub fn get_numbering_systems(this: &Locale) -> Array<JsString>;
12932
12933 /// Returns an array of available time zones for the locale's region.
12934 ///
12935 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getTimeZones)
12936 #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getTimeZones)]
12937 pub fn get_time_zones(this: &Locale) -> Option<Array<JsString>>;
12938
12939 /// Returns week information for the locale.
12940 ///
12941 /// May not be available in all environments.
12942 ///
12943 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getWeekInfo)
12944 #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getWeekInfo, catch)]
12945 pub fn get_week_info(this: &Locale) -> Result<WeekInfo, JsValue>;
12946
12947 /// Returns text layout 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/getTextInfo)
12952 #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getTextInfo, catch)]
12953 pub fn get_text_info(this: &Locale) -> Result<TextInfo, JsValue>;
12954
12955 /// Returns a new Locale with the specified calendar.
12956 ///
12957 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/maximize)
12958 #[wasm_bindgen(method, js_class = "Intl.Locale")]
12959 pub fn maximize(this: &Locale) -> Locale;
12960
12961 /// Returns a new Locale with the minimal subtags.
12962 ///
12963 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/minimize)
12964 #[wasm_bindgen(method, js_class = "Intl.Locale")]
12965 pub fn minimize(this: &Locale) -> Locale;
12966 }
12967
12968 // Intl.Locale WeekInfo
12969 #[wasm_bindgen]
12970 extern "C" {
12971 /// Week information for a locale.
12972 ///
12973 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getWeekInfo)
12974 #[wasm_bindgen(extends = Object)]
12975 #[derive(Clone, Debug)]
12976 pub type WeekInfo;
12977
12978 /// The first day of the week (1 = Monday, 7 = Sunday).
12979 #[wasm_bindgen(method, getter = firstDay)]
12980 pub fn first_day(this: &WeekInfo) -> u8;
12981
12982 /// Array of weekend days.
12983 #[wasm_bindgen(method, getter)]
12984 pub fn weekend(this: &WeekInfo) -> Array<Number>;
12985
12986 /// Minimal days in the first week of the year.
12987 #[wasm_bindgen(method, getter = minimalDays)]
12988 pub fn minimal_days(this: &WeekInfo) -> u8;
12989 }
12990
12991 // Intl.Locale TextInfo
12992 #[wasm_bindgen]
12993 extern "C" {
12994 /// Text layout information for a locale.
12995 ///
12996 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getTextInfo)
12997 #[wasm_bindgen(extends = Object)]
12998 #[derive(Clone, Debug)]
12999 pub type TextInfo;
13000
13001 /// The text direction ("ltr" or "rtl").
13002 #[wasm_bindgen(method, getter)]
13003 pub fn direction(this: &TextInfo) -> JsString;
13004 }
13005
13006 // Intl.DurationFormat enums
13007
13008 /// The style for duration formatting.
13009 ///
13010 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat#style)
13011 #[wasm_bindgen]
13012 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
13013 pub enum DurationFormatStyle {
13014 Long = "long",
13015 Short = "short",
13016 Narrow = "narrow",
13017 Digital = "digital",
13018 }
13019
13020 /// The display style for individual duration units.
13021 ///
13022 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat#years)
13023 #[wasm_bindgen]
13024 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
13025 pub enum DurationUnitStyle {
13026 Long = "long",
13027 Short = "short",
13028 Narrow = "narrow",
13029 }
13030
13031 /// The display style for time duration units (hours, minutes, seconds).
13032 ///
13033 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat#hours)
13034 #[wasm_bindgen]
13035 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
13036 pub enum DurationTimeUnitStyle {
13037 Long = "long",
13038 Short = "short",
13039 Narrow = "narrow",
13040 Numeric = "numeric",
13041 #[wasm_bindgen(js_name = "2-digit")]
13042 TwoDigit = "2-digit",
13043 }
13044
13045 /// The display option for duration units.
13046 ///
13047 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat#yearsdisplay)
13048 #[wasm_bindgen]
13049 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
13050 pub enum DurationUnitDisplay {
13051 Auto = "auto",
13052 Always = "always",
13053 }
13054
13055 /// The type of a duration format part.
13056 ///
13057 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/formatToParts#type)
13058 #[wasm_bindgen]
13059 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
13060 pub enum DurationFormatPartType {
13061 Years = "years",
13062 Months = "months",
13063 Weeks = "weeks",
13064 Days = "days",
13065 Hours = "hours",
13066 Minutes = "minutes",
13067 Seconds = "seconds",
13068 Milliseconds = "milliseconds",
13069 Microseconds = "microseconds",
13070 Nanoseconds = "nanoseconds",
13071 Literal = "literal",
13072 Integer = "integer",
13073 Decimal = "decimal",
13074 Fraction = "fraction",
13075 }
13076
13077 // Intl.DurationFormatOptions
13078 #[wasm_bindgen]
13079 extern "C" {
13080 /// Options for `Intl.DurationFormat` constructor.
13081 ///
13082 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat#options)
13083 #[wasm_bindgen(extends = Object)]
13084 #[derive(Clone, Debug)]
13085 pub type DurationFormatOptions;
13086
13087 #[wasm_bindgen(method, getter = localeMatcher)]
13088 pub fn get_locale_matcher(this: &DurationFormatOptions) -> Option<LocaleMatcher>;
13089 #[wasm_bindgen(method, setter = localeMatcher)]
13090 pub fn set_locale_matcher(this: &DurationFormatOptions, value: LocaleMatcher);
13091
13092 #[wasm_bindgen(method, getter = style)]
13093 pub fn get_style(this: &DurationFormatOptions) -> Option<DurationFormatStyle>;
13094 #[wasm_bindgen(method, setter = style)]
13095 pub fn set_style(this: &DurationFormatOptions, value: DurationFormatStyle);
13096
13097 #[wasm_bindgen(method, getter = years)]
13098 pub fn get_years(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
13099 #[wasm_bindgen(method, setter = years)]
13100 pub fn set_years(this: &DurationFormatOptions, value: DurationUnitStyle);
13101
13102 #[wasm_bindgen(method, getter = yearsDisplay)]
13103 pub fn get_years_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
13104 #[wasm_bindgen(method, setter = yearsDisplay)]
13105 pub fn set_years_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
13106
13107 #[wasm_bindgen(method, getter = months)]
13108 pub fn get_months(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
13109 #[wasm_bindgen(method, setter = months)]
13110 pub fn set_months(this: &DurationFormatOptions, value: DurationUnitStyle);
13111
13112 #[wasm_bindgen(method, getter = monthsDisplay)]
13113 pub fn get_months_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
13114 #[wasm_bindgen(method, setter = monthsDisplay)]
13115 pub fn set_months_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
13116
13117 #[wasm_bindgen(method, getter = weeks)]
13118 pub fn get_weeks(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
13119 #[wasm_bindgen(method, setter = weeks)]
13120 pub fn set_weeks(this: &DurationFormatOptions, value: DurationUnitStyle);
13121
13122 #[wasm_bindgen(method, getter = weeksDisplay)]
13123 pub fn get_weeks_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
13124 #[wasm_bindgen(method, setter = weeksDisplay)]
13125 pub fn set_weeks_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
13126
13127 #[wasm_bindgen(method, getter = days)]
13128 pub fn get_days(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
13129 #[wasm_bindgen(method, setter = days)]
13130 pub fn set_days(this: &DurationFormatOptions, value: DurationUnitStyle);
13131
13132 #[wasm_bindgen(method, getter = daysDisplay)]
13133 pub fn get_days_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
13134 #[wasm_bindgen(method, setter = daysDisplay)]
13135 pub fn set_days_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
13136
13137 #[wasm_bindgen(method, getter = hours)]
13138 pub fn get_hours(this: &DurationFormatOptions) -> Option<DurationTimeUnitStyle>;
13139 #[wasm_bindgen(method, setter = hours)]
13140 pub fn set_hours(this: &DurationFormatOptions, value: DurationTimeUnitStyle);
13141
13142 #[wasm_bindgen(method, getter = hoursDisplay)]
13143 pub fn get_hours_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
13144 #[wasm_bindgen(method, setter = hoursDisplay)]
13145 pub fn set_hours_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
13146
13147 #[wasm_bindgen(method, getter = minutes)]
13148 pub fn get_minutes(this: &DurationFormatOptions) -> Option<DurationTimeUnitStyle>;
13149 #[wasm_bindgen(method, setter = minutes)]
13150 pub fn set_minutes(this: &DurationFormatOptions, value: DurationTimeUnitStyle);
13151
13152 #[wasm_bindgen(method, getter = minutesDisplay)]
13153 pub fn get_minutes_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
13154 #[wasm_bindgen(method, setter = minutesDisplay)]
13155 pub fn set_minutes_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
13156
13157 #[wasm_bindgen(method, getter = seconds)]
13158 pub fn get_seconds(this: &DurationFormatOptions) -> Option<DurationTimeUnitStyle>;
13159 #[wasm_bindgen(method, setter = seconds)]
13160 pub fn set_seconds(this: &DurationFormatOptions, value: DurationTimeUnitStyle);
13161
13162 #[wasm_bindgen(method, getter = secondsDisplay)]
13163 pub fn get_seconds_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
13164 #[wasm_bindgen(method, setter = secondsDisplay)]
13165 pub fn set_seconds_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
13166
13167 #[wasm_bindgen(method, getter = milliseconds)]
13168 pub fn get_milliseconds(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
13169 #[wasm_bindgen(method, setter = milliseconds)]
13170 pub fn set_milliseconds(this: &DurationFormatOptions, value: DurationUnitStyle);
13171
13172 #[wasm_bindgen(method, getter = millisecondsDisplay)]
13173 pub fn get_milliseconds_display(
13174 this: &DurationFormatOptions,
13175 ) -> Option<DurationUnitDisplay>;
13176 #[wasm_bindgen(method, setter = millisecondsDisplay)]
13177 pub fn set_milliseconds_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
13178
13179 #[wasm_bindgen(method, getter = microseconds)]
13180 pub fn get_microseconds(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
13181 #[wasm_bindgen(method, setter = microseconds)]
13182 pub fn set_microseconds(this: &DurationFormatOptions, value: DurationUnitStyle);
13183
13184 #[wasm_bindgen(method, getter = microsecondsDisplay)]
13185 pub fn get_microseconds_display(
13186 this: &DurationFormatOptions,
13187 ) -> Option<DurationUnitDisplay>;
13188 #[wasm_bindgen(method, setter = microsecondsDisplay)]
13189 pub fn set_microseconds_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
13190
13191 #[wasm_bindgen(method, getter = nanoseconds)]
13192 pub fn get_nanoseconds(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
13193 #[wasm_bindgen(method, setter = nanoseconds)]
13194 pub fn set_nanoseconds(this: &DurationFormatOptions, value: DurationUnitStyle);
13195
13196 #[wasm_bindgen(method, getter = nanosecondsDisplay)]
13197 pub fn get_nanoseconds_display(this: &DurationFormatOptions)
13198 -> Option<DurationUnitDisplay>;
13199 #[wasm_bindgen(method, setter = nanosecondsDisplay)]
13200 pub fn set_nanoseconds_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
13201
13202 #[wasm_bindgen(method, getter = fractionalDigits)]
13203 pub fn get_fractional_digits(this: &DurationFormatOptions) -> Option<u8>;
13204 #[wasm_bindgen(method, setter = fractionalDigits)]
13205 pub fn set_fractional_digits(this: &DurationFormatOptions, value: u8);
13206 }
13207
13208 impl DurationFormatOptions {
13209 pub fn new() -> DurationFormatOptions {
13210 JsCast::unchecked_into(Object::new())
13211 }
13212 }
13213
13214 impl Default for DurationFormatOptions {
13215 fn default() -> Self {
13216 DurationFormatOptions::new()
13217 }
13218 }
13219
13220 // Intl.ResolvedDurationFormatOptions
13221 #[wasm_bindgen]
13222 extern "C" {
13223 /// Resolved options returned by `Intl.DurationFormat.prototype.resolvedOptions()`.
13224 ///
13225 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/resolvedOptions)
13226 #[wasm_bindgen(extends = DurationFormatOptions)]
13227 #[derive(Clone, Debug)]
13228 pub type ResolvedDurationFormatOptions;
13229
13230 /// The resolved locale string.
13231 #[wasm_bindgen(method, getter = locale)]
13232 pub fn get_locale(this: &ResolvedDurationFormatOptions) -> JsString;
13233
13234 /// The resolved numbering system.
13235 #[wasm_bindgen(method, getter = numberingSystem)]
13236 pub fn get_numbering_system(this: &ResolvedDurationFormatOptions) -> JsString;
13237 }
13238
13239 // Intl.Duration (input object for DurationFormat)
13240 #[wasm_bindgen]
13241 extern "C" {
13242 /// A duration object used as input to `Intl.DurationFormat.format()`.
13243 ///
13244 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/format#duration)
13245 #[wasm_bindgen(extends = Object)]
13246 #[derive(Clone, Debug)]
13247 pub type Duration;
13248
13249 #[wasm_bindgen(method, getter)]
13250 pub fn years(this: &Duration) -> Option<f64>;
13251 #[wasm_bindgen(method, setter)]
13252 pub fn set_years(this: &Duration, value: f64);
13253
13254 #[wasm_bindgen(method, getter)]
13255 pub fn months(this: &Duration) -> Option<f64>;
13256 #[wasm_bindgen(method, setter)]
13257 pub fn set_months(this: &Duration, value: f64);
13258
13259 #[wasm_bindgen(method, getter)]
13260 pub fn weeks(this: &Duration) -> Option<f64>;
13261 #[wasm_bindgen(method, setter)]
13262 pub fn set_weeks(this: &Duration, value: f64);
13263
13264 #[wasm_bindgen(method, getter)]
13265 pub fn days(this: &Duration) -> Option<f64>;
13266 #[wasm_bindgen(method, setter)]
13267 pub fn set_days(this: &Duration, value: f64);
13268
13269 #[wasm_bindgen(method, getter)]
13270 pub fn hours(this: &Duration) -> Option<f64>;
13271 #[wasm_bindgen(method, setter)]
13272 pub fn set_hours(this: &Duration, value: f64);
13273
13274 #[wasm_bindgen(method, getter)]
13275 pub fn minutes(this: &Duration) -> Option<f64>;
13276 #[wasm_bindgen(method, setter)]
13277 pub fn set_minutes(this: &Duration, value: f64);
13278
13279 #[wasm_bindgen(method, getter)]
13280 pub fn seconds(this: &Duration) -> Option<f64>;
13281 #[wasm_bindgen(method, setter)]
13282 pub fn set_seconds(this: &Duration, value: f64);
13283
13284 #[wasm_bindgen(method, getter)]
13285 pub fn milliseconds(this: &Duration) -> Option<f64>;
13286 #[wasm_bindgen(method, setter)]
13287 pub fn set_milliseconds(this: &Duration, value: f64);
13288
13289 #[wasm_bindgen(method, getter)]
13290 pub fn microseconds(this: &Duration) -> Option<f64>;
13291 #[wasm_bindgen(method, setter)]
13292 pub fn set_microseconds(this: &Duration, value: f64);
13293
13294 #[wasm_bindgen(method, getter)]
13295 pub fn nanoseconds(this: &Duration) -> Option<f64>;
13296 #[wasm_bindgen(method, setter)]
13297 pub fn set_nanoseconds(this: &Duration, value: f64);
13298 }
13299
13300 impl Duration {
13301 pub fn new() -> Duration {
13302 JsCast::unchecked_into(Object::new())
13303 }
13304 }
13305
13306 impl Default for Duration {
13307 fn default() -> Self {
13308 Duration::new()
13309 }
13310 }
13311
13312 // Intl.DurationFormatPart
13313 #[wasm_bindgen]
13314 extern "C" {
13315 /// A part of the formatted duration returned by `formatToParts()`.
13316 ///
13317 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/formatToParts)
13318 #[wasm_bindgen(extends = Object)]
13319 #[derive(Clone, Debug)]
13320 pub type DurationFormatPart;
13321
13322 /// The type of the part.
13323 #[wasm_bindgen(method, getter = type)]
13324 pub fn type_(this: &DurationFormatPart) -> DurationFormatPartType;
13325
13326 /// The value of the part.
13327 #[wasm_bindgen(method, getter)]
13328 pub fn value(this: &DurationFormatPart) -> JsString;
13329
13330 /// The unit this part represents (if applicable).
13331 #[wasm_bindgen(method, getter)]
13332 pub fn unit(this: &DurationFormatPart) -> Option<JsString>;
13333 }
13334
13335 // Intl.DurationFormat
13336 #[wasm_bindgen]
13337 extern "C" {
13338 /// The `Intl.DurationFormat` object enables language-sensitive duration formatting.
13339 ///
13340 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat)
13341 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.DurationFormat")]
13342 #[derive(Clone, Debug)]
13343 pub type DurationFormat;
13344
13345 /// Creates a new `Intl.DurationFormat` object.
13346 ///
13347 /// Throws a `RangeError` if locales or options contain invalid values.
13348 ///
13349 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat)
13350 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
13351 pub fn new(
13352 locales: &[JsString],
13353 options: &DurationFormatOptions,
13354 ) -> Result<DurationFormat, JsValue>;
13355
13356 /// Formats a duration according to the locale and formatting options.
13357 ///
13358 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/format)
13359 #[wasm_bindgen(method, js_class = "Intl.DurationFormat")]
13360 pub fn format(this: &DurationFormat, duration: &Duration) -> JsString;
13361
13362 /// Returns an array of objects representing the formatted duration in parts.
13363 ///
13364 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/formatToParts)
13365 #[wasm_bindgen(method, js_class = "Intl.DurationFormat", js_name = formatToParts)]
13366 pub fn format_to_parts(
13367 this: &DurationFormat,
13368 duration: &Duration,
13369 ) -> Array<DurationFormatPart>;
13370
13371 /// Returns an object with properties reflecting the options used.
13372 ///
13373 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/resolvedOptions)
13374 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
13375 pub fn resolved_options(this: &DurationFormat) -> ResolvedDurationFormatOptions;
13376
13377 /// Returns an array of supported locales.
13378 ///
13379 /// Throws a `RangeError` if locales contain invalid values.
13380 ///
13381 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/supportedLocalesOf)
13382 #[wasm_bindgen(static_method_of = DurationFormat, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
13383 pub fn supported_locales_of(
13384 locales: &[JsString],
13385 options: &LocaleMatcherOptions,
13386 ) -> Result<Array<JsString>, JsValue>;
13387 }
13388
13389 impl Default for DurationFormat {
13390 fn default() -> Self {
13391 Self::new(&[], &Default::default()).unwrap()
13392 }
13393 }
13394}
13395
13396#[wasm_bindgen]
13397extern "C" {
13398 /// The `PromiseState` object represents the the status of the promise,
13399 /// as used in `allSettled`.
13400 ///
13401 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled)
13402 #[must_use]
13403 #[wasm_bindgen(extends = Object, typescript_type = "any")]
13404 #[derive(Clone, Debug)]
13405 pub type PromiseState<T = JsValue>;
13406
13407 /// A string, either "fulfilled" or "rejected", indicating the eventual state of the promise.
13408 #[wasm_bindgen(method, getter = status)]
13409 pub fn get_status<T>(this: &PromiseState<T>) -> String;
13410
13411 /// Only present if status is "fulfilled". The value that the promise was fulfilled with.
13412 #[wasm_bindgen(method, getter = value)]
13413 pub fn get_value<T>(this: &PromiseState<T>) -> Option<T>;
13414
13415 /// Only present if status is "rejected". The reason that the promise was rejected with.
13416 #[wasm_bindgen(method, getter = reason)]
13417 pub fn get_reason<T>(this: &PromiseState<T>) -> Option<JsValue>;
13418}
13419
13420impl<T> PromiseState<T> {
13421 pub fn is_fulfilled(&self) -> bool {
13422 self.get_status() == "fulfilled"
13423 }
13424
13425 pub fn is_rejected(&self) -> bool {
13426 self.get_status() == "rejected"
13427 }
13428}
13429
13430/// Converts a `PromiseState<T>` into a `Result<T, JsValue>`, matching the
13431/// spec invariant that exactly one of the fulfilled value or the rejection
13432/// reason is populated per slot.
13433impl<T: JsGeneric + FromWasmAbi> From<PromiseState<T>> for Result<T, JsValue> {
13434 fn from(state: PromiseState<T>) -> Result<T, JsValue> {
13435 if state.is_fulfilled() {
13436 Ok(state.get_value().unwrap())
13437 } else {
13438 Err(state.get_reason().unwrap())
13439 }
13440 }
13441}
13442
13443// Promise
13444#[wasm_bindgen]
13445extern "C" {
13446 /// The `Promise` object represents the eventual completion (or failure) of
13447 /// an asynchronous operation, and its resulting value.
13448 ///
13449 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
13450 #[must_use]
13451 #[wasm_bindgen(extends = Object, typescript_type = "Promise<any>", no_promising)]
13452 #[derive(Clone, Debug)]
13453 pub type Promise<T = JsValue>;
13454
13455 /// Creates a new `Promise` with the provided executor `cb`
13456 ///
13457 /// The `cb` is a function that is passed with the arguments `resolve` and
13458 /// `reject`. The `cb` function is executed immediately by the `Promise`
13459 /// implementation, passing `resolve` and `reject` functions (the executor
13460 /// is called before the `Promise` constructor even returns the created
13461 /// object). The `resolve` and `reject` functions, when called, resolve or
13462 /// reject the promise, respectively. The executor normally initiates
13463 /// some asynchronous work, and then, once that completes, either calls
13464 /// the `resolve` function to resolve the promise or else rejects it if an
13465 /// error occurred.
13466 ///
13467 /// If an error is thrown in the executor function, the promise is rejected.
13468 /// The return value of the executor is ignored.
13469 ///
13470 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
13471 #[cfg(not(js_sys_unstable_apis))]
13472 #[wasm_bindgen(constructor)]
13473 pub fn new(cb: &mut dyn FnMut(Function, Function)) -> Promise;
13474
13475 /// Creates a new `Promise` with the provided executor `cb`
13476 ///
13477 /// The `cb` is a function that is passed with the arguments `resolve` and
13478 /// `reject`. The `cb` function is executed immediately by the `Promise`
13479 /// implementation, passing `resolve` and `reject` functions (the executor
13480 /// is called before the `Promise` constructor even returns the created
13481 /// object). The `resolve` and `reject` functions, when called, resolve or
13482 /// reject the promise, respectively. The executor normally initiates
13483 /// some asynchronous work, and then, once that completes, either calls
13484 /// the `resolve` function to resolve the promise or else rejects it if an
13485 /// error occurred.
13486 ///
13487 /// If an error is thrown in the executor function, the promise is rejected.
13488 /// The return value of the executor is ignored.
13489 ///
13490 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
13491 #[cfg(js_sys_unstable_apis)]
13492 #[wasm_bindgen(constructor)]
13493 pub fn new<T: JsGeneric>(
13494 cb: &mut dyn FnMut(Function<fn(T) -> Undefined>, Function<fn(JsValue) -> Undefined>),
13495 ) -> Promise<T>;
13496
13497 // Next major: deprecate
13498 /// Creates a new `Promise` with the provided executor `cb`
13499 ///
13500 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
13501 #[wasm_bindgen(constructor)]
13502 pub fn new_typed<T: Promising + JsGeneric>(
13503 cb: &mut dyn FnMut(Function<fn(T) -> Undefined>, Function<fn(JsValue) -> Undefined>),
13504 ) -> Promise<<T as Promising>::Resolution>;
13505
13506 /// The `Promise.all(iterable)` method returns a single `Promise` that
13507 /// resolves when all of the promises in the iterable argument have resolved
13508 /// or when the iterable argument contains no promises. It rejects with the
13509 /// reason of the first promise that rejects.
13510 ///
13511 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all)
13512 #[cfg(not(js_sys_unstable_apis))]
13513 #[wasm_bindgen(static_method_of = Promise)]
13514 pub fn all(obj: &JsValue) -> Promise;
13515
13516 /// The `Promise.all(iterable)` method returns a single `Promise` that
13517 /// resolves when all of the promises in the iterable argument have resolved
13518 /// or when the iterable argument contains no promises. It rejects with the
13519 /// reason of the first promise that rejects.
13520 ///
13521 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all)
13522 #[cfg(js_sys_unstable_apis)]
13523 #[wasm_bindgen(static_method_of = Promise, js_name = all)]
13524 pub fn all<I: Iterable>(obj: &I) -> Promise<Array<<I::Item as Promising>::Resolution>>
13525 where
13526 I::Item: Promising;
13527
13528 // Next major: deprecate
13529 /// The `Promise.all(iterable)` method returns a single `Promise` that
13530 /// resolves when all of the promises in the iterable argument have resolved
13531 /// or when the iterable argument contains no promises. It rejects with the
13532 /// reason of the first promise that rejects.
13533 ///
13534 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all)
13535 #[wasm_bindgen(static_method_of = Promise, js_name = all)]
13536 pub fn all_iterable<I: Iterable>(obj: &I) -> Promise<Array<<I::Item as Promising>::Resolution>>
13537 where
13538 I::Item: Promising;
13539
13540 /// The `Promise.allSettled(iterable)` method returns a single `Promise` that
13541 /// resolves when all of the promises in the iterable argument have either
13542 /// fulfilled or rejected or when the iterable argument contains no promises.
13543 ///
13544 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled)
13545 #[cfg(not(js_sys_unstable_apis))]
13546 #[wasm_bindgen(static_method_of = Promise, js_name = allSettled)]
13547 pub fn all_settled(obj: &JsValue) -> Promise;
13548
13549 /// The `Promise.allSettled(iterable)` method returns a single `Promise` that
13550 /// resolves when all of the promises in the iterable argument have either
13551 /// fulfilled or rejected or when the iterable argument contains no promises.
13552 ///
13553 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled)
13554 #[cfg(js_sys_unstable_apis)]
13555 #[wasm_bindgen(static_method_of = Promise, js_name = allSettled)]
13556 pub fn all_settled<I: Iterable>(
13557 obj: &I,
13558 ) -> Promise<Array<PromiseState<<I::Item as Promising>::Resolution>>>
13559 where
13560 I::Item: Promising;
13561
13562 // Next major: deprecate
13563 /// The `Promise.allSettled(iterable)` method returns a single `Promise` that
13564 /// resolves when all of the promises in the iterable argument have either
13565 /// fulfilled or rejected or when the iterable argument contains no promises.
13566 ///
13567 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled)
13568 #[wasm_bindgen(static_method_of = Promise, js_name = allSettled)]
13569 pub fn all_settled_iterable<I: Iterable>(
13570 obj: &I,
13571 ) -> Promise<Array<PromiseState<<I::Item as Promising>::Resolution>>>
13572 where
13573 I::Item: Promising;
13574
13575 /// The `Promise.any(iterable)` method returns a single `Promise` that
13576 /// resolves when any of the promises in the iterable argument have resolved
13577 /// or when the iterable argument contains no promises. It rejects with an
13578 /// `AggregateError` if all promises in the iterable rejected.
13579 ///
13580 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/any)
13581 #[cfg(not(js_sys_unstable_apis))]
13582 #[wasm_bindgen(static_method_of = Promise)]
13583 pub fn any(obj: &JsValue) -> Promise;
13584
13585 /// The `Promise.any(iterable)` method returns a single `Promise` that
13586 /// resolves when any of the promises in the iterable argument have resolved
13587 /// or when the iterable argument contains no promises. It rejects with an
13588 /// `AggregateError` if all promises in the iterable rejected.
13589 ///
13590 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/any)
13591 #[cfg(js_sys_unstable_apis)]
13592 #[wasm_bindgen(static_method_of = Promise, js_name = any)]
13593 pub fn any<I: Iterable>(obj: &I) -> Promise<<I::Item as Promising>::Resolution>
13594 where
13595 I::Item: Promising;
13596
13597 // Next major: deprecate
13598 /// The `Promise.any(iterable)` method returns a single `Promise` that
13599 /// resolves when any of the promises in the iterable argument have resolved
13600 /// or when the iterable argument contains no promises. It rejects with an
13601 /// `AggregateError` if all promises in the iterable rejected.
13602 ///
13603 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/any)
13604 #[wasm_bindgen(static_method_of = Promise, js_name = any)]
13605 pub fn any_iterable<I: Iterable>(obj: &I) -> Promise<<I::Item as Promising>::Resolution>
13606 where
13607 I::Item: Promising;
13608
13609 /// The `Promise.race(iterable)` method returns a promise that resolves or
13610 /// rejects as soon as one of the promises in the iterable resolves or
13611 /// rejects, with the value or reason from that promise.
13612 ///
13613 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/race)
13614 #[cfg(not(js_sys_unstable_apis))]
13615 #[wasm_bindgen(static_method_of = Promise)]
13616 pub fn race(obj: &JsValue) -> Promise;
13617
13618 /// The `Promise.race(iterable)` method returns a promise that resolves or
13619 /// rejects as soon as one of the promises in the iterable resolves or
13620 /// rejects, with the value or reason from that promise.
13621 ///
13622 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/race)
13623 #[cfg(js_sys_unstable_apis)]
13624 #[wasm_bindgen(static_method_of = Promise, js_name = race)]
13625 pub fn race<I: Iterable>(obj: &I) -> Promise<<I::Item as Promising>::Resolution>
13626 where
13627 I::Item: Promising;
13628
13629 // Next major: deprecate
13630 /// The `Promise.race(iterable)` method returns a promise that resolves or
13631 /// rejects as soon as one of the promises in the iterable resolves or
13632 /// rejects, with the value or reason from that promise.
13633 ///
13634 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/race)
13635 #[wasm_bindgen(static_method_of = Promise, js_name = race)]
13636 pub fn race_iterable<I: Iterable>(obj: &I) -> Promise<<I::Item as Promising>::Resolution>
13637 where
13638 I::Item: Promising;
13639
13640 /// The `Promise.reject(reason)` method returns a `Promise` object that is
13641 /// rejected with the given reason.
13642 ///
13643 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/reject)
13644 #[cfg(not(js_sys_unstable_apis))]
13645 #[wasm_bindgen(static_method_of = Promise)]
13646 pub fn reject(obj: &JsValue) -> Promise;
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(js_sys_unstable_apis)]
13653 #[wasm_bindgen(static_method_of = Promise, js_name = reject)]
13654 pub fn reject<T>(obj: &JsValue) -> Promise<T>;
13655
13656 // Next major: deprecate
13657 /// The `Promise.reject(reason)` method returns a `Promise` object that is
13658 /// rejected with the given reason.
13659 ///
13660 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/reject)
13661 #[wasm_bindgen(static_method_of = Promise, js_name = reject)]
13662 pub fn reject_typed<T>(obj: &JsValue) -> Promise<T>;
13663
13664 /// The `Promise.resolve(value)` method returns a `Promise` object that is
13665 /// resolved with the given value. If the value is a promise, that promise
13666 /// is returned; if the value is a thenable (i.e. has a "then" method), the
13667 /// returned promise will "follow" that thenable, adopting its eventual
13668 /// state; otherwise the returned promise will be fulfilled with the value.
13669 ///
13670 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/resolve)
13671 #[wasm_bindgen(static_method_of = Promise, js_name = resolve)]
13672 pub fn resolve<U: Promising>(obj: &U) -> Promise<U::Resolution>;
13673
13674 /// The `catch()` method returns a `Promise` and deals with rejected cases
13675 /// only. It behaves the same as calling `Promise.prototype.then(undefined,
13676 /// onRejected)` (in fact, calling `obj.catch(onRejected)` internally calls
13677 /// `obj.then(undefined, onRejected)`).
13678 ///
13679 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch)
13680 #[cfg(not(js_sys_unstable_apis))]
13681 #[wasm_bindgen(method)]
13682 pub fn catch<T>(this: &Promise<T>, cb: &ScopedClosure<dyn FnMut(JsValue)>) -> Promise<JsValue>;
13683
13684 /// The `catch()` method returns a `Promise` and deals with rejected cases
13685 /// only. It behaves the same as calling `Promise.prototype.then(undefined,
13686 /// onRejected)` (in fact, calling `obj.catch(onRejected)` internally calls
13687 /// `obj.then(undefined, onRejected)`).
13688 ///
13689 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch)
13690 #[cfg(js_sys_unstable_apis)]
13691 #[wasm_bindgen(method, js_name = catch)]
13692 pub fn catch<'a, T, R: Promising>(
13693 this: &Promise<T>,
13694 cb: &ScopedClosure<'a, dyn FnMut(T) -> Result<R, JsError>>,
13695 ) -> Promise<R::Resolution>;
13696
13697 // Next major: deprecate
13698 /// Same as `catch`, but returning a result to become the new Promise value.
13699 #[wasm_bindgen(method, js_name = catch)]
13700 pub fn catch_map<'a, T, R: Promising>(
13701 this: &Promise<T>,
13702 cb: &ScopedClosure<'a, dyn FnMut(T) -> Result<R, JsError>>,
13703 ) -> Promise<R::Resolution>;
13704
13705 /// The `then()` method returns a `Promise`. It takes up to two arguments:
13706 /// callback functions for the success and failure cases of the `Promise`.
13707 ///
13708 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then)
13709 #[cfg(not(js_sys_unstable_apis))]
13710 #[wasm_bindgen(method)]
13711 pub fn then<'a, T>(this: &Promise<T>, cb: &ScopedClosure<'a, dyn FnMut(T)>)
13712 -> Promise<JsValue>;
13713
13714 /// The `then()` method returns a `Promise`. It takes up to two arguments:
13715 /// callback functions for the success and failure cases of the `Promise`.
13716 ///
13717 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then)
13718 #[cfg(js_sys_unstable_apis)]
13719 #[wasm_bindgen(method, js_name = then)]
13720 pub fn then<'a, T, R: Promising>(
13721 this: &Promise<T>,
13722 cb: &ScopedClosure<'a, dyn FnMut(T) -> Result<R, JsError>>,
13723 ) -> Promise<R::Resolution>;
13724
13725 /// The `then()` method returns a `Promise`. It takes up to two arguments:
13726 /// callback functions for the success and failure cases of the `Promise`.
13727 ///
13728 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then)
13729 #[wasm_bindgen(method, js_name = then)]
13730 pub fn then_with_reject<'a, T, R: Promising>(
13731 this: &Promise<T>,
13732 resolve: &ScopedClosure<'a, dyn FnMut(T) -> Result<R, JsError>>,
13733 reject: &ScopedClosure<'a, dyn FnMut(JsValue) -> Result<R, JsError>>,
13734 ) -> Promise<R::Resolution>;
13735
13736 // Next major: deprecate
13737 /// Alias for `then()` with a return value.
13738 /// The `then()` method returns a `Promise`. It takes up to two arguments:
13739 /// callback functions for the success and failure cases of the `Promise`.
13740 ///
13741 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then)
13742 #[wasm_bindgen(method, js_name = then)]
13743 pub fn then_map<'a, T, R: Promising>(
13744 this: &Promise<T>,
13745 cb: &ScopedClosure<'a, dyn FnMut(T) -> Result<R, JsError>>,
13746 ) -> Promise<R::Resolution>;
13747
13748 /// Same as `then`, only with both arguments provided.
13749 ///
13750 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then)
13751 #[wasm_bindgen(method, js_name = then)]
13752 pub fn then2(
13753 this: &Promise,
13754 resolve: &ScopedClosure<dyn FnMut(JsValue)>,
13755 reject: &ScopedClosure<dyn FnMut(JsValue)>,
13756 ) -> Promise;
13757
13758 /// The `finally()` method returns a `Promise`. When the promise is settled,
13759 /// whether fulfilled or rejected, the specified callback function is
13760 /// executed. This provides a way for code that must be executed once the
13761 /// `Promise` has been dealt with to be run whether the promise was
13762 /// fulfilled successfully or rejected.
13763 ///
13764 /// This lets you avoid duplicating code in both the promise's `then()` and
13765 /// `catch()` handlers.
13766 ///
13767 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/finally)
13768 #[wasm_bindgen(method)]
13769 pub fn finally<T>(this: &Promise<T>, cb: &ScopedClosure<dyn FnMut()>) -> Promise<JsValue>;
13770}
13771
13772impl<T: JsGeneric> Promising for Promise<T> {
13773 type Resolution = T;
13774}
13775
13776/// Internal: maps a tuple of `Promise<T_i>` to the result shapes of
13777/// [`Promise::all_tuple`] and [`Promise::all_settled_tuple`].
13778///
13779/// Implemented for every tuple arity 1..=8 of `Promise<T: JsGeneric>`. The
13780/// associated `Joined` / `Settled` types pin down the [`ArrayTuple`] shape
13781/// of the result so the one [`JsCast::unchecked_into`] needed to reinterpret
13782/// the [`Array<JsValue>`] returned by `Promise.all` / `Promise.allSettled`
13783/// is encapsulated inside each impl — the caller sees a fully-typed
13784/// `Promise<ArrayTuple<...>>`.
13785///
13786/// The soundness of the `unchecked_into`s here rests on `Promise.all` and
13787/// `Promise.allSettled` preserving input order and arity, which they do by
13788/// spec.
13789///
13790/// You normally call [`Promise::all_tuple`] / [`Promise::all_settled_tuple`]
13791/// rather than using this trait directly.
13792#[doc(hidden)]
13793pub trait PromiseTuple {
13794 /// The typed `ArrayTuple` shape the joined promise resolves to.
13795 ///
13796 /// For a tuple `(Promise<T1>, Promise<T2>, ...)` this is
13797 /// `ArrayTuple<(T1, T2, ...)>`.
13798 type Joined: JsGeneric;
13799
13800 /// The typed `ArrayTuple` shape the all-settled promise resolves to.
13801 ///
13802 /// For a tuple `(Promise<T1>, Promise<T2>, ...)` this is
13803 /// `ArrayTuple<(PromiseState<T1>, PromiseState<T2>, ...)>`.
13804 type Settled: JsGeneric;
13805
13806 /// Join via `Promise.all`, returning a typed `Promise`.
13807 fn all(self) -> Promise<Self::Joined>;
13808
13809 /// Settle via `Promise.allSettled`, returning a typed `Promise`.
13810 fn all_settled(self) -> Promise<Self::Settled>;
13811}
13812
13813macro_rules! impl_promise_tuple {
13814 ([$($T:ident)+] [$($idx:tt)+]) => {
13815 // Rust tuple of `Promise<T_i>`. Builds the heterogeneous
13816 // `ArrayTuple` of promises via the existing `From<(...)>` impl
13817 // (each element upcasts through `JsGeneric`), then delegates to
13818 // the `ArrayTuple` impl below.
13819 impl<$($T: JsGeneric),+> PromiseTuple for ($(Promise<$T>,)+) {
13820 type Joined = ArrayTuple<($($T,)+)>;
13821 type Settled = ArrayTuple<($(PromiseState<$T>,)+)>;
13822
13823 fn all(self) -> Promise<Self::Joined> {
13824 let tuple: ArrayTuple<($(Promise<$T>,)+)> = ($(self.$idx,)+).into();
13825 tuple.all()
13826 }
13827
13828 fn all_settled(self) -> Promise<Self::Settled> {
13829 let tuple: ArrayTuple<($(Promise<$T>,)+)> = ($(self.$idx,)+).into();
13830 tuple.all_settled()
13831 }
13832 }
13833
13834 // `ArrayTuple<(Promise<T_1>, ..., Promise<T_n>)>` — callers who
13835 // already have an `ArrayTuple` (e.g. from a binding that returns
13836 // one, or built via `.into()` earlier in a pipeline) can pass it
13837 // directly without unpacking into a Rust tuple.
13838 //
13839 // Hands the `ArrayTuple` straight to `Promise.all_iterable` /
13840 // `Promise.allSettled_iterable` and reinterprets the result
13841 // `Array<JsValue>` as the intended typed `ArrayTuple`. Safe because
13842 // `Promise.all` / `Promise.allSettled` preserve input order and
13843 // arity by spec.
13844 impl<$($T: JsGeneric),+> PromiseTuple for ArrayTuple<($(Promise<$T>,)+)> {
13845 type Joined = ArrayTuple<($($T,)+)>;
13846 type Settled = ArrayTuple<($(PromiseState<$T>,)+)>;
13847
13848 fn all(self) -> Promise<Self::Joined> {
13849 use wasm_bindgen::JsCast;
13850 Promise::all_iterable(&self).unchecked_into()
13851 }
13852
13853 fn all_settled(self) -> Promise<Self::Settled> {
13854 use wasm_bindgen::JsCast;
13855 Promise::all_settled_iterable(&self).unchecked_into()
13856 }
13857 }
13858 };
13859}
13860
13861impl_promise_tuple!([T1][0]);
13862impl_promise_tuple!([T1 T2] [0 1]);
13863impl_promise_tuple!([T1 T2 T3] [0 1 2]);
13864impl_promise_tuple!([T1 T2 T3 T4] [0 1 2 3]);
13865impl_promise_tuple!([T1 T2 T3 T4 T5] [0 1 2 3 4]);
13866impl_promise_tuple!([T1 T2 T3 T4 T5 T6] [0 1 2 3 4 5]);
13867impl_promise_tuple!([T1 T2 T3 T4 T5 T6 T7] [0 1 2 3 4 5 6]);
13868impl_promise_tuple!([T1 T2 T3 T4 T5 T6 T7 T8] [0 1 2 3 4 5 6 7]);
13869
13870impl Promise {
13871 /// Heterogeneous counterpart to [`Promise::all_iterable`]: accepts a Rust
13872 /// tuple of `Promise<T_i>` and returns a single [`Promise`] resolving to a
13873 /// typed [`ArrayTuple<(T_1, T_2, ..., T_n)>`].
13874 ///
13875 /// Destructure the awaited result via [`ArrayTuple::into_tuple`] to get
13876 /// the individual values back as a native Rust tuple. Implemented for
13877 /// arity 1..=8.
13878 ///
13879 /// Rejects with the first rejection, matching `Promise.all` semantics.
13880 ///
13881 /// # Example
13882 ///
13883 /// ```ignore
13884 /// use js_sys::Promise;
13885 ///
13886 /// let (response, buffer) = Promise::all_tuple((fetch_promise, buffer_promise))
13887 /// .await?
13888 /// .into_tuple();
13889 /// ```
13890 #[inline]
13891 pub fn all_tuple<T: PromiseTuple>(promises: T) -> Promise<T::Joined> {
13892 promises.all()
13893 }
13894
13895 /// Heterogeneous counterpart to [`Promise::all_settled_iterable`]: accepts
13896 /// a Rust tuple of `Promise<T_i>` and returns a single [`Promise`]
13897 /// resolving to a typed
13898 /// `ArrayTuple<(PromiseState<T_1>, ..., PromiseState<T_n>)>`.
13899 ///
13900 /// Unlike [`Promise::all_tuple`], this never rejects early: every input
13901 /// settles (fulfills or rejects) and is reflected by its [`PromiseState`]
13902 /// slot in the result tuple. Implemented for arity 1..=8.
13903 ///
13904 /// # Example
13905 ///
13906 /// ```ignore
13907 /// use js_sys::Promise;
13908 ///
13909 /// let results = Promise::all_settled_tuple((fetch_promise, buffer_promise)).await?;
13910 /// let (response_state, buffer_state) = results.into_tuple();
13911 /// ```
13912 #[inline]
13913 pub fn all_settled_tuple<T: PromiseTuple>(promises: T) -> Promise<T::Settled> {
13914 promises.all_settled()
13915 }
13916}
13917
13918/// Returns a handle to the global scope object.
13919///
13920/// This allows access to the global properties and global names by accessing
13921/// the `Object` returned.
13922pub fn global() -> Object {
13923 use wasm_bindgen::__rt::LazyCell;
13924
13925 #[cfg_attr(target_feature = "atomics", thread_local)]
13926 static GLOBAL: LazyCell<Object> = LazyCell::new(get_global_object);
13927
13928 return GLOBAL.clone();
13929
13930 fn get_global_object() -> Object {
13931 // Accessing the global object is not an easy thing to do, and what we
13932 // basically want is `globalThis` but we can't rely on that existing
13933 // everywhere. In the meantime we've got the fallbacks mentioned in:
13934 //
13935 // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis
13936 //
13937 // Note that this is pretty heavy code-size wise but it at least gets
13938 // the job largely done for now and avoids the `Function` constructor at
13939 // the end which triggers CSP errors.
13940 #[wasm_bindgen]
13941 extern "C" {
13942 #[derive(Clone, Debug)]
13943 type Global;
13944
13945 #[wasm_bindgen(thread_local_v2, js_name = globalThis)]
13946 static GLOBAL_THIS: Option<Object>;
13947
13948 #[wasm_bindgen(thread_local_v2, js_name = self)]
13949 static SELF: Option<Object>;
13950
13951 #[wasm_bindgen(thread_local_v2, js_name = window)]
13952 static WINDOW: Option<Object>;
13953
13954 #[wasm_bindgen(thread_local_v2, js_name = global)]
13955 static GLOBAL: Option<Object>;
13956 }
13957
13958 // The order is important: in Firefox Extension Content Scripts `globalThis`
13959 // is a Sandbox (not Window), so `globalThis` must be checked after `window`.
13960 let static_object = SELF
13961 .with(Option::clone)
13962 .or_else(|| WINDOW.with(Option::clone))
13963 .or_else(|| GLOBAL_THIS.with(Option::clone))
13964 .or_else(|| GLOBAL.with(Option::clone));
13965 if let Some(obj) = static_object {
13966 if !obj.is_undefined() {
13967 return obj;
13968 }
13969 }
13970
13971 // Global object not found
13972 JsValue::undefined().unchecked_into()
13973 }
13974}
13975
13976// Float16Array
13977//
13978// Rust does not yet have a stable builtin `f16`, so the raw JS bindings live
13979// here and any Rust-side helper APIs use explicit `u16` / `f32` naming. The
13980// unsuffixed float APIs are reserved for a future native `f16` binding.
13981#[wasm_bindgen]
13982extern "C" {
13983 #[wasm_bindgen(extends = Object, typescript_type = "Float16Array")]
13984 #[derive(Clone, Debug)]
13985 pub type Float16Array;
13986
13987 /// The `Float16Array()` constructor creates a new array.
13988 ///
13989 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float16Array)
13990 #[wasm_bindgen(constructor)]
13991 pub fn new(constructor_arg: &JsValue) -> Float16Array;
13992
13993 /// The `Float16Array()` constructor creates an array with an internal
13994 /// buffer large enough for `length` elements.
13995 ///
13996 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float16Array)
13997 #[wasm_bindgen(constructor)]
13998 pub fn new_with_length(length: u32) -> Float16Array;
13999
14000 /// The `Float16Array()` constructor creates an array with the given
14001 /// buffer but is a view starting at `byte_offset`.
14002 ///
14003 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float16Array)
14004 #[wasm_bindgen(constructor)]
14005 pub fn new_with_byte_offset(buffer: &JsValue, byte_offset: u32) -> Float16Array;
14006
14007 /// The `Float16Array()` constructor creates an array with the given
14008 /// buffer but is a view starting at `byte_offset` for `length` elements.
14009 ///
14010 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float16Array)
14011 #[wasm_bindgen(constructor)]
14012 pub fn new_with_byte_offset_and_length(
14013 buffer: &JsValue,
14014 byte_offset: u32,
14015 length: u32,
14016 ) -> Float16Array;
14017
14018 /// The `fill()` method fills all elements from a start index to an end
14019 /// index with a static `f32` value.
14020 ///
14021 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/fill)
14022 #[wasm_bindgen(method, js_name = fill)]
14023 pub fn fill_with_f32(this: &Float16Array, value: f32, start: u32, end: u32) -> Float16Array;
14024
14025 /// The buffer accessor property represents the `ArrayBuffer` referenced
14026 /// by a `TypedArray` at construction time.
14027 #[wasm_bindgen(getter, method)]
14028 pub fn buffer(this: &Float16Array) -> ArrayBuffer;
14029
14030 /// The `subarray()` method returns a new `TypedArray` on the same
14031 /// `ArrayBuffer` store and with the same element types as this array.
14032 #[wasm_bindgen(method)]
14033 pub fn subarray(this: &Float16Array, begin: u32, end: u32) -> Float16Array;
14034
14035 /// The `slice()` method returns a shallow copy of a portion of a typed
14036 /// array into a new typed array object.
14037 #[wasm_bindgen(method)]
14038 pub fn slice(this: &Float16Array, begin: u32, end: u32) -> Float16Array;
14039
14040 /// The `forEach()` method executes a provided function once per array
14041 /// element, passing values as `f32`.
14042 #[wasm_bindgen(method, js_name = forEach)]
14043 pub fn for_each_as_f32(this: &Float16Array, callback: &mut dyn FnMut(f32, u32, Float16Array));
14044
14045 /// The `forEach()` method executes a provided function once per array
14046 /// element, passing values as `f32`.
14047 #[wasm_bindgen(method, js_name = forEach, catch)]
14048 pub fn try_for_each_as_f32(
14049 this: &Float16Array,
14050 callback: &mut dyn FnMut(f32, u32, Float16Array) -> Result<(), JsError>,
14051 ) -> Result<(), JsValue>;
14052
14053 /// The length accessor property represents the length (in elements) of a
14054 /// typed array.
14055 #[wasm_bindgen(method, getter)]
14056 pub fn length(this: &Float16Array) -> u32;
14057
14058 /// The byteLength accessor property represents the length (in bytes) of a
14059 /// typed array.
14060 #[wasm_bindgen(method, getter, js_name = byteLength)]
14061 pub fn byte_length(this: &Float16Array) -> u32;
14062
14063 /// The byteOffset accessor property represents the offset (in bytes) of a
14064 /// typed array from the start of its `ArrayBuffer`.
14065 #[wasm_bindgen(method, getter, js_name = byteOffset)]
14066 pub fn byte_offset(this: &Float16Array) -> u32;
14067
14068 /// The `set()` method stores multiple values in the typed array, reading
14069 /// input values from a specified array.
14070 #[wasm_bindgen(method)]
14071 pub fn set(this: &Float16Array, src: &JsValue, offset: u32);
14072
14073 /// Gets the value at `idx` as an `f32`, counting from the end if negative.
14074 #[wasm_bindgen(method, js_name = at)]
14075 pub fn at_as_f32(this: &Float16Array, idx: i32) -> Option<f32>;
14076
14077 /// The `copyWithin()` method shallow copies part of a typed array to another
14078 /// location in the same typed array and returns it, without modifying its size.
14079 ///
14080 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin)
14081 #[wasm_bindgen(method, js_name = copyWithin)]
14082 pub fn copy_within(this: &Float16Array, target: i32, start: i32, end: i32) -> Float16Array;
14083
14084 /// Gets the value at `idx` as an `f32`, equivalent to JavaScript
14085 /// `arr[idx]`.
14086 #[wasm_bindgen(method, indexing_getter)]
14087 pub fn get_index_as_f32(this: &Float16Array, idx: u32) -> f32;
14088
14089 /// Sets the value at `idx` from an `f32`, equivalent to JavaScript
14090 /// `arr[idx] = value`.
14091 #[wasm_bindgen(method, indexing_setter)]
14092 pub fn set_index_from_f32(this: &Float16Array, idx: u32, value: f32);
14093}
14094
14095impl Default for Float16Array {
14096 fn default() -> Self {
14097 Self::new(&JsValue::UNDEFINED.unchecked_into())
14098 }
14099}
14100
14101impl TypedArray for Float16Array {}
14102
14103impl Float16Array {
14104 fn as_uint16_view(&self) -> Uint16Array {
14105 let buffer = self.buffer();
14106 Uint16Array::new_with_byte_offset_and_length(
14107 buffer.as_ref(),
14108 self.byte_offset(),
14109 self.length(),
14110 )
14111 }
14112
14113 /// Creates an array from raw IEEE 754 binary16 bit patterns.
14114 ///
14115 /// This pairs naturally with the optional `half` crate:
14116 ///
14117 /// ```rust
14118 /// use half::f16;
14119 /// use js_sys::Float16Array;
14120 ///
14121 /// let values = [f16::from_f32(1.0), f16::from_f32(-2.0)];
14122 /// let bits = values.map(f16::to_bits);
14123 /// let array = Float16Array::new_from_u16_slice(&bits);
14124 /// ```
14125 pub fn new_from_u16_slice(slice: &[u16]) -> Float16Array {
14126 let array = Float16Array::new_with_length(slice.len() as u32);
14127 array.copy_from_u16_slice(slice);
14128 array
14129 }
14130
14131 /// Copy the raw IEEE 754 binary16 bit patterns from this JS typed array
14132 /// into the destination Rust slice.
14133 ///
14134 /// # Panics
14135 ///
14136 /// This function will panic if this typed array's length is different than
14137 /// the length of the provided `dst` array.
14138 ///
14139 /// Values copied into `dst` can be converted back into `half::f16` with
14140 /// `half::f16::from_bits`.
14141 pub fn copy_to_u16_slice(&self, dst: &mut [u16]) {
14142 self.as_uint16_view().copy_to(dst);
14143 }
14144
14145 /// Copy raw IEEE 754 binary16 bit patterns from the source Rust slice into
14146 /// this JS typed array.
14147 ///
14148 /// # Panics
14149 ///
14150 /// This function will panic if this typed array's length is different than
14151 /// the length of the provided `src` array.
14152 ///
14153 /// When using the optional `half` crate, populate `src` with
14154 /// `half::f16::to_bits()`.
14155 pub fn copy_from_u16_slice(&self, src: &[u16]) {
14156 self.as_uint16_view().copy_from(src);
14157 }
14158
14159 /// Efficiently copies the contents of this JS typed array into a new Vec of
14160 /// raw IEEE 754 binary16 bit patterns.
14161 ///
14162 /// This makes it easy to round-trip through the optional `half` crate:
14163 ///
14164 /// ```rust
14165 /// use half::f16;
14166 ///
14167 /// let bits = array.to_u16_vec();
14168 /// let values: Vec<f16> = bits.into_iter().map(f16::from_bits).collect();
14169 /// ```
14170 pub fn to_u16_vec(&self) -> Vec<u16> {
14171 self.as_uint16_view().to_vec()
14172 }
14173}
14174
14175macro_rules! arrays {
14176 ($(#[doc = $ctor:literal] #[doc = $mdn:literal] $name:ident: $ty:ident,)*) => ($(
14177 #[wasm_bindgen]
14178 extern "C" {
14179 #[wasm_bindgen(extends = Object, typescript_type = $name)]
14180 #[derive(Clone, Debug)]
14181 pub type $name;
14182
14183 /// The
14184 #[doc = $ctor]
14185 /// constructor creates a new array.
14186 ///
14187 /// [MDN documentation](
14188 #[doc = $mdn]
14189 /// )
14190 #[wasm_bindgen(constructor)]
14191 pub fn new(constructor_arg: &JsValue) -> $name;
14192
14193 /// An
14194 #[doc = $ctor]
14195 /// which creates an array with an internal buffer large
14196 /// enough for `length` elements.
14197 ///
14198 /// [MDN documentation](
14199 #[doc = $mdn]
14200 /// )
14201 #[wasm_bindgen(constructor)]
14202 pub fn new_with_length(length: u32) -> $name;
14203
14204 /// An
14205 #[doc = $ctor]
14206 /// which creates an array from a Rust slice.
14207 ///
14208 /// [MDN documentation](
14209 #[doc = $mdn]
14210 /// )
14211 #[wasm_bindgen(constructor)]
14212 pub fn new_from_slice(slice: &[$ty]) -> $name;
14213
14214 /// An
14215 #[doc = $ctor]
14216 /// which creates an array with the given buffer but is a
14217 /// view starting at `byte_offset`.
14218 ///
14219 /// [MDN documentation](
14220 #[doc = $mdn]
14221 /// )
14222 #[wasm_bindgen(constructor)]
14223 pub fn new_with_byte_offset(buffer: &JsValue, byte_offset: u32) -> $name;
14224
14225 /// An
14226 #[doc = $ctor]
14227 /// which creates an array with the given buffer but is a
14228 /// view starting at `byte_offset` for `length` elements.
14229 ///
14230 /// [MDN documentation](
14231 #[doc = $mdn]
14232 /// )
14233 #[wasm_bindgen(constructor)]
14234 pub fn new_with_byte_offset_and_length(
14235 buffer: &JsValue,
14236 byte_offset: u32,
14237 length: u32,
14238 ) -> $name;
14239
14240 /// The `fill()` method fills all the elements of an array from a start index
14241 /// to an end index with a static value. The end index is not included.
14242 ///
14243 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/fill)
14244 #[wasm_bindgen(method)]
14245 pub fn fill(this: &$name, value: $ty, start: u32, end: u32) -> $name;
14246
14247 /// The buffer accessor property represents the `ArrayBuffer` referenced
14248 /// by a `TypedArray` at construction time.
14249 #[wasm_bindgen(getter, method)]
14250 pub fn buffer(this: &$name) -> ArrayBuffer;
14251
14252 /// The `subarray()` method returns a new `TypedArray` on the same
14253 /// `ArrayBuffer` store and with the same element types as for this
14254 /// `TypedArray` object.
14255 #[wasm_bindgen(method)]
14256 pub fn subarray(this: &$name, begin: u32, end: u32) -> $name;
14257
14258 /// The `slice()` method returns a shallow copy of a portion of a typed
14259 /// array into a new typed array object. This method has the same algorithm
14260 /// as `Array.prototype.slice()`.
14261 #[wasm_bindgen(method)]
14262 pub fn slice(this: &$name, begin: u32, end: u32) -> $name;
14263
14264 /// The `forEach()` method executes a provided function once per array
14265 /// element. This method has the same algorithm as
14266 /// `Array.prototype.forEach()`. `TypedArray` is one of the typed array
14267 /// types here.
14268 #[wasm_bindgen(method, js_name = forEach)]
14269 pub fn for_each(this: &$name, callback: &mut dyn FnMut($ty, u32, $name));
14270
14271 /// The `forEach()` method executes a provided function once per array
14272 /// element. This method has the same algorithm as
14273 /// `Array.prototype.forEach()`. `TypedArray` is one of the typed array
14274 /// types here.
14275 #[wasm_bindgen(method, js_name = forEach, catch)]
14276 pub fn try_for_each(this: &$name, callback: &mut dyn FnMut($ty, u32, $name) -> Result<(), JsError>) -> Result<(), JsValue>;
14277
14278 /// The length accessor property represents the length (in elements) of a
14279 /// typed array.
14280 #[wasm_bindgen(method, getter)]
14281 pub fn length(this: &$name) -> u32;
14282
14283 /// The byteLength accessor property represents the length (in bytes) of a
14284 /// typed array.
14285 #[wasm_bindgen(method, getter, js_name = byteLength)]
14286 pub fn byte_length(this: &$name) -> u32;
14287
14288 /// The byteOffset accessor property represents the offset (in bytes) of a
14289 /// typed array from the start of its `ArrayBuffer`.
14290 #[wasm_bindgen(method, getter, js_name = byteOffset)]
14291 pub fn byte_offset(this: &$name) -> u32;
14292
14293 /// The `set()` method stores multiple values in the typed array, reading
14294 /// input values from a specified array.
14295 #[wasm_bindgen(method)]
14296 pub fn set(this: &$name, src: &JsValue, offset: u32);
14297
14298 /// Gets the value at `idx`, counting from the end if negative.
14299 #[wasm_bindgen(method)]
14300 pub fn at(this: &$name, idx: i32) -> Option<$ty>;
14301
14302 /// The `copyWithin()` method shallow copies part of a typed array to another
14303 /// location in the same typed array and returns it, without modifying its size.
14304 ///
14305 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin)
14306 #[wasm_bindgen(method, js_name = copyWithin)]
14307 pub fn copy_within(this: &$name, target: i32, start: i32, end: i32) -> $name;
14308
14309 /// Gets the value at `idx`, equivalent to the javascript `my_var = arr[idx]`.
14310 #[wasm_bindgen(method, indexing_getter)]
14311 pub fn get_index(this: &$name, idx: u32) -> $ty;
14312
14313 /// Sets the value at `idx`, equivalent to the javascript `arr[idx] = value`.
14314 #[wasm_bindgen(method, indexing_setter)]
14315 pub fn set_index(this: &$name, idx: u32, value: $ty);
14316
14317 /// Copies the Rust slice's data to self.
14318 ///
14319 /// This method is not expected to be public. It requires the length of the
14320 /// TypedArray to be the same as the slice, use `self.copy_from(slice)` instead.
14321 #[wasm_bindgen(method, js_name = set)]
14322 fn copy_from_slice(this: &$name, slice: &[$ty]);
14323
14324 /// Copies this TypedArray's data to Rust slice;
14325 ///
14326 /// This method is not expected to be public. It requires the length of the
14327 /// TypedArray to be the same as the slice, use `self.copy_to(slice)` instead.
14328 ///
14329 /// # Workaround
14330 ///
14331 /// We actually need `slice.set(typed_array)` here, but since slice cannot be treated as
14332 /// `Uint8Array` on the Rust side, we use `Uint8Array.prototype.set.call`, which allows
14333 /// us to specify the `this` value inside the function.
14334 ///
14335 /// Therefore, `Uint8Array.prototype.set.call(slice, typed_array)` is equivalent to
14336 /// `slice.set(typed_array)`.
14337 #[wasm_bindgen(js_namespace = $name, js_name = "prototype.set.call")]
14338 fn copy_to_slice(slice: &mut [$ty], this: &$name);
14339 }
14340
14341 impl $name {
14342 /// Creates a JS typed array which is a view into wasm's linear
14343 /// memory at the slice specified.
14344 ///
14345 /// This function returns a new typed array which is a view into
14346 /// wasm's memory. This view does not copy the underlying data.
14347 ///
14348 /// # Safety
14349 ///
14350 /// Views into WebAssembly memory are only valid so long as the
14351 /// backing buffer isn't resized in JS. Once this function is called
14352 /// any future calls to `Box::new` (or malloc of any form) may cause
14353 /// the returned value here to be invalidated. Use with caution!
14354 ///
14355 /// Additionally the returned object can be safely mutated but the
14356 /// input slice isn't guaranteed to be mutable.
14357 ///
14358 /// Finally, the returned object is disconnected from the input
14359 /// slice's lifetime, so there's no guarantee that the data is read
14360 /// at the right time.
14361 pub unsafe fn view(rust: &[$ty]) -> $name {
14362 wasm_bindgen::__rt::wbg_cast(rust)
14363 }
14364
14365 /// Creates a JS typed array which is a view into wasm's linear
14366 /// memory at the specified pointer with specified length.
14367 ///
14368 /// This function returns a new typed array which is a view into
14369 /// wasm's memory. This view does not copy the underlying data.
14370 ///
14371 /// # Safety
14372 ///
14373 /// Views into WebAssembly memory are only valid so long as the
14374 /// backing buffer isn't resized in JS. Once this function is called
14375 /// any future calls to `Box::new` (or malloc of any form) may cause
14376 /// the returned value here to be invalidated. Use with caution!
14377 ///
14378 /// Additionally the returned object can be safely mutated,
14379 /// the changes are guaranteed to be reflected in the input array.
14380 pub unsafe fn view_mut_raw(ptr: *mut $ty, length: usize) -> $name {
14381 let slice = core::slice::from_raw_parts_mut(ptr, length);
14382 Self::view(slice)
14383 }
14384
14385 /// Copy the contents of this JS typed array into the destination
14386 /// Rust pointer.
14387 ///
14388 /// This function will efficiently copy the memory from a typed
14389 /// array into this Wasm module's own linear memory, initializing
14390 /// the memory destination provided.
14391 ///
14392 /// # Safety
14393 ///
14394 /// This function requires `dst` to point to a buffer
14395 /// large enough to fit this array's contents.
14396 pub unsafe fn raw_copy_to_ptr(&self, dst: *mut $ty) {
14397 let slice = core::slice::from_raw_parts_mut(dst, self.length() as usize);
14398 self.copy_to(slice);
14399 }
14400
14401 /// Copy the contents of this JS typed array into the destination
14402 /// Rust slice.
14403 ///
14404 /// This function will efficiently copy the memory from a typed
14405 /// array into this Wasm module's own linear memory, initializing
14406 /// the memory destination provided.
14407 ///
14408 /// # Panics
14409 ///
14410 /// This function will panic if this typed array's length is
14411 /// different than the length of the provided `dst` array.
14412 pub fn copy_to(&self, dst: &mut [$ty]) {
14413 core::assert_eq!(self.length() as usize, dst.len());
14414 $name::copy_to_slice(dst, self);
14415 }
14416
14417 /// Copy the contents of this JS typed array into the destination
14418 /// Rust slice.
14419 ///
14420 /// This function will efficiently copy the memory from a typed
14421 /// array into this Wasm module's own linear memory, initializing
14422 /// the memory destination provided.
14423 ///
14424 /// # Panics
14425 ///
14426 /// This function will panic if this typed array's length is
14427 /// different than the length of the provided `dst` array.
14428 pub fn copy_to_uninit<'dst>(&self, dst: &'dst mut [MaybeUninit<$ty>]) -> &'dst mut [$ty] {
14429 core::assert_eq!(self.length() as usize, dst.len());
14430 let dst = unsafe { &mut *(dst as *mut [MaybeUninit<$ty>] as *mut [$ty]) };
14431 self.copy_to(dst);
14432 dst
14433 }
14434
14435 /// Copy the contents of the source Rust slice into this
14436 /// JS typed array.
14437 ///
14438 /// This function will efficiently copy the memory from within
14439 /// the Wasm module's own linear memory to this typed array.
14440 ///
14441 /// # Panics
14442 ///
14443 /// This function will panic if this typed array's length is
14444 /// different than the length of the provided `src` array.
14445 pub fn copy_from(&self, src: &[$ty]) {
14446 core::assert_eq!(self.length() as usize, src.len());
14447 self.copy_from_slice(src);
14448 }
14449
14450 /// Efficiently copies the contents of this JS typed array into a new Vec.
14451 pub fn to_vec(&self) -> Vec<$ty> {
14452 let len = self.length() as usize;
14453 let mut output = Vec::with_capacity(len);
14454 // Safety: the capacity has been set
14455 unsafe {
14456 self.raw_copy_to_ptr(output.as_mut_ptr());
14457 output.set_len(len);
14458 }
14459 output
14460 }
14461 }
14462
14463 impl<'a> From<&'a [$ty]> for $name {
14464 #[inline]
14465 fn from(slice: &'a [$ty]) -> $name {
14466 // This is safe because the `new` function makes a copy if its argument is a TypedArray
14467 $name::new_from_slice(slice)
14468 }
14469 }
14470
14471 impl Default for $name {
14472 fn default() -> Self {
14473 Self::new(&JsValue::UNDEFINED.unchecked_into())
14474 }
14475 }
14476
14477 impl TypedArray for $name {}
14478
14479
14480 )*);
14481}
14482
14483arrays! {
14484 /// `Int8Array()`
14485 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int8Array
14486 Int8Array: i8,
14487
14488 /// `Int16Array()`
14489 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int16Array
14490 Int16Array: i16,
14491
14492 /// `Int32Array()`
14493 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int32Array
14494 Int32Array: i32,
14495
14496 /// `Uint8Array()`
14497 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array
14498 Uint8Array: u8,
14499
14500 /// `Uint8ClampedArray()`
14501 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8ClampedArray
14502 Uint8ClampedArray: u8,
14503
14504 /// `Uint16Array()`
14505 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint16Array
14506 Uint16Array: u16,
14507
14508 /// `Uint32Array()`
14509 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint32Array
14510 Uint32Array: u32,
14511
14512 /// `Float32Array()`
14513 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array
14514 Float32Array: f32,
14515
14516 /// `Float64Array()`
14517 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float64Array
14518 Float64Array: f64,
14519
14520 /// `BigInt64Array()`
14521 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt64Array
14522 BigInt64Array: i64,
14523
14524 /// `BigUint64Array()`
14525 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigUint64Array
14526 BigUint64Array: u64,
14527}
14528
14529/// Bridging between JavaScript `Promise`s and Rust `Future`s.
14530///
14531/// Enables `promise.await` directly on any [`Promise`].
14532/// This module is also re-exported by `wasm-bindgen-futures` for backwards compatibility.
14533pub mod futures;