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
32extern crate alloc;
33
34use alloc::string::String;
35use alloc::vec::Vec;
36use core::cmp::Ordering;
37#[cfg(not(js_sys_unstable_apis))]
38use core::convert::Infallible;
39use core::convert::{self, TryFrom};
40use core::f64;
41use core::fmt;
42use core::iter::{self, Product, Sum};
43use core::marker::PhantomData;
44use core::mem::MaybeUninit;
45use core::ops::{Add, BitAnd, BitOr, BitXor, Div, Mul, Neg, Not, Rem, Shl, Shr, Sub};
46use core::str;
47use core::str::FromStr;
48pub use wasm_bindgen;
49use wasm_bindgen::closure::{ScopedClosure, WasmClosure};
50use wasm_bindgen::convert::{FromWasmAbi, IntoWasmAbi, Upcast, UpcastFrom};
51use wasm_bindgen::prelude::*;
52use wasm_bindgen::JsError;
53
54// Re-export sys types as js-sys types
55pub use wasm_bindgen::sys::{JsOption, Null, Promising, Undefined};
56pub use wasm_bindgen::{IntoJsGeneric, JsGeneric};
57
58// When adding new imports:
59//
60// * Keep imports in alphabetical order.
61//
62// * Rename imports with `js_name = ...` according to the note about `camelCase`
63// and `snake_case` in the module's documentation above.
64//
65// * Include the one sentence summary of the import from the MDN link in the
66// module's documentation above, and the MDN link itself.
67//
68// * If a function or method can throw an exception, make it catchable by adding
69// `#[wasm_bindgen(catch)]`.
70//
71// * Add a new `#[test]` into the appropriate file in the
72// `crates/js-sys/tests/wasm/` directory. If the imported function or method
73// can throw an exception, make sure to also add test coverage for that case.
74//
75// * Arguments that are `JsValue`s or imported JavaScript types should be taken
76// by reference.
77//
78// * Name JavaScript's `toString()` method as `to_js_string()` to avoid conflict
79// with Rust's `ToString` trait.
80
81macro_rules! forward_deref_unop {
82 (impl $imp:ident, $method:ident for $t:ty) => {
83 impl $imp for $t {
84 type Output = <&'static $t as $imp>::Output;
85
86 #[inline]
87 fn $method(self) -> Self::Output {
88 $imp::$method(&self)
89 }
90 }
91 };
92 (impl<$($gen:ident),+> $imp:ident, $method:ident for $t:ty) => {
93 impl<$($gen),+> $imp for $t {
94 type Output = <&'static $t as $imp>::Output;
95
96 #[inline]
97 fn $method(self) -> Self::Output {
98 $imp::$method(&self)
99 }
100 }
101 };
102}
103
104macro_rules! forward_deref_binop {
105 (impl $imp:ident, $method:ident for $t:ty) => {
106 impl<'a> $imp<$t> for &'a $t {
107 type Output = <&'static $t as $imp<&'static $t>>::Output;
108
109 #[inline]
110 fn $method(self, other: $t) -> Self::Output {
111 $imp::$method(self, &other)
112 }
113 }
114
115 impl $imp<&$t> for $t {
116 type Output = <&'static $t as $imp<&'static $t>>::Output;
117
118 #[inline]
119 fn $method(self, other: &$t) -> Self::Output {
120 $imp::$method(&self, other)
121 }
122 }
123
124 impl $imp<$t> for $t {
125 type Output = <&'static $t as $imp<&'static $t>>::Output;
126
127 #[inline]
128 fn $method(self, other: $t) -> Self::Output {
129 $imp::$method(&self, &other)
130 }
131 }
132 };
133 (impl<$($gen:ident),+> $imp:ident, $method:ident for $t:ty) => {
134 impl<'a, $($gen),+> $imp<$t> for &'a $t {
135 type Output = <&'static $t as $imp<&'static $t>>::Output;
136
137 #[inline]
138 fn $method(self, other: $t) -> Self::Output {
139 $imp::$method(self, &other)
140 }
141 }
142
143 impl<$($gen),+> $imp<&$t> for $t {
144 type Output = <&'static $t as $imp<&'static $t>>::Output;
145
146 #[inline]
147 fn $method(self, other: &$t) -> Self::Output {
148 $imp::$method(&self, other)
149 }
150 }
151
152 impl<$($gen),+> $imp<$t> for $t {
153 type Output = <&'static $t as $imp<&'static $t>>::Output;
154
155 #[inline]
156 fn $method(self, other: $t) -> Self::Output {
157 $imp::$method(&self, &other)
158 }
159 }
160 };
161}
162
163macro_rules! forward_js_unop {
164 (impl $imp:ident, $method:ident for $t:ty) => {
165 impl $imp for &$t {
166 type Output = $t;
167
168 #[inline]
169 fn $method(self) -> Self::Output {
170 $imp::$method(JsValue::as_ref(self)).unchecked_into()
171 }
172 }
173
174 forward_deref_unop!(impl $imp, $method for $t);
175 };
176 (impl<$($gen:ident),+> $imp:ident, $method:ident for $t:ty) => {
177 impl<$($gen),+> $imp for &$t {
178 type Output = $t;
179
180 #[inline]
181 fn $method(self) -> Self::Output {
182 $imp::$method(JsValue::as_ref(self)).unchecked_into()
183 }
184 }
185
186 forward_deref_unop!(impl<$($gen),+> $imp, $method for $t);
187 };
188}
189
190macro_rules! forward_js_binop {
191 (impl $imp:ident, $method:ident for $t:ty) => {
192 impl $imp<&$t> for &$t {
193 type Output = $t;
194
195 #[inline]
196 fn $method(self, other: &$t) -> Self::Output {
197 $imp::$method(JsValue::as_ref(self), JsValue::as_ref(other)).unchecked_into()
198 }
199 }
200
201 forward_deref_binop!(impl $imp, $method for $t);
202 };
203 (impl<$($gen:ident),+> $imp:ident, $method:ident for $t:ty) => {
204 impl<$($gen),+> $imp<&$t> for &$t {
205 type Output = $t;
206
207 #[inline]
208 fn $method(self, other: &$t) -> Self::Output {
209 $imp::$method(JsValue::as_ref(self), JsValue::as_ref(other)).unchecked_into()
210 }
211 }
212
213 forward_deref_binop!(impl<$($gen),+> $imp, $method for $t);
214 };
215}
216
217macro_rules! sum_product {
218 ($($a:ident)*) => ($(
219 impl Sum for $a {
220 #[inline]
221 fn sum<I: iter::Iterator<Item=Self>>(iter: I) -> Self {
222 iter.fold(
223 $a::from(0),
224 |a, b| a + b,
225 )
226 }
227 }
228
229 impl Product for $a {
230 #[inline]
231 fn product<I: iter::Iterator<Item=Self>>(iter: I) -> Self {
232 iter.fold(
233 $a::from(1),
234 |a, b| a * b,
235 )
236 }
237 }
238
239 impl<'a> Sum<&'a $a> for $a {
240 fn sum<I: iter::Iterator<Item=&'a Self>>(iter: I) -> Self {
241 iter.fold(
242 $a::from(0),
243 |a, b| a + b,
244 )
245 }
246 }
247
248 impl<'a> Product<&'a $a> for $a {
249 #[inline]
250 fn product<I: iter::Iterator<Item=&'a Self>>(iter: I) -> Self {
251 iter.fold(
252 $a::from(1),
253 |a, b| a * b,
254 )
255 }
256 }
257 )*);
258 // Generic variant: impl<T> for Type<T>
259 (impl<$gen:ident> $a:ident<$g2:ident>) => {
260 impl<$gen> Sum for $a<$g2>
261 where
262 $a<$g2>: From<$gen>,
263 $g2: From<u32>
264 {
265 #[inline]
266 fn sum<I: iter::Iterator<Item=Self>>(iter: I) -> Self {
267 iter.fold(
268 $a::from($g2::from(0)),
269 |a, b| a + b,
270 )
271 }
272 }
273
274 impl<$gen> Product for $a<$g2>
275 where
276 $a<$g2>: From<$gen>,
277 $g2: From<u32>
278 {
279 #[inline]
280 fn product<I: iter::Iterator<Item=Self>>(iter: I) -> Self {
281 iter.fold(
282 $a::from($g2::from(1)),
283 |a, b| a * b,
284 )
285 }
286 }
287
288 impl<'a, $gen> Sum<&'a $a<$g2>> for $a<$g2>
289 where
290 $a<$g2>: From<$gen>,
291 $g2: From<u32>
292 {
293 fn sum<I: iter::Iterator<Item=&'a Self>>(iter: I) -> Self {
294 iter.fold(
295 $a::from($g2::from(0)),
296 |a, b| a + b,
297 )
298 }
299 }
300
301 impl<'a, $gen> Product<&'a $a<$g2>> for $a<$g2>
302 where
303 $a<$g2>: From<$gen>,
304 $g2: From<u32>
305 {
306 #[inline]
307 fn product<I: iter::Iterator<Item=&'a Self>>(iter: I) -> Self {
308 iter.fold(
309 $a::from($g2::from(1)),
310 |a, b| a * b,
311 )
312 }
313 }
314 };
315}
316
317macro_rules! partialord_ord {
318 ($t:ident) => {
319 impl PartialOrd for $t {
320 #[inline]
321 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
322 Some(self.cmp(other))
323 }
324
325 #[inline]
326 fn lt(&self, other: &Self) -> bool {
327 JsValue::as_ref(self).lt(JsValue::as_ref(other))
328 }
329
330 #[inline]
331 fn le(&self, other: &Self) -> bool {
332 JsValue::as_ref(self).le(JsValue::as_ref(other))
333 }
334
335 #[inline]
336 fn ge(&self, other: &Self) -> bool {
337 JsValue::as_ref(self).ge(JsValue::as_ref(other))
338 }
339
340 #[inline]
341 fn gt(&self, other: &Self) -> bool {
342 JsValue::as_ref(self).gt(JsValue::as_ref(other))
343 }
344 }
345
346 impl Ord for $t {
347 #[inline]
348 fn cmp(&self, other: &Self) -> Ordering {
349 if self == other {
350 Ordering::Equal
351 } else if self.lt(other) {
352 Ordering::Less
353 } else {
354 Ordering::Greater
355 }
356 }
357 }
358 };
359}
360
361#[wasm_bindgen]
362extern "C" {
363 /// The `decodeURI()` function decodes a Uniform Resource Identifier (URI)
364 /// previously created by `encodeURI` or by a similar routine.
365 ///
366 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURI)
367 #[wasm_bindgen(catch, js_name = decodeURI)]
368 pub fn decode_uri(encoded: &str) -> Result<JsString, JsValue>;
369
370 /// The `decodeURIComponent()` function decodes a Uniform Resource Identifier (URI) component
371 /// previously created by `encodeURIComponent` or by a similar routine.
372 ///
373 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURIComponent)
374 #[wasm_bindgen(catch, js_name = decodeURIComponent)]
375 pub fn decode_uri_component(encoded: &str) -> Result<JsString, JsValue>;
376
377 /// The `encodeURI()` function encodes a Uniform Resource Identifier (URI)
378 /// by replacing each instance of certain characters by one, two, three, or
379 /// four escape sequences representing the UTF-8 encoding of the character
380 /// (will only be four escape sequences for characters composed of two
381 /// "surrogate" characters).
382 ///
383 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURI)
384 #[wasm_bindgen(js_name = encodeURI)]
385 pub fn encode_uri(decoded: &str) -> JsString;
386
387 /// The `encodeURIComponent()` function encodes a Uniform Resource Identifier (URI) component
388 /// by replacing each instance of certain characters by one, two, three, or four escape sequences
389 /// representing the UTF-8 encoding of the character
390 /// (will only be four escape sequences for characters composed of two "surrogate" characters).
391 ///
392 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent)
393 #[wasm_bindgen(js_name = encodeURIComponent)]
394 pub fn encode_uri_component(decoded: &str) -> JsString;
395
396 /// The `eval()` function evaluates JavaScript code represented as a string.
397 ///
398 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval)
399 #[cfg(feature = "unsafe-eval")]
400 #[wasm_bindgen(catch)]
401 pub fn eval(js_source_text: &str) -> Result<JsValue, JsValue>;
402
403 /// The global `isFinite()` function determines whether the passed value is a finite number.
404 /// If needed, the parameter is first converted to a number.
405 ///
406 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isFinite)
407 #[wasm_bindgen(js_name = isFinite)]
408 pub fn is_finite(value: &JsValue) -> bool;
409
410 /// The `parseInt()` function parses a string argument and returns an integer
411 /// of the specified radix (the base in mathematical numeral systems), or NaN on error.
412 ///
413 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt)
414 #[wasm_bindgen(js_name = parseInt)]
415 pub fn parse_int(text: &str, radix: u8) -> f64;
416
417 /// The `parseFloat()` function parses an argument and returns a floating point number,
418 /// or NaN on error.
419 ///
420 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseFloat)
421 #[wasm_bindgen(js_name = parseFloat)]
422 pub fn parse_float(text: &str) -> f64;
423
424 /// The `escape()` function computes a new string in which certain characters have been
425 /// replaced by a hexadecimal escape sequence.
426 ///
427 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/escape)
428 #[wasm_bindgen]
429 pub fn escape(string: &str) -> JsString;
430
431 /// The `unescape()` function computes a new string in which hexadecimal escape
432 /// sequences are replaced with the character that it represents. The escape sequences might
433 /// be introduced by a function like `escape`. Usually, `decodeURI` or `decodeURIComponent`
434 /// are preferred over `unescape`.
435 ///
436 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/unescape)
437 #[wasm_bindgen]
438 pub fn unescape(string: &str) -> JsString;
439}
440
441// AggregateError
442#[wasm_bindgen]
443extern "C" {
444 /// The `AggregateError` object represents an error when several errors need
445 /// to be wrapped in a single error. It is thrown when multiple errors need
446 /// to be reported by an operation, for example by [`Promise::any`], when
447 /// all promises passed to it reject.
448 ///
449 /// `AggregateError` is a subclass of [`Error`].
450 ///
451 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AggregateError)
452 #[wasm_bindgen(extends = Error, extends = Object, typescript_type = "AggregateError")]
453 #[derive(Clone, Debug, PartialEq, Eq)]
454 pub type AggregateError;
455
456 /// Creates a new `AggregateError` from the given iterable of errors.
457 ///
458 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AggregateError/AggregateError)
459 #[wasm_bindgen(constructor)]
460 pub fn new(errors: &[JsValue]) -> AggregateError;
461
462 /// Creates a new `AggregateError` from the given iterable of errors with a
463 /// human-readable description of the aggregate error.
464 ///
465 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AggregateError/AggregateError)
466 #[wasm_bindgen(constructor)]
467 pub fn new_with_message(errors: &[JsValue], message: &str) -> AggregateError;
468
469 /// Creates a new `AggregateError` from the given iterable of errors, a
470 /// human-readable description of the aggregate error, and an
471 /// [`ErrorOptions`] dictionary whose `cause` property indicates the
472 /// original cause of the error.
473 ///
474 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AggregateError/AggregateError)
475 #[wasm_bindgen(constructor)]
476 pub fn new_with_options(
477 errors: &[JsValue],
478 message: &str,
479 options: &ErrorOptions,
480 ) -> AggregateError;
481
482 /// The `errors` property of an `AggregateError` instance is an array
483 /// representing the errors that were aggregated.
484 ///
485 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AggregateError/errors)
486 #[wasm_bindgen(method, getter)]
487 pub fn errors(this: &AggregateError) -> Array;
488}
489
490// ErrorOptions
491#[wasm_bindgen]
492extern "C" {
493 /// The options dictionary accepted as the second argument to the
494 /// [`Error`] constructor (and other built-in error constructors such as
495 /// [`AggregateError`]). Its sole standard property is `cause`, which
496 /// indicates the original cause of the error.
497 ///
498 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/Error)
499 #[wasm_bindgen(extends = Object, typescript_type = "ErrorOptions")]
500 #[derive(Clone, Debug, PartialEq, Eq)]
501 pub type ErrorOptions;
502
503 /// The `cause` property indicates the underlying cause of an error.
504 ///
505 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/cause)
506 #[wasm_bindgen(method, getter = "cause")]
507 pub fn get_cause(this: &ErrorOptions) -> JsValue;
508
509 /// Sets the `cause` property of this `ErrorOptions` dictionary.
510 ///
511 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/cause)
512 #[wasm_bindgen(method, setter = "cause")]
513 pub fn set_cause(this: &ErrorOptions, cause: &JsValue);
514}
515
516impl ErrorOptions {
517 /// Construct a new `ErrorOptions` dictionary with the given `cause`.
518 pub fn new(cause: &JsValue) -> Self {
519 let ret: Self = ::wasm_bindgen::JsCast::unchecked_into(Object::new());
520 ret.set_cause(cause);
521 ret
522 }
523}
524
525// Array
526#[wasm_bindgen]
527extern "C" {
528 #[wasm_bindgen(extends = Object, is_type_of = Array::is_array, typescript_type = "Array<any>")]
529 #[derive(Clone, Debug, PartialEq, Eq)]
530 pub type Array<T = JsValue>;
531
532 /// Creates a new empty array.
533 ///
534 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Array)
535 #[cfg(not(js_sys_unstable_apis))]
536 #[wasm_bindgen(constructor)]
537 pub fn new() -> Array;
538
539 /// Creates a new empty array.
540 ///
541 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Array)
542 #[cfg(js_sys_unstable_apis)]
543 #[wasm_bindgen(constructor)]
544 pub fn new<T>() -> Array<T>;
545
546 // Next major: deprecate
547 /// Creates a new empty array.
548 ///
549 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Array)
550 #[wasm_bindgen(constructor)]
551 pub fn new_typed<T>() -> Array<T>;
552
553 /// Creates a new array with the specified length (elements are initialized to `undefined`).
554 ///
555 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Array)
556 #[cfg(not(js_sys_unstable_apis))]
557 #[wasm_bindgen(constructor)]
558 pub fn new_with_length(len: u32) -> Array;
559
560 /// Creates a new array with the specified length (elements are initialized to `undefined`).
561 ///
562 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Array)
563 #[cfg(js_sys_unstable_apis)]
564 #[wasm_bindgen(constructor)]
565 pub fn new_with_length<T>(len: u32) -> Array<T>;
566
567 // Next major: deprecate
568 /// Creates a new array with the specified length (elements are initialized to `undefined`).
569 ///
570 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Array)
571 #[wasm_bindgen(constructor)]
572 pub fn new_with_length_typed<T>(len: u32) -> Array<T>;
573
574 /// Retrieves the element at the index, counting from the end if negative
575 /// (returns `undefined` if the index is out of range).
576 ///
577 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at)
578 #[cfg(not(js_sys_unstable_apis))]
579 #[wasm_bindgen(method)]
580 pub fn at<T>(this: &Array<T>, index: i32) -> T;
581
582 /// Retrieves the element at the index, counting from the end if negative
583 /// (returns `None` if the index is out of range).
584 ///
585 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at)
586 #[cfg(js_sys_unstable_apis)]
587 #[wasm_bindgen(method)]
588 pub fn at<T>(this: &Array<T>, index: i32) -> Option<T>;
589
590 /// Retrieves the element at the index (returns `undefined` if the index is out of range).
591 ///
592 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at)
593 #[cfg(not(js_sys_unstable_apis))]
594 #[wasm_bindgen(method, indexing_getter)]
595 pub fn get<T>(this: &Array<T>, index: u32) -> T;
596
597 /// Retrieves the element at the index (returns `None` if the index is out of range).
598 ///
599 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at)
600 #[cfg(js_sys_unstable_apis)]
601 #[wasm_bindgen(method, indexing_getter)]
602 pub fn get<T>(this: &Array<T>, index: u32) -> Option<T>;
603
604 /// Retrieves the element at the index (returns `undefined` if the index is out of range).
605 ///
606 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at)
607 #[wasm_bindgen(method, indexing_getter)]
608 pub fn get_unchecked<T>(this: &Array<T>, index: u32) -> T;
609
610 // Next major: deprecate
611 /// Retrieves the element at the index (returns `None` if the index is out of range,
612 /// or if the element is explicitly `undefined`).
613 #[wasm_bindgen(method, indexing_getter)]
614 pub fn get_checked<T>(this: &Array<T>, index: u32) -> Option<T>;
615
616 /// Sets the element at the index (auto-enlarges the array if the index is out of range).
617 #[cfg(not(js_sys_unstable_apis))]
618 #[wasm_bindgen(method, indexing_setter)]
619 pub fn set<T>(this: &Array<T>, index: u32, value: T);
620
621 /// Sets the element at the index (auto-enlarges the array if the index is out of range).
622 #[cfg(js_sys_unstable_apis)]
623 #[wasm_bindgen(method, indexing_setter)]
624 pub fn set<T>(this: &Array<T>, index: u32, value: &T);
625
626 // Next major: deprecate
627 /// Sets the element at the index (auto-enlarges the array if the index is out of range).
628 #[wasm_bindgen(method, indexing_setter)]
629 pub fn set_ref<T>(this: &Array<T>, index: u32, value: &T);
630
631 /// Deletes the element at the index (does nothing if the index is out of range).
632 ///
633 /// The element at the index is set to `undefined`.
634 ///
635 /// This does not resize the array, the array will still be the same length.
636 #[wasm_bindgen(method, indexing_deleter)]
637 pub fn delete<T>(this: &Array<T>, index: u32);
638
639 /// The `Array.from()` static method creates a new, shallow-copied `Array` instance
640 /// from an array-like or iterable object.
641 ///
642 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from)
643 #[cfg(not(js_sys_unstable_apis))]
644 #[wasm_bindgen(static_method_of = Array)]
645 pub fn from(val: &JsValue) -> Array;
646
647 /// The `Array.from()` static method creates a new, shallow-copied `Array` instance
648 /// from an array-like or iterable object.
649 ///
650 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from)
651 #[cfg(js_sys_unstable_apis)]
652 #[wasm_bindgen(static_method_of = Array, catch, js_name = from)]
653 pub fn from<I: Iterable>(val: &I) -> Result<Array<I::Item>, JsValue>;
654
655 // Next major: deprecate
656 /// The `Array.from()` static method creates a new, shallow-copied `Array` instance
657 /// from an array-like or iterable object.
658 ///
659 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from)
660 #[wasm_bindgen(static_method_of = Array, catch, js_name = from)]
661 pub fn from_iterable<I: Iterable>(val: &I) -> Result<Array<I::Item>, JsValue>;
662
663 /// The `Array.from()` static method with a map function creates a new, shallow-copied
664 /// `Array` instance from an array-like or iterable object, applying the map function
665 /// to each value.
666 ///
667 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from)
668 #[wasm_bindgen(static_method_of = Array, catch, js_name = from)]
669 pub fn from_iterable_map<I: Iterable, U>(
670 val: &I,
671 map: &mut dyn FnMut(I::Item, u32) -> Result<U, JsError>,
672 ) -> Result<Array<U>, JsValue>;
673
674 /// The `Array.fromAsync()` static method creates a new, shallow-copied `Array` instance
675 /// from an async iterable, iterable or array-like object.
676 ///
677 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fromAsync)
678 #[wasm_bindgen(static_method_of = Array, catch, js_name = fromAsync)]
679 pub fn from_async<I: AsyncIterable>(val: &I) -> Result<Promise<Array<I::Item>>, JsValue>;
680
681 /// The `Array.fromAsync()` static method with a map function creates a new, shallow-copied
682 /// `Array` instance from an async iterable, iterable or array-like object, applying the map
683 /// function to each value.
684 ///
685 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fromAsync)
686 #[wasm_bindgen(static_method_of = Array, catch, js_name = fromAsync)]
687 pub fn from_async_map<'a, I: AsyncIterable, R: Promising>(
688 val: &I,
689 map: &ScopedClosure<'a, dyn FnMut(I::Item, u32) -> Result<R, JsError>>,
690 ) -> Result<Promise<Array<R::Resolution>>, JsValue>;
691
692 /// The `copyWithin()` method shallow copies part of an array to another
693 /// location in the same array and returns it, without modifying its size.
694 ///
695 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin)
696 #[wasm_bindgen(method, js_name = copyWithin)]
697 pub fn copy_within<T>(this: &Array<T>, target: i32, start: i32, end: i32) -> Array<T>;
698
699 /// The `concat()` method is used to merge two or more arrays. This method
700 /// does not change the existing arrays, but instead returns a new array.
701 ///
702 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat)
703 #[wasm_bindgen(method)]
704 pub fn concat<T, U: Upcast<T>>(this: &Array<T>, array: &Array<U>) -> Array<T>;
705
706 /// The `concat()` method is used to merge two or more arrays. This method
707 /// does not change the existing arrays, but instead returns a new array.
708 ///
709 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat)
710 #[wasm_bindgen(method)]
711 pub fn concat_many<T, U: Upcast<T>>(this: &Array<T>, array: &[Array<U>]) -> Array<T>;
712
713 /// The `every()` method tests whether all elements in the array pass the test
714 /// implemented by the provided function.
715 ///
716 /// **Note:** Consider using [`Array::try_every`] if the predicate might throw an error.
717 ///
718 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every)
719 #[wasm_bindgen(method)]
720 pub fn every<T>(this: &Array<T>, predicate: &mut dyn FnMut(T, u32, Array<T>) -> bool) -> bool;
721
722 /// The `every()` method tests whether all elements in the array pass the test
723 /// implemented by the provided function. _(Fallible variation)_
724 ///
725 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every)
726 #[wasm_bindgen(method, js_name = every, catch)]
727 pub fn try_every<T>(
728 this: &Array<T>,
729 predicate: &mut dyn FnMut(T, u32) -> Result<bool, JsError>,
730 ) -> Result<bool, JsValue>;
731
732 /// The `fill()` method fills all the elements of an array from a start index
733 /// to an end index with a static value. The end index is not included.
734 ///
735 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill)
736 #[wasm_bindgen(method)]
737 pub fn fill<T>(this: &Array<T>, value: &T, start: u32, end: u32) -> Array<T>;
738
739 /// The `filter()` method creates a new array with all elements that pass the
740 /// test implemented by the provided function.
741 ///
742 /// **Note:** Consider using [`Array::try_filter`] if the predicate might throw an error.
743 ///
744 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter)
745 #[wasm_bindgen(method)]
746 pub fn filter<T>(
747 this: &Array<T>,
748 predicate: &mut dyn FnMut(T, u32, Array<T>) -> bool,
749 ) -> Array<T>;
750
751 /// The `filter()` method creates a new array with all elements that pass the
752 /// test implemented by the provided function. _(Fallible variation)_
753 ///
754 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter)
755 #[wasm_bindgen(method, js_name = filter, catch)]
756 pub fn try_filter<T>(
757 this: &Array<T>,
758 predicate: &mut dyn FnMut(T, u32) -> Result<bool, JsError>,
759 ) -> Result<Array<T>, JsValue>;
760
761 /// The `find()` method returns the value of the first element in the array that satisfies
762 /// the provided testing function. Otherwise `undefined` is returned.
763 ///
764 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)
765 #[cfg(not(js_sys_unstable_apis))]
766 #[wasm_bindgen(method)]
767 pub fn find<T>(this: &Array<T>, predicate: &mut dyn FnMut(T, u32, Array<T>) -> bool) -> T;
768
769 /// The `find()` method returns the value of the first element in the array that satisfies
770 /// the provided testing function. Returns `None` if no element matches.
771 ///
772 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)
773 #[cfg(js_sys_unstable_apis)]
774 #[wasm_bindgen(method)]
775 pub fn find<T>(
776 this: &Array<T>,
777 predicate: &mut dyn FnMut(T, u32, Array<T>) -> bool,
778 ) -> Option<T>;
779
780 /// The `find()` method returns the value of the first element in the array that satisfies
781 /// the provided testing function. Otherwise `undefined` is returned. _(Fallible variation)_
782 ///
783 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)
784 #[wasm_bindgen(method, js_name = find, catch)]
785 pub fn try_find<T>(
786 this: &Array<T>,
787 predicate: &mut dyn FnMut(T, u32) -> Result<bool, JsError>,
788 ) -> Result<Option<T>, JsValue>;
789
790 /// The `findIndex()` method returns the index of the first element in the array that
791 /// satisfies the provided testing function. Otherwise -1 is returned.
792 ///
793 /// **Note:** Consider using [`Array::try_find_index`] if the predicate might throw an error.
794 ///
795 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex)
796 #[wasm_bindgen(method, js_name = findIndex)]
797 pub fn find_index<T>(
798 this: &Array<T>,
799 predicate: &mut dyn FnMut(T, u32, Array<T>) -> bool,
800 ) -> i32;
801
802 /// The `findIndex()` method returns the index of the first element in the array that
803 /// satisfies the provided testing function. Otherwise -1 is returned. _(Fallible variation)_
804 ///
805 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex)
806 #[wasm_bindgen(method, js_name = findIndex, catch)]
807 pub fn try_find_index<T>(
808 this: &Array<T>,
809 predicate: &mut dyn FnMut(T, u32) -> Result<bool, JsError>,
810 ) -> Result<i32, JsValue>;
811
812 /// The `findLast()` method of Array instances iterates the array in reverse order
813 /// and returns the value of the first element that satisfies the provided testing function.
814 /// If no elements satisfy the testing function, undefined is returned.
815 ///
816 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLast)
817 #[cfg(not(js_sys_unstable_apis))]
818 #[wasm_bindgen(method, js_name = findLast)]
819 pub fn find_last<T>(this: &Array<T>, predicate: &mut dyn FnMut(T, u32, Array<T>) -> bool) -> T;
820
821 /// The `findLast()` method of Array instances iterates the array in reverse order
822 /// and returns the value of the first element that satisfies the provided testing function.
823 /// Returns `None` if no element matches.
824 ///
825 /// **Note:** Consider using [`Array::try_find_last`] if the predicate might throw an error.
826 ///
827 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLast)
828 #[cfg(js_sys_unstable_apis)]
829 #[wasm_bindgen(method, js_name = findLast)]
830 pub fn find_last<T>(this: &Array<T>, predicate: &mut dyn FnMut(T, u32) -> bool) -> Option<T>;
831
832 /// The `findLast()` method of Array instances iterates the array in reverse order
833 /// and returns the value of the first element that satisfies the provided testing function.
834 /// If no elements satisfy the testing function, undefined is returned. _(Fallible variation)_
835 ///
836 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLast)
837 #[wasm_bindgen(method, js_name = findLast, catch)]
838 pub fn try_find_last<T>(
839 this: &Array<T>,
840 predicate: &mut dyn FnMut(T, u32) -> Result<bool, JsError>,
841 ) -> Result<Option<T>, JsValue>;
842
843 /// The `findLastIndex()` method of Array instances iterates the array in reverse order
844 /// and returns the index of the first element that satisfies the provided testing function.
845 /// If no elements satisfy the testing function, -1 is returned.
846 ///
847 /// **Note:** Consider using [`Array::try_find_last_index`] if the predicate might throw an error.
848 ///
849 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLastIndex)
850 #[wasm_bindgen(method, js_name = findLastIndex)]
851 pub fn find_last_index<T>(
852 this: &Array<T>,
853 predicate: &mut dyn FnMut(T, u32, Array<T>) -> bool,
854 ) -> i32;
855
856 /// The `findLastIndex()` method of Array instances iterates the array in reverse order
857 /// and returns the index of the first element that satisfies the provided testing function.
858 /// If no elements satisfy the testing function, -1 is returned. _(Fallible variation)_
859 ///
860 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLastIndex)
861 #[wasm_bindgen(method, js_name = findLastIndex, catch)]
862 pub fn try_find_last_index<T>(
863 this: &Array<T>,
864 predicate: &mut dyn FnMut(T, u32) -> Result<bool, JsError>,
865 ) -> Result<i32, JsValue>;
866
867 /// The `flat()` method creates a new array with all sub-array elements concatenated into it
868 /// recursively up to the specified depth.
869 ///
870 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat)
871 #[wasm_bindgen(method)]
872 pub fn flat<T>(this: &Array<T>, depth: i32) -> Array<JsValue>;
873
874 /// The `flatMap()` method first maps each element using a mapping function, then flattens
875 /// the result into a new array.
876 ///
877 /// **Note:** Consider using [`Array::try_flat_map`] for safer fallible handling.
878 ///
879 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap)
880 #[wasm_bindgen(method, js_name = flatMap)]
881 pub fn flat_map<T, U>(
882 this: &Array<T>,
883 callback: &mut dyn FnMut(T, u32, Array<T>) -> Vec<U>,
884 ) -> Array<U>;
885
886 /// The `flatMap()` method first maps each element using a mapping function, then flattens
887 /// the result into a new array.
888 ///
889 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap)
890 #[wasm_bindgen(method, js_name = flatMap, catch)]
891 pub fn try_flat_map<T, U>(
892 this: &Array<T>,
893 callback: &mut dyn FnMut(T, u32) -> Vec<U>,
894 ) -> Result<Array<U>, JsValue>;
895
896 /// The `forEach()` method executes a provided function once for each array element.
897 ///
898 /// **Note:** Consider using [`Array::try_for_each`] if the callback might throw an error.
899 ///
900 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach)
901 #[wasm_bindgen(method, js_name = forEach)]
902 pub fn for_each<T: JsGeneric>(this: &Array<T>, callback: &mut dyn FnMut(T, u32, Array<T>));
903
904 /// The `forEach()` method executes a provided function once for each array element. _(Fallible variation)_
905 ///
906 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach)
907 #[wasm_bindgen(method, js_name = forEach, catch)]
908 pub fn try_for_each<T>(
909 this: &Array<T>,
910 callback: &mut dyn FnMut(T, u32) -> Result<(), JsError>,
911 ) -> Result<(), JsValue>;
912
913 /// The `includes()` method determines whether an array includes a certain
914 /// element, returning true or false as appropriate.
915 ///
916 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes)
917 #[wasm_bindgen(method)]
918 pub fn includes<T>(this: &Array<T>, value: &T, from_index: i32) -> bool;
919
920 /// The `indexOf()` method returns the first index at which a given element
921 /// can be found in the array, or -1 if it is not present.
922 ///
923 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf)
924 #[wasm_bindgen(method, js_name = indexOf)]
925 pub fn index_of<T>(this: &Array<T>, value: &T, from_index: i32) -> i32;
926
927 /// The `Array.isArray()` method determines whether the passed value is an Array.
928 ///
929 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray)
930 #[wasm_bindgen(static_method_of = Array, js_name = isArray)]
931 pub fn is_array(value: &JsValue) -> bool;
932
933 /// The `join()` method joins all elements of an array (or an array-like object)
934 /// into a string and returns this string.
935 ///
936 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join)
937 #[wasm_bindgen(method)]
938 pub fn join<T>(this: &Array<T>, delimiter: &str) -> JsString;
939
940 /// The `lastIndexOf()` method returns the last index at which a given element
941 /// can be found in the array, or -1 if it is not present. The array is
942 /// searched backwards, starting at fromIndex.
943 ///
944 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/lastIndexOf)
945 #[wasm_bindgen(method, js_name = lastIndexOf)]
946 pub fn last_index_of<T>(this: &Array<T>, value: &T, from_index: i32) -> i32;
947
948 /// The length property of an object which is an instance of type Array
949 /// sets or returns the number of elements in that array. The value is an
950 /// unsigned, 32-bit integer that is always numerically greater than the
951 /// highest index in the array.
952 ///
953 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/length)
954 #[wasm_bindgen(method, getter)]
955 pub fn length<T>(this: &Array<T>) -> u32;
956
957 /// Sets the length of the array.
958 ///
959 /// If it is set to less than the current length of the array, it will
960 /// shrink the array.
961 ///
962 /// If it is set to more than the current length of the array, it will
963 /// increase the length of the array, filling the new space with empty
964 /// slots.
965 ///
966 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/length)
967 #[wasm_bindgen(method, setter)]
968 pub fn set_length<T>(this: &Array<T>, value: u32);
969
970 /// `map()` calls a provided callback function once for each element in an array,
971 /// in order, and constructs a new array from the results. callback is invoked
972 /// only for indexes of the array which have assigned values, including undefined.
973 /// It is not called for missing elements of the array (that is, indexes that have
974 /// never been set, which have been deleted or which have never been assigned a value).
975 ///
976 /// **Note:** Consider using [`Array::try_map`] for safer fallible handling.
977 ///
978 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map)
979 #[wasm_bindgen(method)]
980 pub fn map<T, U>(this: &Array<T>, predicate: &mut dyn FnMut(T, u32, Array<T>) -> U)
981 -> Array<U>;
982
983 /// `map()` calls a provided callback function once for each element in an array,
984 /// in order, and constructs a new array from the results. callback is invoked
985 /// only for indexes of the array which have assigned values, including undefined.
986 /// It is not called for missing elements of the array (that is, indexes that have
987 /// never been set, which have been deleted or which have never been assigned a value).
988 /// _(Fallible variation)_
989 ///
990 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map)
991 #[wasm_bindgen(method, js_name = map, catch)]
992 pub fn try_map<T, U>(
993 this: &Array<T>,
994 predicate: &mut dyn FnMut(T, u32) -> Result<U, JsError>,
995 ) -> Result<Array<U>, JsValue>;
996
997 /// The `Array.of()` method creates a new Array instance with a variable
998 /// number of arguments, regardless of number or type of the arguments.
999 ///
1000 /// Note: For type inference use `Array::<T>::of(&[T])`.
1001 ///
1002 /// The difference between `Array.of()` and the `Array` constructor is in the
1003 /// handling of integer arguments: `Array.of(7)` creates an array with a single
1004 /// element, `7`, whereas `Array(7)` creates an empty array with a `length`
1005 /// property of `7` (Note: this implies an array of 7 empty slots, not slots
1006 /// with actual undefined values).
1007 ///
1008 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of)
1009 #[wasm_bindgen(static_method_of = Array, js_name = of, variadic)]
1010 pub fn of<T>(values: &[T]) -> Array<T>;
1011
1012 // Next major: deprecate these
1013 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of)
1014 #[wasm_bindgen(static_method_of = Array, js_name = of)]
1015 pub fn of1(a: &JsValue) -> Array;
1016
1017 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of)
1018 #[wasm_bindgen(static_method_of = Array, js_name = of)]
1019 pub fn of2(a: &JsValue, b: &JsValue) -> Array;
1020
1021 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of)
1022 #[wasm_bindgen(static_method_of = Array, js_name = of)]
1023 pub fn of3(a: &JsValue, b: &JsValue, c: &JsValue) -> Array;
1024
1025 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of)
1026 #[wasm_bindgen(static_method_of = Array, js_name = of)]
1027 pub fn of4(a: &JsValue, b: &JsValue, c: &JsValue, d: &JsValue) -> Array;
1028
1029 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of)
1030 #[wasm_bindgen(static_method_of = Array, js_name = of)]
1031 pub fn of5(a: &JsValue, b: &JsValue, c: &JsValue, d: &JsValue, e: &JsValue) -> Array;
1032
1033 /// The `pop()` method removes the last element from an array and returns that
1034 /// element. This method changes the length of the array.
1035 ///
1036 /// **Note:** Consider using [`Array::pop_checked`] for handling empty arrays.
1037 ///
1038 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pop)
1039 #[cfg(not(js_sys_unstable_apis))]
1040 #[wasm_bindgen(method)]
1041 pub fn pop<T>(this: &Array<T>) -> T;
1042
1043 /// The `pop()` method removes the last element from an array and returns that
1044 /// element. This method changes the length of the array.
1045 /// Returns `None` if the array is empty.
1046 ///
1047 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pop)
1048 #[cfg(js_sys_unstable_apis)]
1049 #[wasm_bindgen(method)]
1050 pub fn pop<T>(this: &Array<T>) -> Option<T>;
1051
1052 // Next major: deprecate
1053 /// The `pop()` method removes the last element from an array and returns that
1054 /// element. This method changes the length of the array.
1055 ///
1056 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pop)
1057 #[wasm_bindgen(method, js_name = pop)]
1058 pub fn pop_checked<T>(this: &Array<T>) -> Option<T>;
1059
1060 /// The `push()` method adds one element to the end of an array and
1061 /// returns the new length of the array.
1062 ///
1063 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push)
1064 #[wasm_bindgen(method)]
1065 pub fn push<T>(this: &Array<T>, value: &T) -> u32;
1066
1067 /// The `push()` method adds one or more elements to the end of an array and
1068 /// returns the new length of the array.
1069 ///
1070 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push)
1071 #[wasm_bindgen(method, js_name = push, variadic)]
1072 pub fn push_many<T>(this: &Array<T>, values: &[T]) -> u32;
1073
1074 /// The `reduce()` method applies a function against an accumulator and each element in
1075 /// the array (from left to right) to reduce it to a single value.
1076 ///
1077 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce)
1078 #[cfg(not(js_sys_unstable_apis))]
1079 #[wasm_bindgen(method)]
1080 pub fn reduce<T>(
1081 this: &Array<T>,
1082 predicate: &mut dyn FnMut(JsValue, T, u32, Array<T>) -> JsValue,
1083 initial_value: &JsValue,
1084 ) -> JsValue;
1085
1086 /// The `reduce()` method applies a function against an accumulator and each element in
1087 /// the array (from left to right) to reduce it to a single value.
1088 ///
1089 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce)
1090 #[cfg(js_sys_unstable_apis)]
1091 #[wasm_bindgen(method)]
1092 pub fn reduce<T, A>(
1093 this: &Array<T>,
1094 predicate: &mut dyn FnMut(A, T, u32, Array<T>) -> A,
1095 initial_value: &A,
1096 ) -> A;
1097
1098 /// The `reduce()` method applies a function against an accumulator and each element in
1099 /// the array (from left to right) to reduce it to a single value. _(Fallible variation)_
1100 ///
1101 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce)
1102 #[wasm_bindgen(method, js_name = reduce, catch)]
1103 pub fn try_reduce<T, A>(
1104 this: &Array<T>,
1105 predicate: &mut dyn FnMut(A, T, u32) -> Result<A, JsError>,
1106 initial_value: &A,
1107 ) -> Result<A, JsValue>;
1108
1109 /// The `reduceRight()` method applies a function against an accumulator and each value
1110 /// of the array (from right-to-left) to reduce it to a single value.
1111 ///
1112 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/ReduceRight)
1113 #[cfg(not(js_sys_unstable_apis))]
1114 #[wasm_bindgen(method, js_name = reduceRight)]
1115 pub fn reduce_right<T>(
1116 this: &Array<T>,
1117 predicate: &mut dyn FnMut(JsValue, T, u32, Array<T>) -> JsValue,
1118 initial_value: &JsValue,
1119 ) -> JsValue;
1120
1121 /// The `reduceRight()` method applies a function against an accumulator and each value
1122 /// of the array (from right-to-left) to reduce it to a single value.
1123 ///
1124 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/ReduceRight)
1125 #[cfg(js_sys_unstable_apis)]
1126 #[wasm_bindgen(method, js_name = reduceRight)]
1127 pub fn reduce_right<T, A>(
1128 this: &Array<T>,
1129 predicate: &mut dyn FnMut(A, T, u32, Array<T>) -> A,
1130 initial_value: &A,
1131 ) -> A;
1132
1133 /// The `reduceRight()` method applies a function against an accumulator and each value
1134 /// of the array (from right-to-left) to reduce it to a single value. _(Fallible variation)_
1135 ///
1136 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/ReduceRight)
1137 #[wasm_bindgen(method, js_name = reduceRight, catch)]
1138 pub fn try_reduce_right<T, A>(
1139 this: &Array<T>,
1140 predicate: &mut dyn FnMut(JsValue, T, u32) -> Result<A, JsError>,
1141 initial_value: &A,
1142 ) -> Result<A, JsValue>;
1143
1144 /// The `reverse()` method reverses an array in place. The first array
1145 /// element becomes the last, and the last array element becomes the first.
1146 ///
1147 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse)
1148 #[wasm_bindgen(method)]
1149 pub fn reverse<T>(this: &Array<T>) -> Array<T>;
1150
1151 /// The `shift()` method removes the first element from an array and returns
1152 /// that removed element. This method changes the length of the array.
1153 ///
1154 /// **Note:** Consider using [`Array::shift_checked`] for handling empty arrays.
1155 ///
1156 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift)
1157 #[cfg(not(js_sys_unstable_apis))]
1158 #[wasm_bindgen(method)]
1159 pub fn shift<T>(this: &Array<T>) -> T;
1160
1161 /// The `shift()` method removes the first element from an array and returns
1162 /// that removed element. This method changes the length of the array.
1163 /// Returns `None` if the array is empty.
1164 ///
1165 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift)
1166 #[cfg(js_sys_unstable_apis)]
1167 #[wasm_bindgen(method)]
1168 pub fn shift<T>(this: &Array<T>) -> Option<T>;
1169
1170 // Next major: deprecate
1171 /// The `shift()` method removes the first element from an array and returns
1172 /// that removed element. This method changes the length of the array.
1173 ///
1174 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift)
1175 #[wasm_bindgen(method, js_name = shift)]
1176 pub fn shift_checked<T>(this: &Array<T>) -> Option<T>;
1177
1178 /// The `slice()` method returns a shallow copy of a portion of an array into
1179 /// a new array object selected from begin to end (end not included).
1180 /// The original array will not be modified.
1181 ///
1182 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)
1183 #[cfg(not(js_sys_unstable_apis))]
1184 #[wasm_bindgen(method)]
1185 pub fn slice<T>(this: &Array<T>, start: u32, end: u32) -> Array<T>;
1186
1187 /// The `slice()` method returns a shallow copy of a portion of an array into
1188 /// a new array object selected from begin to end (end not included).
1189 /// The original array will not be modified. Negative indices count from the end.
1190 ///
1191 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)
1192 #[cfg(js_sys_unstable_apis)]
1193 #[wasm_bindgen(method)]
1194 pub fn slice<T>(this: &Array<T>, start: i32, end: i32) -> Array<T>;
1195
1196 /// The `slice()` method returns a shallow copy of a portion of an array into
1197 /// a new array object selected from the given index to the end.
1198 /// The original array will not be modified.
1199 ///
1200 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)
1201 #[cfg(not(js_sys_unstable_apis))]
1202 #[wasm_bindgen(method, js_name = slice)]
1203 pub fn slice_from<T>(this: &Array<T>, start: u32) -> Array<T>;
1204
1205 /// The `slice()` method returns a shallow copy of a portion of an array into
1206 /// a new array object selected from the given index to the end.
1207 /// The original array will not be modified. Negative indices count from the end.
1208 ///
1209 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)
1210 #[cfg(js_sys_unstable_apis)]
1211 #[wasm_bindgen(method, js_name = slice)]
1212 pub fn slice_from<T>(this: &Array<T>, start: i32) -> Array<T>;
1213
1214 /// The `some()` method tests whether at least one element in the array passes the test implemented
1215 /// by the provided function.
1216 /// Note: This method returns false for any condition put on an empty array.
1217 ///
1218 /// **Note:** Consider using [`Array::try_some`] if the predicate might throw an error.
1219 ///
1220 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some)
1221 #[wasm_bindgen(method)]
1222 pub fn some<T>(this: &Array<T>, predicate: &mut dyn FnMut(T) -> bool) -> bool;
1223
1224 /// The `some()` method tests whether at least one element in the array passes the test implemented
1225 /// by the provided function. _(Fallible variation)_
1226 /// Note: This method returns false for any condition put on an empty array.
1227 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some)
1228 #[wasm_bindgen(method, js_name = some, catch)]
1229 pub fn try_some<T>(
1230 this: &Array<T>,
1231 predicate: &mut dyn FnMut(T) -> Result<bool, JsError>,
1232 ) -> Result<bool, JsValue>;
1233
1234 /// The `sort()` method sorts the elements of an array in place and returns
1235 /// the array. The sort is not necessarily stable. The default sort
1236 /// order is according to string Unicode code points.
1237 ///
1238 /// The time and space complexity of the sort cannot be guaranteed as it
1239 /// is implementation dependent.
1240 ///
1241 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)
1242 #[wasm_bindgen(method)]
1243 pub fn sort<T>(this: &Array<T>) -> Array<T>;
1244
1245 /// The `sort()` method with a custom compare function.
1246 ///
1247 /// **Note:** Consider using [`Array::try_sort_by`] if the predicate might throw an error.
1248 ///
1249 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)
1250 #[wasm_bindgen(method, js_name = sort)]
1251 pub fn sort_by<T>(this: &Array<T>, compare_fn: &mut dyn FnMut(T, T) -> i32) -> Array<T>;
1252
1253 /// The `sort()` method with a custom compare function. _(Fallible variation)_
1254 ///
1255 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)
1256 #[wasm_bindgen(method, js_name = sort, catch)]
1257 pub fn try_sort_by<T>(
1258 this: &Array<T>,
1259 compare_fn: &mut dyn FnMut(T, T) -> Result<i32, JsError>,
1260 ) -> Result<Array<T>, JsValue>;
1261
1262 /// The `splice()` method changes the contents of an array by removing existing elements and/or
1263 /// adding new elements.
1264 ///
1265 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice)
1266 #[wasm_bindgen(method)]
1267 pub fn splice<T>(this: &Array<T>, start: u32, delete_count: u32, item: &T) -> Array<T>;
1268
1269 /// The `splice()` method changes the contents of an array by removing existing elements and/or
1270 /// adding new elements.
1271 ///
1272 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice)
1273 #[wasm_bindgen(method, js_name = splice, variadic)]
1274 pub fn splice_many<T>(this: &Array<T>, start: u32, delete_count: u32, items: &[T]) -> Array<T>;
1275
1276 /// The `toLocaleString()` method returns a string representing the elements of the array.
1277 /// The elements are converted to Strings using their toLocaleString methods and these
1278 /// Strings are separated by a locale-specific String (such as a comma ",").
1279 ///
1280 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toLocaleString)
1281 #[cfg(not(js_sys_unstable_apis))]
1282 #[wasm_bindgen(method, js_name = toLocaleString)]
1283 pub fn to_locale_string<T>(this: &Array<T>, locales: &JsValue, options: &JsValue) -> JsString;
1284
1285 /// The `toLocaleString()` method returns a string representing the elements of the array.
1286 /// The elements are converted to Strings using their toLocaleString methods and these
1287 /// Strings are separated by a locale-specific String (such as a comma ",").
1288 ///
1289 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toLocaleString)
1290 #[cfg(js_sys_unstable_apis)]
1291 #[wasm_bindgen(method, js_name = toLocaleString)]
1292 pub fn to_locale_string<T>(
1293 this: &Array<T>,
1294 locales: &[JsString],
1295 options: &Intl::NumberFormatOptions,
1296 ) -> JsString;
1297
1298 /// The `toReversed()` method returns a new array with the elements in reversed order,
1299 /// without modifying the original array.
1300 ///
1301 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toReversed)
1302 #[wasm_bindgen(method, js_name = toReversed)]
1303 pub fn to_reversed<T>(this: &Array<T>) -> Array<T>;
1304
1305 /// The `toSorted()` method returns a new array with the elements sorted in ascending order,
1306 /// without modifying the original array.
1307 ///
1308 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toSorted)
1309 #[wasm_bindgen(method, js_name = toSorted)]
1310 pub fn to_sorted<T>(this: &Array<T>) -> Array<T>;
1311
1312 /// The `toSorted()` method with a custom compare function.
1313 ///
1314 /// **Note:** Consider using [`Array::try_to_sorted_by`] if the predicate might throw an error.
1315 ///
1316 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toSorted)
1317 #[wasm_bindgen(method, js_name = toSorted)]
1318 pub fn to_sorted_by<T>(this: &Array<T>, compare_fn: &mut dyn FnMut(T, T) -> i32) -> Array<T>;
1319
1320 /// The `toSorted()` method with a custom compare function. _(Fallible variation)_
1321 ///
1322 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toSorted)
1323 #[wasm_bindgen(method, js_name = toSorted, catch)]
1324 pub fn try_to_sorted_by<T>(
1325 this: &Array<T>,
1326 compare_fn: &mut dyn FnMut(T, T) -> Result<i32, JsError>,
1327 ) -> Result<Array<T>, JsValue>;
1328
1329 /// The `toSpliced()` method returns a new array with some elements removed and/or
1330 /// replaced at a given index, without modifying the original array.
1331 ///
1332 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toSpliced)
1333 #[wasm_bindgen(method, js_name = toSpliced, variadic)]
1334 pub fn to_spliced<T>(this: &Array<T>, start: u32, delete_count: u32, items: &[T]) -> Array<T>;
1335
1336 /// The `toString()` method returns a string representing the specified array
1337 /// and its elements.
1338 ///
1339 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toString)
1340 #[cfg(not(js_sys_unstable_apis))]
1341 #[wasm_bindgen(method, js_name = toString)]
1342 pub fn to_string<T>(this: &Array<T>) -> JsString;
1343
1344 /// Converts the Array into a Vector.
1345 #[wasm_bindgen(method, js_name = slice)]
1346 pub fn to_vec<T>(this: &Array<T>) -> Vec<T>;
1347
1348 /// The `unshift()` method adds one element to the beginning of an
1349 /// array and returns the new length of the array.
1350 ///
1351 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift)
1352 #[wasm_bindgen(method)]
1353 pub fn unshift<T>(this: &Array<T>, value: &T) -> u32;
1354
1355 /// The `unshift()` method adds one or more elements to the beginning of an
1356 /// array and returns the new length of the array.
1357 ///
1358 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift)
1359 #[wasm_bindgen(method, js_name = unshift, variadic)]
1360 pub fn unshift_many<T>(this: &Array<T>, values: &[T]) -> u32;
1361
1362 /// The `with()` method returns a new array with the element at the given index
1363 /// replaced with the given value, without modifying the original array.
1364 ///
1365 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/with)
1366 #[wasm_bindgen(method, js_name = with)]
1367 pub fn with<T>(this: &Array<T>, index: u32, value: &T) -> Array<T>;
1368}
1369
1370// Tuples as a typed array variant
1371#[wasm_bindgen]
1372extern "C" {
1373 #[wasm_bindgen(extends = Object, js_name = Array, is_type_of = Array::is_array, no_upcast, typescript_type = "Array<any>")]
1374 #[derive(Clone, Debug)]
1375 pub type ArrayTuple<T: JsTuple = (JsValue,)>;
1376
1377 /// Creates a new JS array typed as a 1-tuple.
1378 #[wasm_bindgen(js_class = Array, static_method_of = ArrayTuple, js_name = of)]
1379 pub fn new1<T1>(t1: &T1) -> ArrayTuple<(T1,)>;
1380
1381 /// Creates a new JS array typed as a 2-tuple.
1382 #[wasm_bindgen(js_class = Array, static_method_of = ArrayTuple, js_name = of)]
1383 pub fn new2<T1, T2>(t1: &T1, t2: &T2) -> ArrayTuple<(T1, T2)>;
1384
1385 /// Creates a new JS array typed as a 3-tuple.
1386 #[wasm_bindgen(js_class = Array, static_method_of = ArrayTuple, js_name = of)]
1387 pub fn new3<T1, T2, T3>(t1: &T1, t2: &T2, t3: &T3) -> ArrayTuple<(T1, T2, T3)>;
1388
1389 /// Creates a new JS array typed as a 4-tuple.
1390 #[wasm_bindgen(js_class = Array, static_method_of = ArrayTuple, js_name = of)]
1391 pub fn new4<T1, T2, T3, T4>(t1: &T1, t2: &T2, t3: &T3, t4: &T4)
1392 -> ArrayTuple<(T1, T2, T3, T4)>;
1393
1394 /// Creates a new JS array typed as a 5-tuple.
1395 #[wasm_bindgen(js_class = Array, static_method_of = ArrayTuple, js_name = of)]
1396 pub fn new5<T1, T2, T3, T4, T5>(
1397 t1: &T1,
1398 t2: &T2,
1399 t3: &T3,
1400 t4: &T4,
1401 t5: &T5,
1402 ) -> ArrayTuple<(T1, T2, T3, T4, T5)>;
1403
1404 /// Creates a new JS array typed as a 6-tuple.
1405 #[wasm_bindgen(js_class = Array, static_method_of = ArrayTuple, js_name = of)]
1406 pub fn new6<T1, T2, T3, T4, T5, T6>(
1407 t1: &T1,
1408 t2: &T2,
1409 t3: &T3,
1410 t4: &T4,
1411 t5: &T5,
1412 t6: &T6,
1413 ) -> ArrayTuple<(T1, T2, T3, T4, T5, T6)>;
1414
1415 /// Creates a new JS array typed as a 7-tuple.
1416 #[wasm_bindgen(js_class = Array, static_method_of = ArrayTuple, js_name = of)]
1417 pub fn new7<T1, T2, T3, T4, T5, T6, T7>(
1418 t1: &T1,
1419 t2: &T2,
1420 t3: &T3,
1421 t4: &T4,
1422 t5: &T5,
1423 t6: &T6,
1424 t7: &T7,
1425 ) -> ArrayTuple<(T1, T2, T3, T4, T5, T6, T7)>;
1426
1427 /// Creates a new JS array typed as a 8-tuple.
1428 #[wasm_bindgen(js_class = Array, static_method_of = ArrayTuple, js_name = of)]
1429 pub fn new8<T1, T2, T3, T4, T5, T6, T7, T8>(
1430 t1: &T1,
1431 t2: &T2,
1432 t3: &T3,
1433 t4: &T4,
1434 t5: &T5,
1435 t6: &T6,
1436 t7: &T7,
1437 t8: &T8,
1438 ) -> ArrayTuple<(T1, T2, T3, T4, T5, T6, T7, T8)>;
1439
1440 /// Gets the 1st item
1441 #[wasm_bindgen(
1442 method,
1443 js_class = Array,
1444 getter,
1445 js_name = "0"
1446 )]
1447 pub fn get0<T: JsTuple1 = (JsValue,)>(this: &ArrayTuple<T>) -> <T as JsTuple1>::T1;
1448
1449 /// Gets the 2nd item
1450 #[wasm_bindgen(
1451 method,
1452 js_class = Array,
1453 getter,
1454 js_name = "1"
1455 )]
1456 pub fn get1<T: JsTuple2 = (JsValue, JsValue)>(this: &ArrayTuple<T>) -> <T as JsTuple2>::T2;
1457
1458 /// Gets the 3rd item
1459 #[wasm_bindgen(
1460 method,
1461 js_class = Array,
1462 getter,
1463 js_name = "2"
1464 )]
1465 pub fn get2<T: JsTuple3 = (JsValue, JsValue, JsValue)>(
1466 this: &ArrayTuple<T>,
1467 ) -> <T as JsTuple3>::T3;
1468
1469 /// Gets the 4th item
1470 #[wasm_bindgen(
1471 method,
1472 js_class = Array,
1473 getter,
1474 js_name = "3"
1475 )]
1476 pub fn get3<T: JsTuple4 = (JsValue, JsValue, JsValue, JsValue)>(
1477 this: &ArrayTuple<T>,
1478 ) -> <T as JsTuple4>::T4;
1479
1480 /// Gets the 5th item
1481 #[wasm_bindgen(
1482 method,
1483 js_class = Array,
1484 getter,
1485 js_name = "4"
1486 )]
1487 pub fn get4<T: JsTuple5 = (JsValue, JsValue, JsValue, JsValue, JsValue)>(
1488 this: &ArrayTuple<T>,
1489 ) -> <T as JsTuple5>::T5;
1490
1491 /// Gets the 6th item
1492 #[wasm_bindgen(
1493 method,
1494 js_class = Array,
1495 getter,
1496 js_name = "5"
1497 )]
1498 pub fn get5<T: JsTuple6 = (JsValue, JsValue, JsValue, JsValue, JsValue, JsValue)>(
1499 this: &ArrayTuple<T>,
1500 ) -> <T as JsTuple6>::T6;
1501
1502 /// Gets the 7th item
1503 #[wasm_bindgen(
1504 method,
1505 js_class = Array,
1506 getter,
1507 js_name = "6"
1508 )]
1509 pub fn get6<
1510 T: JsTuple7 = (
1511 JsValue,
1512 JsValue,
1513 JsValue,
1514 JsValue,
1515 JsValue,
1516 JsValue,
1517 JsValue,
1518 ),
1519 >(
1520 this: &ArrayTuple<T>,
1521 ) -> <T as JsTuple7>::T7;
1522
1523 /// Gets the 8th item
1524 #[wasm_bindgen(
1525 method,
1526 js_class = Array,
1527 getter,
1528 js_name = "7"
1529 )]
1530 pub fn get7<
1531 T: JsTuple8 = (
1532 JsValue,
1533 JsValue,
1534 JsValue,
1535 JsValue,
1536 JsValue,
1537 JsValue,
1538 JsValue,
1539 JsValue,
1540 ),
1541 >(
1542 this: &ArrayTuple<T>,
1543 ) -> <T as JsTuple8>::T8;
1544
1545 /// Sets the 1st item
1546 #[wasm_bindgen(
1547 method,
1548 js_class = Array,
1549 setter,
1550 js_name = "0"
1551 )]
1552 pub fn set0<T: JsTuple1 = (JsValue,)>(this: &ArrayTuple<T>, value: &<T as JsTuple1>::T1);
1553
1554 /// Sets the 2nd item
1555 #[wasm_bindgen(
1556 method,
1557 js_class = Array,
1558 setter,
1559 js_name = "1"
1560 )]
1561 pub fn set1<T: JsTuple2 = (JsValue, JsValue)>(
1562 this: &ArrayTuple<T>,
1563 value: &<T as JsTuple2>::T2,
1564 );
1565
1566 /// Sets the 3rd item
1567 #[wasm_bindgen(
1568 method,
1569 js_class = Array,
1570 setter,
1571 js_name = "2"
1572 )]
1573 pub fn set2<T: JsTuple3 = (JsValue, JsValue, JsValue)>(
1574 this: &ArrayTuple<T>,
1575 value: &<T as JsTuple3>::T3,
1576 );
1577
1578 /// Sets the 4th item
1579 #[wasm_bindgen(
1580 method,
1581 js_class = Array,
1582 setter,
1583 js_name = "3"
1584 )]
1585 pub fn set3<T: JsTuple4 = (JsValue, JsValue, JsValue, JsValue)>(
1586 this: &ArrayTuple<T>,
1587 value: &<T as JsTuple4>::T4,
1588 );
1589
1590 /// Sets the 5th item
1591 #[wasm_bindgen(
1592 method,
1593 js_class = Array,
1594 setter,
1595 js_name = "4"
1596 )]
1597 pub fn set4<T: JsTuple5 = (JsValue, JsValue, JsValue, JsValue, JsValue)>(
1598 this: &ArrayTuple<T>,
1599 value: &<T as JsTuple5>::T5,
1600 );
1601
1602 /// Sets the 6th item
1603 #[wasm_bindgen(
1604 method,
1605 js_class = Array,
1606 setter,
1607 js_name = "5"
1608 )]
1609 pub fn set5<T: JsTuple6 = (JsValue, JsValue, JsValue, JsValue, JsValue, JsValue)>(
1610 this: &ArrayTuple<T>,
1611 value: &<T as JsTuple6>::T6,
1612 );
1613
1614 /// Sets the 7th item
1615 #[wasm_bindgen(
1616 method,
1617 js_class = Array,
1618 setter,
1619 js_name = "6"
1620 )]
1621 pub fn set6<
1622 T: JsTuple7 = (
1623 JsValue,
1624 JsValue,
1625 JsValue,
1626 JsValue,
1627 JsValue,
1628 JsValue,
1629 JsValue,
1630 ),
1631 >(
1632 this: &ArrayTuple<T>,
1633 value: &<T as JsTuple7>::T7,
1634 );
1635
1636 /// Sets the 8th item
1637 #[wasm_bindgen(
1638 method,
1639 js_class = Array,
1640 setter,
1641 js_name = "7"
1642 )]
1643 pub fn set7<
1644 T: JsTuple8 = (
1645 JsValue,
1646 JsValue,
1647 JsValue,
1648 JsValue,
1649 JsValue,
1650 JsValue,
1651 JsValue,
1652 JsValue,
1653 ),
1654 >(
1655 this: &ArrayTuple<T>,
1656 value: &<T as JsTuple8>::T8,
1657 );
1658}
1659
1660/// Base trait for tuple types.
1661pub trait JsTuple {
1662 const ARITY: usize;
1663}
1664
1665macro_rules! impl_tuple_traits {
1666 // Base case: first trait has no parent (besides JsTuple)
1667 ($name:ident $ty:tt) => {
1668 pub trait $name: JsTuple {
1669 type $ty;
1670 }
1671 };
1672
1673 // Recursive case: define trait with parent, then recurse
1674 ($name:ident $ty:tt $($rest_name:ident $rest_ty:tt)+) => {
1675 pub trait $name: JsTuple {
1676 type $ty;
1677 }
1678
1679 impl_tuple_traits!(@with_parent $name $($rest_name $rest_ty)+);
1680 };
1681
1682 // Internal: traits that have a parent
1683 (@with_parent $trait:ident $name:ident $ty:tt) => {
1684 pub trait $name: $trait {
1685 type $ty;
1686 }
1687 };
1688
1689 (@with_parent $trait:ident $name:ident $ty:tt $($rest_name:ident $rest_ty:tt)+) => {
1690 pub trait $name: $trait {
1691 type $ty;
1692 }
1693
1694 impl_tuple_traits!(@with_parent $name $($rest_name $rest_ty)+);
1695 };
1696}
1697
1698macro_rules! impl_parent_traits {
1699 ([$($types:tt),+] [] []) => {};
1700
1701 ([$($types:tt),+] [$trait:ident $($rest_traits:ident)*] [$ty:tt $($rest_tys:tt)*]) => {
1702 impl<$($types),+> $trait for ($($types),+,) {
1703 type $ty = $ty;
1704 }
1705
1706 impl_parent_traits!([$($types),+] [$($rest_traits)*] [$($rest_tys)*]);
1707 };
1708}
1709
1710// Define the trait hierarchy once
1711impl_tuple_traits!(
1712 JsTuple1 T1
1713 JsTuple2 T2
1714 JsTuple3 T3
1715 JsTuple4 T4
1716 JsTuple5 T5
1717 JsTuple6 T6
1718 JsTuple7 T7
1719 JsTuple8 T8
1720);
1721
1722impl<T: JsTuple> ArrayTuple<T> {
1723 /// Get the static arity of the ArrayTuple type.
1724 #[allow(clippy::len_without_is_empty)]
1725 pub fn len(&self) -> usize {
1726 <T as JsTuple>::ARITY
1727 }
1728}
1729
1730macro_rules! impl_tuple {
1731 ($arity:literal [$($traits:ident)*] [$($T:tt)+] [$($vars:tt)+] $new:ident $last:ident $last_ty:tt) => {
1732 impl<$($T),+> JsTuple for ($($T),+,) {
1733 const ARITY: usize = $arity;
1734 }
1735
1736 impl_parent_traits!([$($T),+] [$($traits)*] [$($T)*]);
1737
1738 impl<$($T: JsGeneric),+> From<($($T,)+)> for ArrayTuple<($($T),+,)> {
1739 fn from(($($vars,)+): ($($T,)+)) -> Self {
1740 $(let $vars: JsValue = $vars.upcast_into();)+
1741 Array::of(&[$($vars),+]).unchecked_into()
1742 }
1743 }
1744
1745 impl<$($T: JsGeneric + Default),+> Default for ArrayTuple<($($T),+,)> {
1746 fn default() -> Self {
1747 (
1748 $($T::default(),)+
1749 ).into()
1750 }
1751 }
1752
1753 impl<$($T: JsGeneric),+> ArrayTuple<($($T),+,)> {
1754 /// Get the first element of the ArrayTuple
1755 pub fn first(&self) -> T1 {
1756 self.get0()
1757 }
1758
1759 /// Get the last element of the ArrayTuple
1760 pub fn last(&self) -> $last_ty {
1761 self.$last()
1762 }
1763
1764 /// Convert the ArrayTuple into its corresponding Rust tuple.
1765 pub fn into_tuple(self) -> ($($T,)+) {
1766 ($(self.$vars(),)+)
1767 }
1768
1769 /// Deprecated alias for [`ArrayTuple::into_tuple`].
1770 #[deprecated(note = "renamed to `into_tuple`")]
1771 pub fn into_parts(self) -> ($($T,)+) {
1772 self.into_tuple()
1773 }
1774
1775 /// Create a new ArrayTuple from the corresponding parts.
1776 ///
1777 /// # Example
1778 ///
1779 /// ```
1780 /// use js_sys::{ArrayTuple, JsString};
1781 ///
1782 /// let tuple = ArrayTuple::<JsString, JsString>::new(&"a".into(), &"b".into());
1783 /// ```
1784 ///
1785 /// Note: You must specify the T using `::<...>` syntax on `ArrayTuple`.
1786 /// Alternatively, use `new1`, `new2`, etc. for type inference from the left-hand side.
1787 pub fn new($($vars: &$T),+) -> ArrayTuple<($($T),+,)> {
1788 ArrayTuple::$new($($vars),+)
1789 }
1790 }
1791 };
1792}
1793
1794// Implement for each tuple size
1795impl_tuple!(1 [JsTuple1] [T1] [get0] new1 get0 T1);
1796impl_tuple!(2 [JsTuple1 JsTuple2] [T1 T2] [get0 get1] new2 get1 T2);
1797impl_tuple!(3 [JsTuple1 JsTuple2 JsTuple3] [T1 T2 T3] [get0 get1 get2] new3 get2 T3);
1798impl_tuple!(4 [JsTuple1 JsTuple2 JsTuple3 JsTuple4] [T1 T2 T3 T4] [get0 get1 get2 get3] new4 get3 T4);
1799impl_tuple!(5 [JsTuple1 JsTuple2 JsTuple3 JsTuple4 JsTuple5] [T1 T2 T3 T4 T5] [get0 get1 get2 get3 get4] new5 get4 T5);
1800impl_tuple!(6 [JsTuple1 JsTuple2 JsTuple3 JsTuple4 JsTuple5 JsTuple6] [T1 T2 T3 T4 T5 T6] [get0 get1 get2 get3 get4 get5] new6 get5 T6);
1801impl_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);
1802impl_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);
1803
1804// Macro to generate structural covariance impls for each arity
1805macro_rules! impl_tuple_covariance {
1806 ([$($T:ident)+] [$($Target:ident)+] [$($Ts:ident)+]) => {
1807 // ArrayTuple -> Array
1808 // Allows (T1, T2, ...) to be used where (Target) is expected
1809 // when all T1, T2, ... are covariant to Target
1810 impl<$($T,)+ Target> UpcastFrom<ArrayTuple<($($T,)+)>> for Array<Target>
1811 where
1812 $(Target: UpcastFrom<$T>,)+
1813 {
1814 }
1815 impl<$($T,)+ Target> UpcastFrom<ArrayTuple<($($T,)+)>> for JsOption<Array<Target>>
1816 where
1817 $(Target: UpcastFrom<$T>,)+
1818 {}
1819 // Array<T> -> ArrayTuple<T, ...>
1820 impl<T> UpcastFrom<Array<T>> for ArrayTuple<($($Ts,)+)> {}
1821 impl<T: JsGeneric> UpcastFrom<Array<T>> for ArrayTuple<($(JsOption<$Ts>,)+)> {}
1822 };
1823}
1824
1825impl_tuple_covariance!([T1][Target1][T]);
1826impl_tuple_covariance!([T1 T2] [Target1 Target2] [T T]);
1827impl_tuple_covariance!([T1 T2 T3] [Target1 Target2 Target3] [T T T]);
1828impl_tuple_covariance!([T1 T2 T3 T4] [Target1 Target2 Target3 Target4] [T T T T]);
1829impl_tuple_covariance!([T1 T2 T3 T4 T5] [Target1 Target2 Target3 Target4 Target5] [T T T T T]);
1830impl_tuple_covariance!([T1 T2 T3 T4 T5 T6] [Target1 Target2 Target3 Target4 Target5 Target6] [T T T T T T]);
1831impl_tuple_covariance!([T1 T2 T3 T4 T5 T6 T7] [Target1 Target2 Target3 Target4 Target5 Target6 Target7] [T T T T T T T]);
1832impl_tuple_covariance!([T1 T2 T3 T4 T5 T6 T7 T8] [Target1 Target2 Target3 Target4 Target5 Target6 Target7 Target8] [T T T T T T T T]);
1833
1834// Tuple casting is implemented in core
1835impl<T: JsTuple, U: JsTuple> UpcastFrom<ArrayTuple<T>> for ArrayTuple<U> where U: UpcastFrom<T> {}
1836impl<T: JsTuple> UpcastFrom<ArrayTuple<T>> for JsValue {}
1837impl<T: JsTuple> UpcastFrom<ArrayTuple<T>> for JsOption<JsValue> {}
1838
1839/// Iterator returned by `Array::into_iter`
1840#[derive(Debug, Clone)]
1841pub struct ArrayIntoIter<T: JsGeneric = JsValue> {
1842 range: core::ops::Range<u32>,
1843 array: Array<T>,
1844}
1845
1846#[cfg(not(js_sys_unstable_apis))]
1847impl<T: JsGeneric> core::iter::Iterator for ArrayIntoIter<T> {
1848 type Item = T;
1849
1850 fn next(&mut self) -> Option<Self::Item> {
1851 let index = self.range.next()?;
1852 Some(self.array.get(index))
1853 }
1854
1855 #[inline]
1856 fn size_hint(&self) -> (usize, Option<usize>) {
1857 self.range.size_hint()
1858 }
1859
1860 #[inline]
1861 fn count(self) -> usize
1862 where
1863 Self: Sized,
1864 {
1865 self.range.count()
1866 }
1867
1868 #[inline]
1869 fn last(self) -> Option<Self::Item>
1870 where
1871 Self: Sized,
1872 {
1873 let Self { range, array } = self;
1874 range.last().map(|index| array.get(index))
1875 }
1876
1877 #[inline]
1878 fn nth(&mut self, n: usize) -> Option<Self::Item> {
1879 self.range.nth(n).map(|index| self.array.get(index))
1880 }
1881}
1882
1883#[cfg(js_sys_unstable_apis)]
1884impl<T: JsGeneric> core::iter::Iterator for ArrayIntoIter<T> {
1885 type Item = T;
1886
1887 fn next(&mut self) -> Option<Self::Item> {
1888 let index = self.range.next()?;
1889 self.array.get(index)
1890 }
1891
1892 #[inline]
1893 fn size_hint(&self) -> (usize, Option<usize>) {
1894 self.range.size_hint()
1895 }
1896
1897 #[inline]
1898 fn count(self) -> usize
1899 where
1900 Self: Sized,
1901 {
1902 self.range.count()
1903 }
1904
1905 #[inline]
1906 fn last(self) -> Option<Self::Item>
1907 where
1908 Self: Sized,
1909 {
1910 let Self { range, array } = self;
1911 range.last().and_then(|index| array.get(index))
1912 }
1913
1914 #[inline]
1915 fn nth(&mut self, n: usize) -> Option<Self::Item> {
1916 self.range.nth(n).and_then(|index| self.array.get(index))
1917 }
1918}
1919
1920#[cfg(not(js_sys_unstable_apis))]
1921impl<T: JsGeneric> core::iter::DoubleEndedIterator for ArrayIntoIter<T> {
1922 fn next_back(&mut self) -> Option<Self::Item> {
1923 let index = self.range.next_back()?;
1924 Some(self.array.get(index))
1925 }
1926
1927 fn nth_back(&mut self, n: usize) -> Option<Self::Item> {
1928 self.range.nth_back(n).map(|index| self.array.get(index))
1929 }
1930}
1931
1932#[cfg(js_sys_unstable_apis)]
1933impl<T: JsGeneric> core::iter::DoubleEndedIterator for ArrayIntoIter<T> {
1934 fn next_back(&mut self) -> Option<Self::Item> {
1935 let index = self.range.next_back()?;
1936 self.array.get(index)
1937 }
1938
1939 fn nth_back(&mut self, n: usize) -> Option<Self::Item> {
1940 self.range
1941 .nth_back(n)
1942 .and_then(|index| self.array.get(index))
1943 }
1944}
1945
1946impl<T: JsGeneric> core::iter::FusedIterator for ArrayIntoIter<T> {}
1947
1948impl<T: JsGeneric> core::iter::ExactSizeIterator for ArrayIntoIter<T> {}
1949
1950/// Iterator returned by `Array::iter`
1951#[derive(Debug, Clone)]
1952pub struct ArrayIter<'a, T: JsGeneric = JsValue> {
1953 range: core::ops::Range<u32>,
1954 array: &'a Array<T>,
1955}
1956
1957impl<T: JsGeneric> core::iter::Iterator for ArrayIter<'_, T> {
1958 type Item = T;
1959
1960 fn next(&mut self) -> Option<Self::Item> {
1961 let index = self.range.next()?;
1962 Some(self.array.get_unchecked(index))
1963 }
1964
1965 #[inline]
1966 fn size_hint(&self) -> (usize, Option<usize>) {
1967 self.range.size_hint()
1968 }
1969
1970 #[inline]
1971 fn count(self) -> usize
1972 where
1973 Self: Sized,
1974 {
1975 self.range.count()
1976 }
1977
1978 #[inline]
1979 fn last(self) -> Option<Self::Item>
1980 where
1981 Self: Sized,
1982 {
1983 let Self { range, array } = self;
1984 range.last().map(|index| array.get_unchecked(index))
1985 }
1986
1987 #[inline]
1988 fn nth(&mut self, n: usize) -> Option<Self::Item> {
1989 self.range
1990 .nth(n)
1991 .map(|index| self.array.get_unchecked(index))
1992 }
1993}
1994
1995impl<T: JsGeneric> core::iter::DoubleEndedIterator for ArrayIter<'_, T> {
1996 fn next_back(&mut self) -> Option<Self::Item> {
1997 let index = self.range.next_back()?;
1998 Some(self.array.get_unchecked(index))
1999 }
2000
2001 fn nth_back(&mut self, n: usize) -> Option<Self::Item> {
2002 self.range
2003 .nth_back(n)
2004 .map(|index| self.array.get_unchecked(index))
2005 }
2006}
2007
2008impl<T: JsGeneric> core::iter::FusedIterator for ArrayIter<'_, T> {}
2009
2010impl<T: JsGeneric> core::iter::ExactSizeIterator for ArrayIter<'_, T> {}
2011
2012impl<T: JsGeneric> Array<T> {
2013 /// Returns an iterator over the values of the JS array.
2014 pub fn iter(&self) -> ArrayIter<'_, T> {
2015 ArrayIter {
2016 range: 0..self.length(),
2017 array: self,
2018 }
2019 }
2020}
2021
2022impl<T: JsGeneric> core::iter::IntoIterator for Array<T> {
2023 type Item = T;
2024 type IntoIter = ArrayIntoIter<T>;
2025
2026 fn into_iter(self) -> Self::IntoIter {
2027 ArrayIntoIter {
2028 range: 0..self.length(),
2029 array: self,
2030 }
2031 }
2032}
2033
2034// `FromIterator` / `Extend` for `Array` (= `Array<JsValue>` via the default
2035// type parameter) preserve the long-standing stable behaviour: any iterator
2036// of items convertible to `&JsValue` collects into an erased `Array<JsValue>`.
2037//
2038// Typed collection (where the element type is inferred from the iterator
2039// item via [`IntoJsGeneric`]) is exposed as the inherent constructor
2040// [`Array::from_iter_typed`] rather than a second `FromIterator` impl. A
2041// blanket `impl<A: IntoJsGeneric> FromIterator<A> for Array<A::JsCanon>`
2042// would overlap with the stable `AsRef<JsValue>` impl on `Array<JsValue>`
2043// (since `JsValue: IntoJsGeneric` with `JsCanon = JsValue`), so the two
2044// cannot coexist as `FromIterator` impls without coherence violations.
2045//
2046// TODO(next major): deprecate this `FromIterator`/`Extend` pair in favour
2047// of a single `IntoJsGeneric`-based impl, and rename `from_iter_typed` to
2048// take its place. That migration is source-breaking for callers relying on
2049// `.collect::<Array>()` implicit erasure of typed items, so it is deferred.
2050
2051impl<A> core::iter::FromIterator<A> for Array
2052where
2053 A: AsRef<JsValue>,
2054{
2055 fn from_iter<I>(iter: I) -> Array
2056 where
2057 I: IntoIterator<Item = A>,
2058 {
2059 let mut out = Array::new();
2060 out.extend(iter);
2061 out
2062 }
2063}
2064
2065impl<A> core::iter::Extend<A> for Array
2066where
2067 A: AsRef<JsValue>,
2068{
2069 fn extend<I>(&mut self, iter: I)
2070 where
2071 I: IntoIterator<Item = A>,
2072 {
2073 for value in iter {
2074 self.push(value.as_ref());
2075 }
2076 }
2077}
2078
2079impl<T: JsGeneric> Array<T> {
2080 /// Collect an iterator into a typed `Array<T>`, projecting each item
2081 /// through its canonical [`JsGeneric`] via [`IntoJsGeneric`].
2082 ///
2083 /// This is the typed counterpart to the stable
2084 /// `impl FromIterator<A> for Array where A: AsRef<JsValue>`, which always
2085 /// produces an erased `Array<JsValue>`. Use `from_iter_typed` when you
2086 /// want the element type inferred from the iterator item:
2087 ///
2088 /// ```ignore
2089 /// use js_sys::{Array, Number};
2090 ///
2091 /// let arr = Array::from_iter_typed((0..10).map(Number::from));
2092 /// // arr: Array<Number>
2093 /// ```
2094 ///
2095 /// Reference iteration (`Item = &U`) is supported transparently via the
2096 /// `&U: IntoJsGeneric` blanket in `wasm-bindgen` core.
2097 //
2098 // TODO(next major): replace the stable `FromIterator` impl above with
2099 // this behaviour and remove `from_iter_typed`.
2100 pub fn from_iter_typed<A, I>(iter: I) -> Array<T>
2101 where
2102 A: IntoJsGeneric<JsCanon = T>,
2103 I: IntoIterator<Item = A>,
2104 {
2105 let mut out = Array::<T>::new_typed();
2106 out.extend_typed(iter);
2107 out
2108 }
2109
2110 /// Extend a typed `Array<T>` with an iterator of items convertible to
2111 /// `T` via [`IntoJsGeneric`]. Companion to [`Array::from_iter_typed`].
2112 //
2113 // TODO(next major): replace the stable `Extend` impl above with this
2114 // behaviour and remove `extend_typed`.
2115 pub fn extend_typed<A, I>(&mut self, iter: I)
2116 where
2117 A: IntoJsGeneric<JsCanon = T>,
2118 I: IntoIterator<Item = A>,
2119 {
2120 for value in iter {
2121 self.push(&value.to_js());
2122 }
2123 }
2124}
2125
2126impl Default for Array<JsValue> {
2127 fn default() -> Self {
2128 Self::new()
2129 }
2130}
2131
2132impl<T> Iterable for Array<T> {
2133 type Item = T;
2134}
2135
2136impl<T: JsTuple> Iterable for ArrayTuple<T> {
2137 type Item = JsValue;
2138}
2139
2140// ArrayBufferOptions
2141#[wasm_bindgen]
2142extern "C" {
2143 #[wasm_bindgen(extends = Object, typescript_type = "ArrayBufferOptions")]
2144 #[derive(Clone, Debug, PartialEq, Eq)]
2145 pub type ArrayBufferOptions;
2146
2147 /// The maximum size, in bytes, that the array buffer can be resized to.
2148 #[wasm_bindgen(method, setter, js_name = maxByteLength)]
2149 pub fn set_max_byte_length(this: &ArrayBufferOptions, max_byte_length: usize);
2150
2151 /// The maximum size, in bytes, that the array buffer can be resized to.
2152 #[wasm_bindgen(method, getter, js_name = maxByteLength)]
2153 pub fn get_max_byte_length(this: &ArrayBufferOptions) -> usize;
2154}
2155
2156impl ArrayBufferOptions {
2157 #[cfg(not(js_sys_unstable_apis))]
2158 pub fn new(max_byte_length: usize) -> ArrayBufferOptions {
2159 let options = JsCast::unchecked_into::<ArrayBufferOptions>(Object::new());
2160 options.set_max_byte_length(max_byte_length);
2161 options
2162 }
2163
2164 #[cfg(js_sys_unstable_apis)]
2165 pub fn new(max_byte_length: usize) -> ArrayBufferOptions {
2166 let options = JsCast::unchecked_into::<ArrayBufferOptions>(Object::<JsValue>::new());
2167 options.set_max_byte_length(max_byte_length);
2168 options
2169 }
2170}
2171
2172// ArrayBuffer
2173#[wasm_bindgen]
2174extern "C" {
2175 #[wasm_bindgen(extends = Object, typescript_type = "ArrayBuffer")]
2176 #[derive(Clone, Debug, PartialEq, Eq)]
2177 pub type ArrayBuffer;
2178
2179 /// The `ArrayBuffer` object is used to represent a generic,
2180 /// fixed-length raw binary data buffer. You cannot directly
2181 /// manipulate the contents of an `ArrayBuffer`; instead, you
2182 /// create one of the typed array objects or a `DataView` object
2183 /// which represents the buffer in a specific format, and use that
2184 /// to read and write the contents of the buffer.
2185 ///
2186 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer)
2187 #[cfg(not(js_sys_unstable_apis))]
2188 #[wasm_bindgen(constructor)]
2189 pub fn new(length: u32) -> ArrayBuffer;
2190
2191 /// The `ArrayBuffer` object is used to represent a generic,
2192 /// fixed-length raw binary data buffer. You cannot directly
2193 /// manipulate the contents of an `ArrayBuffer`; instead, you
2194 /// create one of the typed array objects or a `DataView` object
2195 /// which represents the buffer in a specific format, and use that
2196 /// to read and write the contents of the buffer.
2197 ///
2198 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer)
2199 #[cfg(js_sys_unstable_apis)]
2200 #[wasm_bindgen(constructor)]
2201 pub fn new(length: usize) -> ArrayBuffer;
2202
2203 /// The `ArrayBuffer` object is used to represent a generic,
2204 /// fixed-length raw binary data buffer. You cannot directly
2205 /// manipulate the contents of an `ArrayBuffer`; instead, you
2206 /// create one of the typed array objects or a `DataView` object
2207 /// which represents the buffer in a specific format, and use that
2208 /// to read and write the contents of the buffer.
2209 ///
2210 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer)
2211 #[wasm_bindgen(constructor)]
2212 pub fn new_with_options(length: usize, options: &ArrayBufferOptions) -> ArrayBuffer;
2213
2214 /// The `byteLength` property of an object which is an instance of type ArrayBuffer
2215 /// it's an accessor property whose set accessor function is undefined,
2216 /// meaning that you can only read this property.
2217 /// The value is established when the array is constructed and cannot be changed.
2218 /// This property returns 0 if this ArrayBuffer has been detached.
2219 ///
2220 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/byteLength)
2221 #[cfg(not(js_sys_unstable_apis))]
2222 #[wasm_bindgen(method, getter, js_name = byteLength)]
2223 pub fn byte_length(this: &ArrayBuffer) -> u32;
2224
2225 /// The `byteLength` property of an object which is an instance of type ArrayBuffer
2226 /// it's an accessor property whose set accessor function is undefined,
2227 /// meaning that you can only read this property.
2228 /// The value is established when the array is constructed and cannot be changed.
2229 /// This property returns 0 if this ArrayBuffer has been detached.
2230 ///
2231 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/byteLength)
2232 #[cfg(js_sys_unstable_apis)]
2233 #[wasm_bindgen(method, getter, js_name = byteLength)]
2234 pub fn byte_length(this: &ArrayBuffer) -> usize;
2235
2236 /// The `detached` accessor property of `ArrayBuffer` instances returns a boolean indicating
2237 /// whether or not this buffer has been detached (transferred).
2238 ///
2239 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/detached)
2240 #[wasm_bindgen(method, getter)]
2241 pub fn detached(this: &ArrayBuffer) -> bool;
2242
2243 /// The `isView()` method returns true if arg is one of the `ArrayBuffer`
2244 /// views, such as typed array objects or a DataView; false otherwise.
2245 ///
2246 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/isView)
2247 #[wasm_bindgen(static_method_of = ArrayBuffer, js_name = isView)]
2248 pub fn is_view(value: &JsValue) -> bool;
2249
2250 /// The `maxByteLength` accessor property of ArrayBuffer instances returns the maximum
2251 /// length (in bytes) that this array buffer can be resized to.
2252 ///
2253 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/maxByteLength)
2254 #[wasm_bindgen(method, getter, js_name = maxByteLength)]
2255 pub fn max_byte_length(this: &ArrayBuffer) -> usize;
2256
2257 /// The `resizable` accessor property of `ArrayBuffer` instances returns whether this array buffer
2258 /// can be resized or not.
2259 ///
2260 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/resizable)
2261 #[wasm_bindgen(method, getter)]
2262 pub fn resizable(this: &ArrayBuffer) -> bool;
2263
2264 /// The `resize()` method of ArrayBuffer instances resizes the ArrayBuffer to the
2265 /// specified size, in bytes.
2266 ///
2267 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/resize)
2268 #[wasm_bindgen(method, catch)]
2269 pub fn resize(this: &ArrayBuffer, new_len: usize) -> Result<(), JsValue>;
2270
2271 /// The `slice()` method returns a new `ArrayBuffer` whose contents
2272 /// are a copy of this `ArrayBuffer`'s bytes from begin, inclusive,
2273 /// up to end, exclusive.
2274 ///
2275 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/slice)
2276 #[cfg(not(js_sys_unstable_apis))]
2277 #[wasm_bindgen(method)]
2278 pub fn slice(this: &ArrayBuffer, begin: u32) -> ArrayBuffer;
2279
2280 /// The `slice()` method returns a new `ArrayBuffer` whose contents
2281 /// are a copy of this `ArrayBuffer`'s bytes from begin, inclusive,
2282 /// up to end, exclusive. Negative indices count from the end.
2283 ///
2284 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/slice)
2285 #[cfg(js_sys_unstable_apis)]
2286 #[wasm_bindgen(method)]
2287 pub fn slice(this: &ArrayBuffer, begin: isize, end: isize) -> ArrayBuffer;
2288
2289 /// The `slice()` method returns a new `ArrayBuffer` whose contents
2290 /// are a copy of this `ArrayBuffer`'s bytes from begin, inclusive,
2291 /// up to end, exclusive.
2292 ///
2293 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/slice)
2294 #[cfg(not(js_sys_unstable_apis))]
2295 #[wasm_bindgen(method, js_name = slice)]
2296 pub fn slice_from(this: &ArrayBuffer, begin: isize) -> ArrayBuffer;
2297
2298 /// The `slice()` method returns a new `ArrayBuffer` whose contents
2299 /// are a copy of this `ArrayBuffer`'s bytes from begin to the end.
2300 /// Negative indices count from the end.
2301 ///
2302 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/slice)
2303 #[cfg(js_sys_unstable_apis)]
2304 #[wasm_bindgen(method, js_name = slice)]
2305 pub fn slice_from(this: &ArrayBuffer, begin: isize) -> ArrayBuffer;
2306
2307 // Next major: deprecate
2308 /// Like `slice()` but with the `end` argument.
2309 ///
2310 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/slice)
2311 #[wasm_bindgen(method, js_name = slice)]
2312 pub fn slice_with_end(this: &ArrayBuffer, begin: u32, end: u32) -> ArrayBuffer;
2313
2314 /// The `transfer()` method of ArrayBuffer instances creates a new `ArrayBuffer`
2315 /// with the same byte content as this buffer, then detaches this buffer.
2316 ///
2317 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/transfer)
2318 #[wasm_bindgen(method, catch)]
2319 pub fn transfer(this: &ArrayBuffer) -> Result<ArrayBuffer, JsValue>;
2320
2321 /// The `transfer()` method of `ArrayBuffer` instances creates a new `ArrayBuffer`
2322 /// with the same byte content as this buffer, then detaches this buffer.
2323 ///
2324 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/transfer)
2325 #[wasm_bindgen(method, catch, js_name = transfer)]
2326 pub fn transfer_with_length(
2327 this: &ArrayBuffer,
2328 new_byte_length: usize,
2329 ) -> Result<ArrayBuffer, JsValue>;
2330
2331 /// The `transferToFixedLength()` method of `ArrayBuffer` instances creates a new non-resizable
2332 /// ArrayBuffer with the same byte content as this buffer, then detaches this buffer.
2333 ///
2334 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/transferToFixedLength)
2335 #[wasm_bindgen(method, catch, js_name = transferToFixedLength)]
2336 pub fn transfer_to_fixed_length(this: &ArrayBuffer) -> Result<ArrayBuffer, JsValue>;
2337
2338 /// The `transferToFixedLength()` method of `ArrayBuffer` instances creates a new non-resizable
2339 /// `ArrayBuffer` with the same byte content as this buffer, then detaches this buffer.
2340 ///
2341 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/transferToFixedLength)
2342 #[wasm_bindgen(method, catch, js_name = transferToFixedLength)]
2343 pub fn transfer_to_fixed_length_with_length(
2344 this: &ArrayBuffer,
2345 new_byte_length: usize,
2346 ) -> Result<ArrayBuffer, JsValue>;
2347}
2348
2349impl UpcastFrom<&[u8]> for ArrayBuffer {}
2350
2351// SharedArrayBuffer
2352#[wasm_bindgen]
2353extern "C" {
2354 #[wasm_bindgen(extends = Object, typescript_type = "SharedArrayBuffer")]
2355 #[derive(Clone, Debug)]
2356 pub type SharedArrayBuffer;
2357
2358 /// The `SharedArrayBuffer` object is used to represent a generic,
2359 /// fixed-length raw binary data buffer, similar to the `ArrayBuffer`
2360 /// object, but in a way that they can be used to create views
2361 /// on shared memory. Unlike an `ArrayBuffer`, a `SharedArrayBuffer`
2362 /// cannot become detached.
2363 ///
2364 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer)
2365 #[cfg(not(js_sys_unstable_apis))]
2366 #[wasm_bindgen(constructor)]
2367 pub fn new(length: u32) -> SharedArrayBuffer;
2368
2369 /// The `SharedArrayBuffer` object is used to represent a generic,
2370 /// fixed-length raw binary data buffer, similar to the `ArrayBuffer`
2371 /// object, but in a way that they can be used to create views
2372 /// on shared memory. Unlike an `ArrayBuffer`, a `SharedArrayBuffer`
2373 /// cannot become detached.
2374 ///
2375 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer)
2376 #[cfg(js_sys_unstable_apis)]
2377 #[wasm_bindgen(constructor)]
2378 pub fn new(length: usize) -> SharedArrayBuffer;
2379
2380 /// The `SharedArrayBuffer` object is used to represent a generic,
2381 /// fixed-length raw binary data buffer, similar to the `ArrayBuffer`
2382 /// object, but in a way that they can be used to create views
2383 /// on shared memory. Unlike an `ArrayBuffer`, a `SharedArrayBuffer`
2384 /// cannot become detached.
2385 ///
2386 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer)
2387 #[wasm_bindgen(constructor)]
2388 pub fn new_with_options(length: usize, options: &ArrayBufferOptions) -> SharedArrayBuffer;
2389
2390 /// The `byteLength` accessor property represents the length of
2391 /// an `SharedArrayBuffer` in bytes. This is established when
2392 /// the `SharedArrayBuffer` is constructed and cannot be changed.
2393 ///
2394 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/byteLength)
2395 #[cfg(not(js_sys_unstable_apis))]
2396 #[wasm_bindgen(method, getter, js_name = byteLength)]
2397 pub fn byte_length(this: &SharedArrayBuffer) -> u32;
2398
2399 /// The `byteLength` accessor property represents the length of
2400 /// an `SharedArrayBuffer` in bytes. This is established when
2401 /// the `SharedArrayBuffer` is constructed and cannot be changed.
2402 ///
2403 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/byteLength)
2404 #[cfg(js_sys_unstable_apis)]
2405 #[wasm_bindgen(method, getter, js_name = byteLength)]
2406 pub fn byte_length(this: &SharedArrayBuffer) -> usize;
2407
2408 /// The `growable` accessor property of `SharedArrayBuffer` instances returns whether
2409 /// this `SharedArrayBuffer` can be grown or not.
2410 ///
2411 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/growable)
2412 #[wasm_bindgen(method, getter)]
2413 pub fn growable(this: &SharedArrayBuffer) -> bool;
2414
2415 /// The `grow()` method of `SharedArrayBuffer` instances grows the
2416 /// `SharedArrayBuffer` to the specified size, in bytes.
2417 ///
2418 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/grow)
2419 #[wasm_bindgen(method, catch)]
2420 pub fn grow(this: &SharedArrayBuffer, new_byte_length: usize) -> Result<(), JsValue>;
2421
2422 /// The `maxByteLength` accessor property of `SharedArrayBuffer` instances returns the maximum
2423 /// length (in bytes) that this `SharedArrayBuffer` can be resized to.
2424 ///
2425 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/maxByteLength)
2426 #[wasm_bindgen(method, getter, js_name = maxByteLength)]
2427 pub fn max_byte_length(this: &SharedArrayBuffer) -> usize;
2428
2429 /// The `slice()` method returns a new `SharedArrayBuffer` whose contents
2430 /// are a copy of this `SharedArrayBuffer`'s bytes from begin, inclusive,
2431 /// up to end, exclusive.
2432 ///
2433 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/slice)
2434 #[cfg(not(js_sys_unstable_apis))]
2435 #[wasm_bindgen(method)]
2436 pub fn slice(this: &SharedArrayBuffer, begin: u32) -> SharedArrayBuffer;
2437
2438 /// The `slice()` method returns a new `SharedArrayBuffer` whose contents
2439 /// are a copy of this `SharedArrayBuffer`'s bytes from begin, inclusive,
2440 /// up to end, exclusive. Negative indices count from the end.
2441 ///
2442 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/slice)
2443 #[cfg(js_sys_unstable_apis)]
2444 #[wasm_bindgen(method)]
2445 pub fn slice(this: &SharedArrayBuffer, begin: isize, end: isize) -> SharedArrayBuffer;
2446
2447 /// The `slice()` method returns a new `SharedArrayBuffer` whose contents
2448 /// are a copy of this `SharedArrayBuffer`'s bytes from begin, inclusive,
2449 /// up to end, exclusive.
2450 ///
2451 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/slice)
2452 #[cfg(not(js_sys_unstable_apis))]
2453 #[wasm_bindgen(method)]
2454 pub fn slice_from(this: &SharedArrayBuffer, begin: isize) -> SharedArrayBuffer;
2455
2456 /// The `slice()` method returns a new `SharedArrayBuffer` whose contents
2457 /// are a copy of this `SharedArrayBuffer`'s bytes from begin to end.
2458 /// Negative indices count from the end.
2459 ///
2460 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/slice)
2461 #[cfg(js_sys_unstable_apis)]
2462 #[wasm_bindgen(method)]
2463 pub fn slice_from(this: &SharedArrayBuffer, begin: isize) -> SharedArrayBuffer;
2464
2465 // Next major: deprecate
2466 /// Like `slice()` but with the `end` argument.
2467 ///
2468 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/slice)
2469 #[wasm_bindgen(method, js_name = slice)]
2470 pub fn slice_with_end(this: &SharedArrayBuffer, begin: u32, end: u32) -> SharedArrayBuffer;
2471}
2472
2473// Array Iterator
2474#[wasm_bindgen]
2475extern "C" {
2476 /// The `keys()` method returns a new Array Iterator object that contains the
2477 /// keys for each index in the array.
2478 ///
2479 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/keys)
2480 #[wasm_bindgen(method)]
2481 pub fn keys<T>(this: &Array<T>) -> Iterator<T>;
2482
2483 /// The `entries()` method returns a new Array Iterator object that contains
2484 /// the key/value pairs for each index in the array.
2485 ///
2486 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries)
2487 #[cfg(not(js_sys_unstable_apis))]
2488 #[wasm_bindgen(method)]
2489 #[deprecated(note = "recommended to use `Array::entries_typed` instead for typing")]
2490 #[allow(deprecated)]
2491 pub fn entries<T>(this: &Array<T>) -> Iterator<T>;
2492
2493 /// The `entries()` method returns a new Array Iterator object that contains
2494 /// the key/value pairs for each index in the array.
2495 ///
2496 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries)
2497 #[cfg(js_sys_unstable_apis)]
2498 #[wasm_bindgen(method)]
2499 pub fn entries<T: JsGeneric>(this: &Array<T>) -> Iterator<ArrayTuple<(Number, T)>>;
2500
2501 // Next major: deprecate
2502 /// The `entries()` method returns a new Array Iterator object that contains
2503 /// the key/value pairs for each index in the array.
2504 ///
2505 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries)
2506 #[wasm_bindgen(method, js_name = entries)]
2507 pub fn entries_typed<T: JsGeneric>(this: &Array<T>) -> Iterator<ArrayTuple<(Number, T)>>;
2508
2509 /// The `values()` method returns a new Array Iterator object that
2510 /// contains the values for each index in the array.
2511 ///
2512 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/values)
2513 #[wasm_bindgen(method)]
2514 pub fn values<T>(this: &Array<T>) -> Iterator<T>;
2515}
2516
2517// FIXME(next-major): rename this trait to `ArrayBufferView`. The DOM/WebIDL
2518// spec name `ArrayBufferView` covers both `DataView` and the typed-array
2519// types, which more accurately reflects the set of types that implement this
2520// trait. The `TypedArray` name is kept for now to avoid a breaking change.
2521pub trait TypedArray: JsGeneric {}
2522
2523impl TypedArray for DataView {}
2524
2525// Next major: use usize/isize for indices
2526/// The `Atomics` object provides atomic operations as static methods.
2527/// They are used with `SharedArrayBuffer` objects.
2528///
2529/// The Atomic operations are installed on an `Atomics` module. Unlike
2530/// the other global objects, `Atomics` is not a constructor. You cannot
2531/// use it with a new operator or invoke the `Atomics` object as a
2532/// function. All properties and methods of `Atomics` are static
2533/// (as is the case with the Math object, for example).
2534/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics)
2535#[allow(non_snake_case)]
2536pub mod Atomics {
2537 use super::*;
2538
2539 #[wasm_bindgen]
2540 extern "C" {
2541 /// The static `Atomics.add()` method adds a given value at a given
2542 /// position in the array and returns the old value at that position.
2543 /// This atomic operation guarantees that no other write happens
2544 /// until the modified value is written back.
2545 ///
2546 /// You should use `add_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2547 ///
2548 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/add)
2549 #[wasm_bindgen(js_namespace = Atomics, catch)]
2550 pub fn add<T: TypedArray = Int32Array>(
2551 typed_array: &T,
2552 index: u32,
2553 value: i32,
2554 ) -> Result<i32, JsValue>;
2555
2556 /// The static `Atomics.add()` method adds a given value at a given
2557 /// position in the array and returns the old value at that position.
2558 /// This atomic operation guarantees that no other write happens
2559 /// until the modified value is written back.
2560 ///
2561 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2562 ///
2563 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/add)
2564 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = add)]
2565 pub fn add_bigint<T: TypedArray = Int32Array>(
2566 typed_array: &T,
2567 index: u32,
2568 value: i64,
2569 ) -> Result<i64, JsValue>;
2570
2571 /// The static `Atomics.and()` method computes a bitwise AND with a given
2572 /// value at a given position in the array, and returns the old value
2573 /// at that position.
2574 /// This atomic operation guarantees that no other write happens
2575 /// until the modified value is written back.
2576 ///
2577 /// You should use `and_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2578 ///
2579 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/and)
2580 #[wasm_bindgen(js_namespace = Atomics, catch)]
2581 pub fn and<T: TypedArray = Int32Array>(
2582 typed_array: &T,
2583 index: u32,
2584 value: i32,
2585 ) -> Result<i32, JsValue>;
2586
2587 /// The static `Atomics.and()` method computes a bitwise AND with a given
2588 /// value at a given position in the array, and returns the old value
2589 /// at that position.
2590 /// This atomic operation guarantees that no other write happens
2591 /// until the modified value is written back.
2592 ///
2593 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2594 ///
2595 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/and)
2596 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = and)]
2597 pub fn and_bigint<T: TypedArray = Int32Array>(
2598 typed_array: &T,
2599 index: u32,
2600 value: i64,
2601 ) -> Result<i64, JsValue>;
2602
2603 /// The static `Atomics.compareExchange()` method exchanges a given
2604 /// replacement value at a given position in the array, if a given expected
2605 /// value equals the old value. It returns the old value at that position
2606 /// whether it was equal to the expected value or not.
2607 /// This atomic operation guarantees that no other write happens
2608 /// until the modified value is written back.
2609 ///
2610 /// You should use `compare_exchange_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2611 ///
2612 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/compareExchange)
2613 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = compareExchange)]
2614 pub fn compare_exchange<T: TypedArray = Int32Array>(
2615 typed_array: &T,
2616 index: u32,
2617 expected_value: i32,
2618 replacement_value: i32,
2619 ) -> Result<i32, JsValue>;
2620
2621 /// The static `Atomics.compareExchange()` method exchanges a given
2622 /// replacement value at a given position in the array, if a given expected
2623 /// value equals the old value. It returns the old value at that position
2624 /// whether it was equal to the expected value or not.
2625 /// This atomic operation guarantees that no other write happens
2626 /// until the modified value is written back.
2627 ///
2628 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2629 ///
2630 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/compareExchange)
2631 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = compareExchange)]
2632 pub fn compare_exchange_bigint<T: TypedArray = Int32Array>(
2633 typed_array: &T,
2634 index: u32,
2635 expected_value: i64,
2636 replacement_value: i64,
2637 ) -> Result<i64, JsValue>;
2638
2639 /// The static `Atomics.exchange()` method stores a given value at a given
2640 /// position in the array and returns the old value at that position.
2641 /// This atomic operation guarantees that no other write happens
2642 /// until the modified value is written back.
2643 ///
2644 /// You should use `exchange_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2645 ///
2646 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/exchange)
2647 #[wasm_bindgen(js_namespace = Atomics, catch)]
2648 pub fn exchange<T: TypedArray = Int32Array>(
2649 typed_array: &T,
2650 index: u32,
2651 value: i32,
2652 ) -> Result<i32, JsValue>;
2653
2654 /// The static `Atomics.exchange()` method stores a given value at a given
2655 /// position in the array and returns the old value at that position.
2656 /// This atomic operation guarantees that no other write happens
2657 /// until the modified value is written back.
2658 ///
2659 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2660 ///
2661 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/exchange)
2662 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = exchange)]
2663 pub fn exchange_bigint<T: TypedArray = Int32Array>(
2664 typed_array: &T,
2665 index: u32,
2666 value: i64,
2667 ) -> Result<i64, JsValue>;
2668
2669 /// The static `Atomics.isLockFree()` method is used to determine
2670 /// whether to use locks or atomic operations. It returns true,
2671 /// if the given size is one of the `BYTES_PER_ELEMENT` property
2672 /// of integer `TypedArray` types.
2673 ///
2674 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/isLockFree)
2675 #[wasm_bindgen(js_namespace = Atomics, js_name = isLockFree)]
2676 pub fn is_lock_free(size: u32) -> bool;
2677
2678 /// The static `Atomics.load()` method returns a value at a given
2679 /// position in the array.
2680 ///
2681 /// You should use `load_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2682 ///
2683 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/load)
2684 #[wasm_bindgen(js_namespace = Atomics, catch)]
2685 pub fn load<T: TypedArray = Int32Array>(
2686 typed_array: &T,
2687 index: u32,
2688 ) -> Result<i32, JsValue>;
2689
2690 /// The static `Atomics.load()` method returns a value at a given
2691 /// position in the array.
2692 ///
2693 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2694 ///
2695 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/load)
2696 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = load)]
2697 pub fn load_bigint<T: TypedArray = Int32Array>(
2698 typed_array: &T,
2699 index: i64,
2700 ) -> Result<i64, JsValue>;
2701
2702 /// The static `Atomics.notify()` method notifies up some agents that
2703 /// are sleeping in the wait queue.
2704 /// Note: This operation works with a shared `Int32Array` only.
2705 /// If `count` is not provided, notifies all the agents in the queue.
2706 ///
2707 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/notify)
2708 #[wasm_bindgen(js_namespace = Atomics, catch)]
2709 pub fn notify(typed_array: &Int32Array, index: u32) -> Result<u32, JsValue>;
2710
2711 /// The static `Atomics.notify()` method notifies up some agents that
2712 /// are sleeping in the wait queue.
2713 /// Note: This operation works with a shared `Int32Array` only.
2714 /// If `count` is not provided, notifies all the agents in the queue.
2715 ///
2716 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/notify)
2717 #[wasm_bindgen(js_namespace = Atomics, catch)]
2718 pub fn notify_bigint(typed_array: &BigInt64Array, index: u32) -> Result<u32, JsValue>;
2719
2720 /// Notifies up to `count` agents in the wait queue.
2721 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = notify)]
2722 pub fn notify_with_count(
2723 typed_array: &Int32Array,
2724 index: u32,
2725 count: u32,
2726 ) -> Result<u32, JsValue>;
2727
2728 /// Notifies up to `count` agents in the wait queue.
2729 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = notify)]
2730 pub fn notify_bigint_with_count(
2731 typed_array: &BigInt64Array,
2732 index: u32,
2733 count: u32,
2734 ) -> Result<u32, JsValue>;
2735
2736 /// The static `Atomics.or()` method computes a bitwise OR with a given value
2737 /// at a given position in the array, and returns the old value at that position.
2738 /// This atomic operation guarantees that no other write happens
2739 /// until the modified value is written back.
2740 ///
2741 /// You should use `or_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2742 ///
2743 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/or)
2744 #[wasm_bindgen(js_namespace = Atomics, catch)]
2745 pub fn or<T: TypedArray = Int32Array>(
2746 typed_array: &T,
2747 index: u32,
2748 value: i32,
2749 ) -> Result<i32, JsValue>;
2750
2751 /// The static `Atomics.or()` method computes a bitwise OR with a given value
2752 /// at a given position in the array, and returns the old value at that position.
2753 /// This atomic operation guarantees that no other write happens
2754 /// until the modified value is written back.
2755 ///
2756 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2757 ///
2758 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/or)
2759 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = or)]
2760 pub fn or_bigint<T: TypedArray = Int32Array>(
2761 typed_array: &T,
2762 index: u32,
2763 value: i64,
2764 ) -> Result<i64, JsValue>;
2765
2766 /// The static `Atomics.pause()` static method provides a micro-wait primitive that hints to the CPU
2767 /// that the caller is spinning while waiting on access to a shared resource. This allows the system
2768 /// to reduce the resources allocated to the core (such as power) or thread, without yielding the
2769 /// current thread.
2770 ///
2771 /// `pause()` has no observable behavior other than timing. The exact behavior is dependent on the CPU
2772 /// architecture and the operating system. For example, in Intel x86, it may be a pause instruction as
2773 /// per Intel's optimization manual. It could be a no-op in certain platforms.
2774 ///
2775 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2776 ///
2777 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/xor)
2778 #[wasm_bindgen(js_namespace = Atomics)]
2779 pub fn pause();
2780
2781 /// The static `Atomics.pause()` static method provides a micro-wait primitive that hints to the CPU
2782 /// that the caller is spinning while waiting on access to a shared resource. This allows the system
2783 /// to reduce the resources allocated to the core (such as power) or thread, without yielding the
2784 /// current thread.
2785 ///
2786 /// `pause()` has no observable behavior other than timing. The exact behavior is dependent on the CPU
2787 /// architecture and the operating system. For example, in Intel x86, it may be a pause instruction as
2788 /// per Intel's optimization manual. It could be a no-op in certain platforms.
2789 ///
2790 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2791 ///
2792 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/xor)
2793 #[wasm_bindgen(js_namespace = Atomics)]
2794 pub fn pause_with_hint(duration_hint: u32);
2795
2796 /// The static `Atomics.store()` method stores a given value at the given
2797 /// position in the array and returns that value.
2798 ///
2799 /// You should use `store_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2800 ///
2801 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/store)
2802 #[wasm_bindgen(js_namespace = Atomics, catch)]
2803 pub fn store<T: TypedArray = Int32Array>(
2804 typed_array: &T,
2805 index: u32,
2806 value: i32,
2807 ) -> Result<i32, JsValue>;
2808
2809 /// The static `Atomics.store()` method stores a given value at the given
2810 /// position in the array and returns that value.
2811 ///
2812 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2813 ///
2814 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/store)
2815 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = store)]
2816 pub fn store_bigint<T: TypedArray = Int32Array>(
2817 typed_array: &T,
2818 index: u32,
2819 value: i64,
2820 ) -> Result<i64, JsValue>;
2821
2822 /// The static `Atomics.sub()` method subtracts a given value at a
2823 /// given position in the array and returns the old value at that position.
2824 /// This atomic operation guarantees that no other write happens
2825 /// until the modified value is written back.
2826 ///
2827 /// You should use `sub_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2828 ///
2829 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/sub)
2830 #[wasm_bindgen(js_namespace = Atomics, catch)]
2831 pub fn sub<T: TypedArray = Int32Array>(
2832 typed_array: &T,
2833 index: u32,
2834 value: i32,
2835 ) -> Result<i32, JsValue>;
2836
2837 /// The static `Atomics.sub()` method subtracts a given value at a
2838 /// given position in the array and returns the old value at that position.
2839 /// This atomic operation guarantees that no other write happens
2840 /// until the modified value is written back.
2841 ///
2842 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2843 ///
2844 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/sub)
2845 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = sub)]
2846 pub fn sub_bigint<T: TypedArray = Int32Array>(
2847 typed_array: &T,
2848 index: u32,
2849 value: i64,
2850 ) -> Result<i64, JsValue>;
2851
2852 /// The static `Atomics.wait()` method verifies that a given
2853 /// position in an `Int32Array` still contains a given value
2854 /// and if so sleeps, awaiting a wakeup or a timeout.
2855 /// It returns a string which is either "ok", "not-equal", or "timed-out".
2856 /// Note: This operation only works with a shared `Int32Array`
2857 /// and may not be allowed on the main thread.
2858 ///
2859 /// You should use `wait_bigint` to operate on a `BigInt64Array`.
2860 ///
2861 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait)
2862 #[wasm_bindgen(js_namespace = Atomics, catch)]
2863 pub fn wait(typed_array: &Int32Array, index: u32, value: i32) -> Result<JsString, JsValue>;
2864
2865 /// The static `Atomics.wait()` method verifies that a given
2866 /// position in an `BigInt64Array` still contains a given value
2867 /// and if so sleeps, awaiting a wakeup or a timeout.
2868 /// It returns a string which is either "ok", "not-equal", or "timed-out".
2869 /// Note: This operation only works with a shared `BigInt64Array`
2870 /// and may not be allowed on the main thread.
2871 ///
2872 /// You should use `wait` to operate on a `Int32Array`.
2873 ///
2874 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait)
2875 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = wait)]
2876 pub fn wait_bigint(
2877 typed_array: &BigInt64Array,
2878 index: u32,
2879 value: i64,
2880 ) -> Result<JsString, JsValue>;
2881
2882 /// Like `wait()`, but with timeout
2883 ///
2884 /// You should use `wait_with_timeout_bigint` to operate on a `BigInt64Array`.
2885 ///
2886 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait)
2887 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = wait)]
2888 pub fn wait_with_timeout(
2889 typed_array: &Int32Array,
2890 index: u32,
2891 value: i32,
2892 timeout: f64,
2893 ) -> Result<JsString, JsValue>;
2894
2895 /// Like `wait()`, but with timeout
2896 ///
2897 /// You should use `wait_with_timeout` to operate on a `Int32Array`.
2898 ///
2899 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait)
2900 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = wait)]
2901 pub fn wait_with_timeout_bigint(
2902 typed_array: &BigInt64Array,
2903 index: u32,
2904 value: i64,
2905 timeout: f64,
2906 ) -> Result<JsString, JsValue>;
2907
2908 /// The static `Atomics.waitAsync()` method verifies that a given position in an
2909 /// `Int32Array` still contains a given value and if so sleeps, awaiting a
2910 /// wakeup or a timeout. It returns an object with two properties. The first
2911 /// property `async` is a boolean which if true indicates that the second
2912 /// property `value` is a promise. If `async` is false then value is a string
2913 /// whether equal to either "not-equal" or "timed-out".
2914 /// Note: This operation only works with a shared `Int32Array` and may be used
2915 /// on the main thread.
2916 ///
2917 /// You should use `wait_async_bigint` to operate on a `BigInt64Array`.
2918 ///
2919 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/waitAsync)
2920 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = waitAsync)]
2921 pub fn wait_async(
2922 typed_array: &Int32Array,
2923 index: u32,
2924 value: i32,
2925 ) -> Result<Object, JsValue>;
2926
2927 /// The static `Atomics.waitAsync()` method verifies that a given position in an
2928 /// `Int32Array` still contains a given value and if so sleeps, awaiting a
2929 /// wakeup or a timeout. It returns an object with two properties. The first
2930 /// property `async` is a boolean which if true indicates that the second
2931 /// property `value` is a promise. If `async` is false then value is a string
2932 /// whether equal to either "not-equal" or "timed-out".
2933 /// Note: This operation only works with a shared `BigInt64Array` and may be used
2934 /// on the main thread.
2935 ///
2936 /// You should use `wait_async` to operate on a `Int32Array`.
2937 ///
2938 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/waitAsync)
2939 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = waitAsync)]
2940 pub fn wait_async_bigint(
2941 typed_array: &BigInt64Array,
2942 index: u32,
2943 value: i64,
2944 ) -> Result<Object, JsValue>;
2945
2946 /// Like `waitAsync()`, but with timeout
2947 ///
2948 /// You should use `wait_async_with_timeout_bigint` to operate on a `BigInt64Array`.
2949 ///
2950 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/waitAsync)
2951 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = waitAsync)]
2952 pub fn wait_async_with_timeout(
2953 typed_array: &Int32Array,
2954 index: u32,
2955 value: i32,
2956 timeout: f64,
2957 ) -> Result<Object, JsValue>;
2958
2959 /// Like `waitAsync()`, but with timeout
2960 ///
2961 /// You should use `wait_async_with_timeout` to operate on a `Int32Array`.
2962 ///
2963 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/waitAsync)
2964 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = waitAsync)]
2965 pub fn wait_async_with_timeout_bigint(
2966 typed_array: &BigInt64Array,
2967 index: u32,
2968 value: i64,
2969 timeout: f64,
2970 ) -> Result<Object, JsValue>;
2971
2972 /// The static `Atomics.xor()` method computes a bitwise XOR
2973 /// with a given value at a given position in the array,
2974 /// and returns the old value at that position.
2975 /// This atomic operation guarantees that no other write happens
2976 /// until the modified value is written back.
2977 ///
2978 /// You should use `xor_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2979 ///
2980 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/xor)
2981 #[wasm_bindgen(js_namespace = Atomics, catch)]
2982 pub fn xor<T: TypedArray = Int32Array>(
2983 typed_array: &T,
2984 index: u32,
2985 value: i32,
2986 ) -> Result<i32, JsValue>;
2987
2988 /// The static `Atomics.xor()` method computes a bitwise XOR
2989 /// with a given value at a given position in the array,
2990 /// and returns the old value at that position.
2991 /// This atomic operation guarantees that no other write happens
2992 /// until the modified value is written back.
2993 ///
2994 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2995 ///
2996 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/xor)
2997 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = xor)]
2998 pub fn xor_bigint<T: TypedArray = Int32Array>(
2999 typed_array: &T,
3000 index: u32,
3001 value: i64,
3002 ) -> Result<i64, JsValue>;
3003 }
3004}
3005
3006// BigInt
3007#[wasm_bindgen]
3008extern "C" {
3009 #[wasm_bindgen(extends = Object, is_type_of = |v| v.is_bigint(), typescript_type = "bigint")]
3010 #[derive(Clone, PartialEq, Eq)]
3011 pub type BigInt;
3012
3013 #[wasm_bindgen(catch, js_name = BigInt)]
3014 fn new_bigint(value: &JsValue) -> Result<BigInt, Error>;
3015
3016 #[wasm_bindgen(js_name = BigInt)]
3017 fn new_bigint_unchecked(value: &JsValue) -> BigInt;
3018
3019 /// Clamps a BigInt value to a signed integer value, and returns that value.
3020 ///
3021 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/asIntN)
3022 #[wasm_bindgen(static_method_of = BigInt, js_name = asIntN)]
3023 pub fn as_int_n(bits: f64, bigint: &BigInt) -> BigInt;
3024
3025 /// Clamps a BigInt value to an unsigned integer value, and returns that value.
3026 ///
3027 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/asUintN)
3028 #[wasm_bindgen(static_method_of = BigInt, js_name = asUintN)]
3029 pub fn as_uint_n(bits: f64, bigint: &BigInt) -> BigInt;
3030
3031 /// 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.
3032 ///
3033 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/toLocaleString)
3034 #[cfg(not(js_sys_unstable_apis))]
3035 #[wasm_bindgen(method, js_name = toLocaleString)]
3036 pub fn to_locale_string(this: &BigInt, locales: &JsValue, options: &JsValue) -> JsString;
3037
3038 /// 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.
3039 ///
3040 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/toLocaleString)
3041 #[cfg(js_sys_unstable_apis)]
3042 #[wasm_bindgen(method, js_name = toLocaleString)]
3043 pub fn to_locale_string(
3044 this: &BigInt,
3045 locales: &[JsString],
3046 options: &Intl::NumberFormatOptions,
3047 ) -> JsString;
3048
3049 // Next major: deprecate
3050 /// 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.
3051 ///
3052 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/toString)
3053 #[wasm_bindgen(catch, method, js_name = toString)]
3054 pub fn to_string(this: &BigInt, radix: u8) -> Result<JsString, RangeError>;
3055
3056 /// Returns a string representing this BigInt value in the specified radix (base).
3057 ///
3058 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/toString)
3059 #[cfg(js_sys_unstable_apis)]
3060 #[wasm_bindgen(catch, method, js_name = toString)]
3061 pub fn to_string_with_radix(this: &BigInt, radix: u8) -> Result<JsString, RangeError>;
3062
3063 #[wasm_bindgen(method, js_name = toString)]
3064 fn to_string_unchecked(this: &BigInt, radix: u8) -> String;
3065
3066 /// Returns this BigInt value. Overrides the [`Object.prototype.valueOf()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf) method.
3067 ///
3068 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/valueOf)
3069 #[wasm_bindgen(method, js_name = valueOf)]
3070 pub fn value_of(this: &BigInt, radix: u8) -> BigInt;
3071}
3072
3073impl BigInt {
3074 /// Creates a new BigInt value.
3075 ///
3076 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/BigInt)
3077 #[inline]
3078 pub fn new(value: &JsValue) -> Result<BigInt, Error> {
3079 new_bigint(value)
3080 }
3081
3082 /// Applies the binary `/` JS operator on two `BigInt`s, catching and returning any `RangeError` thrown.
3083 ///
3084 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Division)
3085 pub fn checked_div(&self, rhs: &Self) -> Result<Self, RangeError> {
3086 let result = JsValue::as_ref(self).checked_div(JsValue::as_ref(rhs));
3087
3088 if result.is_instance_of::<RangeError>() {
3089 Err(result.unchecked_into())
3090 } else {
3091 Ok(result.unchecked_into())
3092 }
3093 }
3094
3095 /// Applies the binary `**` JS operator on the two `BigInt`s.
3096 ///
3097 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Exponentiation)
3098 #[inline]
3099 pub fn pow(&self, rhs: &Self) -> Self {
3100 JsValue::as_ref(self)
3101 .pow(JsValue::as_ref(rhs))
3102 .unchecked_into()
3103 }
3104
3105 /// Returns a tuple of this [`BigInt`]'s absolute value along with a
3106 /// [`bool`] indicating whether the [`BigInt`] was negative.
3107 fn abs(&self) -> (Self, bool) {
3108 if self < &BigInt::from(0) {
3109 (-self, true)
3110 } else {
3111 (self.clone(), false)
3112 }
3113 }
3114}
3115
3116macro_rules! bigint_from {
3117 ($($x:ident)*) => ($(
3118 impl From<$x> for BigInt {
3119 #[inline]
3120 fn from(x: $x) -> BigInt {
3121 new_bigint_unchecked(&JsValue::from(x))
3122 }
3123 }
3124
3125 impl PartialEq<$x> for BigInt {
3126 #[inline]
3127 fn eq(&self, other: &$x) -> bool {
3128 JsValue::from(self) == JsValue::from(BigInt::from(*other))
3129 }
3130 }
3131 )*)
3132}
3133bigint_from!(i8 u8 i16 u16 i32 u32 isize usize);
3134
3135macro_rules! bigint_from_big {
3136 ($($x:ident)*) => ($(
3137 impl From<$x> for BigInt {
3138 #[inline]
3139 fn from(x: $x) -> BigInt {
3140 JsValue::from(x).unchecked_into()
3141 }
3142 }
3143
3144 impl PartialEq<$x> for BigInt {
3145 #[inline]
3146 fn eq(&self, other: &$x) -> bool {
3147 self == &BigInt::from(*other)
3148 }
3149 }
3150
3151 impl TryFrom<BigInt> for $x {
3152 type Error = BigInt;
3153
3154 #[inline]
3155 fn try_from(x: BigInt) -> Result<Self, BigInt> {
3156 Self::try_from(JsValue::from(x)).map_err(JsCast::unchecked_into)
3157 }
3158 }
3159 )*)
3160}
3161bigint_from_big!(i64 u64 i128 u128);
3162
3163impl PartialEq<Number> for BigInt {
3164 #[inline]
3165 fn eq(&self, other: &Number) -> bool {
3166 JsValue::as_ref(self).loose_eq(JsValue::as_ref(other))
3167 }
3168}
3169
3170impl Not for &BigInt {
3171 type Output = BigInt;
3172
3173 #[inline]
3174 fn not(self) -> Self::Output {
3175 JsValue::as_ref(self).bit_not().unchecked_into()
3176 }
3177}
3178
3179forward_deref_unop!(impl Not, not for BigInt);
3180forward_js_unop!(impl Neg, neg for BigInt);
3181forward_js_binop!(impl BitAnd, bitand for BigInt);
3182forward_js_binop!(impl BitOr, bitor for BigInt);
3183forward_js_binop!(impl BitXor, bitxor for BigInt);
3184forward_js_binop!(impl Shl, shl for BigInt);
3185forward_js_binop!(impl Shr, shr for BigInt);
3186forward_js_binop!(impl Add, add for BigInt);
3187forward_js_binop!(impl Sub, sub for BigInt);
3188forward_js_binop!(impl Div, div for BigInt);
3189forward_js_binop!(impl Mul, mul for BigInt);
3190forward_js_binop!(impl Rem, rem for BigInt);
3191sum_product!(BigInt);
3192
3193partialord_ord!(BigInt);
3194
3195impl Default for BigInt {
3196 fn default() -> Self {
3197 BigInt::from(i32::default())
3198 }
3199}
3200
3201impl FromStr for BigInt {
3202 type Err = Error;
3203
3204 #[inline]
3205 fn from_str(s: &str) -> Result<Self, Self::Err> {
3206 BigInt::new(&s.into())
3207 }
3208}
3209
3210impl fmt::Debug for BigInt {
3211 #[inline]
3212 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3213 fmt::Display::fmt(self, f)
3214 }
3215}
3216
3217impl fmt::Display for BigInt {
3218 #[inline]
3219 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3220 let (abs, is_neg) = self.abs();
3221 f.pad_integral(!is_neg, "", &abs.to_string_unchecked(10))
3222 }
3223}
3224
3225impl fmt::Binary for BigInt {
3226 #[inline]
3227 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3228 let (abs, is_neg) = self.abs();
3229 f.pad_integral(!is_neg, "0b", &abs.to_string_unchecked(2))
3230 }
3231}
3232
3233impl fmt::Octal for BigInt {
3234 #[inline]
3235 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3236 let (abs, is_neg) = self.abs();
3237 f.pad_integral(!is_neg, "0o", &abs.to_string_unchecked(8))
3238 }
3239}
3240
3241impl fmt::LowerHex for BigInt {
3242 #[inline]
3243 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3244 let (abs, is_neg) = self.abs();
3245 f.pad_integral(!is_neg, "0x", &abs.to_string_unchecked(16))
3246 }
3247}
3248
3249impl fmt::UpperHex for BigInt {
3250 #[inline]
3251 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3252 let (abs, is_neg) = self.abs();
3253 let mut s: String = abs.to_string_unchecked(16);
3254 s.make_ascii_uppercase();
3255 f.pad_integral(!is_neg, "0x", &s)
3256 }
3257}
3258
3259// Boolean
3260#[wasm_bindgen]
3261extern "C" {
3262 #[wasm_bindgen(extends = Object, is_type_of = |v| v.as_bool().is_some(), typescript_type = "boolean")]
3263 #[derive(Clone, PartialEq, Eq)]
3264 pub type Boolean;
3265
3266 /// The `Boolean()` constructor creates an object wrapper for a boolean value.
3267 ///
3268 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)
3269 #[cfg(not(js_sys_unstable_apis))]
3270 #[wasm_bindgen(constructor)]
3271 #[deprecated(note = "recommended to use `Boolean::from` instead")]
3272 #[allow(deprecated)]
3273 pub fn new(value: &JsValue) -> Boolean;
3274
3275 /// The `valueOf()` method returns the primitive value of a `Boolean` object.
3276 ///
3277 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean/valueOf)
3278 #[wasm_bindgen(method, js_name = valueOf)]
3279 pub fn value_of(this: &Boolean) -> bool;
3280}
3281
3282impl UpcastFrom<bool> for Boolean {}
3283impl UpcastFrom<Boolean> for bool {}
3284
3285impl Boolean {
3286 /// Typed Boolean true constant.
3287 pub const TRUE: Boolean = Self {
3288 obj: Object {
3289 obj: JsValue::TRUE,
3290 generics: PhantomData,
3291 },
3292 };
3293
3294 /// Typed Boolean false constant.
3295 pub const FALSE: Boolean = Self {
3296 obj: Object {
3297 obj: JsValue::FALSE,
3298 generics: PhantomData,
3299 },
3300 };
3301}
3302
3303impl From<bool> for Boolean {
3304 #[inline]
3305 fn from(b: bool) -> Boolean {
3306 Boolean::unchecked_from_js(JsValue::from(b))
3307 }
3308}
3309
3310impl From<Boolean> for bool {
3311 #[inline]
3312 fn from(b: Boolean) -> bool {
3313 b.value_of()
3314 }
3315}
3316
3317impl PartialEq<bool> for Boolean {
3318 #[inline]
3319 fn eq(&self, other: &bool) -> bool {
3320 self.value_of() == *other
3321 }
3322}
3323
3324impl fmt::Debug for Boolean {
3325 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3326 fmt::Debug::fmt(&self.value_of(), f)
3327 }
3328}
3329
3330impl fmt::Display for Boolean {
3331 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3332 fmt::Display::fmt(&self.value_of(), f)
3333 }
3334}
3335
3336impl Default for Boolean {
3337 fn default() -> Self {
3338 Self::from(bool::default())
3339 }
3340}
3341
3342impl Not for &Boolean {
3343 type Output = Boolean;
3344
3345 #[inline]
3346 fn not(self) -> Self::Output {
3347 (!JsValue::as_ref(self)).into()
3348 }
3349}
3350
3351forward_deref_unop!(impl Not, not for Boolean);
3352
3353partialord_ord!(Boolean);
3354
3355// DataView
3356#[wasm_bindgen]
3357extern "C" {
3358 #[wasm_bindgen(extends = Object, typescript_type = "DataView")]
3359 #[derive(Clone, Debug, PartialEq, Eq)]
3360 pub type DataView;
3361
3362 /// The `DataView` view provides a low-level interface for reading and
3363 /// writing multiple number types in an `ArrayBuffer` irrespective of the
3364 /// platform's endianness.
3365 ///
3366 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView)
3367 #[wasm_bindgen(constructor)]
3368 pub fn new(buffer: &ArrayBuffer, byteOffset: usize, byteLength: usize) -> DataView;
3369
3370 /// The `DataView` view provides a low-level interface for reading and
3371 /// writing multiple number types in an `ArrayBuffer` irrespective of the
3372 /// platform's endianness.
3373 ///
3374 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView)
3375 #[wasm_bindgen(constructor)]
3376 pub fn new_with_shared_array_buffer(
3377 buffer: &SharedArrayBuffer,
3378 byteOffset: usize,
3379 byteLength: usize,
3380 ) -> DataView;
3381
3382 /// The ArrayBuffer referenced by this view. Fixed at construction time and thus read only.
3383 ///
3384 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/buffer)
3385 #[wasm_bindgen(method, getter)]
3386 pub fn buffer(this: &DataView) -> ArrayBuffer;
3387
3388 /// The length (in bytes) of this view from the start of its ArrayBuffer.
3389 /// Fixed at construction time and thus read only.
3390 ///
3391 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/byteLength)
3392 #[wasm_bindgen(method, getter, js_name = byteLength)]
3393 pub fn byte_length(this: &DataView) -> usize;
3394
3395 /// The offset (in bytes) of this view from the start of its ArrayBuffer.
3396 /// Fixed at construction time and thus read only.
3397 ///
3398 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/byteOffset)
3399 #[wasm_bindgen(method, getter, js_name = byteOffset)]
3400 pub fn byte_offset(this: &DataView) -> usize;
3401
3402 /// The `getInt8()` method gets a signed 8-bit integer (byte) at the
3403 /// specified byte offset from the start of the DataView.
3404 ///
3405 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt8)
3406 #[wasm_bindgen(method, js_name = getInt8)]
3407 pub fn get_int8(this: &DataView, byte_offset: usize) -> i8;
3408
3409 /// The `getUint8()` method gets a unsigned 8-bit integer (byte) at the specified
3410 /// byte offset from the start of the DataView.
3411 ///
3412 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint8)
3413 #[wasm_bindgen(method, js_name = getUint8)]
3414 pub fn get_uint8(this: &DataView, byte_offset: usize) -> u8;
3415
3416 /// The `getInt16()` method gets a signed 16-bit integer (short) at the specified
3417 /// byte offset from the start of the DataView.
3418 ///
3419 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt16)
3420 #[wasm_bindgen(method, js_name = getInt16)]
3421 pub fn get_int16(this: &DataView, byte_offset: usize) -> i16;
3422
3423 /// The `getInt16()` method gets a signed 16-bit integer (short) at the specified
3424 /// byte offset from the start of the DataView.
3425 ///
3426 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt16)
3427 #[wasm_bindgen(method, js_name = getInt16)]
3428 pub fn get_int16_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> i16;
3429
3430 /// The `getUint16()` method gets an unsigned 16-bit integer (unsigned short) at the specified
3431 /// byte offset from the start of the view.
3432 ///
3433 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint16)
3434 #[wasm_bindgen(method, js_name = getUint16)]
3435 pub fn get_uint16(this: &DataView, byte_offset: usize) -> u16;
3436
3437 /// The `getUint16()` method gets an unsigned 16-bit integer (unsigned short) at the specified
3438 /// byte offset from the start of the view.
3439 ///
3440 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint16)
3441 #[wasm_bindgen(method, js_name = getUint16)]
3442 pub fn get_uint16_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> u16;
3443
3444 /// The `getInt32()` method gets a signed 32-bit integer (long) at the specified
3445 /// byte offset from the start of the DataView.
3446 ///
3447 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt32)
3448 #[wasm_bindgen(method, js_name = getInt32)]
3449 pub fn get_int32(this: &DataView, byte_offset: usize) -> i32;
3450
3451 /// The `getInt32()` method gets a signed 32-bit integer (long) at the specified
3452 /// byte offset from the start of the DataView.
3453 ///
3454 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt32)
3455 #[wasm_bindgen(method, js_name = getInt32)]
3456 pub fn get_int32_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> i32;
3457
3458 /// The `getUint32()` method gets an unsigned 32-bit integer (unsigned long) at the specified
3459 /// byte offset from the start of the view.
3460 ///
3461 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint32)
3462 #[wasm_bindgen(method, js_name = getUint32)]
3463 pub fn get_uint32(this: &DataView, byte_offset: usize) -> u32;
3464
3465 /// The `getUint32()` method gets an unsigned 32-bit integer (unsigned long) at the specified
3466 /// byte offset from the start of the view.
3467 ///
3468 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint32)
3469 #[wasm_bindgen(method, js_name = getUint32)]
3470 pub fn get_uint32_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> u32;
3471
3472 /// The `getFloat32()` method gets a signed 32-bit float (float) at the specified
3473 /// byte offset from the start of the DataView.
3474 ///
3475 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat32)
3476 #[wasm_bindgen(method, js_name = getFloat32)]
3477 pub fn get_float32(this: &DataView, byte_offset: usize) -> f32;
3478
3479 /// The `getFloat32()` method gets a signed 32-bit float (float) at the specified
3480 /// byte offset from the start of the DataView.
3481 ///
3482 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat32)
3483 #[wasm_bindgen(method, js_name = getFloat32)]
3484 pub fn get_float32_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> f32;
3485
3486 /// The `getFloat16()` method gets a signed 16-bit float at the specified
3487 /// byte offset from the start of the DataView as an `f32`.
3488 ///
3489 /// The unsuffixed `get_float16` name is reserved for a future native
3490 /// `f16` binding once Rust stabilizes the type.
3491 ///
3492 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat16)
3493 #[wasm_bindgen(method, js_name = getFloat16)]
3494 pub fn get_float16_as_f32(this: &DataView, byte_offset: usize) -> f32;
3495
3496 /// The `getFloat16()` method gets a signed 16-bit float at the specified
3497 /// byte offset from the start of the DataView as an `f32`.
3498 ///
3499 /// The unsuffixed `get_float16_endian` name is reserved for a future
3500 /// native `f16` binding once Rust stabilizes the type.
3501 ///
3502 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat16)
3503 #[wasm_bindgen(method, js_name = getFloat16)]
3504 pub fn get_float16_endian_as_f32(
3505 this: &DataView,
3506 byte_offset: usize,
3507 little_endian: bool,
3508 ) -> f32;
3509
3510 /// The `getFloat64()` method gets a signed 64-bit float (double) at the specified
3511 /// byte offset from the start of the DataView.
3512 ///
3513 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat64)
3514 #[wasm_bindgen(method, js_name = getFloat64)]
3515 pub fn get_float64(this: &DataView, byte_offset: usize) -> f64;
3516
3517 /// The `getFloat64()` method gets a signed 64-bit float (double) at the specified
3518 /// byte offset from the start of the DataView.
3519 ///
3520 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat64)
3521 #[wasm_bindgen(method, js_name = getFloat64)]
3522 pub fn get_float64_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> f64;
3523
3524 /// The `setInt8()` method stores a signed 8-bit integer (byte) value at the
3525 /// specified byte offset from the start of the DataView.
3526 ///
3527 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt8)
3528 #[wasm_bindgen(method, js_name = setInt8)]
3529 pub fn set_int8(this: &DataView, byte_offset: usize, value: i8);
3530
3531 /// The `setUint8()` method stores an unsigned 8-bit integer (byte) value at the
3532 /// specified byte offset from the start of the DataView.
3533 ///
3534 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint8)
3535 #[wasm_bindgen(method, js_name = setUint8)]
3536 pub fn set_uint8(this: &DataView, byte_offset: usize, value: u8);
3537
3538 /// The `setInt16()` method stores a signed 16-bit integer (short) value at the
3539 /// specified byte offset from the start of the DataView.
3540 ///
3541 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt16)
3542 #[wasm_bindgen(method, js_name = setInt16)]
3543 pub fn set_int16(this: &DataView, byte_offset: usize, value: i16);
3544
3545 /// The `setInt16()` method stores a signed 16-bit integer (short) value at the
3546 /// specified byte offset from the start of the DataView.
3547 ///
3548 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt16)
3549 #[wasm_bindgen(method, js_name = setInt16)]
3550 pub fn set_int16_endian(this: &DataView, byte_offset: usize, value: i16, little_endian: bool);
3551
3552 /// The `setUint16()` method stores an unsigned 16-bit integer (unsigned short) value at the
3553 /// specified byte offset from the start of the DataView.
3554 ///
3555 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint16)
3556 #[wasm_bindgen(method, js_name = setUint16)]
3557 pub fn set_uint16(this: &DataView, byte_offset: usize, value: u16);
3558
3559 /// The `setUint16()` method stores an unsigned 16-bit integer (unsigned short) value at the
3560 /// specified byte offset from the start of the DataView.
3561 ///
3562 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint16)
3563 #[wasm_bindgen(method, js_name = setUint16)]
3564 pub fn set_uint16_endian(this: &DataView, byte_offset: usize, value: u16, little_endian: bool);
3565
3566 /// The `setInt32()` method stores a signed 32-bit integer (long) value at the
3567 /// specified byte offset from the start of the DataView.
3568 ///
3569 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt32)
3570 #[wasm_bindgen(method, js_name = setInt32)]
3571 pub fn set_int32(this: &DataView, byte_offset: usize, value: i32);
3572
3573 /// The `setInt32()` method stores a signed 32-bit integer (long) value at the
3574 /// specified byte offset from the start of the DataView.
3575 ///
3576 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt32)
3577 #[wasm_bindgen(method, js_name = setInt32)]
3578 pub fn set_int32_endian(this: &DataView, byte_offset: usize, value: i32, little_endian: bool);
3579
3580 /// The `setUint32()` method stores an unsigned 32-bit integer (unsigned long) value at the
3581 /// specified byte offset from the start of the DataView.
3582 ///
3583 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint32)
3584 #[wasm_bindgen(method, js_name = setUint32)]
3585 pub fn set_uint32(this: &DataView, byte_offset: usize, value: u32);
3586
3587 /// The `setUint32()` method stores an unsigned 32-bit integer (unsigned long) value at the
3588 /// specified byte offset from the start of the DataView.
3589 ///
3590 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint32)
3591 #[wasm_bindgen(method, js_name = setUint32)]
3592 pub fn set_uint32_endian(this: &DataView, byte_offset: usize, value: u32, little_endian: bool);
3593
3594 /// The `setFloat32()` method stores a signed 32-bit float (float) value at the
3595 /// specified byte offset from the start of the DataView.
3596 ///
3597 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat32)
3598 #[wasm_bindgen(method, js_name = setFloat32)]
3599 pub fn set_float32(this: &DataView, byte_offset: usize, value: f32);
3600
3601 /// The `setFloat32()` method stores a signed 32-bit float (float) value at the
3602 /// specified byte offset from the start of the DataView.
3603 ///
3604 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat32)
3605 #[wasm_bindgen(method, js_name = setFloat32)]
3606 pub fn set_float32_endian(this: &DataView, byte_offset: usize, value: f32, little_endian: bool);
3607
3608 /// The `setFloat16()` method stores a signed 16-bit float value from an
3609 /// `f32` at the specified byte offset from the start of the DataView.
3610 ///
3611 /// The unsuffixed `set_float16` name is reserved for a future native
3612 /// `f16` binding once Rust stabilizes the type.
3613 ///
3614 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat16)
3615 #[wasm_bindgen(method, js_name = setFloat16)]
3616 pub fn set_float16_from_f32(this: &DataView, byte_offset: usize, value: f32);
3617
3618 /// The `setFloat16()` method stores a signed 16-bit float value from an
3619 /// `f32` at the specified byte offset from the start of the DataView.
3620 ///
3621 /// The unsuffixed `set_float16_endian` name is reserved for a future
3622 /// native `f16` binding once Rust stabilizes the type.
3623 ///
3624 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat16)
3625 #[wasm_bindgen(method, js_name = setFloat16)]
3626 pub fn set_float16_endian_from_f32(
3627 this: &DataView,
3628 byte_offset: usize,
3629 value: f32,
3630 little_endian: bool,
3631 );
3632
3633 /// The `setFloat64()` method stores a signed 64-bit float (double) value at the
3634 /// specified byte offset from the start of the DataView.
3635 ///
3636 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat64)
3637 #[wasm_bindgen(method, js_name = setFloat64)]
3638 pub fn set_float64(this: &DataView, byte_offset: usize, value: f64);
3639
3640 /// The `setFloat64()` method stores a signed 64-bit float (double) value at the
3641 /// specified byte offset from the start of the DataView.
3642 ///
3643 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat64)
3644 #[wasm_bindgen(method, js_name = setFloat64)]
3645 pub fn set_float64_endian(this: &DataView, byte_offset: usize, value: f64, little_endian: bool);
3646}
3647
3648// Error
3649#[wasm_bindgen]
3650extern "C" {
3651 #[wasm_bindgen(extends = Object, typescript_type = "Error")]
3652 #[derive(Clone, Debug, PartialEq, Eq)]
3653 pub type Error;
3654
3655 /// The Error constructor creates an error object.
3656 /// Instances of Error objects are thrown when runtime errors occur.
3657 /// The Error object can also be used as a base object for user-defined exceptions.
3658 /// See below for standard built-in error types.
3659 ///
3660 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)
3661 #[wasm_bindgen(constructor)]
3662 pub fn new(message: &str) -> Error;
3663
3664 /// Creates a new `Error` with the given message and an untyped options
3665 /// object whose `cause` property indicates the original cause of the
3666 /// error.
3667 ///
3668 /// New code should prefer [`Error::new_with_error_options`], which takes
3669 /// a typed [`ErrorOptions`] dictionary.
3670 ///
3671 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/Error)
3672 #[wasm_bindgen(constructor)]
3673 pub fn new_with_options(message: &str, options: &Object) -> Error;
3674
3675 /// Creates a new `Error` with the given message and a typed
3676 /// [`ErrorOptions`] dictionary whose `cause` property indicates the
3677 /// original cause of the error.
3678 ///
3679 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/Error)
3680 #[wasm_bindgen(constructor)]
3681 pub fn new_with_error_options(message: &str, options: &ErrorOptions) -> Error;
3682
3683 /// The cause property is the underlying cause of the error.
3684 /// Usually this is used to add context to re-thrown errors.
3685 ///
3686 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error#differentiate_between_similar_errors)
3687 #[wasm_bindgen(method, getter)]
3688 pub fn cause(this: &Error) -> JsValue;
3689 #[wasm_bindgen(method, setter)]
3690 pub fn set_cause(this: &Error, cause: &JsValue);
3691
3692 /// The message property is a human-readable description of the error.
3693 ///
3694 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/message)
3695 #[wasm_bindgen(method, getter)]
3696 pub fn message(this: &Error) -> JsString;
3697 #[wasm_bindgen(method, setter)]
3698 pub fn set_message(this: &Error, message: &str);
3699
3700 /// The name property represents a name for the type of error. The initial value is "Error".
3701 ///
3702 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/name)
3703 #[wasm_bindgen(method, getter)]
3704 pub fn name(this: &Error) -> JsString;
3705 #[wasm_bindgen(method, setter)]
3706 pub fn set_name(this: &Error, name: &str);
3707
3708 /// The `toString()` method returns a string representing the specified Error object
3709 ///
3710 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/toString)
3711 #[cfg(not(js_sys_unstable_apis))]
3712 #[wasm_bindgen(method, js_name = toString)]
3713 pub fn to_string(this: &Error) -> JsString;
3714
3715 /// The `Error.stackTraceLimit` property controls the number of stack
3716 /// frames collected by a stack trace.
3717 ///
3718 /// This is a non-standard V8/Node.js API.
3719 ///
3720 /// [V8 documentation](https://v8.dev/docs/stack-trace-api#stack-trace-collection-for-custom-exceptions)
3721 #[wasm_bindgen(static_method_of = Error, getter, js_name = stackTraceLimit)]
3722 pub fn stack_trace_limit() -> JsValue;
3723
3724 /// Set `Error.stackTraceLimit` to control the number of stack frames
3725 /// collected by a stack trace.
3726 ///
3727 /// This is a non-standard V8/Node.js API.
3728 ///
3729 /// [V8 documentation](https://v8.dev/docs/stack-trace-api#stack-trace-collection-for-custom-exceptions)
3730 #[wasm_bindgen(static_method_of = Error, setter, js_name = stackTraceLimit)]
3731 pub fn set_stack_trace_limit(value: &JsValue);
3732}
3733
3734partialord_ord!(JsString);
3735
3736// EvalError
3737#[wasm_bindgen]
3738extern "C" {
3739 #[wasm_bindgen(extends = Object, extends = Error, typescript_type = "EvalError")]
3740 #[derive(Clone, Debug, PartialEq, Eq)]
3741 pub type EvalError;
3742
3743 /// The `EvalError` object indicates an error regarding the global eval() function. This
3744 /// exception is not thrown by JavaScript anymore, however the EvalError object remains for
3745 /// compatibility.
3746 ///
3747 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/EvalError)
3748 #[wasm_bindgen(constructor)]
3749 pub fn new(message: &str) -> EvalError;
3750
3751 /// Creates a new `EvalError` with the given message and a typed
3752 /// [`ErrorOptions`] dictionary whose `cause` property indicates the
3753 /// original cause of the error.
3754 ///
3755 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/EvalError/EvalError)
3756 #[wasm_bindgen(constructor)]
3757 pub fn new_with_options(message: &str, options: &ErrorOptions) -> EvalError;
3758}
3759
3760#[wasm_bindgen]
3761extern "C" {
3762 #[wasm_bindgen(extends = Object, is_type_of = JsValue::is_function, no_upcast, typescript_type = "Function")]
3763 #[derive(Clone, Debug, PartialEq, Eq)]
3764 /// `Function` represents any generic Function in JS, by treating all arguments as `JsValue`.
3765 ///
3766 /// It takes a generic parameter of phantom type `fn (Arg1, ..., Argn) -> Ret` which
3767 /// is used to type the JS function. For example, `Function<fn () -> Number>` represents
3768 /// a function taking no arguments that returns a number.
3769 ///
3770 /// The 8 generic argument parameters (`Arg1` through `Arg8`) are the argument
3771 /// types. Arguments not provided enable strict arity checking at compile time.
3772 ///
3773 /// A void function is represented by `fn (Arg) -> Undefined`, and **not** the `()` unit
3774 /// type. This is because generics must be based on JS values in the JS generic type system.
3775 ///
3776 /// _The default without any parameters is as a void function - no arguments, `Undefined` return._
3777 ///
3778 /// _The default generic for `Function` is `fn (JsValue, JsValue, ...) -> JsValue`,
3779 /// representing any function, since all functions safely upcast into this function._
3780 ///
3781 /// ### Arity Enforcement
3782 ///
3783 /// It is not possible to use `call4` or `bind4` on a function that does not have
3784 /// at least 4 arguments — the compiler will reject this because only arguments that
3785 /// are not `None` support the trait bound for `ErasableGeneric`.
3786 ///
3787 /// ### Examples
3788 ///
3789 /// ```ignore
3790 /// // A function taking no args, returning Number
3791 /// let f: Function<Number> = get_some_fn();
3792 ///
3793 /// // A function taking (String, Number) and returning Boolean
3794 /// let f: Function<Boolean, String, Number> = get_some_fn();
3795 ///
3796 /// ### Upcasting
3797 ///
3798 /// To pass a typed `Function` where a different generic Function is expected, `upcast()` may be used
3799 /// to convert into any generic `Function` at zero cost with type-safety.
3800 ///
3801 /// MDN documentation (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
3802 pub type Function<
3803 T: JsFunction = fn(
3804 JsValue,
3805 JsValue,
3806 JsValue,
3807 JsValue,
3808 JsValue,
3809 JsValue,
3810 JsValue,
3811 JsValue,
3812 ) -> JsValue,
3813 >;
3814}
3815
3816#[wasm_bindgen]
3817extern "C" {
3818 /// The `Function` constructor creates a new `Function` object. Calling the
3819 /// constructor directly can create functions dynamically, but suffers from
3820 /// security and similar (but far less significant) performance issues
3821 /// similar to `eval`. However, unlike `eval`, the `Function` constructor
3822 /// allows executing code in the global scope, prompting better programming
3823 /// habits and allowing for more efficient code minification.
3824 ///
3825 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
3826 #[cfg(all(feature = "unsafe-eval", not(js_sys_unstable_apis)))]
3827 #[wasm_bindgen(constructor)]
3828 pub fn new_with_args(args: &str, body: &str) -> Function;
3829
3830 /// The `Function` constructor creates a new `Function` object. Calling the
3831 /// constructor directly can create functions dynamically, but suffers from
3832 /// security and similar (but far less significant) performance issues
3833 /// similar to `eval`. However, unlike `eval`, the `Function` constructor
3834 /// allows executing code in the global scope, prompting better programming
3835 /// habits and allowing for more efficient code minification.
3836 ///
3837 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
3838 #[cfg(all(feature = "unsafe-eval", js_sys_unstable_apis))]
3839 #[wasm_bindgen(constructor)]
3840 pub fn new_with_args<T: JsFunction = fn() -> JsValue>(args: &str, body: &str) -> Function<T>;
3841
3842 // Next major: deprecate
3843 /// The `Function` constructor creates a new `Function` object. Calling the
3844 /// constructor directly can create functions dynamically, but suffers from
3845 /// security and similar (but far less significant) performance issues
3846 /// similar to `eval`. However, unlike `eval`, the `Function` constructor
3847 /// allows executing code in the global scope, prompting better programming
3848 /// habits and allowing for more efficient code minification.
3849 ///
3850 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
3851 #[cfg(feature = "unsafe-eval")]
3852 #[wasm_bindgen(constructor)]
3853 pub fn new_with_args_typed<T: JsFunction = fn() -> JsValue>(
3854 args: &str,
3855 body: &str,
3856 ) -> Function<T>;
3857
3858 /// The `Function` constructor creates a new `Function` object. Calling the
3859 /// constructor directly can create functions dynamically, but suffers from
3860 /// security and similar (but far less significant) performance issues
3861 /// similar to `eval`. However, unlike `eval`, the `Function` constructor
3862 /// allows executing code in the global scope, prompting better programming
3863 /// habits and allowing for more efficient code minification.
3864 ///
3865 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
3866 #[cfg(all(feature = "unsafe-eval", not(js_sys_unstable_apis)))]
3867 #[wasm_bindgen(constructor)]
3868 pub fn new_no_args(body: &str) -> Function;
3869
3870 /// The `Function` constructor creates a new `Function` object. Calling the
3871 /// constructor directly can create functions dynamically, but suffers from
3872 /// security and similar (but far less significant) performance issues
3873 /// similar to `eval`. However, unlike `eval`, the `Function` constructor
3874 /// allows executing code in the global scope, prompting better programming
3875 /// habits and allowing for more efficient code minification.
3876 ///
3877 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
3878 #[cfg(all(feature = "unsafe-eval", js_sys_unstable_apis))]
3879 #[wasm_bindgen(constructor)]
3880 pub fn new_no_args<T: JsFunction = fn() -> JsValue>(body: &str) -> Function<T>;
3881
3882 // Next major: deprecate
3883 /// The `Function` constructor creates a new `Function` object.
3884 ///
3885 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
3886 #[cfg(feature = "unsafe-eval")]
3887 #[wasm_bindgen(constructor)]
3888 pub fn new_no_args_typed<T: JsFunction = fn() -> JsValue>(body: &str) -> Function<T>;
3889
3890 /// The `apply()` method calls a function with a given this value, and arguments provided as an array
3891 /// (or an array-like object).
3892 ///
3893 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply)
3894 #[wasm_bindgen(method, catch)]
3895 pub fn apply<T: JsFunction = fn() -> JsValue>(
3896 this: &Function<T>,
3897 context: &JsValue,
3898 args: &Array,
3899 ) -> Result<<T as JsFunction>::Ret, JsValue>;
3900
3901 // Next major: Deprecate, and separately provide provide impl
3902 /// The `call()` method calls a function with a given this value and
3903 /// arguments provided individually.
3904 ///
3905 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3906 ///
3907 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3908 #[wasm_bindgen(method, catch, js_name = call)]
3909 pub fn call0<Ret: JsGeneric, F: JsFunction<Ret = Ret> = fn() -> JsValue>(
3910 this: &Function<F>,
3911 context: &JsValue,
3912 ) -> Result<Ret, JsValue>;
3913
3914 // Next major: Deprecate, and separately provide provide impl
3915 /// The `call()` method calls a function with a given this value and
3916 /// arguments provided individually.
3917 ///
3918 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3919 ///
3920 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3921 #[wasm_bindgen(method, catch, js_name = call)]
3922 pub fn call1<
3923 Ret: JsGeneric,
3924 Arg1: JsGeneric,
3925 F: JsFunction<Ret = Ret> + JsFunction1<Arg1 = Arg1> = fn(JsValue) -> JsValue,
3926 >(
3927 this: &Function<F>,
3928 context: &JsValue,
3929 arg1: &Arg1,
3930 ) -> Result<Ret, JsValue>;
3931
3932 // Next major: Deprecate, and separately provide provide impl
3933 /// The `call()` method calls a function with a given this value and
3934 /// arguments provided individually.
3935 ///
3936 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3937 ///
3938 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3939 #[wasm_bindgen(method, catch, js_name = call)]
3940 pub fn call2<
3941 Ret: JsGeneric,
3942 Arg1: JsGeneric,
3943 Arg2: JsGeneric,
3944 F: JsFunction<Ret = Ret> + JsFunction1<Arg1 = Arg1> + JsFunction2<Arg2 = Arg2> = fn(
3945 JsValue,
3946 JsValue,
3947 ) -> JsValue,
3948 >(
3949 this: &Function<F>,
3950 context: &JsValue,
3951 arg1: &Arg1,
3952 arg2: &Arg2,
3953 ) -> Result<Ret, JsValue>;
3954
3955 // Next major: Deprecate, and separately provide provide impl
3956 /// The `call()` method calls a function with a given this value and
3957 /// arguments provided individually.
3958 ///
3959 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3960 ///
3961 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3962 #[wasm_bindgen(method, catch, js_name = call)]
3963 pub fn call3<
3964 Ret: JsGeneric,
3965 Arg1: JsGeneric,
3966 Arg2: JsGeneric,
3967 Arg3: JsGeneric,
3968 F: JsFunction<Ret = Ret> + JsFunction3<Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3> = fn(
3969 JsValue,
3970 JsValue,
3971 JsValue,
3972 ) -> JsValue,
3973 >(
3974 this: &Function<F>,
3975 context: &JsValue,
3976 arg1: &Arg1,
3977 arg2: &Arg2,
3978 arg3: &Arg3,
3979 ) -> Result<Ret, JsValue>;
3980
3981 // Next major: Deprecate, and separately provide provide impl
3982 /// The `call()` method calls a function with a given this value and
3983 /// arguments provided individually.
3984 ///
3985 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3986 ///
3987 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3988 #[wasm_bindgen(method, catch, js_name = call)]
3989 pub fn call4<
3990 Ret: JsGeneric,
3991 Arg1: JsGeneric,
3992 Arg2: JsGeneric,
3993 Arg3: JsGeneric,
3994 Arg4: JsGeneric,
3995 F: JsFunction<Ret = Ret> + JsFunction4<Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3, Arg4 = Arg4> = fn(
3996 JsValue,
3997 JsValue,
3998 JsValue,
3999 JsValue,
4000 ) -> JsValue,
4001 >(
4002 this: &Function<F>,
4003 context: &JsValue,
4004 arg1: &Arg1,
4005 arg2: &Arg2,
4006 arg3: &Arg3,
4007 arg4: &Arg4,
4008 ) -> Result<Ret, JsValue>;
4009
4010 // Next major: Deprecate, and separately provide provide impl
4011 /// The `call()` method calls a function with a given this value and
4012 /// arguments provided individually.
4013 ///
4014 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
4015 ///
4016 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
4017 #[wasm_bindgen(method, catch, js_name = call)]
4018 pub fn call5<
4019 Ret: JsGeneric,
4020 Arg1: JsGeneric,
4021 Arg2: JsGeneric,
4022 Arg3: JsGeneric,
4023 Arg4: JsGeneric,
4024 Arg5: JsGeneric,
4025 F: JsFunction<Ret = Ret>
4026 + JsFunction5<Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3, Arg4 = Arg4, Arg5 = Arg5> = fn(
4027 JsValue,
4028 JsValue,
4029 JsValue,
4030 JsValue,
4031 JsValue,
4032 ) -> JsValue,
4033 >(
4034 this: &Function<F>,
4035 context: &JsValue,
4036 arg1: &Arg1,
4037 arg2: &Arg2,
4038 arg3: &Arg3,
4039 arg4: &Arg4,
4040 arg5: &Arg5,
4041 ) -> Result<Ret, JsValue>;
4042
4043 // Next major: Deprecate, and separately provide provide impl
4044 /// The `call()` method calls a function with a given this value and
4045 /// arguments provided individually.
4046 ///
4047 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
4048 ///
4049 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
4050 #[wasm_bindgen(method, catch, js_name = call)]
4051 pub fn call6<
4052 Ret: JsGeneric,
4053 Arg1: JsGeneric,
4054 Arg2: JsGeneric,
4055 Arg3: JsGeneric,
4056 Arg4: JsGeneric,
4057 Arg5: JsGeneric,
4058 Arg6: JsGeneric,
4059 F: JsFunction<Ret = Ret>
4060 + JsFunction6<
4061 Arg1 = Arg1,
4062 Arg2 = Arg2,
4063 Arg3 = Arg3,
4064 Arg4 = Arg4,
4065 Arg5 = Arg5,
4066 Arg6 = Arg6,
4067 > = fn(JsValue, JsValue, JsValue, JsValue, JsValue, JsValue) -> JsValue,
4068 >(
4069 this: &Function<F>,
4070 context: &JsValue,
4071 arg1: &Arg1,
4072 arg2: &Arg2,
4073 arg3: &Arg3,
4074 arg4: &Arg4,
4075 arg5: &Arg5,
4076 arg6: &Arg6,
4077 ) -> Result<Ret, JsValue>;
4078
4079 // Next major: Deprecate, and separately provide provide impl
4080 /// The `call()` method calls a function with a given this value and
4081 /// arguments provided individually.
4082 ///
4083 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
4084 ///
4085 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
4086 #[wasm_bindgen(method, catch, js_name = call)]
4087 pub fn call7<
4088 Ret: JsGeneric,
4089 Arg1: JsGeneric,
4090 Arg2: JsGeneric,
4091 Arg3: JsGeneric,
4092 Arg4: JsGeneric,
4093 Arg5: JsGeneric,
4094 Arg6: JsGeneric,
4095 Arg7: JsGeneric,
4096 F: JsFunction<Ret = Ret>
4097 + JsFunction7<
4098 Arg1 = Arg1,
4099 Arg2 = Arg2,
4100 Arg3 = Arg3,
4101 Arg4 = Arg4,
4102 Arg5 = Arg5,
4103 Arg6 = Arg6,
4104 Arg7 = Arg7,
4105 > = fn(
4106 JsValue,
4107 JsValue,
4108 JsValue,
4109 JsValue,
4110 JsValue,
4111 JsValue,
4112 JsValue,
4113 ) -> JsValue,
4114 >(
4115 this: &Function<F>,
4116 context: &JsValue,
4117 arg1: &Arg1,
4118 arg2: &Arg2,
4119 arg3: &Arg3,
4120 arg4: &Arg4,
4121 arg5: &Arg5,
4122 arg6: &Arg6,
4123 arg7: &Arg7,
4124 ) -> Result<Ret, JsValue>;
4125
4126 // Next major: Deprecate, and separately provide provide impl
4127 /// The `call()` method calls a function with a given this value and
4128 /// arguments provided individually.
4129 ///
4130 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
4131 ///
4132 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
4133 #[wasm_bindgen(method, catch, js_name = call)]
4134 pub fn call8<
4135 Ret: JsGeneric,
4136 Arg1: JsGeneric,
4137 Arg2: JsGeneric,
4138 Arg3: JsGeneric,
4139 Arg4: JsGeneric,
4140 Arg5: JsGeneric,
4141 Arg6: JsGeneric,
4142 Arg7: JsGeneric,
4143 Arg8: JsGeneric,
4144 F: JsFunction8<
4145 Ret = Ret,
4146 Arg1 = Arg1,
4147 Arg2 = Arg2,
4148 Arg3 = Arg3,
4149 Arg4 = Arg4,
4150 Arg5 = Arg5,
4151 Arg6 = Arg6,
4152 Arg7 = Arg7,
4153 Arg8 = Arg8,
4154 > = fn(
4155 JsValue,
4156 JsValue,
4157 JsValue,
4158 JsValue,
4159 JsValue,
4160 JsValue,
4161 JsValue,
4162 JsValue,
4163 ) -> JsValue,
4164 >(
4165 this: &Function<F>,
4166 context: &JsValue,
4167 arg1: &Arg1,
4168 arg2: &Arg2,
4169 arg3: &Arg3,
4170 arg4: &Arg4,
4171 arg5: &Arg5,
4172 arg6: &Arg6,
4173 arg7: &Arg7,
4174 arg8: &Arg8,
4175 ) -> Result<Ret, JsValue>;
4176
4177 /// The `call()` method calls a function with a given this value and
4178 /// arguments provided individually.
4179 ///
4180 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
4181 ///
4182 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
4183 #[deprecated]
4184 #[allow(deprecated)]
4185 #[wasm_bindgen(method, catch, js_name = call)]
4186 pub fn call9<
4187 Ret: JsGeneric,
4188 Arg1: JsGeneric,
4189 Arg2: JsGeneric,
4190 Arg3: JsGeneric,
4191 Arg4: JsGeneric,
4192 Arg5: JsGeneric,
4193 Arg6: JsGeneric,
4194 Arg7: JsGeneric,
4195 Arg8: JsGeneric,
4196 F: JsFunction8<
4197 Ret = Ret,
4198 Arg1 = Arg1,
4199 Arg2 = Arg2,
4200 Arg3 = Arg3,
4201 Arg4 = Arg4,
4202 Arg5 = Arg5,
4203 Arg6 = Arg6,
4204 Arg7 = Arg7,
4205 Arg8 = Arg8,
4206 > = fn(
4207 JsValue,
4208 JsValue,
4209 JsValue,
4210 JsValue,
4211 JsValue,
4212 JsValue,
4213 JsValue,
4214 JsValue,
4215 ) -> JsValue,
4216 >(
4217 this: &Function<F>,
4218 context: &JsValue,
4219 arg1: &Arg1,
4220 arg2: &Arg2,
4221 arg3: &Arg3,
4222 arg4: &Arg4,
4223 arg5: &Arg5,
4224 arg6: &Arg6,
4225 arg7: &Arg7,
4226 arg8: &Arg8,
4227 arg9: &JsValue,
4228 ) -> Result<Ret, JsValue>;
4229
4230 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4231 /// with a given sequence of arguments preceding any provided when the new function is called.
4232 ///
4233 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4234 #[cfg(not(js_sys_unstable_apis))]
4235 #[deprecated(note = "Use `Function::bind0` instead.")]
4236 #[allow(deprecated)]
4237 #[wasm_bindgen(method, js_name = bind)]
4238 pub fn bind<T: JsFunction = fn() -> JsValue>(
4239 this: &Function<T>,
4240 context: &JsValue,
4241 ) -> Function<T>;
4242
4243 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4244 /// with a given sequence of arguments preceding any provided when the new function is called.
4245 ///
4246 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4247 ///
4248 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4249 #[wasm_bindgen(method, js_name = bind)]
4250 pub fn bind0<T: JsFunction = fn() -> JsValue>(
4251 this: &Function<T>,
4252 context: &JsValue,
4253 ) -> Function<T>;
4254
4255 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4256 /// with a given sequence of arguments preceding any provided when the new function is called.
4257 ///
4258 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4259 ///
4260 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4261 #[wasm_bindgen(method, js_name = bind)]
4262 pub fn bind1<
4263 Ret: JsGeneric,
4264 Arg1: JsGeneric,
4265 F: JsFunction1<Ret = Ret, Arg1 = Arg1> = fn(JsValue) -> JsValue,
4266 >(
4267 this: &Function<F>,
4268 context: &JsValue,
4269 arg1: &Arg1,
4270 ) -> Function<<F as JsFunction1>::Bind1>;
4271
4272 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4273 /// with a given sequence of arguments preceding any provided when the new function is called.
4274 ///
4275 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4276 ///
4277 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4278 #[wasm_bindgen(method, js_name = bind)]
4279 pub fn bind2<
4280 Ret: JsGeneric,
4281 Arg1: JsGeneric,
4282 Arg2: JsGeneric,
4283 F: JsFunction2<Ret = Ret, Arg1 = Arg1, Arg2 = Arg2> = fn(JsValue, JsValue) -> JsValue,
4284 >(
4285 this: &Function<F>,
4286 context: &JsValue,
4287 arg1: &Arg1,
4288 arg2: &Arg2,
4289 ) -> Function<<F as JsFunction2>::Bind2>;
4290
4291 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4292 /// with a given sequence of arguments preceding any provided when the new function is called.
4293 ///
4294 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4295 ///
4296 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4297 #[wasm_bindgen(method, js_name = bind)]
4298 pub fn bind3<
4299 Ret: JsGeneric,
4300 Arg1: JsGeneric,
4301 Arg2: JsGeneric,
4302 Arg3: JsGeneric,
4303 F: JsFunction3<Ret = Ret, Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3> = fn(
4304 JsValue,
4305 JsValue,
4306 JsValue,
4307 ) -> JsValue,
4308 >(
4309 this: &Function<F>,
4310 context: &JsValue,
4311 arg1: &Arg1,
4312 arg2: &Arg2,
4313 arg3: &Arg3,
4314 ) -> Function<<F as JsFunction3>::Bind3>;
4315
4316 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4317 /// with a given sequence of arguments preceding any provided when the new function is called.
4318 ///
4319 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4320 ///
4321 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4322 #[wasm_bindgen(method, js_name = bind)]
4323 pub fn bind4<
4324 Ret: JsGeneric,
4325 Arg1: JsGeneric,
4326 Arg2: JsGeneric,
4327 Arg3: JsGeneric,
4328 Arg4: JsGeneric,
4329 F: JsFunction4<Ret = Ret, Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3, Arg4 = Arg4> = fn(
4330 JsValue,
4331 JsValue,
4332 JsValue,
4333 JsValue,
4334 ) -> JsValue,
4335 >(
4336 this: &Function<F>,
4337 context: &JsValue,
4338 arg1: &Arg1,
4339 arg2: &Arg2,
4340 arg3: &Arg3,
4341 arg4: &Arg4,
4342 ) -> Function<<F as JsFunction4>::Bind4>;
4343
4344 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4345 /// with a given sequence of arguments preceding any provided when the new function is called.
4346 ///
4347 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4348 ///
4349 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4350 #[wasm_bindgen(method, js_name = bind)]
4351 pub fn bind5<
4352 Ret: JsGeneric,
4353 Arg1: JsGeneric,
4354 Arg2: JsGeneric,
4355 Arg3: JsGeneric,
4356 Arg4: JsGeneric,
4357 Arg5: JsGeneric,
4358 F: JsFunction5<Ret = Ret, Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3, Arg4 = Arg4, Arg5 = Arg5> = fn(
4359 JsValue,
4360 JsValue,
4361 JsValue,
4362 JsValue,
4363 JsValue,
4364 ) -> JsValue,
4365 >(
4366 this: &Function<F>,
4367 context: &JsValue,
4368 arg1: &Arg1,
4369 arg2: &Arg2,
4370 arg3: &Arg3,
4371 arg4: &Arg4,
4372 arg5: &Arg5,
4373 ) -> Function<<F as JsFunction5>::Bind5>;
4374
4375 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4376 /// with a given sequence of arguments preceding any provided when the new function is called.
4377 ///
4378 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4379 ///
4380 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4381 #[wasm_bindgen(method, js_name = bind)]
4382 pub fn bind6<
4383 Ret: JsGeneric,
4384 Arg1: JsGeneric,
4385 Arg2: JsGeneric,
4386 Arg3: JsGeneric,
4387 Arg4: JsGeneric,
4388 Arg5: JsGeneric,
4389 Arg6: JsGeneric,
4390 F: JsFunction6<
4391 Ret = Ret,
4392 Arg1 = Arg1,
4393 Arg2 = Arg2,
4394 Arg3 = Arg3,
4395 Arg4 = Arg4,
4396 Arg5 = Arg5,
4397 Arg6 = Arg6,
4398 > = fn(JsValue, JsValue, JsValue, JsValue, JsValue, JsValue) -> JsValue,
4399 >(
4400 this: &Function<F>,
4401 context: &JsValue,
4402 arg1: &Arg1,
4403 arg2: &Arg2,
4404 arg3: &Arg3,
4405 arg4: &Arg4,
4406 arg5: &Arg5,
4407 arg6: &Arg6,
4408 ) -> Function<<F as JsFunction6>::Bind6>;
4409
4410 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4411 /// with a given sequence of arguments preceding any provided when the new function is called.
4412 ///
4413 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4414 ///
4415 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4416 #[wasm_bindgen(method, js_name = bind)]
4417 pub fn bind7<
4418 Ret: JsGeneric,
4419 Arg1: JsGeneric,
4420 Arg2: JsGeneric,
4421 Arg3: JsGeneric,
4422 Arg4: JsGeneric,
4423 Arg5: JsGeneric,
4424 Arg6: JsGeneric,
4425 Arg7: JsGeneric,
4426 F: JsFunction7<
4427 Ret = Ret,
4428 Arg1 = Arg1,
4429 Arg2 = Arg2,
4430 Arg3 = Arg3,
4431 Arg4 = Arg4,
4432 Arg5 = Arg5,
4433 Arg6 = Arg6,
4434 Arg7 = Arg7,
4435 > = fn(
4436 JsValue,
4437 JsValue,
4438 JsValue,
4439 JsValue,
4440 JsValue,
4441 JsValue,
4442 JsValue,
4443 ) -> JsValue,
4444 >(
4445 this: &Function<F>,
4446 context: &JsValue,
4447 arg1: &Arg1,
4448 arg2: &Arg2,
4449 arg3: &Arg3,
4450 arg4: &Arg4,
4451 arg5: &Arg5,
4452 arg6: &Arg6,
4453 arg7: &Arg7,
4454 ) -> Function<<F as JsFunction7>::Bind7>;
4455
4456 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4457 /// with a given sequence of arguments preceding any provided when the new function is called.
4458 ///
4459 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4460 ///
4461 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4462 #[wasm_bindgen(method, js_name = bind)]
4463 pub fn bind8<
4464 Ret: JsGeneric,
4465 Arg1: JsGeneric,
4466 Arg2: JsGeneric,
4467 Arg3: JsGeneric,
4468 Arg4: JsGeneric,
4469 Arg5: JsGeneric,
4470 Arg6: JsGeneric,
4471 Arg7: JsGeneric,
4472 Arg8: JsGeneric,
4473 F: JsFunction8<
4474 Ret = Ret,
4475 Arg1 = Arg1,
4476 Arg2 = Arg2,
4477 Arg3 = Arg3,
4478 Arg4 = Arg4,
4479 Arg5 = Arg5,
4480 Arg6 = Arg6,
4481 Arg7 = Arg7,
4482 Arg8 = Arg8,
4483 > = fn(
4484 JsValue,
4485 JsValue,
4486 JsValue,
4487 JsValue,
4488 JsValue,
4489 JsValue,
4490 JsValue,
4491 JsValue,
4492 ) -> JsValue,
4493 >(
4494 this: &Function<F>,
4495 context: &JsValue,
4496 arg1: &Arg1,
4497 arg2: &Arg2,
4498 arg3: &Arg3,
4499 arg4: &Arg4,
4500 arg5: &Arg5,
4501 arg6: &Arg6,
4502 arg7: &Arg7,
4503 arg8: &Arg8,
4504 ) -> Function<<F as JsFunction8>::Bind8>;
4505
4506 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4507 /// with a given sequence of arguments preceding any provided when the new function is called.
4508 ///
4509 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4510 ///
4511 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4512 #[deprecated]
4513 #[allow(deprecated)]
4514 #[wasm_bindgen(method, js_name = bind)]
4515 pub fn bind9<
4516 Ret: JsGeneric,
4517 Arg1: JsGeneric,
4518 Arg2: JsGeneric,
4519 Arg3: JsGeneric,
4520 Arg4: JsGeneric,
4521 Arg5: JsGeneric,
4522 Arg6: JsGeneric,
4523 Arg7: JsGeneric,
4524 Arg8: JsGeneric,
4525 F: JsFunction8<
4526 Ret = Ret,
4527 Arg1 = Arg1,
4528 Arg2 = Arg2,
4529 Arg3 = Arg3,
4530 Arg4 = Arg4,
4531 Arg5 = Arg5,
4532 Arg6 = Arg6,
4533 Arg7 = Arg7,
4534 Arg8 = Arg8,
4535 > = fn(
4536 JsValue,
4537 JsValue,
4538 JsValue,
4539 JsValue,
4540 JsValue,
4541 JsValue,
4542 JsValue,
4543 JsValue,
4544 ) -> JsValue,
4545 >(
4546 this: &Function<F>,
4547 context: &JsValue,
4548 arg1: &Arg1,
4549 arg2: &Arg2,
4550 arg3: &Arg3,
4551 arg4: &Arg4,
4552 arg5: &Arg5,
4553 arg6: &Arg6,
4554 arg7: &Arg7,
4555 arg8: &Arg8,
4556 arg9: &JsValue,
4557 ) -> Function<fn() -> Ret>;
4558
4559 /// The length property indicates the number of arguments expected by the function.
4560 ///
4561 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/length)
4562 #[wasm_bindgen(method, getter)]
4563 pub fn length<T: JsFunction = fn() -> JsValue>(this: &Function<T>) -> u32;
4564
4565 /// A Function object's read-only name property indicates the function's
4566 /// name as specified when it was created or "anonymous" for functions
4567 /// created anonymously.
4568 ///
4569 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name)
4570 #[wasm_bindgen(method, getter)]
4571 pub fn name<T: JsFunction = fn() -> JsValue>(this: &Function<T>) -> JsString;
4572
4573 /// The `toString()` method returns a string representing the source code of the function.
4574 ///
4575 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/toString)
4576 #[cfg(not(js_sys_unstable_apis))]
4577 #[wasm_bindgen(method, js_name = toString)]
4578 pub fn to_string<T: JsFunction = fn() -> JsValue>(this: &Function<T>) -> JsString;
4579}
4580
4581// Basic UpcastFrom impls for Function<T>
4582impl<T: JsFunction> UpcastFrom<Function<T>> for JsValue {}
4583impl<T: JsFunction> UpcastFrom<Function<T>> for JsOption<JsValue> {}
4584impl<T: JsFunction> UpcastFrom<Function<T>> for Object {}
4585impl<T: JsFunction> UpcastFrom<Function<T>> for JsOption<Object> {}
4586
4587// Blanket trait for Function upcast
4588// Function<T> upcasts to Function<U> when the underlying fn type T upcasts to U.
4589// The fn signature UpcastFrom impls already encode correct variance (covariant return, contravariant args).
4590impl<T: JsFunction, U: JsFunction> UpcastFrom<Function<T>> for Function<U> where U: UpcastFrom<T> {}
4591
4592// len() method for Function<T> using JsFunction::ARITY
4593impl<T: JsFunction> Function<T> {
4594 /// Get the static arity of this function type.
4595 #[allow(clippy::len_without_is_empty)]
4596 pub fn len(&self) -> usize {
4597 T::ARITY
4598 }
4599
4600 /// Returns true if this is a zero-argument function.
4601 pub fn is_empty(&self) -> bool {
4602 T::ARITY == 0
4603 }
4604}
4605
4606// Base traits for function signature types.
4607pub trait JsFunction {
4608 type Ret: JsGeneric;
4609 const ARITY: usize;
4610}
4611
4612pub trait JsFunction1: JsFunction {
4613 type Arg1: JsGeneric;
4614 type Bind1: JsFunction;
4615}
4616pub trait JsFunction2: JsFunction1 {
4617 type Arg2: JsGeneric;
4618 type Bind2: JsFunction;
4619}
4620pub trait JsFunction3: JsFunction2 {
4621 type Arg3: JsGeneric;
4622 type Bind3: JsFunction;
4623}
4624pub trait JsFunction4: JsFunction3 {
4625 type Arg4: JsGeneric;
4626 type Bind4: JsFunction;
4627}
4628pub trait JsFunction5: JsFunction4 {
4629 type Arg5: JsGeneric;
4630 type Bind5: JsFunction;
4631}
4632pub trait JsFunction6: JsFunction5 {
4633 type Arg6: JsGeneric;
4634 type Bind6: JsFunction;
4635}
4636pub trait JsFunction7: JsFunction6 {
4637 type Arg7: JsGeneric;
4638 type Bind7: JsFunction;
4639}
4640pub trait JsFunction8: JsFunction7 {
4641 type Arg8: JsGeneric;
4642 type Bind8: JsFunction;
4643}
4644
4645// Manual impl for fn() -> R
4646impl<Ret: JsGeneric> JsFunction for fn() -> Ret {
4647 type Ret = Ret;
4648 const ARITY: usize = 0;
4649}
4650
4651macro_rules! impl_fn {
4652 () => {
4653 impl_fn!(@impl 1 [Arg1] [
4654 JsFunction1 Arg1 Bind1 {fn() -> Ret}
4655 ]);
4656 impl_fn!(@impl 2 [Arg1 Arg2] [
4657 JsFunction1 Arg1 Bind1 {fn(Arg2) -> Ret}
4658 JsFunction2 Arg2 Bind2 {fn() -> Ret}
4659 ]);
4660 impl_fn!(@impl 3 [Arg1 Arg2 Arg3] [
4661 JsFunction1 Arg1 Bind1 {fn(Arg2, Arg3) -> Ret}
4662 JsFunction2 Arg2 Bind2 {fn(Arg3) -> Ret}
4663 JsFunction3 Arg3 Bind3 {fn() -> Ret}
4664 ]);
4665 impl_fn!(@impl 4 [Arg1 Arg2 Arg3 Arg4] [
4666 JsFunction1 Arg1 Bind1 {fn(Arg2, Arg3, Arg4) -> Ret}
4667 JsFunction2 Arg2 Bind2 {fn(Arg3, Arg4) -> Ret}
4668 JsFunction3 Arg3 Bind3 {fn(Arg4) -> Ret}
4669 JsFunction4 Arg4 Bind4 {fn() -> Ret}
4670 ]);
4671 impl_fn!(@impl 5 [Arg1 Arg2 Arg3 Arg4 Arg5] [
4672 JsFunction1 Arg1 Bind1 {fn(Arg2, Arg3, Arg4, Arg5) -> Ret}
4673 JsFunction2 Arg2 Bind2 {fn(Arg3, Arg4, Arg5) -> Ret}
4674 JsFunction3 Arg3 Bind3 {fn(Arg4, Arg5) -> Ret}
4675 JsFunction4 Arg4 Bind4 {fn(Arg5) -> Ret}
4676 JsFunction5 Arg5 Bind5 {fn() -> Ret}
4677 ]);
4678 impl_fn!(@impl 6 [Arg1 Arg2 Arg3 Arg4 Arg5 Arg6] [
4679 JsFunction1 Arg1 Bind1 {fn(Arg2, Arg3, Arg4, Arg5, Arg6) -> Ret}
4680 JsFunction2 Arg2 Bind2 {fn(Arg3, Arg4, Arg5, Arg6) -> Ret}
4681 JsFunction3 Arg3 Bind3 {fn(Arg4, Arg5, Arg6) -> Ret}
4682 JsFunction4 Arg4 Bind4 {fn(Arg5, Arg6) -> Ret}
4683 JsFunction5 Arg5 Bind5 {fn(Arg6) -> Ret}
4684 JsFunction6 Arg6 Bind6 {fn() -> Ret}
4685 ]);
4686 impl_fn!(@impl 7 [Arg1 Arg2 Arg3 Arg4 Arg5 Arg6 Arg7] [
4687 JsFunction1 Arg1 Bind1 {fn(Arg2, Arg3, Arg4, Arg5, Arg6, Arg7) -> Ret}
4688 JsFunction2 Arg2 Bind2 {fn(Arg3, Arg4, Arg5, Arg6, Arg7) -> Ret}
4689 JsFunction3 Arg3 Bind3 {fn(Arg4, Arg5, Arg6, Arg7) -> Ret}
4690 JsFunction4 Arg4 Bind4 {fn(Arg5, Arg6, Arg7) -> Ret}
4691 JsFunction5 Arg5 Bind5 {fn(Arg6, Arg7) -> Ret}
4692 JsFunction6 Arg6 Bind6 {fn(Arg7) -> Ret}
4693 JsFunction7 Arg7 Bind7 {fn() -> Ret}
4694 ]);
4695 impl_fn!(@impl 8 [Arg1 Arg2 Arg3 Arg4 Arg5 Arg6 Arg7 Arg8] [
4696 JsFunction1 Arg1 Bind1 {fn(Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8) -> Ret}
4697 JsFunction2 Arg2 Bind2 {fn(Arg3, Arg4, Arg5, Arg6, Arg7, Arg8) -> Ret}
4698 JsFunction3 Arg3 Bind3 {fn(Arg4, Arg5, Arg6, Arg7, Arg8) -> Ret}
4699 JsFunction4 Arg4 Bind4 {fn(Arg5, Arg6, Arg7, Arg8) -> Ret}
4700 JsFunction5 Arg5 Bind5 {fn(Arg6, Arg7, Arg8) -> Ret}
4701 JsFunction6 Arg6 Bind6 {fn(Arg7, Arg8) -> Ret}
4702 JsFunction7 Arg7 Bind7 {fn(Arg8) -> Ret}
4703 JsFunction8 Arg8 Bind8 {fn() -> Ret}
4704 ]);
4705 };
4706
4707 (@impl $arity:literal [$($A:ident)+] [$($trait:ident $arg:ident $bind:ident {$bind_ty:ty})+]) => {
4708 impl<Ret: JsGeneric $(, $A: JsGeneric)+> JsFunction for fn($($A),+) -> Ret {
4709 type Ret = Ret;
4710 const ARITY: usize = $arity;
4711 }
4712
4713 impl_fn!(@traits [$($A)+] [$($trait $arg $bind {$bind_ty})+]);
4714 };
4715
4716 (@traits [$($A:ident)+] []) => {};
4717
4718 (@traits [$($A:ident)+] [$trait:ident $arg:ident $bind:ident {$bind_ty:ty} $($rest:tt)*]) => {
4719 impl<Ret: JsGeneric $(, $A: JsGeneric)+> $trait for fn($($A),+) -> Ret {
4720 type $arg = $arg;
4721 type $bind = $bind_ty;
4722 }
4723
4724 impl_fn!(@traits [$($A)+] [$($rest)*]);
4725 };
4726}
4727
4728impl_fn!();
4729
4730/// Trait for argument tuples that can call or bind a `Function<T>`.
4731pub trait JsArgs<T: JsFunction> {
4732 type BindOutput;
4733 fn apply_call(self, func: &Function<T>, context: &JsValue) -> Result<T::Ret, JsValue>;
4734 fn apply_bind(self, func: &Function<T>, context: &JsValue) -> Self::BindOutput;
4735}
4736
4737// Manual impl for 0-arg
4738impl<Ret: JsGeneric, F: JsFunction<Ret = Ret>> JsArgs<F> for () {
4739 type BindOutput = Function<F>;
4740
4741 #[inline]
4742 fn apply_call(self, func: &Function<F>, context: &JsValue) -> Result<Ret, JsValue> {
4743 func.call0(context)
4744 }
4745
4746 #[inline]
4747 fn apply_bind(self, func: &Function<F>, context: &JsValue) -> Self::BindOutput {
4748 func.bind0(context)
4749 }
4750}
4751
4752macro_rules! impl_js_args {
4753 ($arity:literal $trait:ident $bind_output:ident [$($A:ident)+] [$($idx:tt)+] $call:ident $bind:ident) => {
4754 impl<Ret: JsGeneric, $($A: JsGeneric,)+ F: $trait<Ret = Ret, $($A = $A,)*>> JsArgs<F> for ($(&$A,)+)
4755 {
4756 type BindOutput = Function<<F as $trait>::$bind_output>;
4757
4758 #[inline]
4759 fn apply_call(self, func: &Function<F>, context: &JsValue) -> Result<Ret, JsValue> {
4760 func.$call(context, $(self.$idx),+)
4761 }
4762
4763 #[inline]
4764 fn apply_bind(self, func: &Function<F>, context: &JsValue) -> Self::BindOutput {
4765 func.$bind(context, $(self.$idx),+)
4766 }
4767 }
4768 };
4769}
4770
4771impl_js_args!(1 JsFunction1 Bind1 [Arg1] [0] call1 bind1);
4772impl_js_args!(2 JsFunction2 Bind2 [Arg1 Arg2] [0 1] call2 bind2);
4773impl_js_args!(3 JsFunction3 Bind3 [Arg1 Arg2 Arg3] [0 1 2] call3 bind3);
4774impl_js_args!(4 JsFunction4 Bind4 [Arg1 Arg2 Arg3 Arg4] [0 1 2 3] call4 bind4);
4775impl_js_args!(5 JsFunction5 Bind5 [Arg1 Arg2 Arg3 Arg4 Arg5] [0 1 2 3 4] call5 bind5);
4776impl_js_args!(6 JsFunction6 Bind6 [Arg1 Arg2 Arg3 Arg4 Arg5 Arg6] [0 1 2 3 4 5] call6 bind6);
4777impl_js_args!(7 JsFunction7 Bind7 [Arg1 Arg2 Arg3 Arg4 Arg5 Arg6 Arg7] [0 1 2 3 4 5 6] call7 bind7);
4778impl_js_args!(8 JsFunction8 Bind8 [Arg1 Arg2 Arg3 Arg4 Arg5 Arg6 Arg7 Arg8] [0 1 2 3 4 5 6 7] call8 bind8);
4779
4780impl<T: JsFunction> Function<T> {
4781 /// The `call()` method calls a function with a given `this` value and
4782 /// arguments provided as a tuple.
4783 ///
4784 /// This method accepts a tuple of references matching the function's
4785 /// argument types.
4786 ///
4787 /// # Example
4788 ///
4789 /// ```ignore
4790 /// // 0-arg function
4791 /// let f: Function<fn() -> Number> = get_fn();
4792 /// let result = f.call(&JsValue::NULL, ())?;
4793 ///
4794 /// // 1-arg function (note trailing comma for 1-tuple)
4795 /// let f: Function<fn(JsString) -> Number> = get_fn();
4796 /// let result = f.call(&JsValue::NULL, (&name,))?;
4797 ///
4798 /// // 2-arg function
4799 /// let f: Function<fn(JsString, Boolean) -> Number> = get_fn();
4800 /// let result = f.call(&JsValue::NULL, (&name, &flag))?;
4801 /// ```
4802 ///
4803 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
4804 #[inline]
4805 pub fn call<Args: JsArgs<T>>(&self, context: &JsValue, args: Args) -> Result<T::Ret, JsValue> {
4806 args.apply_call(self, context)
4807 }
4808
4809 /// The `bind()` method creates a new function that, when called, has its
4810 /// `this` keyword set to the provided value, with a given sequence of
4811 /// arguments preceding any provided when the new function is called.
4812 ///
4813 /// This method accepts a tuple of references to bind.
4814 ///
4815 /// # Example
4816 ///
4817 /// ```ignore
4818 /// let f: Function<fn(JsString, Boolean) -> Number> = get_fn();
4819 ///
4820 /// // Bind no args - same signature
4821 /// let bound: Function<fn(JsString, Boolean) -> Number> = f.bind(&ctx, ());
4822 ///
4823 /// // Bind one arg (use 1-tuple of references)
4824 /// let bound: Function<fn(Boolean) -> Number> = f.bind(&ctx, (&my_string,));
4825 ///
4826 /// // Bind two args - becomes 0-arg function
4827 /// let bound: Function<fn() -> Number> = f.bind(&ctx, (&my_string, &my_bool));
4828 /// ```
4829 ///
4830 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4831 #[inline]
4832 pub fn bindn<Args: JsArgs<T>>(&self, context: &JsValue, args: Args) -> Args::BindOutput {
4833 args.apply_bind(self, context)
4834 }
4835
4836 /// The `bind()` method creates a new function that, when called, has its
4837 /// `this` keyword set to the provided value, with a given sequence of
4838 /// arguments preceding any provided when the new function is called.
4839 ///
4840 /// This method accepts a tuple of references to bind.
4841 ///
4842 /// # Example
4843 ///
4844 /// ```ignore
4845 /// let f: Function<fn(JsString, Boolean) -> Number> = get_fn();
4846 ///
4847 /// // Bind no args - same signature
4848 /// let bound: Function<fn(JsString, Boolean) -> Number> = f.bind(&ctx, ());
4849 ///
4850 /// // Bind one arg (use 1-tuple of references)
4851 /// let bound: Function<fn(Boolean) -> Number> = f.bind(&ctx, (&my_string,));
4852 ///
4853 /// // Bind two args - becomes 0-arg function
4854 /// let bound: Function<fn() -> Number> = f.bind(&ctx, (&my_string, &my_bool));
4855 /// ```
4856 ///
4857 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4858 #[cfg(js_sys_unstable_apis)]
4859 #[inline]
4860 pub fn bind<Args: JsArgs<T>>(&self, context: &JsValue, args: Args) -> Args::BindOutput {
4861 args.apply_bind(self, context)
4862 }
4863}
4864
4865pub trait FunctionIntoClosure: JsFunction {
4866 type ClosureTypeMut: WasmClosure + ?Sized;
4867}
4868
4869macro_rules! impl_function_into_closure {
4870 ( $(($($var:ident)*))* ) => {$(
4871 impl<$($var: FromWasmAbi + JsGeneric,)* R: IntoWasmAbi + JsGeneric> FunctionIntoClosure for fn($($var),*) -> R {
4872 type ClosureTypeMut = dyn FnMut($($var),*) -> R;
4873 }
4874 )*};
4875}
4876
4877impl_function_into_closure! {
4878 ()
4879 (A)
4880 (A B)
4881 (A B C)
4882 (A B C D)
4883 (A B C D E)
4884 (A B C D E F)
4885 (A B C D E F G)
4886 (A B C D E F G H)
4887}
4888
4889impl<F: JsFunction> Function<F> {
4890 /// Convert a borrowed `ScopedClosure` into a typed JavaScript Function reference.
4891 ///
4892 /// The conversion is a direct type-safe conversion and upcast of a
4893 /// closure into its corresponding typed JavaScript Function,
4894 /// based on covariance and contravariance [`Upcast`] trait hierarchy.
4895 ///
4896 /// For transferring ownership to JS, use [`Function::from_closure`].
4897 #[inline]
4898 pub fn closure_ref<'a, C>(closure: &'a ScopedClosure<'_, C>) -> &'a Self
4899 where
4900 F: FunctionIntoClosure,
4901 C: WasmClosure + ?Sized,
4902 <F as FunctionIntoClosure>::ClosureTypeMut: UpcastFrom<<C as WasmClosure>::AsMut>,
4903 {
4904 closure.as_js_value().unchecked_ref()
4905 }
4906
4907 /// Convert a Rust closure into a typed JavaScript Function.
4908 ///
4909 /// This function releases ownership of the closure to JS, and provides
4910 /// an owned function handle for the same closure.
4911 ///
4912 /// The conversion is a direct type-safe conversion and upcast of a
4913 /// closure into its corresponding typed JavaScript Function,
4914 /// based on covariance and contravariance [`Upcast`] trait hierarchy.
4915 ///
4916 /// This method is only supported for static closures which do not have
4917 /// borrowed lifetime data, and thus can be released into JS.
4918 ///
4919 /// For borrowed closures, which cannot cede ownership to JS,
4920 /// instead use [`Function::closure_ref`].
4921 #[inline]
4922 pub fn from_closure<C>(closure: ScopedClosure<'static, C>) -> Self
4923 where
4924 F: FunctionIntoClosure,
4925 C: WasmClosure + ?Sized,
4926 <F as FunctionIntoClosure>::ClosureTypeMut: UpcastFrom<<C as WasmClosure>::AsMut>,
4927 {
4928 closure.into_js_value().unchecked_into()
4929 }
4930}
4931
4932#[cfg(not(js_sys_unstable_apis))]
4933impl Function {
4934 /// Returns the `Function` value of this JS value if it's an instance of a
4935 /// function.
4936 ///
4937 /// If this JS value is not an instance of a function then this returns
4938 /// `None`.
4939 #[deprecated(note = "recommended to use dyn_ref instead which is now equivalent")]
4940 pub fn try_from(val: &JsValue) -> Option<&Function> {
4941 val.dyn_ref()
4942 }
4943}
4944
4945#[cfg(feature = "unsafe-eval")]
4946impl Default for Function {
4947 fn default() -> Self {
4948 Self::new_no_args("")
4949 }
4950}
4951
4952// FinalizationRegistry
4953#[wasm_bindgen]
4954extern "C" {
4955 /// The `FinalizationRegistry` object lets you request a callback when an
4956 /// object is garbage-collected.
4957 ///
4958 /// `FinalizationRegistry` provides a way to request that a cleanup
4959 /// callback get called at some point when an object registered with the
4960 /// registry has been reclaimed (garbage-collected). Cleanup callbacks
4961 /// are sometimes called *finalizers*.
4962 ///
4963 /// Avoid where possible: cleanup callbacks should not be relied upon for
4964 /// anything essential. They are best used to reduce memory usage over the
4965 /// course of a program for objects that benefit from cleanup. Whether,
4966 /// when, and in what order callbacks fire is implementation-defined.
4967 ///
4968 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/FinalizationRegistry)
4969 #[wasm_bindgen(extends = Object, typescript_type = "FinalizationRegistry<any>")]
4970 #[derive(Clone, Debug, PartialEq, Eq)]
4971 pub type FinalizationRegistry;
4972
4973 /// Creates a new `FinalizationRegistry` with the given cleanup callback.
4974 ///
4975 /// The cleanup callback is invoked, at some point after a registered
4976 /// target is garbage-collected, with the `held_value` that was passed to
4977 /// [`FinalizationRegistry::register`]. Because callbacks may be deferred
4978 /// or skipped entirely, the callback should normally outlive the
4979 /// `FinalizationRegistry` (for example by being created via
4980 /// [`Function::from_closure`]).
4981 ///
4982 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/FinalizationRegistry/FinalizationRegistry)
4983 #[wasm_bindgen(constructor)]
4984 pub fn new(cleanup_callback: &Function<fn(JsValue) -> Undefined>) -> FinalizationRegistry;
4985
4986 /// Registers `target` with this `FinalizationRegistry`. When `target` is
4987 /// reclaimed by the garbage collector the cleanup callback may be called
4988 /// with `held_value`.
4989 ///
4990 /// `target` must be an object (or a non-registered symbol).
4991 ///
4992 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/FinalizationRegistry/register)
4993 #[wasm_bindgen(method)]
4994 pub fn register(this: &FinalizationRegistry, target: &JsValue, held_value: &JsValue);
4995
4996 /// Registers `target` with this `FinalizationRegistry`, with an
4997 /// `unregister_token` that can later be passed to
4998 /// [`FinalizationRegistry::unregister`] to remove the registration.
4999 ///
5000 /// `target` and `unregister_token` must be objects (or non-registered
5001 /// symbols), and the same value may be passed for both.
5002 ///
5003 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/FinalizationRegistry/register)
5004 #[wasm_bindgen(method, js_name = register)]
5005 pub fn register_with_token(
5006 this: &FinalizationRegistry,
5007 target: &JsValue,
5008 held_value: &JsValue,
5009 unregister_token: &JsValue,
5010 );
5011
5012 /// Unregisters all entries registered with this `FinalizationRegistry`
5013 /// using `unregister_token`. Returns `true` if any cells were removed.
5014 ///
5015 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/FinalizationRegistry/unregister)
5016 #[wasm_bindgen(method)]
5017 pub fn unregister(this: &FinalizationRegistry, unregister_token: &JsValue) -> bool;
5018}
5019
5020// Generator
5021#[wasm_bindgen]
5022extern "C" {
5023 #[wasm_bindgen(extends = Object, typescript_type = "Generator<any, any, any>")]
5024 #[derive(Clone, Debug, PartialEq, Eq)]
5025 pub type Generator<T = JsValue>;
5026
5027 /// The `next()` method returns an object with two properties done and value.
5028 /// You can also provide a parameter to the next method to send a value to the generator.
5029 ///
5030 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/next)
5031 #[cfg(not(js_sys_unstable_apis))]
5032 #[wasm_bindgen(method, catch)]
5033 pub fn next<T>(this: &Generator<T>, value: &T) -> Result<JsValue, JsValue>;
5034
5035 /// The `next()` method returns an object with two properties done and value.
5036 /// You can also provide a parameter to the next method to send a value to the generator.
5037 ///
5038 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/next)
5039 #[cfg(js_sys_unstable_apis)]
5040 #[wasm_bindgen(method, catch, js_name = next)]
5041 pub fn next<T: FromWasmAbi>(this: &Generator<T>, value: &T)
5042 -> Result<IteratorNext<T>, JsValue>;
5043
5044 // Next major: deprecate
5045 /// The `next()` method returns an object with two properties done and value.
5046 /// You can also provide a parameter to the next method to send a value to the generator.
5047 ///
5048 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/next)
5049 #[wasm_bindgen(method, catch)]
5050 pub fn next_iterator<T: FromWasmAbi>(
5051 this: &Generator<T>,
5052 value: &T,
5053 ) -> Result<IteratorNext<T>, JsValue>;
5054
5055 /// The `return()` method returns the given value and finishes the generator.
5056 ///
5057 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/return)
5058 #[cfg(not(js_sys_unstable_apis))]
5059 #[wasm_bindgen(method, js_name = "return")]
5060 pub fn return_<T>(this: &Generator<T>, value: &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(js_sys_unstable_apis)]
5066 #[wasm_bindgen(method, catch, js_name = "return")]
5067 pub fn return_<T: FromWasmAbi>(
5068 this: &Generator<T>,
5069 value: &T,
5070 ) -> Result<IteratorNext<T>, JsValue>;
5071
5072 // Next major: deprecate
5073 /// The `return()` method returns the given value and finishes the generator.
5074 ///
5075 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/return)
5076 #[wasm_bindgen(method, catch, js_name = "return")]
5077 pub fn try_return<T: FromWasmAbi>(
5078 this: &Generator<T>,
5079 value: &T,
5080 ) -> Result<IteratorNext<T>, JsValue>;
5081
5082 /// The `throw()` method resumes the execution of a generator by throwing an error into it
5083 /// and returns an object with two properties done and value.
5084 ///
5085 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/throw)
5086 #[cfg(not(js_sys_unstable_apis))]
5087 #[wasm_bindgen(method, catch)]
5088 pub fn throw<T>(this: &Generator<T>, error: &Error) -> Result<JsValue, JsValue>;
5089
5090 /// The `throw()` method resumes the execution of a generator by throwing an error into it
5091 /// and returns an object with two properties done and value.
5092 ///
5093 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/throw)
5094 #[cfg(js_sys_unstable_apis)]
5095 #[wasm_bindgen(method, catch, js_name = throw)]
5096 pub fn throw<T: FromWasmAbi>(
5097 this: &Generator<T>,
5098 error: &JsValue,
5099 ) -> Result<IteratorNext<T>, JsValue>;
5100
5101 // Next major: deprecate
5102 /// The `throw()` method resumes the execution of a generator by throwing an error into it
5103 /// and returns an object with two properties done and value.
5104 ///
5105 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/throw)
5106 #[wasm_bindgen(method, catch, js_name = throw)]
5107 pub fn throw_value<T: FromWasmAbi>(
5108 this: &Generator<T>,
5109 error: &JsValue,
5110 ) -> Result<IteratorNext<T>, JsValue>;
5111}
5112
5113impl<T: FromWasmAbi> Iterable for Generator<T> {
5114 type Item = T;
5115}
5116
5117// AsyncGenerator
5118#[wasm_bindgen]
5119extern "C" {
5120 #[wasm_bindgen(extends = Object, typescript_type = "AsyncGenerator<any, any, any>")]
5121 #[derive(Clone, Debug, PartialEq, Eq)]
5122 pub type AsyncGenerator<T = JsValue>;
5123
5124 /// The `next()` method returns an object with two properties done and value.
5125 /// You can also provide a parameter to the next method to send a value to the generator.
5126 ///
5127 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncGenerator/next)
5128 #[wasm_bindgen(method, catch)]
5129 pub fn next<T>(
5130 this: &AsyncGenerator<T>,
5131 value: &T,
5132 ) -> Result<Promise<IteratorNext<T>>, JsValue>;
5133
5134 /// The `return()` method returns the given value and finishes the generator.
5135 ///
5136 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncGenerator/return)
5137 #[wasm_bindgen(method, js_name = "return", catch)]
5138 pub fn return_<T>(
5139 this: &AsyncGenerator<T>,
5140 value: &T,
5141 ) -> Result<Promise<IteratorNext<T>>, JsValue>;
5142
5143 /// The `throw()` method resumes the execution of a generator by throwing an error into it
5144 /// and returns an object with two properties done and value.
5145 ///
5146 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncGenerator/throw)
5147 #[wasm_bindgen(method, catch)]
5148 pub fn throw<T>(
5149 this: &AsyncGenerator<T>,
5150 error: &JsValue,
5151 ) -> Result<Promise<IteratorNext<T>>, JsValue>;
5152}
5153
5154impl<T: FromWasmAbi> AsyncIterable for AsyncGenerator<T> {
5155 type Item = T;
5156}
5157
5158// Map
5159#[wasm_bindgen]
5160extern "C" {
5161 #[wasm_bindgen(extends = Object, typescript_type = "Map<any, any>")]
5162 #[derive(Clone, Debug, PartialEq, Eq)]
5163 pub type Map<K = JsValue, V = JsValue>;
5164
5165 /// The Map object holds key-value pairs. Any value (both objects and
5166 /// primitive values) maybe used as either a key or a value.
5167 ///
5168 /// **Note:** Consider using [`Map::new_typed`] for typing support.
5169 ///
5170 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)
5171 #[cfg(not(js_sys_unstable_apis))]
5172 #[wasm_bindgen(constructor)]
5173 pub fn new() -> Map;
5174
5175 /// The Map object holds key-value pairs. Any value (both objects and
5176 /// primitive values) maybe used as either a key or a value.
5177 ///
5178 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)
5179 #[cfg(js_sys_unstable_apis)]
5180 #[wasm_bindgen(constructor)]
5181 pub fn new<K, V>() -> Map<K, V>;
5182
5183 // Next major: deprecate
5184 /// The Map object holds key-value pairs. Any value (both objects and
5185 /// primitive values) maybe used as either a key or a value.
5186 ///
5187 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)
5188 #[wasm_bindgen(constructor)]
5189 pub fn new_typed<K, V>() -> Map<K, V>;
5190
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, js_name = new)]
5196 pub fn new_from_entries<K, V, I: Iterable<Item = ArrayTuple<(K, V)>>>(entries: &I)
5197 -> Map<K, V>;
5198
5199 /// The `clear()` method removes all elements from a Map object.
5200 ///
5201 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/clear)
5202 #[wasm_bindgen(method)]
5203 pub fn clear<K, V>(this: &Map<K, V>);
5204
5205 /// The `delete()` method removes the specified element from a Map object.
5206 ///
5207 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/delete)
5208 #[wasm_bindgen(method)]
5209 pub fn delete<K, V>(this: &Map<K, V>, key: &K) -> bool;
5210
5211 /// The `forEach()` method executes a provided function once per each
5212 /// key/value pair in the Map object, in insertion order.
5213 /// Note that in Javascript land the `Key` and `Value` are reversed compared to normal expectations:
5214 /// # Examples
5215 /// ```
5216 /// let js_map = Map::new();
5217 /// js_map.for_each(&mut |value, key| {
5218 /// // Do something here...
5219 /// })
5220 /// ```
5221 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/forEach)
5222 #[wasm_bindgen(method, js_name = forEach)]
5223 pub fn for_each<K, V>(this: &Map<K, V>, callback: &mut dyn FnMut(V, K));
5224
5225 /// The `forEach()` method executes a provided function once per each
5226 /// key/value pair in the Map object, in insertion order. _(Fallible variation)_
5227 /// Note that in Javascript land the `Key` and `Value` are reversed compared to normal expectations:
5228 /// # Examples
5229 /// ```
5230 /// let js_map = Map::new();
5231 /// js_map.for_each(&mut |value, key| {
5232 /// // Do something here...
5233 /// })
5234 /// ```
5235 ///
5236 /// **Note:** Consider using [`Map::try_for_each`] if the callback might throw an error.
5237 ///
5238 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/forEach)
5239 #[wasm_bindgen(method, js_name = forEach, catch)]
5240 pub fn try_for_each<K, V>(
5241 this: &Map<K, V>,
5242 callback: &mut dyn FnMut(V, K) -> Result<(), JsError>,
5243 ) -> Result<(), JsValue>;
5244
5245 /// The `get()` method returns a specified element from a Map object.
5246 /// Returns `undefined` if the key is not found.
5247 ///
5248 /// **Note:** Consider using [`Map::get_checked`] to get an `Option<V>` instead.
5249 ///
5250 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get)
5251 #[cfg(not(js_sys_unstable_apis))]
5252 #[wasm_bindgen(method)]
5253 pub fn get<K, V>(this: &Map<K, V>, key: &K) -> V;
5254
5255 /// The `get()` method returns a specified element from a Map object.
5256 /// Returns `None` if the key is not found.
5257 ///
5258 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get)
5259 #[cfg(js_sys_unstable_apis)]
5260 #[wasm_bindgen(method)]
5261 pub fn get<K, V>(this: &Map<K, V>, key: &K) -> Option<V>;
5262
5263 /// The `get()` method returns a specified element from a Map object.
5264 /// Returns `None` if the key is not found.
5265 ///
5266 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get)
5267 #[wasm_bindgen(method, js_name = get)]
5268 pub fn get_checked<K, V>(this: &Map<K, V>, key: &K) -> Option<V>;
5269
5270 /// The `has()` method returns a boolean indicating whether an element with
5271 /// the specified key exists or not.
5272 ///
5273 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/has)
5274 #[wasm_bindgen(method)]
5275 pub fn has<K, V>(this: &Map<K, V>, key: &K) -> bool;
5276
5277 /// The `set()` method adds or updates an element with a specified key
5278 /// and value to a Map object.
5279 ///
5280 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/set)
5281 #[wasm_bindgen(method)]
5282 pub fn set<K, V>(this: &Map<K, V>, key: &K, value: &V) -> Map<K, V>;
5283
5284 /// The value of size is an integer representing how many entries
5285 /// the Map object has. A set accessor function for size is undefined;
5286 /// you can not change this property.
5287 ///
5288 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/size)
5289 #[wasm_bindgen(method, getter)]
5290 pub fn size<K, V>(this: &Map<K, V>) -> u32;
5291}
5292
5293impl Default for Map<JsValue, JsValue> {
5294 fn default() -> Self {
5295 Self::new()
5296 }
5297}
5298
5299// Map Iterator
5300#[wasm_bindgen]
5301extern "C" {
5302 /// The `entries()` method returns a new Iterator object that contains
5303 /// the [key, value] pairs for each element in the Map object in
5304 /// insertion order.
5305 ///
5306 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries)
5307 #[cfg(not(js_sys_unstable_apis))]
5308 #[wasm_bindgen(method)]
5309 pub fn entries<K, V: FromWasmAbi>(this: &Map<K, V>) -> Iterator;
5310
5311 /// The `entries()` method returns a new Iterator object that contains
5312 /// the [key, value] pairs for each element in the Map object in
5313 /// insertion order.
5314 ///
5315 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries)
5316 #[cfg(js_sys_unstable_apis)]
5317 #[wasm_bindgen(method, js_name = entries)]
5318 pub fn entries<K: JsGeneric, V: FromWasmAbi + JsGeneric>(
5319 this: &Map<K, V>,
5320 ) -> Iterator<ArrayTuple<(K, V)>>;
5321
5322 // Next major: deprecate
5323 /// The `entries()` method returns a new Iterator object that contains
5324 /// the [key, value] pairs for each element in the Map object in
5325 /// insertion order.
5326 ///
5327 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries)
5328 #[wasm_bindgen(method, js_name = entries)]
5329 pub fn entries_typed<K: JsGeneric, V: FromWasmAbi + JsGeneric>(
5330 this: &Map<K, V>,
5331 ) -> Iterator<ArrayTuple<(K, V)>>;
5332
5333 /// The `keys()` method returns a new Iterator object that contains the
5334 /// keys for each element in the Map object in insertion order.
5335 ///
5336 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/keys)
5337 #[wasm_bindgen(method)]
5338 pub fn keys<K: FromWasmAbi, V: FromWasmAbi>(this: &Map<K, V>) -> Iterator<K>;
5339
5340 /// The `values()` method returns a new Iterator object that contains the
5341 /// values 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/values)
5344 #[wasm_bindgen(method)]
5345 pub fn values<K, V: FromWasmAbi>(this: &Map<K, V>) -> Iterator<V>;
5346}
5347
5348impl<K, V> Iterable for Map<K, V> {
5349 type Item = ArrayTuple<(K, V)>;
5350}
5351
5352// Iterator
5353#[wasm_bindgen]
5354extern "C" {
5355 /// Any object that conforms to the JS iterator protocol. For example,
5356 /// something returned by `myArray[Symbol.iterator]()`.
5357 ///
5358 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols)
5359 #[derive(Clone, Debug)]
5360 #[wasm_bindgen(is_type_of = Iterator::looks_like_iterator, typescript_type = "Iterator<any>")]
5361 pub type Iterator<T = JsValue>;
5362
5363 /// The `next()` method always has to return an object with appropriate
5364 /// properties including done and value. If a non-object value gets returned
5365 /// (such as false or undefined), a TypeError ("iterator.next() returned a
5366 /// non-object value") will be thrown.
5367 #[wasm_bindgen(catch, method)]
5368 pub fn next<T: FromWasmAbi>(this: &Iterator<T>) -> Result<IteratorNext<T>, JsValue>;
5369}
5370
5371impl<T> UpcastFrom<Iterator<T>> for Object {}
5372
5373impl Iterator {
5374 fn looks_like_iterator(it: &JsValue) -> bool {
5375 #[wasm_bindgen]
5376 extern "C" {
5377 #[derive(Clone, Debug)]
5378 type MaybeIterator;
5379
5380 #[wasm_bindgen(method, getter)]
5381 fn next(this: &MaybeIterator) -> JsValue;
5382 }
5383
5384 if !it.is_object() {
5385 return false;
5386 }
5387
5388 let it = it.unchecked_ref::<MaybeIterator>();
5389
5390 it.next().is_function()
5391 }
5392}
5393
5394// iterators in JS are themselves iterable
5395impl<T> Iterable for Iterator<T> {
5396 type Item = T;
5397}
5398
5399// Async Iterator
5400#[wasm_bindgen]
5401extern "C" {
5402 /// Any object that conforms to the JS async iterator protocol. For example,
5403 /// something returned by `myObject[Symbol.asyncIterator]()`.
5404 ///
5405 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of)
5406 #[derive(Clone, Debug)]
5407 #[wasm_bindgen(is_type_of = Iterator::looks_like_iterator, typescript_type = "AsyncIterator<any>")]
5408 pub type AsyncIterator<T = JsValue>;
5409
5410 /// The `next()` method always has to return a Promise which resolves to an object
5411 /// with appropriate properties including done and value. If a non-object value
5412 /// gets returned (such as false or undefined), a TypeError ("iterator.next()
5413 /// returned a non-object value") will be thrown.
5414 #[cfg(not(js_sys_unstable_apis))]
5415 #[wasm_bindgen(catch, method)]
5416 pub fn next<T>(this: &AsyncIterator<T>) -> Result<Promise, JsValue>;
5417
5418 /// The `next()` method always has to return a Promise which resolves to an object
5419 /// with appropriate properties including done and value. If a non-object value
5420 /// gets returned (such as false or undefined), a TypeError ("iterator.next()
5421 /// returned a non-object value") will be thrown.
5422 #[cfg(js_sys_unstable_apis)]
5423 #[wasm_bindgen(catch, method, js_name = next)]
5424 pub fn next<T: FromWasmAbi>(
5425 this: &AsyncIterator<T>,
5426 ) -> Result<Promise<IteratorNext<T>>, JsValue>;
5427
5428 // Next major: deprecate
5429 /// The `next()` method always has to return a Promise which resolves to an object
5430 /// with appropriate properties including done and value. If a non-object value
5431 /// gets returned (such as false or undefined), a TypeError ("iterator.next()
5432 /// returned a non-object value") will be thrown.
5433 #[wasm_bindgen(catch, method, js_name = next)]
5434 pub fn next_iterator<T: FromWasmAbi>(
5435 this: &AsyncIterator<T>,
5436 ) -> Result<Promise<IteratorNext<T>>, JsValue>;
5437}
5438
5439impl<T> UpcastFrom<AsyncIterator<T>> for Object {}
5440
5441// iterators in JS are themselves iterable
5442impl<T> AsyncIterable for AsyncIterator<T> {
5443 type Item = T;
5444}
5445
5446/// An iterator over the JS `Symbol.iterator` iteration protocol.
5447///
5448/// Use the `IntoIterator for &js_sys::Iterator` implementation to create this.
5449pub struct Iter<'a, T = JsValue> {
5450 js: &'a Iterator<T>,
5451 state: IterState,
5452}
5453
5454/// An iterator over the JS `Symbol.iterator` iteration protocol.
5455///
5456/// Use the `IntoIterator for js_sys::Iterator` implementation to create this.
5457pub struct IntoIter<T = JsValue> {
5458 js: Iterator<T>,
5459 state: IterState,
5460}
5461
5462struct IterState {
5463 done: bool,
5464}
5465
5466impl<'a, T: FromWasmAbi + JsGeneric> IntoIterator for &'a Iterator<T> {
5467 type Item = Result<T, JsValue>;
5468 type IntoIter = Iter<'a, T>;
5469
5470 fn into_iter(self) -> Iter<'a, T> {
5471 Iter {
5472 js: self,
5473 state: IterState::new(),
5474 }
5475 }
5476}
5477
5478impl<T: FromWasmAbi + JsGeneric> core::iter::Iterator for Iter<'_, T> {
5479 type Item = Result<T, JsValue>;
5480
5481 fn next(&mut self) -> Option<Self::Item> {
5482 self.state.next(self.js)
5483 }
5484}
5485
5486impl<T: FromWasmAbi + JsGeneric> IntoIterator for Iterator<T> {
5487 type Item = Result<T, JsValue>;
5488 type IntoIter = IntoIter<T>;
5489
5490 fn into_iter(self) -> IntoIter<T> {
5491 IntoIter {
5492 js: self,
5493 state: IterState::new(),
5494 }
5495 }
5496}
5497
5498impl<T: FromWasmAbi + JsGeneric> core::iter::Iterator for IntoIter<T> {
5499 type Item = Result<T, JsValue>;
5500
5501 fn next(&mut self) -> Option<Self::Item> {
5502 self.state.next(&self.js)
5503 }
5504}
5505
5506impl IterState {
5507 fn new() -> IterState {
5508 IterState { done: false }
5509 }
5510
5511 fn next<T: FromWasmAbi + JsGeneric>(&mut self, js: &Iterator<T>) -> Option<Result<T, JsValue>> {
5512 if self.done {
5513 return None;
5514 }
5515 let next = match js.next() {
5516 Ok(val) => val,
5517 Err(e) => {
5518 self.done = true;
5519 return Some(Err(e));
5520 }
5521 };
5522 if next.done() {
5523 self.done = true;
5524 None
5525 } else {
5526 Some(Ok(next.value()))
5527 }
5528 }
5529}
5530
5531/// Create an iterator over `val` using the JS iteration protocol and
5532/// `Symbol.iterator`.
5533// #[cfg(not(js_sys_unstable_apis))]
5534pub fn try_iter(val: &JsValue) -> Result<Option<IntoIter<JsValue>>, JsValue> {
5535 let iter_sym = Symbol::iterator();
5536
5537 let iter_fn = Reflect::get_symbol::<Object>(val.unchecked_ref(), iter_sym.as_ref())?;
5538 let iter_fn: Function = match iter_fn.dyn_into() {
5539 Ok(iter_fn) => iter_fn,
5540 Err(_) => return Ok(None),
5541 };
5542
5543 let it: Iterator = match iter_fn.call0(val)?.dyn_into() {
5544 Ok(it) => it,
5545 Err(_) => return Ok(None),
5546 };
5547
5548 Ok(Some(it.into_iter()))
5549}
5550
5551/// Trait for JavaScript types that implement the iterable protocol via `Symbol.iterator`.
5552///
5553/// Types implementing this trait can be iterated over using JavaScript's iteration
5554/// protocol. The `Item` associated type specifies the type of values yielded.
5555///
5556/// ## Built-in Iterables
5557///
5558/// Many `js-sys` collection types implement `Iterable` out of the box:
5559///
5560/// ```ignore
5561/// use js_sys::{Array, Map, Set};
5562///
5563/// // Array<T> yields T
5564/// let arr: Array<Number> = get_numbers();
5565/// for value in arr.iter() {
5566/// let num: Number = value?;
5567/// }
5568///
5569/// // Map<K, V> yields Array (key-value pairs)
5570/// let map: Map<JsString, Number> = get_map();
5571/// for entry in map.iter() {
5572/// let pair: Array = entry?;
5573/// }
5574///
5575/// // Set<T> yields T
5576/// let set: Set<JsString> = get_set();
5577/// for value in set.iter() {
5578/// let s: JsString = value?;
5579/// }
5580/// ```
5581///
5582/// ## Typing Foreign Iterators
5583///
5584/// If you have a JavaScript value that implements the iterator protocol (has a `next()`
5585/// method) but isn't a built-in type, you can use [`JsCast`] to cast it to [`Iterator<T>`]:
5586///
5587/// ```ignore
5588/// use js_sys::Iterator;
5589/// use wasm_bindgen::JsCast;
5590///
5591/// // For a value you know implements the iterator protocol
5592/// fn process_iterator(js_iter: JsValue) {
5593/// // Checked cast - returns None if not an iterator
5594/// if let Some(iter) = js_iter.dyn_ref::<Iterator<Number>>() {
5595/// for value in iter.into_iter() {
5596/// let num: Number = value.unwrap();
5597/// // ...
5598/// }
5599/// }
5600/// }
5601///
5602/// // Or with unchecked cast when you're certain of the type
5603/// fn process_known_iterator(js_iter: JsValue) {
5604/// let iter: &Iterator<JsString> = js_iter.unchecked_ref();
5605/// for value in iter.into_iter() {
5606/// let s: JsString = value.unwrap();
5607/// // ...
5608/// }
5609/// }
5610/// ```
5611///
5612/// ## Using with `JsValue`
5613///
5614/// For dynamic or unknown iterables, use [`try_iter`] which returns an untyped iterator:
5615///
5616/// ```ignore
5617/// fn iterate_unknown(val: &JsValue) -> Result<(), JsValue> {
5618/// if let Some(iter) = js_sys::try_iter(val)? {
5619/// for item in iter {
5620/// let value: JsValue = item?;
5621/// // Handle dynamically...
5622/// }
5623/// }
5624/// Ok(())
5625/// }
5626/// ```
5627///
5628/// [`JsCast`]: wasm_bindgen::JsCast
5629/// [`Iterator<T>`]: Iterator
5630/// [`try_iter`]: crate::try_iter
5631pub trait Iterable {
5632 /// The type of values yielded by this iterable.
5633 type Item;
5634}
5635
5636impl<T: Iterable> Iterable for &T {
5637 type Item = T::Item;
5638}
5639
5640/// Trait for types known to implement the iterator protocol on Symbol.asyncIterator
5641pub trait AsyncIterable {
5642 type Item;
5643}
5644
5645impl<T: AsyncIterable> AsyncIterable for &T {
5646 type Item = T::Item;
5647}
5648
5649impl AsyncIterable for JsValue {
5650 type Item = JsValue;
5651}
5652
5653// IteratorNext
5654#[wasm_bindgen]
5655extern "C" {
5656 /// The result of calling `next()` on a JS iterator.
5657 ///
5658 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols)
5659 #[wasm_bindgen(extends = Object, typescript_type = "IteratorResult<any>")]
5660 #[derive(Clone, Debug, PartialEq, Eq)]
5661 pub type IteratorNext<T = JsValue>;
5662
5663 /// Has the value `true` if the iterator is past the end of the iterated
5664 /// sequence. In this case value optionally specifies the return value of
5665 /// the iterator.
5666 ///
5667 /// Has the value `false` if the iterator was able to produce the next value
5668 /// in the sequence. This is equivalent of not specifying the done property
5669 /// altogether.
5670 #[wasm_bindgen(method, getter)]
5671 pub fn done<T>(this: &IteratorNext<T>) -> bool;
5672
5673 /// Any JavaScript value returned by the iterator. Can be omitted when done
5674 /// is true.
5675 #[wasm_bindgen(method, getter)]
5676 pub fn value<T>(this: &IteratorNext<T>) -> T;
5677}
5678
5679#[allow(non_snake_case)]
5680pub mod Math {
5681 use super::*;
5682
5683 // Math
5684 #[wasm_bindgen]
5685 extern "C" {
5686 /// The `Math.abs()` function returns the absolute value of a number, that is
5687 /// Math.abs(x) = |x|
5688 ///
5689 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/abs)
5690 #[wasm_bindgen(js_namespace = Math)]
5691 pub fn abs(x: f64) -> f64;
5692
5693 /// The `Math.acos()` function returns the arccosine (in radians) of a
5694 /// number, that is ∀x∊[-1;1]
5695 /// Math.acos(x) = arccos(x) = the unique y∊[0;π] such that cos(y)=x
5696 ///
5697 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/acos)
5698 #[wasm_bindgen(js_namespace = Math)]
5699 pub fn acos(x: f64) -> f64;
5700
5701 /// The `Math.acosh()` function returns the hyperbolic arc-cosine of a
5702 /// number, that is ∀x ≥ 1
5703 /// Math.acosh(x) = arcosh(x) = the unique y ≥ 0 such that cosh(y) = x
5704 ///
5705 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/acosh)
5706 #[wasm_bindgen(js_namespace = Math)]
5707 pub fn acosh(x: f64) -> f64;
5708
5709 /// The `Math.asin()` function returns the arcsine (in radians) of a
5710 /// number, that is ∀x ∊ [-1;1]
5711 /// Math.asin(x) = arcsin(x) = the unique y∊[-π2;π2] such that sin(y) = x
5712 ///
5713 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/asin)
5714 #[wasm_bindgen(js_namespace = Math)]
5715 pub fn asin(x: f64) -> f64;
5716
5717 /// The `Math.asinh()` function returns the hyperbolic arcsine of a
5718 /// number, that is Math.asinh(x) = arsinh(x) = the unique y such that sinh(y) = x
5719 ///
5720 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/asinh)
5721 #[wasm_bindgen(js_namespace = Math)]
5722 pub fn asinh(x: f64) -> f64;
5723
5724 /// The `Math.atan()` function returns the arctangent (in radians) of a
5725 /// number, that is Math.atan(x) = arctan(x) = the unique y ∊ [-π2;π2]such that
5726 /// tan(y) = x
5727 #[wasm_bindgen(js_namespace = Math)]
5728 pub fn atan(x: f64) -> f64;
5729
5730 /// The `Math.atan2()` function returns the arctangent of the quotient of
5731 /// its arguments.
5732 ///
5733 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/atan2)
5734 #[wasm_bindgen(js_namespace = Math)]
5735 pub fn atan2(y: f64, x: f64) -> f64;
5736
5737 /// The `Math.atanh()` function returns the hyperbolic arctangent of a number,
5738 /// that is ∀x ∊ (-1,1), Math.atanh(x) = arctanh(x) = the unique y such that
5739 /// tanh(y) = x
5740 ///
5741 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/atanh)
5742 #[wasm_bindgen(js_namespace = Math)]
5743 pub fn atanh(x: f64) -> f64;
5744
5745 /// The `Math.cbrt() `function returns the cube root of a number, that is
5746 /// Math.cbrt(x) = ∛x = the unique y such that y^3 = x
5747 ///
5748 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/cbrt)
5749 #[wasm_bindgen(js_namespace = Math)]
5750 pub fn cbrt(x: f64) -> f64;
5751
5752 /// The `Math.ceil()` function returns the smallest integer greater than
5753 /// or equal to a given number.
5754 ///
5755 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/ceil)
5756 #[wasm_bindgen(js_namespace = Math)]
5757 pub fn ceil(x: f64) -> f64;
5758
5759 /// The `Math.clz32()` function returns the number of leading zero bits in
5760 /// the 32-bit binary representation of a number.
5761 ///
5762 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/clz32)
5763 #[wasm_bindgen(js_namespace = Math)]
5764 pub fn clz32(x: i32) -> u32;
5765
5766 /// The `Math.cos()` static function returns the cosine of the specified angle,
5767 /// which must be specified in radians. This value is length(adjacent)/length(hypotenuse).
5768 ///
5769 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/cos)
5770 #[wasm_bindgen(js_namespace = Math)]
5771 pub fn cos(x: f64) -> f64;
5772
5773 /// The `Math.cosh()` function returns the hyperbolic cosine of a number,
5774 /// that can be expressed using the constant e.
5775 ///
5776 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/cosh)
5777 #[wasm_bindgen(js_namespace = Math)]
5778 pub fn cosh(x: f64) -> f64;
5779
5780 /// The `Math.exp()` function returns e^x, where x is the argument, and e is Euler's number
5781 /// (also known as Napier's constant), the base of the natural logarithms.
5782 ///
5783 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/exp)
5784 #[wasm_bindgen(js_namespace = Math)]
5785 pub fn exp(x: f64) -> f64;
5786
5787 /// The `Math.expm1()` function returns e^x - 1, where x is the argument, and e the base of the
5788 /// natural logarithms.
5789 ///
5790 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/expm1)
5791 #[wasm_bindgen(js_namespace = Math)]
5792 pub fn expm1(x: f64) -> f64;
5793
5794 /// The `Math.floor()` function returns the largest integer less than or
5795 /// equal to a given number.
5796 ///
5797 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/floor)
5798 #[wasm_bindgen(js_namespace = Math)]
5799 pub fn floor(x: f64) -> f64;
5800
5801 /// The `Math.fround()` function returns the nearest 32-bit single precision float representation
5802 /// of a Number.
5803 ///
5804 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/fround)
5805 #[wasm_bindgen(js_namespace = Math)]
5806 pub fn fround(x: f64) -> f32;
5807
5808 /// The `Math.hypot()` function returns the square root of the sum of squares of its arguments.
5809 ///
5810 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/hypot)
5811 #[wasm_bindgen(js_namespace = Math)]
5812 pub fn hypot(x: f64, y: f64) -> f64;
5813
5814 /// The `Math.imul()` function returns the result of the C-like 32-bit multiplication of the
5815 /// two parameters.
5816 ///
5817 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/imul)
5818 #[wasm_bindgen(js_namespace = Math)]
5819 pub fn imul(x: i32, y: i32) -> i32;
5820
5821 /// The `Math.log()` function returns the natural logarithm (base e) of a number.
5822 /// The JavaScript `Math.log()` function is equivalent to ln(x) in mathematics.
5823 ///
5824 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log)
5825 #[wasm_bindgen(js_namespace = Math)]
5826 pub fn log(x: f64) -> f64;
5827
5828 /// The `Math.log10()` function returns the base 10 logarithm of a number.
5829 ///
5830 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log10)
5831 #[wasm_bindgen(js_namespace = Math)]
5832 pub fn log10(x: f64) -> f64;
5833
5834 /// The `Math.log1p()` function returns the natural logarithm (base e) of 1 + a number.
5835 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log1p)
5836 #[wasm_bindgen(js_namespace = Math)]
5837 pub fn log1p(x: f64) -> f64;
5838
5839 /// The `Math.log2()` function returns the base 2 logarithm of a number.
5840 ///
5841 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log2)
5842 #[wasm_bindgen(js_namespace = Math)]
5843 pub fn log2(x: f64) -> f64;
5844
5845 /// The `Math.max()` function returns the largest of two numbers.
5846 ///
5847 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/max)
5848 #[wasm_bindgen(js_namespace = Math)]
5849 pub fn max(x: f64, y: f64) -> f64;
5850
5851 /// The static function `Math.min()` returns the lowest-valued number passed into it.
5852 ///
5853 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/min)
5854 #[wasm_bindgen(js_namespace = Math)]
5855 pub fn min(x: f64, y: f64) -> f64;
5856
5857 /// The `Math.pow()` function returns the base to the exponent power, that is, base^exponent.
5858 ///
5859 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/pow)
5860 #[wasm_bindgen(js_namespace = Math)]
5861 pub fn pow(base: f64, exponent: f64) -> f64;
5862
5863 /// The `Math.random()` function returns a floating-point, pseudo-random number
5864 /// in the range 0–1 (inclusive of 0, but not 1) with approximately uniform distribution
5865 /// over that range — which you can then scale to your desired range.
5866 /// The implementation selects the initial seed to the random number generation algorithm;
5867 /// it cannot be chosen or reset by the user.
5868 ///
5869 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random)
5870 #[wasm_bindgen(js_namespace = Math)]
5871 pub fn random() -> f64;
5872
5873 /// The `Math.round()` function returns the value of a number rounded to the nearest integer.
5874 ///
5875 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round)
5876 #[wasm_bindgen(js_namespace = Math)]
5877 pub fn round(x: f64) -> f64;
5878
5879 /// The `Math.sign()` function returns the sign of a number, indicating whether the number is
5880 /// positive, negative or zero.
5881 ///
5882 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign)
5883 #[wasm_bindgen(js_namespace = Math)]
5884 pub fn sign(x: f64) -> f64;
5885
5886 /// The `Math.sin()` function returns the sine of a number.
5887 ///
5888 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sin)
5889 #[wasm_bindgen(js_namespace = Math)]
5890 pub fn sin(x: f64) -> f64;
5891
5892 /// The `Math.sinh()` function returns the hyperbolic sine of a number, that can be expressed
5893 /// using the constant e: Math.sinh(x) = (e^x - e^-x)/2
5894 ///
5895 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sinh)
5896 #[wasm_bindgen(js_namespace = Math)]
5897 pub fn sinh(x: f64) -> f64;
5898
5899 /// The `Math.sqrt()` function returns the square root of a number, that is
5900 /// ∀x ≥ 0, Math.sqrt(x) = √x = the unique y ≥ 0 such that y^2 = x
5901 ///
5902 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sqrt)
5903 #[wasm_bindgen(js_namespace = Math)]
5904 pub fn sqrt(x: f64) -> f64;
5905
5906 /// The `Math.tan()` function returns the tangent of a number.
5907 ///
5908 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/tan)
5909 #[wasm_bindgen(js_namespace = Math)]
5910 pub fn tan(x: f64) -> f64;
5911
5912 /// The `Math.tanh()` function returns the hyperbolic tangent of a number, that is
5913 /// tanh x = sinh x / cosh x = (e^x - e^-x)/(e^x + e^-x) = (e^2x - 1)/(e^2x + 1)
5914 ///
5915 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/tanh)
5916 #[wasm_bindgen(js_namespace = Math)]
5917 pub fn tanh(x: f64) -> f64;
5918
5919 /// The `Math.trunc()` function returns the integer part of a number by removing any fractional
5920 /// digits.
5921 ///
5922 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/trunc)
5923 #[wasm_bindgen(js_namespace = Math)]
5924 pub fn trunc(x: f64) -> f64;
5925
5926 /// The `Math.PI` property represents the ratio of the circumference of a circle to its diameter,
5927 /// approximately 3.14159.
5928 ///
5929 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/PI)
5930 #[wasm_bindgen(thread_local_v2, js_namespace = Math)]
5931 pub static PI: f64;
5932 }
5933}
5934
5935// Number.
5936#[wasm_bindgen]
5937extern "C" {
5938 #[wasm_bindgen(extends = Object, is_type_of = |v| v.as_f64().is_some(), typescript_type = "number")]
5939 #[derive(Clone, PartialEq)]
5940 pub type Number;
5941
5942 /// The `Number.isFinite()` method determines whether the passed value is a finite number.
5943 ///
5944 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isFinite)
5945 #[wasm_bindgen(static_method_of = Number, js_name = isFinite)]
5946 pub fn is_finite(value: &JsValue) -> bool;
5947
5948 /// The `Number.isInteger()` method determines whether the passed value is an integer.
5949 ///
5950 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isInteger)
5951 #[wasm_bindgen(static_method_of = Number, js_name = isInteger)]
5952 pub fn is_integer(value: &JsValue) -> bool;
5953
5954 /// The `Number.isNaN()` method determines whether the passed value is `NaN` and its type is Number.
5955 /// It is a more robust version of the original, global isNaN().
5956 ///
5957 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isNaN)
5958 #[wasm_bindgen(static_method_of = Number, js_name = isNaN)]
5959 pub fn is_nan(value: &JsValue) -> bool;
5960
5961 /// The `Number.isSafeInteger()` method determines whether the provided value is a number
5962 /// that is a safe integer.
5963 ///
5964 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isSafeInteger)
5965 #[wasm_bindgen(static_method_of = Number, js_name = isSafeInteger)]
5966 pub fn is_safe_integer(value: &JsValue) -> bool;
5967
5968 /// The `Number` JavaScript object is a wrapper object allowing
5969 /// you to work with numerical values. A `Number` object is
5970 /// created using the `Number()` constructor.
5971 ///
5972 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
5973 #[cfg(not(js_sys_unstable_apis))]
5974 #[wasm_bindgen(constructor)]
5975 #[deprecated(note = "recommended to use `Number::from` instead")]
5976 #[allow(deprecated)]
5977 pub fn new(value: &JsValue) -> Number;
5978
5979 #[wasm_bindgen(constructor)]
5980 fn new_from_str(value: &str) -> Number;
5981
5982 /// The `Number.parseInt()` method parses a string argument and returns an
5983 /// integer of the specified radix or base.
5984 ///
5985 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/parseInt)
5986 #[wasm_bindgen(static_method_of = Number, js_name = parseInt)]
5987 pub fn parse_int(text: &str, radix: u8) -> f64;
5988
5989 /// The `Number.parseFloat()` method parses a string argument and returns a
5990 /// floating point number.
5991 ///
5992 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/parseFloat)
5993 #[wasm_bindgen(static_method_of = Number, js_name = parseFloat)]
5994 pub fn parse_float(text: &str) -> f64;
5995
5996 /// The `toLocaleString()` method returns a string with a language sensitive
5997 /// representation of this number.
5998 ///
5999 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString)
6000 #[cfg(not(js_sys_unstable_apis))]
6001 #[wasm_bindgen(method, js_name = toLocaleString)]
6002 pub fn to_locale_string(this: &Number, locale: &str) -> JsString;
6003
6004 /// The `toLocaleString()` method returns a string with a language sensitive
6005 /// representation of this number.
6006 ///
6007 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString)
6008 #[cfg(js_sys_unstable_apis)]
6009 #[wasm_bindgen(method, js_name = toLocaleString)]
6010 pub fn to_locale_string(
6011 this: &Number,
6012 locales: &[JsString],
6013 options: &Intl::NumberFormatOptions,
6014 ) -> JsString;
6015
6016 /// The `toPrecision()` method returns a string representing the Number
6017 /// object to the specified precision.
6018 ///
6019 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision)
6020 #[wasm_bindgen(catch, method, js_name = toPrecision)]
6021 pub fn to_precision(this: &Number, precision: u8) -> Result<JsString, JsValue>;
6022
6023 /// The `toFixed()` method returns a string representing the Number
6024 /// object using fixed-point notation.
6025 ///
6026 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed)
6027 #[wasm_bindgen(catch, method, js_name = toFixed)]
6028 pub fn to_fixed(this: &Number, digits: u8) -> Result<JsString, JsValue>;
6029
6030 /// The `toExponential()` method returns a string representing the Number
6031 /// object in exponential notation.
6032 ///
6033 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toExponential)
6034 #[wasm_bindgen(catch, method, js_name = toExponential)]
6035 pub fn to_exponential(this: &Number, fraction_digits: u8) -> Result<JsString, JsValue>;
6036
6037 /// The `toString()` method returns a string representing the
6038 /// specified Number object.
6039 ///
6040 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString)
6041 #[cfg(not(js_sys_unstable_apis))]
6042 #[deprecated(note = "Use `Number::to_string_with_radix` instead.")]
6043 #[allow(deprecated)]
6044 #[wasm_bindgen(catch, method, js_name = toString)]
6045 pub fn to_string(this: &Number, radix: u8) -> Result<JsString, JsValue>;
6046
6047 /// The `toString()` method returns a string representing the
6048 /// specified Number object.
6049 ///
6050 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString)
6051 #[wasm_bindgen(catch, method, js_name = toString)]
6052 pub fn to_string_with_radix(this: &Number, radix: u8) -> Result<JsString, JsValue>;
6053
6054 /// The `valueOf()` method returns the wrapped primitive value of
6055 /// a Number object.
6056 ///
6057 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/valueOf)
6058 #[wasm_bindgen(method, js_name = valueOf)]
6059 pub fn value_of(this: &Number) -> f64;
6060}
6061
6062impl Number {
6063 /// The smallest interval between two representable numbers.
6064 ///
6065 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/EPSILON)
6066 pub const EPSILON: f64 = f64::EPSILON;
6067 /// The maximum safe integer in JavaScript (2^53 - 1).
6068 ///
6069 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER)
6070 pub const MAX_SAFE_INTEGER: f64 = 9007199254740991.0;
6071 /// The largest positive representable number.
6072 ///
6073 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_VALUE)
6074 pub const MAX_VALUE: f64 = f64::MAX;
6075 /// The minimum safe integer in JavaScript (-(2^53 - 1)).
6076 ///
6077 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MIN_SAFE_INTEGER)
6078 pub const MIN_SAFE_INTEGER: f64 = -9007199254740991.0;
6079 /// The smallest positive representable number—that is, the positive number closest to zero
6080 /// (without actually being zero).
6081 ///
6082 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MIN_VALUE)
6083 // Cannot use f64::MIN_POSITIVE since that is the smallest **normal** positive number.
6084 pub const MIN_VALUE: f64 = 5E-324;
6085 /// Special "Not a Number" value.
6086 ///
6087 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/NaN)
6088 pub const NAN: f64 = f64::NAN;
6089 /// Special value representing negative infinity. Returned on overflow.
6090 ///
6091 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/NEGATIVE_INFINITY)
6092 pub const NEGATIVE_INFINITY: f64 = f64::NEG_INFINITY;
6093 /// Special value representing infinity. Returned on overflow.
6094 ///
6095 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/POSITIVE_INFINITY)
6096 pub const POSITIVE_INFINITY: f64 = f64::INFINITY;
6097
6098 /// Applies the binary `**` JS operator on the two `Number`s.
6099 ///
6100 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Exponentiation)
6101 #[inline]
6102 pub fn pow(&self, rhs: &Self) -> Self {
6103 JsValue::as_ref(self)
6104 .pow(JsValue::as_ref(rhs))
6105 .unchecked_into()
6106 }
6107
6108 /// Applies the binary `>>>` JS operator on the two `Number`s.
6109 ///
6110 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Unsigned_right_shift)
6111 #[inline]
6112 pub fn unsigned_shr(&self, rhs: &Self) -> Self {
6113 Number::from(JsValue::as_ref(self).unsigned_shr(JsValue::as_ref(rhs)))
6114 }
6115}
6116
6117macro_rules! number_from {
6118 ($($x:ident)*) => ($(
6119 impl From<$x> for Number {
6120 #[inline]
6121 fn from(x: $x) -> Number {
6122 Number::unchecked_from_js(JsValue::from(x))
6123 }
6124 }
6125
6126 impl PartialEq<$x> for Number {
6127 #[inline]
6128 fn eq(&self, other: &$x) -> bool {
6129 self.value_of() == f64::from(*other)
6130 }
6131 }
6132
6133 impl UpcastFrom<$x> for Number {}
6134 )*)
6135}
6136number_from!(i8 u8 i16 u16 i32 u32 f32 f64);
6137
6138// The only guarantee for a JS number
6139impl UpcastFrom<Number> for f64 {}
6140
6141/// The error type returned when a checked integral type conversion fails.
6142#[derive(Debug, Copy, Clone, PartialEq, Eq)]
6143pub struct TryFromIntError(());
6144
6145impl fmt::Display for TryFromIntError {
6146 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
6147 fmt.write_str("out of range integral type conversion attempted")
6148 }
6149}
6150
6151#[cfg(feature = "std")]
6152impl std::error::Error for TryFromIntError {}
6153
6154macro_rules! number_try_from {
6155 ($($x:ident)*) => ($(
6156 impl TryFrom<$x> for Number {
6157 type Error = TryFromIntError;
6158
6159 #[inline]
6160 fn try_from(x: $x) -> Result<Number, Self::Error> {
6161 let x_f64 = x as f64;
6162 if (Number::MIN_SAFE_INTEGER..=Number::MAX_SAFE_INTEGER).contains(&x_f64) {
6163 Ok(Number::from(x_f64))
6164 } else {
6165 Err(TryFromIntError(()))
6166 }
6167 }
6168 }
6169 )*)
6170}
6171number_try_from!(i64 u64 i128 u128);
6172
6173impl From<&Number> for f64 {
6174 #[inline]
6175 fn from(n: &Number) -> f64 {
6176 n.value_of()
6177 }
6178}
6179
6180impl From<Number> for f64 {
6181 #[inline]
6182 fn from(n: Number) -> f64 {
6183 <f64 as From<&'_ Number>>::from(&n)
6184 }
6185}
6186
6187impl fmt::Debug for Number {
6188 #[inline]
6189 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6190 fmt::Debug::fmt(&self.value_of(), f)
6191 }
6192}
6193
6194impl fmt::Display for Number {
6195 #[inline]
6196 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6197 fmt::Display::fmt(&self.value_of(), f)
6198 }
6199}
6200
6201impl Default for Number {
6202 fn default() -> Self {
6203 Self::from(f64::default())
6204 }
6205}
6206
6207impl PartialEq<BigInt> for Number {
6208 #[inline]
6209 fn eq(&self, other: &BigInt) -> bool {
6210 JsValue::as_ref(self).loose_eq(JsValue::as_ref(other))
6211 }
6212}
6213
6214impl Not for &Number {
6215 type Output = BigInt;
6216
6217 #[inline]
6218 fn not(self) -> Self::Output {
6219 JsValue::as_ref(self).bit_not().unchecked_into()
6220 }
6221}
6222
6223forward_deref_unop!(impl Not, not for Number);
6224forward_js_unop!(impl Neg, neg for Number);
6225forward_js_binop!(impl BitAnd, bitand for Number);
6226forward_js_binop!(impl BitOr, bitor for Number);
6227forward_js_binop!(impl BitXor, bitxor for Number);
6228forward_js_binop!(impl Shl, shl for Number);
6229forward_js_binop!(impl Shr, shr for Number);
6230forward_js_binop!(impl Add, add for Number);
6231forward_js_binop!(impl Sub, sub for Number);
6232forward_js_binop!(impl Div, div for Number);
6233forward_js_binop!(impl Mul, mul for Number);
6234forward_js_binop!(impl Rem, rem for Number);
6235
6236sum_product!(Number);
6237
6238impl PartialOrd for Number {
6239 #[inline]
6240 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
6241 if Number::is_nan(self) || Number::is_nan(other) {
6242 None
6243 } else if self == other {
6244 Some(Ordering::Equal)
6245 } else if self.lt(other) {
6246 Some(Ordering::Less)
6247 } else {
6248 Some(Ordering::Greater)
6249 }
6250 }
6251
6252 #[inline]
6253 fn lt(&self, other: &Self) -> bool {
6254 JsValue::as_ref(self).lt(JsValue::as_ref(other))
6255 }
6256
6257 #[inline]
6258 fn le(&self, other: &Self) -> bool {
6259 JsValue::as_ref(self).le(JsValue::as_ref(other))
6260 }
6261
6262 #[inline]
6263 fn ge(&self, other: &Self) -> bool {
6264 JsValue::as_ref(self).ge(JsValue::as_ref(other))
6265 }
6266
6267 #[inline]
6268 fn gt(&self, other: &Self) -> bool {
6269 JsValue::as_ref(self).gt(JsValue::as_ref(other))
6270 }
6271}
6272
6273#[cfg(not(js_sys_unstable_apis))]
6274impl FromStr for Number {
6275 type Err = Infallible;
6276
6277 #[allow(deprecated)]
6278 #[inline]
6279 fn from_str(s: &str) -> Result<Self, Self::Err> {
6280 Ok(Number::new_from_str(s))
6281 }
6282}
6283
6284// Date.
6285#[wasm_bindgen]
6286extern "C" {
6287 #[wasm_bindgen(extends = Object, typescript_type = "Date")]
6288 #[derive(Clone, Debug, PartialEq, Eq)]
6289 pub type Date;
6290
6291 /// The `getDate()` method returns the day of the month for the
6292 /// specified date according to local time.
6293 ///
6294 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getDate)
6295 #[wasm_bindgen(method, js_name = getDate)]
6296 pub fn get_date(this: &Date) -> u32;
6297
6298 /// The `getDay()` method returns the day of the week for the specified date according to local time,
6299 /// where 0 represents Sunday. For the day of the month see getDate().
6300 ///
6301 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getDay)
6302 #[wasm_bindgen(method, js_name = getDay)]
6303 pub fn get_day(this: &Date) -> u32;
6304
6305 /// The `getFullYear()` method returns the year of the specified date according to local time.
6306 ///
6307 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getFullYear)
6308 #[wasm_bindgen(method, js_name = getFullYear)]
6309 pub fn get_full_year(this: &Date) -> u32;
6310
6311 /// The `getHours()` method returns the hour for the specified date, according to local time.
6312 ///
6313 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getHours)
6314 #[wasm_bindgen(method, js_name = getHours)]
6315 pub fn get_hours(this: &Date) -> u32;
6316
6317 /// The `getMilliseconds()` method returns the milliseconds in the specified date according to local time.
6318 ///
6319 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMilliseconds)
6320 #[wasm_bindgen(method, js_name = getMilliseconds)]
6321 pub fn get_milliseconds(this: &Date) -> u32;
6322
6323 /// The `getMinutes()` method returns the minutes in the specified date according to local time.
6324 ///
6325 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMinutes)
6326 #[wasm_bindgen(method, js_name = getMinutes)]
6327 pub fn get_minutes(this: &Date) -> u32;
6328
6329 /// The `getMonth()` method returns the month in the specified date according to local time,
6330 /// as a zero-based value (where zero indicates the first month of the year).
6331 ///
6332 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMonth)
6333 #[wasm_bindgen(method, js_name = getMonth)]
6334 pub fn get_month(this: &Date) -> u32;
6335
6336 /// The `getSeconds()` method returns the seconds in the specified date according to local time.
6337 ///
6338 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getSeconds)
6339 #[wasm_bindgen(method, js_name = getSeconds)]
6340 pub fn get_seconds(this: &Date) -> u32;
6341
6342 /// The `getTime()` method returns the numeric value corresponding to the time for the specified date
6343 /// according to universal time.
6344 ///
6345 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTime)
6346 #[wasm_bindgen(method, js_name = getTime)]
6347 pub fn get_time(this: &Date) -> f64;
6348
6349 /// The `getTimezoneOffset()` method returns the time zone difference, in minutes,
6350 /// from current locale (host system settings) to UTC.
6351 ///
6352 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTimezoneOffset)
6353 #[wasm_bindgen(method, js_name = getTimezoneOffset)]
6354 pub fn get_timezone_offset(this: &Date) -> f64;
6355
6356 /// The `getUTCDate()` method returns the day (date) of the month in the specified date
6357 /// according to universal time.
6358 ///
6359 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCDate)
6360 #[wasm_bindgen(method, js_name = getUTCDate)]
6361 pub fn get_utc_date(this: &Date) -> u32;
6362
6363 /// The `getUTCDay()` method returns the day of the week in the specified date according to universal time,
6364 /// where 0 represents Sunday.
6365 ///
6366 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCDay)
6367 #[wasm_bindgen(method, js_name = getUTCDay)]
6368 pub fn get_utc_day(this: &Date) -> u32;
6369
6370 /// The `getUTCFullYear()` method returns the year in the specified date according to universal time.
6371 ///
6372 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCFullYear)
6373 #[wasm_bindgen(method, js_name = getUTCFullYear)]
6374 pub fn get_utc_full_year(this: &Date) -> u32;
6375
6376 /// The `getUTCHours()` method returns the hours in the specified date according to universal time.
6377 ///
6378 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCHours)
6379 #[wasm_bindgen(method, js_name = getUTCHours)]
6380 pub fn get_utc_hours(this: &Date) -> u32;
6381
6382 /// The `getUTCMilliseconds()` method returns the milliseconds in the specified date
6383 /// according to universal time.
6384 ///
6385 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCMilliseconds)
6386 #[wasm_bindgen(method, js_name = getUTCMilliseconds)]
6387 pub fn get_utc_milliseconds(this: &Date) -> u32;
6388
6389 /// The `getUTCMinutes()` method returns the minutes in the specified date according to universal time.
6390 ///
6391 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCMinutes)
6392 #[wasm_bindgen(method, js_name = getUTCMinutes)]
6393 pub fn get_utc_minutes(this: &Date) -> u32;
6394
6395 /// The `getUTCMonth()` returns the month of the specified date according to universal time,
6396 /// as a zero-based value (where zero indicates the first month of the year).
6397 ///
6398 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCMonth)
6399 #[wasm_bindgen(method, js_name = getUTCMonth)]
6400 pub fn get_utc_month(this: &Date) -> u32;
6401
6402 /// The `getUTCSeconds()` method returns the seconds in the specified date according to universal time.
6403 ///
6404 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCSeconds)
6405 #[wasm_bindgen(method, js_name = getUTCSeconds)]
6406 pub fn get_utc_seconds(this: &Date) -> u32;
6407
6408 /// Creates a JavaScript `Date` instance that represents
6409 /// a single moment in time. `Date` objects are based on a time value that is
6410 /// the number of milliseconds since 1 January 1970 UTC.
6411 ///
6412 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6413 #[wasm_bindgen(constructor)]
6414 pub fn new(init: &JsValue) -> Date;
6415
6416 /// Creates a JavaScript `Date` instance that represents the current moment in
6417 /// time.
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_0() -> Date;
6422
6423 /// Creates a JavaScript `Date` instance that represents
6424 /// a single moment in time. `Date` objects are based on a time value that is
6425 /// the number of milliseconds since 1 January 1970 UTC.
6426 ///
6427 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6428 #[wasm_bindgen(constructor)]
6429 pub fn new_with_year_month(year: u32, month: i32) -> Date;
6430
6431 /// Creates a JavaScript `Date` instance that represents
6432 /// a single moment in time. `Date` objects are based on a time value that is
6433 /// the number of milliseconds since 1 January 1970 UTC.
6434 ///
6435 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6436 #[wasm_bindgen(constructor)]
6437 pub fn new_with_year_month_day(year: u32, month: i32, day: i32) -> Date;
6438
6439 /// Creates a JavaScript `Date` instance that represents
6440 /// a single moment in time. `Date` objects are based on a time value that is
6441 /// the number of milliseconds since 1 January 1970 UTC.
6442 ///
6443 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6444 #[wasm_bindgen(constructor)]
6445 pub fn new_with_year_month_day_hr(year: u32, month: i32, day: i32, hr: i32) -> Date;
6446
6447 /// Creates a JavaScript `Date` instance that represents
6448 /// a single moment in time. `Date` objects are based on a time value that is
6449 /// the number of milliseconds since 1 January 1970 UTC.
6450 ///
6451 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6452 #[wasm_bindgen(constructor)]
6453 pub fn new_with_year_month_day_hr_min(
6454 year: u32,
6455 month: i32,
6456 day: i32,
6457 hr: i32,
6458 min: i32,
6459 ) -> Date;
6460
6461 /// Creates a JavaScript `Date` instance that represents
6462 /// a single moment in time. `Date` objects are based on a time value that is
6463 /// the number of milliseconds since 1 January 1970 UTC.
6464 ///
6465 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6466 #[wasm_bindgen(constructor)]
6467 pub fn new_with_year_month_day_hr_min_sec(
6468 year: u32,
6469 month: i32,
6470 day: i32,
6471 hr: i32,
6472 min: i32,
6473 sec: i32,
6474 ) -> Date;
6475
6476 /// Creates a JavaScript `Date` instance that represents
6477 /// a single moment in time. `Date` objects are based on a time value that is
6478 /// the number of milliseconds since 1 January 1970 UTC.
6479 ///
6480 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6481 #[wasm_bindgen(constructor)]
6482 pub fn new_with_year_month_day_hr_min_sec_milli(
6483 year: u32,
6484 month: i32,
6485 day: i32,
6486 hr: i32,
6487 min: i32,
6488 sec: i32,
6489 milli: i32,
6490 ) -> Date;
6491
6492 /// The `Date.now()` method returns the number of milliseconds
6493 /// elapsed since January 1, 1970 00:00:00 UTC.
6494 ///
6495 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/now)
6496 #[wasm_bindgen(static_method_of = Date)]
6497 pub fn now() -> f64;
6498
6499 /// The `Date.parse()` method parses a string representation of a date, and returns the number of milliseconds
6500 /// since January 1, 1970, 00:00:00 UTC or `NaN` if the string is unrecognized or, in some cases,
6501 /// contains illegal date values (e.g. 2015-02-31).
6502 ///
6503 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse)
6504 #[wasm_bindgen(static_method_of = Date)]
6505 pub fn parse(date: &str) -> f64;
6506
6507 /// The `setDate()` method sets the day of the Date object relative to the beginning of the currently set month.
6508 ///
6509 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setDate)
6510 #[wasm_bindgen(method, js_name = setDate)]
6511 pub fn set_date(this: &Date, day: u32) -> f64;
6512
6513 /// The `setFullYear()` method sets the full year for a specified date according to local time.
6514 /// Returns new timestamp.
6515 ///
6516 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setFullYear)
6517 #[wasm_bindgen(method, js_name = setFullYear)]
6518 pub fn set_full_year(this: &Date, year: 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_with_month(this: &Date, year: u32, month: i32) -> 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_date(this: &Date, year: u32, month: i32, date: i32) -> f64;
6533
6534 /// The `setHours()` method sets the hours for a specified date according to local time,
6535 /// and returns the number of milliseconds since January 1, 1970 00:00:00 UTC until the time represented
6536 /// by the updated Date instance.
6537 ///
6538 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setHours)
6539 #[wasm_bindgen(method, js_name = setHours)]
6540 pub fn set_hours(this: &Date, hours: u32) -> f64;
6541
6542 /// The `setMilliseconds()` method sets the milliseconds for a specified date according to local time.
6543 ///
6544 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setMilliseconds)
6545 #[wasm_bindgen(method, js_name = setMilliseconds)]
6546 pub fn set_milliseconds(this: &Date, milliseconds: u32) -> f64;
6547
6548 /// The `setMinutes()` method sets the minutes for a specified date according to local time.
6549 ///
6550 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setMinutes)
6551 #[wasm_bindgen(method, js_name = setMinutes)]
6552 pub fn set_minutes(this: &Date, minutes: u32) -> f64;
6553
6554 /// The `setMonth()` method sets the month for a specified date according to the currently set year.
6555 ///
6556 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setMonth)
6557 #[wasm_bindgen(method, js_name = setMonth)]
6558 pub fn set_month(this: &Date, month: u32) -> f64;
6559
6560 /// The `setSeconds()` method sets the seconds for a specified date according to local time.
6561 ///
6562 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setSeconds)
6563 #[wasm_bindgen(method, js_name = setSeconds)]
6564 pub fn set_seconds(this: &Date, seconds: u32) -> f64;
6565
6566 /// The `setTime()` method sets the Date object to the time represented by a number of milliseconds
6567 /// since January 1, 1970, 00:00:00 UTC.
6568 ///
6569 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setTime)
6570 #[wasm_bindgen(method, js_name = setTime)]
6571 pub fn set_time(this: &Date, time: f64) -> f64;
6572
6573 /// The `setUTCDate()` method sets the day of the month for a specified date
6574 /// according to universal time.
6575 ///
6576 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCDate)
6577 #[wasm_bindgen(method, js_name = setUTCDate)]
6578 pub fn set_utc_date(this: &Date, day: u32) -> f64;
6579
6580 /// The `setUTCFullYear()` method sets the full year for a specified date according to universal time.
6581 ///
6582 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCFullYear)
6583 #[wasm_bindgen(method, js_name = setUTCFullYear)]
6584 pub fn set_utc_full_year(this: &Date, year: u32) -> f64;
6585
6586 /// The `setUTCFullYear()` method sets the full year for a specified date according to universal time.
6587 ///
6588 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCFullYear)
6589 #[wasm_bindgen(method, js_name = setUTCFullYear)]
6590 pub fn set_utc_full_year_with_month(this: &Date, year: u32, month: i32) -> f64;
6591
6592 /// The `setUTCFullYear()` method sets the full year for a specified date according to universal time.
6593 ///
6594 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCFullYear)
6595 #[wasm_bindgen(method, js_name = setUTCFullYear)]
6596 pub fn set_utc_full_year_with_month_date(this: &Date, year: u32, month: i32, date: i32) -> f64;
6597
6598 /// The `setUTCHours()` method sets the hour for a specified date according to universal time,
6599 /// and returns the number of milliseconds since January 1, 1970 00:00:00 UTC until the time
6600 /// represented by the updated Date instance.
6601 ///
6602 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCHours)
6603 #[wasm_bindgen(method, js_name = setUTCHours)]
6604 pub fn set_utc_hours(this: &Date, hours: u32) -> f64;
6605
6606 /// The `setUTCMilliseconds()` method sets the milliseconds for a specified date
6607 /// according to universal time.
6608 ///
6609 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCMilliseconds)
6610 #[wasm_bindgen(method, js_name = setUTCMilliseconds)]
6611 pub fn set_utc_milliseconds(this: &Date, milliseconds: u32) -> f64;
6612
6613 /// The `setUTCMinutes()` method sets the minutes for a specified date according to universal time.
6614 ///
6615 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCMinutes)
6616 #[wasm_bindgen(method, js_name = setUTCMinutes)]
6617 pub fn set_utc_minutes(this: &Date, minutes: u32) -> f64;
6618
6619 /// The `setUTCMonth()` method sets the month for a specified date according to universal time.
6620 ///
6621 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCMonth)
6622 #[wasm_bindgen(method, js_name = setUTCMonth)]
6623 pub fn set_utc_month(this: &Date, month: u32) -> f64;
6624
6625 /// The `setUTCSeconds()` method sets the seconds for a specified date according to universal time.
6626 ///
6627 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCSeconds)
6628 #[wasm_bindgen(method, js_name = setUTCSeconds)]
6629 pub fn set_utc_seconds(this: &Date, seconds: u32) -> f64;
6630
6631 /// The `toDateString()` method returns the date portion of a Date object
6632 /// in human readable form in American English.
6633 ///
6634 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toDateString)
6635 #[wasm_bindgen(method, js_name = toDateString)]
6636 pub fn to_date_string(this: &Date) -> JsString;
6637
6638 /// The `toISOString()` method returns a string in simplified extended ISO format (ISO
6639 /// 8601), which is always 24 or 27 characters long (YYYY-MM-DDTHH:mm:ss.sssZ or
6640 /// ±YYYYYY-MM-DDTHH:mm:ss.sssZ, respectively). The timezone is always zero UTC offset,
6641 /// as denoted by the suffix "Z"
6642 ///
6643 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString)
6644 #[wasm_bindgen(method, js_name = toISOString)]
6645 pub fn to_iso_string(this: &Date) -> JsString;
6646
6647 /// The `toJSON()` method returns a string representation of the Date object.
6648 ///
6649 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toJSON)
6650 #[wasm_bindgen(method, js_name = toJSON)]
6651 pub fn to_json(this: &Date) -> JsString;
6652
6653 /// The `toLocaleDateString()` method returns a string with a language sensitive
6654 /// representation of the date portion of this date. The new locales and options
6655 /// arguments let applications specify the language whose formatting conventions
6656 /// should be used and allow to customize the behavior of the function.
6657 /// In older implementations, which ignore the locales and options arguments,
6658 /// the locale used and the form of the string
6659 /// returned are entirely implementation dependent.
6660 ///
6661 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString)
6662 #[cfg(not(js_sys_unstable_apis))]
6663 #[wasm_bindgen(method, js_name = toLocaleDateString)]
6664 pub fn to_locale_date_string(this: &Date, locale: &str, options: &JsValue) -> JsString;
6665
6666 /// The `toLocaleDateString()` method returns a string with a language sensitive
6667 /// representation of the date portion of this date.
6668 ///
6669 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString)
6670 #[cfg(js_sys_unstable_apis)]
6671 #[wasm_bindgen(method, js_name = toLocaleDateString)]
6672 pub fn to_locale_date_string(
6673 this: &Date,
6674 locales: &[JsString],
6675 options: &Intl::DateTimeFormatOptions,
6676 ) -> JsString;
6677
6678 /// The `toLocaleString()` method returns a string with a language sensitive
6679 /// representation of this date. The new locales and options arguments
6680 /// let applications specify the language whose formatting conventions
6681 /// should be used and customize the behavior of the function.
6682 /// In older implementations, which ignore the locales
6683 /// and options arguments, the locale used and the form of the string
6684 /// returned are entirely implementation dependent.
6685 ///
6686 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString)
6687 #[cfg(not(js_sys_unstable_apis))]
6688 #[wasm_bindgen(method, js_name = toLocaleString)]
6689 pub fn to_locale_string(this: &Date, locale: &str, options: &JsValue) -> JsString;
6690
6691 /// The `toLocaleString()` method returns a string with a language sensitive
6692 /// representation of this date.
6693 ///
6694 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString)
6695 #[cfg(js_sys_unstable_apis)]
6696 #[wasm_bindgen(method, js_name = toLocaleString)]
6697 pub fn to_locale_string(
6698 this: &Date,
6699 locales: &[JsString],
6700 options: &Intl::DateTimeFormatOptions,
6701 ) -> JsString;
6702
6703 /// The `toLocaleTimeString()` method returns a string with a language sensitive
6704 /// representation of the time portion of this date. The new locales and options
6705 /// arguments let applications specify the language whose formatting conventions should be
6706 /// used and customize the behavior of the function. In older implementations, which ignore
6707 /// the locales and options arguments, the locale used and the form of the string
6708 /// returned are entirely implementation dependent.
6709 ///
6710 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleTimeString)
6711 #[cfg(not(js_sys_unstable_apis))]
6712 #[wasm_bindgen(method, js_name = toLocaleTimeString)]
6713 pub fn to_locale_time_string(this: &Date, locale: &str) -> JsString;
6714
6715 /// The `toLocaleTimeString()` method returns a string with a language sensitive
6716 /// representation of the time portion of this date.
6717 ///
6718 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleTimeString)
6719 #[cfg(js_sys_unstable_apis)]
6720 #[wasm_bindgen(method, js_name = toLocaleTimeString)]
6721 pub fn to_locale_time_string(
6722 this: &Date,
6723 locales: &[JsString],
6724 options: &Intl::DateTimeFormatOptions,
6725 ) -> JsString;
6726
6727 #[cfg(not(js_sys_unstable_apis))]
6728 #[wasm_bindgen(method, js_name = toLocaleTimeString)]
6729 pub fn to_locale_time_string_with_options(
6730 this: &Date,
6731 locale: &str,
6732 options: &JsValue,
6733 ) -> JsString;
6734
6735 /// The `toString()` method returns a string representing
6736 /// the specified Date object.
6737 ///
6738 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toString)
6739 #[cfg(not(js_sys_unstable_apis))]
6740 #[wasm_bindgen(method, js_name = toString)]
6741 pub fn to_string(this: &Date) -> JsString;
6742
6743 /// The `toTimeString()` method returns the time portion of a Date object in human
6744 /// readable form in American English.
6745 ///
6746 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toTimeString)
6747 #[wasm_bindgen(method, js_name = toTimeString)]
6748 pub fn to_time_string(this: &Date) -> JsString;
6749
6750 /// The `toUTCString()` method converts a date to a string,
6751 /// using the UTC time zone.
6752 ///
6753 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toUTCString)
6754 #[wasm_bindgen(method, js_name = toUTCString)]
6755 pub fn to_utc_string(this: &Date) -> JsString;
6756
6757 /// The `Date.UTC()` method accepts the same parameters as the
6758 /// longest form of the constructor, and returns the number of
6759 /// milliseconds in a `Date` object since January 1, 1970,
6760 /// 00:00:00, universal time.
6761 ///
6762 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/UTC)
6763 #[wasm_bindgen(static_method_of = Date, js_name = UTC)]
6764 pub fn utc(year: f64, month: f64) -> f64;
6765
6766 /// The `valueOf()` method returns the primitive value of
6767 /// a Date object.
6768 ///
6769 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/valueOf)
6770 #[wasm_bindgen(method, js_name = valueOf)]
6771 pub fn value_of(this: &Date) -> f64;
6772
6773 /// The `toTemporalInstant()` method converts a legacy `Date` object to a
6774 /// `Temporal.Instant` object representing the same moment in time.
6775 ///
6776 /// This method is added by the Temporal proposal to facilitate migration
6777 /// from legacy `Date` to the new Temporal API.
6778 ///
6779 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toTemporalInstant)
6780 #[cfg(js_sys_unstable_apis)]
6781 #[wasm_bindgen(method, js_name = toTemporalInstant)]
6782 pub fn to_temporal_instant(this: &Date) -> Temporal::Instant;
6783}
6784
6785// Property Descriptor.
6786#[wasm_bindgen]
6787extern "C" {
6788 #[wasm_bindgen(extends = Object)]
6789 #[derive(Clone, Debug)]
6790 pub type PropertyDescriptor<T = JsValue>;
6791
6792 #[wasm_bindgen(method, getter = writable)]
6793 pub fn get_writable<T>(this: &PropertyDescriptor<T>) -> Option<bool>;
6794
6795 #[wasm_bindgen(method, setter = writable)]
6796 pub fn set_writable<T>(this: &PropertyDescriptor<T>, writable: bool);
6797
6798 #[wasm_bindgen(method, getter = enumerable)]
6799 pub fn get_enumerable<T>(this: &PropertyDescriptor<T>) -> Option<bool>;
6800
6801 #[wasm_bindgen(method, setter = enumerable)]
6802 pub fn set_enumerable<T>(this: &PropertyDescriptor<T>, enumerable: bool);
6803
6804 #[wasm_bindgen(method, getter = configurable)]
6805 pub fn get_configurable<T>(this: &PropertyDescriptor<T>) -> Option<bool>;
6806
6807 #[wasm_bindgen(method, setter = configurable)]
6808 pub fn set_configurable<T>(this: &PropertyDescriptor<T>, configurable: bool);
6809
6810 #[wasm_bindgen(method, getter = get)]
6811 pub fn get_get<T: JsGeneric>(this: &PropertyDescriptor<T>) -> Option<Function<fn() -> T>>;
6812
6813 #[wasm_bindgen(method, setter = get)]
6814 pub fn set_get<T: JsGeneric>(this: &PropertyDescriptor<T>, get: Function<fn() -> T>);
6815
6816 #[wasm_bindgen(method, getter = set)]
6817 pub fn get_set<T: JsGeneric>(
6818 this: &PropertyDescriptor<T>,
6819 ) -> Option<Function<fn(T) -> JsValue>>;
6820
6821 #[wasm_bindgen(method, setter = set)]
6822 pub fn set_set<T: JsGeneric>(this: &PropertyDescriptor<T>, set: Function<fn(T) -> JsValue>);
6823
6824 #[wasm_bindgen(method, getter = value)]
6825 pub fn get_value<T>(this: &PropertyDescriptor<T>) -> Option<T>;
6826
6827 #[wasm_bindgen(method, setter = value)]
6828 pub fn set_value<T>(this: &PropertyDescriptor<T>, value: &T);
6829}
6830
6831impl PropertyDescriptor {
6832 #[cfg(not(js_sys_unstable_apis))]
6833 pub fn new<T>() -> PropertyDescriptor<T> {
6834 JsCast::unchecked_into(Object::new())
6835 }
6836
6837 #[cfg(js_sys_unstable_apis)]
6838 pub fn new<T>() -> PropertyDescriptor<T> {
6839 JsCast::unchecked_into(Object::<JsValue>::new())
6840 }
6841
6842 #[cfg(not(js_sys_unstable_apis))]
6843 pub fn new_value<T: JsGeneric>(value: &T) -> PropertyDescriptor<T> {
6844 let desc: PropertyDescriptor<T> = JsCast::unchecked_into(Object::new());
6845 desc.set_value(value);
6846 desc
6847 }
6848
6849 #[cfg(js_sys_unstable_apis)]
6850 pub fn new_value<T: JsGeneric>(value: &T) -> PropertyDescriptor<T> {
6851 let desc: PropertyDescriptor<T> = JsCast::unchecked_into(Object::<JsValue>::new());
6852 desc.set_value(value);
6853 desc
6854 }
6855}
6856
6857impl Default for PropertyDescriptor {
6858 fn default() -> Self {
6859 PropertyDescriptor::new()
6860 }
6861}
6862
6863// Object.
6864#[wasm_bindgen]
6865extern "C" {
6866 #[wasm_bindgen(typescript_type = "object")]
6867 #[derive(Clone, Debug)]
6868 pub type Object<T = JsValue>;
6869
6870 // Next major: deprecate
6871 /// The `Object.assign()` method is used to copy the values of all enumerable
6872 /// own properties from one or more source objects to a target object. It
6873 /// will return the target object.
6874 ///
6875 /// **Note:** Consider using [`Object::try_assign`] to support error handling.
6876 ///
6877 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
6878 #[wasm_bindgen(static_method_of = Object)]
6879 pub fn assign<T>(target: &Object<T>, source: &Object<T>) -> Object<T>;
6880
6881 // Next major: deprecate
6882 /// The `Object.assign()` method is used to copy the values of all enumerable
6883 /// own properties from one or more source objects to a target object. It
6884 /// will return the target object.
6885 ///
6886 /// **Note:** Consider using [`Object::try_assign`] to support error handling.
6887 ///
6888 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
6889 #[wasm_bindgen(static_method_of = Object, js_name = assign, catch)]
6890 pub fn try_assign<T>(target: &Object<T>, source: &Object<T>) -> Result<Object<T>, JsValue>;
6891
6892 /// The `Object.assign()` method is used to copy the values of all enumerable
6893 /// own properties from one or more source objects to a target object. It
6894 /// will return the target object.
6895 ///
6896 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
6897 #[cfg(not(js_sys_unstable_apis))]
6898 #[wasm_bindgen(static_method_of = Object, js_name = assign)]
6899 #[deprecated(note = "use `assign_many` for arbitrary assign arguments instead")]
6900 #[allow(deprecated)]
6901 pub fn assign2<T>(target: &Object<T>, source1: &Object<T>, source2: &Object<T>) -> Object<T>;
6902
6903 /// The `Object.assign()` method is used to copy the values of all enumerable
6904 /// own properties from one or more source objects to a target object. It
6905 /// will return the target object.
6906 ///
6907 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
6908 #[cfg(not(js_sys_unstable_apis))]
6909 #[wasm_bindgen(static_method_of = Object, js_name = assign)]
6910 #[deprecated(note = "use `assign_many` for arbitrary assign arguments instead")]
6911 #[allow(deprecated)]
6912 pub fn assign3<T>(
6913 target: &Object<T>,
6914 source1: &Object<T>,
6915 source2: &Object<T>,
6916 source3: &Object<T>,
6917 ) -> Object<T>;
6918
6919 /// The `Object.assign()` method is used to copy the values of all enumerable
6920 /// own properties from one or more source objects to a target object. It
6921 /// will return the target object.
6922 ///
6923 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
6924 #[wasm_bindgen(static_method_of = Object, js_name = assign, catch, variadic)]
6925 pub fn assign_many<T>(target: &Object<T>, sources: &[Object<T>]) -> Result<Object<T>, JsValue>;
6926
6927 /// The constructor property returns a reference to the `Object` constructor
6928 /// function that created the instance object.
6929 ///
6930 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/constructor)
6931 #[wasm_bindgen(method, getter)]
6932 pub fn constructor<T>(this: &Object<T>) -> Function;
6933
6934 /// The `Object.create()` method creates a new object, using an existing
6935 /// object to provide the newly created object's prototype.
6936 ///
6937 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/create)
6938 #[wasm_bindgen(static_method_of = Object)]
6939 pub fn create<T>(prototype: &Object<T>) -> Object<T>;
6940
6941 /// The static method `Object.defineProperty()` defines a new
6942 /// property directly on an object, or modifies an existing
6943 /// property on an object, and returns the object.
6944 ///
6945 /// **Note:** Consider using [`Object::define_property_str`] to support typing and error handling.
6946 ///
6947 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty)
6948 #[cfg(not(js_sys_unstable_apis))]
6949 #[wasm_bindgen(static_method_of = Object, js_name = defineProperty)]
6950 pub fn define_property<T>(obj: &Object<T>, prop: &JsValue, descriptor: &Object) -> Object<T>;
6951
6952 /// The static method `Object.defineProperty()` defines a new
6953 /// property directly on an object, or modifies an existing
6954 /// property on an object, and returns the object.
6955 ///
6956 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty)
6957 #[cfg(js_sys_unstable_apis)]
6958 #[wasm_bindgen(static_method_of = Object, js_name = defineProperty, catch)]
6959 pub fn define_property<T>(
6960 obj: &Object<T>,
6961 prop: &JsString,
6962 descriptor: &PropertyDescriptor<T>,
6963 ) -> Result<Object<T>, JsValue>;
6964
6965 // Next major: deprecate
6966 /// The static method `Object.defineProperty()` defines a new
6967 /// property directly on an object, or modifies an existing
6968 /// property on an object, and returns the object.
6969 ///
6970 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty)
6971 #[wasm_bindgen(static_method_of = Object, js_name = defineProperty, catch)]
6972 pub fn define_property_str<T>(
6973 obj: &Object<T>,
6974 prop: &JsString,
6975 descriptor: &PropertyDescriptor<T>,
6976 ) -> Result<Object<T>, JsValue>;
6977
6978 /// The static method `Object.defineProperty()` defines a new
6979 /// property directly on an object, or modifies an existing
6980 /// property on an object, and returns the object.
6981 ///
6982 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty)
6983 #[wasm_bindgen(static_method_of = Object, js_name = defineProperty, catch)]
6984 pub fn define_property_symbol<T>(
6985 obj: &Object<T>,
6986 prop: &Symbol,
6987 descriptor: &PropertyDescriptor<JsValue>,
6988 ) -> Result<Object<T>, JsValue>;
6989
6990 /// The `Object.defineProperties()` method defines new or modifies
6991 /// existing properties directly on an object, returning the
6992 /// object.
6993 ///
6994 /// **Note:** Consider using [`Object::try_define_properties`] to support typing and error handling.
6995 ///
6996 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperties)
6997 #[wasm_bindgen(static_method_of = Object, js_name = defineProperties)]
6998 pub fn define_properties<T>(obj: &Object<T>, props: &Object) -> Object<T>;
6999
7000 /// The `Object.defineProperties()` method defines new or modifies
7001 /// existing properties directly on an object, returning the
7002 /// object.
7003 ///
7004 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperties)
7005 #[cfg(js_sys_unstable_apis)]
7006 #[wasm_bindgen(static_method_of = Object, js_name = defineProperties, catch)]
7007 pub fn try_define_properties<T>(
7008 obj: &Object<T>,
7009 props: &Object<PropertyDescriptor<T>>,
7010 ) -> Result<Object<T>, JsValue>;
7011
7012 /// The `Object.entries()` method returns an array of a given
7013 /// object's own enumerable property [key, value] pairs, in the
7014 /// same order as that provided by a for...in loop (the difference
7015 /// being that a for-in loop enumerates properties in the
7016 /// prototype chain as well).
7017 ///
7018 /// **Note:** Consider using [`Object::entries_typed`] to support typing and error handling.
7019 ///
7020 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries)
7021 #[cfg(not(js_sys_unstable_apis))]
7022 #[wasm_bindgen(static_method_of = Object)]
7023 pub fn entries(object: &Object) -> Array;
7024
7025 /// The `Object.entries()` method returns an array of a given
7026 /// object's own enumerable property [key, value] pairs, in the
7027 /// same order as that provided by a for...in loop (the difference
7028 /// being that a for-in loop enumerates properties in the
7029 /// prototype chain as well).
7030 ///
7031 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries)
7032 #[cfg(js_sys_unstable_apis)]
7033 #[wasm_bindgen(static_method_of = Object, js_name = entries, catch)]
7034 pub fn entries<T: JsGeneric>(
7035 object: &Object<T>,
7036 ) -> Result<Array<ArrayTuple<(JsString, T)>>, JsValue>;
7037
7038 // Next major: deprecate
7039 /// The `Object.entries()` method returns an array of a given
7040 /// object's own enumerable property [key, value] pairs, in the
7041 /// same order as that provided by a for...in loop (the difference
7042 /// being that a for-in loop enumerates properties in the
7043 /// prototype chain as well).
7044 ///
7045 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries)
7046 #[wasm_bindgen(static_method_of = Object, js_name = entries, catch)]
7047 pub fn entries_typed<T: JsGeneric>(
7048 object: &Object<T>,
7049 ) -> Result<Array<ArrayTuple<(JsString, T)>>, JsValue>;
7050
7051 /// The `Object.freeze()` method freezes an object: that is, prevents new
7052 /// properties from being added to it; prevents existing properties from
7053 /// being removed; and prevents existing properties, or their enumerability,
7054 /// configurability, or writability, from being changed, it also prevents
7055 /// the prototype from being changed. The method returns the passed object.
7056 ///
7057 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze)
7058 #[wasm_bindgen(static_method_of = Object)]
7059 pub fn freeze<T>(value: &Object<T>) -> Object<T>;
7060
7061 /// The `Object.fromEntries()` method transforms a list of key-value pairs
7062 /// into an object.
7063 ///
7064 /// **Note:** Consider using [`Object::from_entries_typed`] to support typing and error handling.
7065 ///
7066 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/fromEntries)
7067 #[cfg(not(js_sys_unstable_apis))]
7068 #[wasm_bindgen(static_method_of = Object, catch, js_name = fromEntries)]
7069 pub fn from_entries(entries: &JsValue) -> Result<Object, JsValue>;
7070
7071 /// The `Object.fromEntries()` method transforms a list of key-value pairs
7072 /// into an object.
7073 ///
7074 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/fromEntries)
7075 #[cfg(js_sys_unstable_apis)]
7076 #[wasm_bindgen(static_method_of = Object, catch, js_name = fromEntries)]
7077 pub fn from_entries<T: JsGeneric, I: Iterable<Item = ArrayTuple<(JsString, T)>>>(
7078 entries: &I,
7079 ) -> Result<Object<T>, JsValue>;
7080
7081 // Next major: deprecate
7082 /// The `Object.fromEntries()` method transforms a list of key-value pairs
7083 /// into an object.
7084 ///
7085 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/fromEntries)
7086 #[wasm_bindgen(static_method_of = Object, catch, js_name = fromEntries)]
7087 pub fn from_entries_typed<T: JsGeneric, I: Iterable<Item = ArrayTuple<(JsString, T)>>>(
7088 entries: &I,
7089 ) -> Result<Object<T>, JsValue>;
7090
7091 /// The `Object.getOwnPropertyDescriptor()` method returns a
7092 /// property descriptor for an own property (that is, one directly
7093 /// present on an object and not in the object's prototype chain)
7094 /// of a given object.
7095 ///
7096 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor)
7097 #[cfg(not(js_sys_unstable_apis))]
7098 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptor)]
7099 pub fn get_own_property_descriptor<T>(obj: &Object<T>, prop: &JsValue) -> JsValue;
7100
7101 /// The `Object.getOwnPropertyDescriptor()` method returns a
7102 /// property descriptor for an own property (that is, one directly
7103 /// present on an object and not in the object's prototype chain)
7104 /// of a given object.
7105 ///
7106 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor)
7107 #[cfg(js_sys_unstable_apis)]
7108 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptor, catch)]
7109 pub fn get_own_property_descriptor<T>(
7110 obj: &Object<T>,
7111 prop: &JsString,
7112 ) -> Result<PropertyDescriptor<T>, JsValue>;
7113
7114 // Next major: deprecate
7115 /// The `Object.getOwnPropertyDescriptor()` method returns a
7116 /// property descriptor for an own property (that is, one directly
7117 /// present on an object and not in the object's prototype chain)
7118 /// of a given object.
7119 ///
7120 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor)
7121 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptor, catch)]
7122 pub fn get_own_property_descriptor_str<T>(
7123 obj: &Object<T>,
7124 prop: &JsString,
7125 ) -> Result<PropertyDescriptor<T>, JsValue>;
7126
7127 /// The `Object.getOwnPropertyDescriptor()` method returns a
7128 /// property descriptor for an own property (that is, one directly
7129 /// present on an object and not in the object's prototype chain)
7130 /// of a given object.
7131 ///
7132 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor)
7133 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptor, catch)]
7134 pub fn get_own_property_descriptor_symbol<T>(
7135 obj: &Object<T>,
7136 prop: &Symbol,
7137 ) -> Result<PropertyDescriptor<JsValue>, JsValue>;
7138
7139 /// The `Object.getOwnPropertyDescriptors()` method returns all own
7140 /// property descriptors of a given object.
7141 ///
7142 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptors)
7143 #[cfg(not(js_sys_unstable_apis))]
7144 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptors)]
7145 pub fn get_own_property_descriptors<T>(obj: &Object<T>) -> JsValue;
7146
7147 /// The `Object.getOwnPropertyDescriptors()` method returns all own
7148 /// property descriptors of a given object.
7149 ///
7150 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptors)
7151 #[cfg(js_sys_unstable_apis)]
7152 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptors, catch)]
7153 pub fn get_own_property_descriptors<T>(
7154 obj: &Object<T>,
7155 ) -> Result<Object<PropertyDescriptor<T>>, JsValue>;
7156
7157 /// The `Object.getOwnPropertyNames()` method returns an array of
7158 /// all properties (including non-enumerable properties except for
7159 /// those which use Symbol) found directly upon a given object.
7160 ///
7161 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyNames)
7162 #[cfg(not(js_sys_unstable_apis))]
7163 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyNames)]
7164 pub fn get_own_property_names<T>(obj: &Object<T>) -> Array;
7165
7166 /// The `Object.getOwnPropertyNames()` method returns an array of
7167 /// all properties (including non-enumerable properties except for
7168 /// those which use Symbol) found directly upon a given object.
7169 ///
7170 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyNames)
7171 #[cfg(js_sys_unstable_apis)]
7172 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyNames, catch)]
7173 pub fn get_own_property_names<T>(obj: &Object<T>) -> Result<Array<JsString>, JsValue>;
7174
7175 /// The `Object.getOwnPropertySymbols()` method returns an array of
7176 /// all symbol properties found directly upon a given object.
7177 ///
7178 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertySymbols)
7179 #[cfg(not(js_sys_unstable_apis))]
7180 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertySymbols)]
7181 pub fn get_own_property_symbols<T>(obj: &Object<T>) -> Array;
7182
7183 /// The `Object.getOwnPropertySymbols()` method returns an array of
7184 /// all symbol properties found directly upon a given object.
7185 ///
7186 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertySymbols)
7187 #[cfg(js_sys_unstable_apis)]
7188 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertySymbols, catch)]
7189 pub fn get_own_property_symbols<T>(obj: &Object<T>) -> Result<Array<Symbol>, JsValue>;
7190
7191 /// The `Object.getPrototypeOf()` method returns the prototype
7192 /// (i.e. the value of the internal [[Prototype]] property) of the
7193 /// specified object.
7194 ///
7195 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getPrototypeOf)
7196 #[wasm_bindgen(static_method_of = Object, js_name = getPrototypeOf)]
7197 pub fn get_prototype_of(obj: &JsValue) -> Object;
7198
7199 /// The `hasOwnProperty()` method returns a boolean indicating whether the
7200 /// object has the specified property as its own property (as opposed to
7201 /// inheriting it).
7202 ///
7203 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty)
7204 #[deprecated(note = "Use `Object::hasOwn` instead.")]
7205 #[allow(deprecated)]
7206 #[wasm_bindgen(method, js_name = hasOwnProperty)]
7207 pub fn has_own_property<T>(this: &Object<T>, property: &JsValue) -> bool;
7208
7209 /// The `Object.hasOwn()` method returns a boolean indicating whether the
7210 /// object passed in has the specified property as its own property (as
7211 /// opposed to inheriting it).
7212 ///
7213 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn)
7214 #[cfg(not(js_sys_unstable_apis))]
7215 #[wasm_bindgen(static_method_of = Object, js_name = hasOwn)]
7216 pub fn has_own<T>(instance: &Object<T>, property: &JsValue) -> bool;
7217
7218 /// The `Object.hasOwn()` method returns a boolean indicating whether the
7219 /// object passed in has the specified property as its own property (as
7220 /// opposed to inheriting it).
7221 ///
7222 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn)
7223 #[cfg(js_sys_unstable_apis)]
7224 #[wasm_bindgen(static_method_of = Object, js_name = hasOwn, catch)]
7225 pub fn has_own<T>(instance: &Object<T>, property: &JsString) -> Result<bool, JsValue>;
7226
7227 // Next major: deprecate
7228 /// The `Object.hasOwn()` method returns a boolean indicating whether the
7229 /// object passed in has the specified property as its own property (as
7230 /// opposed to inheriting it).
7231 ///
7232 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn)
7233 #[wasm_bindgen(static_method_of = Object, js_name = hasOwn, catch)]
7234 pub fn has_own_str<T>(instance: &Object<T>, property: &JsString) -> Result<bool, JsValue>;
7235
7236 /// The `Object.hasOwn()` method returns a boolean indicating whether the
7237 /// object passed in has the specified property as its own property (as
7238 /// opposed to inheriting it).
7239 ///
7240 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn)
7241 #[wasm_bindgen(static_method_of = Object, js_name = hasOwn, catch)]
7242 pub fn has_own_symbol<T>(instance: &Object<T>, property: &Symbol) -> Result<bool, JsValue>;
7243
7244 /// The `Object.is()` method determines whether two values are the same value.
7245 ///
7246 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is)
7247 #[wasm_bindgen(static_method_of = Object)]
7248 pub fn is(value1: &JsValue, value_2: &JsValue) -> bool;
7249
7250 /// The `Object.isExtensible()` method determines if an object is extensible
7251 /// (whether it can have new properties added to it).
7252 ///
7253 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isExtensible)
7254 #[wasm_bindgen(static_method_of = Object, js_name = isExtensible)]
7255 pub fn is_extensible<T>(object: &Object<T>) -> bool;
7256
7257 /// The `Object.isFrozen()` determines if an object is frozen.
7258 ///
7259 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isFrozen)
7260 #[wasm_bindgen(static_method_of = Object, js_name = isFrozen)]
7261 pub fn is_frozen<T>(object: &Object<T>) -> bool;
7262
7263 /// The `Object.isSealed()` method determines if an object is sealed.
7264 ///
7265 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isSealed)
7266 #[wasm_bindgen(static_method_of = Object, js_name = isSealed)]
7267 pub fn is_sealed<T>(object: &Object<T>) -> bool;
7268
7269 /// The `isPrototypeOf()` method checks if an object exists in another
7270 /// object's prototype chain.
7271 ///
7272 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isPrototypeOf)
7273 #[wasm_bindgen(method, js_name = isPrototypeOf)]
7274 pub fn is_prototype_of<T>(this: &Object<T>, value: &JsValue) -> bool;
7275
7276 /// The `Object.keys()` method returns an array of a given object's property
7277 /// names, in the same order as we get with a normal loop.
7278 ///
7279 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys)
7280 #[cfg(not(js_sys_unstable_apis))]
7281 #[wasm_bindgen(static_method_of = Object)]
7282 pub fn keys<T>(object: &Object<T>) -> Array;
7283
7284 /// The `Object.keys()` method returns an array of a given object's property
7285 /// names, in the same order as we get with a normal loop.
7286 ///
7287 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys)
7288 #[cfg(js_sys_unstable_apis)]
7289 #[wasm_bindgen(static_method_of = Object)]
7290 pub fn keys<T>(object: &Object<T>) -> Array<JsString>;
7291
7292 /// The [`Object`] constructor creates an object wrapper.
7293 ///
7294 /// **Note:** Consider using [`Object::new_typed`] for typed object records.
7295 ///
7296 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)
7297 #[wasm_bindgen(constructor)]
7298 pub fn new() -> Object;
7299
7300 // Next major: deprecate
7301 /// The [`Object`] constructor creates an object wrapper.
7302 ///
7303 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)
7304 #[wasm_bindgen(constructor)]
7305 pub fn new_typed<T>() -> Object<T>;
7306
7307 /// The `Object.preventExtensions()` method prevents new properties from
7308 /// ever being added to an object (i.e. prevents future extensions to the
7309 /// object).
7310 ///
7311 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/preventExtensions)
7312 #[wasm_bindgen(static_method_of = Object, js_name = preventExtensions)]
7313 pub fn prevent_extensions<T>(object: &Object<T>);
7314
7315 /// The `propertyIsEnumerable()` method returns a Boolean indicating
7316 /// whether the specified property is enumerable.
7317 ///
7318 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/propertyIsEnumerable)
7319 #[wasm_bindgen(method, js_name = propertyIsEnumerable)]
7320 pub fn property_is_enumerable<T>(this: &Object<T>, property: &JsValue) -> bool;
7321
7322 /// The `Object.seal()` method seals an object, preventing new properties
7323 /// from being added to it and marking all existing properties as
7324 /// non-configurable. Values of present properties can still be changed as
7325 /// long as they are writable.
7326 ///
7327 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/seal)
7328 #[wasm_bindgen(static_method_of = Object)]
7329 pub fn seal<T>(value: &Object<T>) -> Object<T>;
7330
7331 /// The `Object.setPrototypeOf()` method sets the prototype (i.e., the
7332 /// internal `[[Prototype]]` property) of a specified object to another
7333 /// object or `null`.
7334 ///
7335 /// **Note:** Consider using [`Object::try_set_prototype_of`] to support errors.
7336 ///
7337 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/setPrototypeOf)
7338 #[wasm_bindgen(static_method_of = Object, js_name = setPrototypeOf)]
7339 pub fn set_prototype_of<T>(object: &Object<T>, prototype: &Object) -> Object<T>;
7340
7341 /// The `Object.setPrototypeOf()` method sets the prototype (i.e., the
7342 /// internal `[[Prototype]]` property) of a specified object to another
7343 /// object or `null`.
7344 ///
7345 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/setPrototypeOf)
7346 #[wasm_bindgen(static_method_of = Object, js_name = setPrototypeOf, catch)]
7347 pub fn try_set_prototype_of<T>(
7348 object: &Object<T>,
7349 prototype: &Object,
7350 ) -> Result<Object<T>, JsValue>;
7351
7352 /// The `toLocaleString()` method returns a string representing the object.
7353 /// This method is meant to be overridden by derived objects for
7354 /// locale-specific purposes.
7355 ///
7356 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toLocaleString)
7357 #[wasm_bindgen(method, js_name = toLocaleString)]
7358 pub fn to_locale_string<T>(this: &Object<T>) -> JsString;
7359
7360 // Next major: deprecate
7361 /// The `toString()` method returns a string representing the object.
7362 ///
7363 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString)
7364 #[wasm_bindgen(method, js_name = toString)]
7365 pub fn to_string<T>(this: &Object<T>) -> JsString;
7366
7367 /// The `toString()` method returns a string representing the object.
7368 ///
7369 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString)
7370 #[wasm_bindgen(method, js_name = toString)]
7371 pub fn to_js_string<T>(this: &Object<T>) -> JsString;
7372
7373 /// The `valueOf()` method returns the primitive value of the
7374 /// specified object.
7375 ///
7376 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf)
7377 #[wasm_bindgen(method, js_name = valueOf)]
7378 pub fn value_of<T>(this: &Object<T>) -> Object;
7379
7380 /// The `Object.values()` method returns an array of a given object's own
7381 /// enumerable property values, in the same order as that provided by a
7382 /// `for...in` loop (the difference being that a for-in loop enumerates
7383 /// properties in the prototype chain as well).
7384 ///
7385 /// **Note:** Consider using [`Object::try_values`] to support errors.
7386 ///
7387 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values)
7388 #[cfg(not(js_sys_unstable_apis))]
7389 #[wasm_bindgen(static_method_of = Object)]
7390 pub fn values<T>(object: &Object<T>) -> Array<T>;
7391
7392 /// The `Object.values()` method returns an array of a given object's own
7393 /// enumerable property values, in the same order as that provided by a
7394 /// `for...in` loop (the difference being that a for-in loop enumerates
7395 /// properties in the prototype chain as well).
7396 ///
7397 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values)
7398 #[cfg(js_sys_unstable_apis)]
7399 #[wasm_bindgen(static_method_of = Object, catch, js_name = values)]
7400 pub fn values<T>(object: &Object<T>) -> Result<Array<T>, JsValue>;
7401
7402 // Next major: deprecate
7403 /// The `Object.values()` method returns an array of a given object's own
7404 /// enumerable property values, in the same order as that provided by a
7405 /// `for...in` loop (the difference being that a for-in loop enumerates
7406 /// properties in the prototype chain as well).
7407 ///
7408 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values)
7409 #[cfg(not(js_sys_unstable_apis))]
7410 #[wasm_bindgen(static_method_of = Object, catch, js_name = values)]
7411 pub fn try_values<T>(object: &Object<T>) -> Result<Array<T>, JsValue>;
7412}
7413
7414impl Object {
7415 /// Returns the `Object` value of this JS value if it's an instance of an
7416 /// object.
7417 ///
7418 /// If this JS value is not an instance of an object then this returns
7419 /// `None`.
7420 pub fn try_from(val: &JsValue) -> Option<&Object> {
7421 if val.is_object() {
7422 Some(val.unchecked_ref())
7423 } else {
7424 None
7425 }
7426 }
7427}
7428
7429impl PartialEq for Object {
7430 #[inline]
7431 fn eq(&self, other: &Object) -> bool {
7432 Object::is(self.as_ref(), other.as_ref())
7433 }
7434}
7435
7436impl Eq for Object {}
7437
7438impl Default for Object<JsValue> {
7439 fn default() -> Self {
7440 Self::new()
7441 }
7442}
7443
7444// Proxy
7445#[wasm_bindgen]
7446extern "C" {
7447 #[wasm_bindgen(typescript_type = "ProxyConstructor")]
7448 #[derive(Clone, Debug)]
7449 pub type Proxy;
7450
7451 /// The [`Proxy`] object is used to define custom behavior for fundamental
7452 /// operations (e.g. property lookup, assignment, enumeration, function
7453 /// invocation, etc).
7454 ///
7455 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy)
7456 #[wasm_bindgen(constructor)]
7457 pub fn new(target: &JsValue, handler: &Object) -> Proxy;
7458
7459 /// The `Proxy.revocable()` method is used to create a revocable [`Proxy`]
7460 /// object.
7461 ///
7462 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy/revocable)
7463 #[wasm_bindgen(static_method_of = Proxy)]
7464 pub fn revocable(target: &JsValue, handler: &Object) -> Object;
7465}
7466
7467// RangeError
7468#[wasm_bindgen]
7469extern "C" {
7470 /// The `RangeError` object indicates an error when a value is not in the set
7471 /// or range of allowed values.
7472 ///
7473 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError)
7474 #[wasm_bindgen(extends = Error, extends = Object, typescript_type = "RangeError")]
7475 #[derive(Clone, Debug, PartialEq, Eq)]
7476 pub type RangeError;
7477
7478 /// The `RangeError` object indicates an error when a value is not in the set
7479 /// or range of allowed values.
7480 ///
7481 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError)
7482 #[wasm_bindgen(constructor)]
7483 pub fn new(message: &str) -> RangeError;
7484
7485 /// Creates a new `RangeError` with the given message and a typed
7486 /// [`ErrorOptions`] dictionary whose `cause` property indicates the
7487 /// original cause of the error.
7488 ///
7489 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError/RangeError)
7490 #[wasm_bindgen(constructor)]
7491 pub fn new_with_options(message: &str, options: &ErrorOptions) -> RangeError;
7492}
7493
7494// ReferenceError
7495#[wasm_bindgen]
7496extern "C" {
7497 /// The `ReferenceError` object represents an error when a non-existent
7498 /// variable is referenced.
7499 ///
7500 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError)
7501 #[wasm_bindgen(extends = Error, extends = Object, typescript_type = "ReferenceError")]
7502 #[derive(Clone, Debug, PartialEq, Eq)]
7503 pub type ReferenceError;
7504
7505 /// The `ReferenceError` object represents an error when a non-existent
7506 /// variable is referenced.
7507 ///
7508 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError)
7509 #[wasm_bindgen(constructor)]
7510 pub fn new(message: &str) -> ReferenceError;
7511
7512 /// Creates a new `ReferenceError` with the given message and a typed
7513 /// [`ErrorOptions`] dictionary whose `cause` property indicates the
7514 /// original cause of the error.
7515 ///
7516 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError/ReferenceError)
7517 #[wasm_bindgen(constructor)]
7518 pub fn new_with_options(message: &str, options: &ErrorOptions) -> ReferenceError;
7519}
7520
7521#[allow(non_snake_case)]
7522pub mod Reflect {
7523 use super::*;
7524
7525 // Reflect
7526 #[wasm_bindgen]
7527 extern "C" {
7528 /// The static `Reflect.apply()` method calls a target function with
7529 /// arguments as specified.
7530 ///
7531 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/apply)
7532 #[wasm_bindgen(js_namespace = Reflect, catch)]
7533 pub fn apply<T: JsFunction = fn() -> JsValue>(
7534 target: &Function<T>,
7535 this_argument: &JsValue,
7536 arguments_list: &Array,
7537 ) -> Result<<T as JsFunction>::Ret, JsValue>;
7538
7539 /// The static `Reflect.construct()` method acts like the new operator, but
7540 /// as a function. It is equivalent to calling `new target(...args)`. It
7541 /// gives also the added option to specify a different prototype.
7542 ///
7543 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/construct)
7544 #[cfg(not(js_sys_unstable_apis))]
7545 #[wasm_bindgen(js_namespace = Reflect, catch)]
7546 pub fn construct<T: JsFunction = fn() -> JsValue>(
7547 target: &Function<T>,
7548 arguments_list: &Array,
7549 ) -> Result<JsValue, JsValue>;
7550
7551 /// The static `Reflect.construct()` method acts like the new operator, but
7552 /// as a function. It is equivalent to calling `new target(...args)`. It
7553 /// gives also the added option to specify a different prototype.
7554 ///
7555 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/construct)
7556 #[cfg(js_sys_unstable_apis)]
7557 #[wasm_bindgen(js_namespace = Reflect, catch)]
7558 pub fn construct<T: JsFunction = fn() -> JsValue>(
7559 target: &Function<T>,
7560 arguments_list: &ArrayTuple, // DOTO: <A1, A2, A3, A4, A5, A6, A7, A8>,
7561 ) -> Result<JsValue, JsValue>;
7562
7563 /// The static `Reflect.construct()` method acts like the new operator, but
7564 /// as a function. It is equivalent to calling `new target(...args)`. It
7565 /// gives also the added option to specify a different prototype.
7566 ///
7567 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/construct)
7568 #[wasm_bindgen(js_namespace = Reflect, js_name = construct, catch)]
7569 pub fn construct_with_new_target(
7570 target: &Function,
7571 arguments_list: &Array,
7572 new_target: &Function,
7573 ) -> Result<JsValue, JsValue>;
7574
7575 /// The static `Reflect.defineProperty()` method is like
7576 /// `Object.defineProperty()` but returns a `Boolean`.
7577 ///
7578 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/defineProperty)
7579 #[cfg(not(js_sys_unstable_apis))]
7580 #[wasm_bindgen(js_namespace = Reflect, js_name = defineProperty, catch)]
7581 pub fn define_property<T>(
7582 target: &Object<T>,
7583 property_key: &JsValue,
7584 attributes: &Object,
7585 ) -> Result<bool, JsValue>;
7586
7587 /// The static `Reflect.defineProperty()` method is like
7588 /// `Object.defineProperty()` but returns a `Boolean`.
7589 ///
7590 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/defineProperty)
7591 #[cfg(js_sys_unstable_apis)]
7592 #[wasm_bindgen(js_namespace = Reflect, js_name = defineProperty, catch)]
7593 pub fn define_property<T>(
7594 target: &Object<T>,
7595 property_key: &JsValue,
7596 attributes: &PropertyDescriptor<T>,
7597 ) -> Result<bool, JsValue>;
7598
7599 /// The static `Reflect.defineProperty()` method is like
7600 /// `Object.defineProperty()` but returns a `Boolean`.
7601 ///
7602 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/defineProperty)
7603 #[wasm_bindgen(js_namespace = Reflect, js_name = defineProperty, catch)]
7604 pub fn define_property_str<T>(
7605 target: &Object<T>,
7606 property_key: &JsString,
7607 attributes: &PropertyDescriptor<T>,
7608 ) -> Result<bool, JsValue>;
7609
7610 /// The static `Reflect.deleteProperty()` method allows to delete
7611 /// properties. It is like the `delete` operator as a function.
7612 ///
7613 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/deleteProperty)
7614 #[wasm_bindgen(js_namespace = Reflect, js_name = deleteProperty, catch)]
7615 pub fn delete_property<T>(target: &Object<T>, key: &JsValue) -> Result<bool, JsValue>;
7616
7617 /// The static `Reflect.deleteProperty()` method allows to delete
7618 /// properties. It is like the `delete` operator as a function.
7619 ///
7620 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/deleteProperty)
7621 #[wasm_bindgen(js_namespace = Reflect, js_name = deleteProperty, catch)]
7622 pub fn delete_property_str<T>(target: &Object<T>, key: &JsString) -> Result<bool, JsValue>;
7623
7624 /// The static `Reflect.get()` method works like getting a property from
7625 /// an object (`target[propertyKey]`) as a function.
7626 ///
7627 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/get)
7628 #[cfg(not(js_sys_unstable_apis))]
7629 #[wasm_bindgen(js_namespace = Reflect, catch)]
7630 pub fn get(target: &JsValue, key: &JsValue) -> Result<JsValue, JsValue>;
7631
7632 /// The static `Reflect.get()` method works like getting a property from
7633 /// an object (`target[propertyKey]`) as a function.
7634 ///
7635 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/get)
7636 #[cfg(js_sys_unstable_apis)]
7637 #[wasm_bindgen(js_namespace = Reflect, catch)]
7638 pub fn get<T>(target: &Object<T>, key: &JsString) -> Result<Option<T>, JsValue>;
7639
7640 /// The static `Reflect.get()` method works like getting a property from
7641 /// an object (`target[propertyKey]`) as a function.
7642 ///
7643 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/get)
7644 #[wasm_bindgen(js_namespace = Reflect, js_name = get, catch)]
7645 pub fn get_str<T>(target: &Object<T>, key: &JsString) -> Result<Option<T>, JsValue>;
7646
7647 /// The static `Reflect.get()` method works like getting a property from
7648 /// an object (`target[propertyKey]`) as a function.
7649 ///
7650 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/get)
7651 #[wasm_bindgen(js_namespace = Reflect, js_name = get, catch)]
7652 pub fn get_symbol<T>(target: &Object<T>, key: &Symbol) -> Result<JsValue, JsValue>;
7653
7654 /// The same as [`get`](fn.get.html)
7655 /// except the key is an `f64`, which is slightly faster.
7656 #[wasm_bindgen(js_namespace = Reflect, js_name = get, catch)]
7657 pub fn get_f64(target: &JsValue, key: f64) -> Result<JsValue, JsValue>;
7658
7659 /// The same as [`get`](fn.get.html)
7660 /// except the key is a `u32`, which is slightly faster.
7661 #[wasm_bindgen(js_namespace = Reflect, js_name = get, catch)]
7662 pub fn get_u32(target: &JsValue, key: u32) -> Result<JsValue, JsValue>;
7663
7664 /// The static `Reflect.getOwnPropertyDescriptor()` method is similar to
7665 /// `Object.getOwnPropertyDescriptor()`. It returns a property descriptor
7666 /// of the given property if it exists on the object, `undefined` otherwise.
7667 ///
7668 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getOwnPropertyDescriptor)
7669 #[wasm_bindgen(js_namespace = Reflect, js_name = getOwnPropertyDescriptor, catch)]
7670 pub fn get_own_property_descriptor<T>(
7671 target: &Object<T>,
7672 property_key: &JsValue,
7673 ) -> Result<JsValue, JsValue>;
7674
7675 /// The static `Reflect.getOwnPropertyDescriptor()` method is similar to
7676 /// `Object.getOwnPropertyDescriptor()`. It returns a property descriptor
7677 /// of the given property if it exists on the object, `undefined` otherwise.
7678 ///
7679 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getOwnPropertyDescriptor)
7680 #[wasm_bindgen(js_namespace = Reflect, js_name = getOwnPropertyDescriptor, catch)]
7681 pub fn get_own_property_descriptor_str<T>(
7682 target: &Object<T>,
7683 property_key: &JsString,
7684 ) -> Result<PropertyDescriptor<T>, JsValue>;
7685
7686 /// The static `Reflect.getPrototypeOf()` method is almost the same
7687 /// method as `Object.getPrototypeOf()`. It returns the prototype
7688 /// (i.e. the value of the internal `[[Prototype]]` property) of
7689 /// the specified object.
7690 ///
7691 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getPrototypeOf)
7692 #[cfg(not(js_sys_unstable_apis))]
7693 #[wasm_bindgen(js_namespace = Reflect, js_name = getPrototypeOf, catch)]
7694 pub fn get_prototype_of(target: &JsValue) -> Result<Object, JsValue>;
7695
7696 /// The static `Reflect.getPrototypeOf()` method is almost the same
7697 /// method as `Object.getPrototypeOf()`. It returns the prototype
7698 /// (i.e. the value of the internal `[[Prototype]]` property) of
7699 /// the specified object.
7700 ///
7701 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getPrototypeOf)
7702 #[cfg(js_sys_unstable_apis)]
7703 #[wasm_bindgen(js_namespace = Reflect, js_name = getPrototypeOf, catch)]
7704 pub fn get_prototype_of(target: &Object) -> Result<Object, JsValue>;
7705
7706 /// The static `Reflect.has()` method works like the in operator as a
7707 /// function.
7708 ///
7709 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/has)
7710 #[cfg(not(js_sys_unstable_apis))]
7711 #[wasm_bindgen(js_namespace = Reflect, catch)]
7712 pub fn has(target: &JsValue, property_key: &JsValue) -> Result<bool, JsValue>;
7713
7714 /// The static `Reflect.has()` method works like the in operator as a
7715 /// function.
7716 ///
7717 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/has)
7718 #[cfg(js_sys_unstable_apis)]
7719 #[wasm_bindgen(js_namespace = Reflect, catch)]
7720 pub fn has(target: &JsValue, property_key: &Symbol) -> Result<bool, JsValue>;
7721
7722 // Next major: deprecate
7723 /// The static `Reflect.has()` method works like the in operator as a
7724 /// function.
7725 ///
7726 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/has)
7727 #[wasm_bindgen(js_namespace = Reflect, js_name = has, catch)]
7728 pub fn has_str<T>(target: &Object<T>, property_key: &JsString) -> Result<bool, JsValue>;
7729
7730 /// The static `Reflect.has()` method works like the in operator as a
7731 /// function.
7732 ///
7733 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/has)
7734 #[wasm_bindgen(js_namespace = Reflect, js_name = has, catch)]
7735 pub fn has_symbol<T>(target: &Object<T>, property_key: &Symbol) -> Result<bool, JsValue>;
7736
7737 /// The static `Reflect.isExtensible()` method determines if an object is
7738 /// extensible (whether it can have new properties added to it). It is
7739 /// similar to `Object.isExtensible()`, but with some differences.
7740 ///
7741 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/isExtensible)
7742 #[wasm_bindgen(js_namespace = Reflect, js_name = isExtensible, catch)]
7743 pub fn is_extensible<T>(target: &Object<T>) -> Result<bool, JsValue>;
7744
7745 /// The static `Reflect.ownKeys()` method returns an array of the
7746 /// target object's own property keys.
7747 ///
7748 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/ownKeys)
7749 #[wasm_bindgen(js_namespace = Reflect, js_name = ownKeys, catch)]
7750 pub fn own_keys(target: &JsValue) -> Result<Array, JsValue>;
7751
7752 /// The static `Reflect.preventExtensions()` method prevents new
7753 /// properties from ever being added to an object (i.e. prevents
7754 /// future extensions to the object). It is similar to
7755 /// `Object.preventExtensions()`, but with some differences.
7756 ///
7757 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/preventExtensions)
7758 #[wasm_bindgen(js_namespace = Reflect, js_name = preventExtensions, catch)]
7759 pub fn prevent_extensions<T>(target: &Object<T>) -> Result<bool, JsValue>;
7760
7761 /// The static `Reflect.set()` method works like setting a
7762 /// property on an object.
7763 ///
7764 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
7765 #[cfg(not(js_sys_unstable_apis))]
7766 #[wasm_bindgen(js_namespace = Reflect, catch)]
7767 pub fn set(
7768 target: &JsValue,
7769 property_key: &JsValue,
7770 value: &JsValue,
7771 ) -> Result<bool, JsValue>;
7772
7773 /// The static `Reflect.set()` method works like setting a
7774 /// property on an object.
7775 ///
7776 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
7777 #[cfg(js_sys_unstable_apis)]
7778 #[wasm_bindgen(js_namespace = Reflect, catch)]
7779 pub fn set<T>(
7780 target: &Object<T>,
7781 property_key: &JsString,
7782 value: &T,
7783 ) -> Result<bool, JsValue>;
7784
7785 /// The static `Reflect.set()` method works like setting a
7786 /// property on an object.
7787 ///
7788 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
7789 #[cfg(js_sys_unstable_apis)]
7790 #[wasm_bindgen(js_namespace = Reflect, catch)]
7791 pub fn set_symbol<T>(
7792 target: &Object<T>,
7793 property_key: &Symbol,
7794 value: &JsValue,
7795 ) -> Result<bool, JsValue>;
7796
7797 // Next major: deprecate
7798 /// The static `Reflect.set()` method works like setting a
7799 /// property on an object.
7800 ///
7801 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
7802 #[wasm_bindgen(js_namespace = Reflect, js_name = set, catch)]
7803 pub fn set_str<T>(
7804 target: &Object<T>,
7805 property_key: &JsString,
7806 value: &T,
7807 ) -> Result<bool, JsValue>;
7808
7809 /// The same as [`set`](fn.set.html)
7810 /// except the key is an `f64`, which is slightly faster.
7811 #[wasm_bindgen(js_namespace = Reflect, js_name = set, catch)]
7812 pub fn set_f64(
7813 target: &JsValue,
7814 property_key: f64,
7815 value: &JsValue,
7816 ) -> Result<bool, JsValue>;
7817
7818 /// The same as [`set`](fn.set.html)
7819 /// except the key is a `u32`, which is slightly faster.
7820 #[wasm_bindgen(js_namespace = Reflect, js_name = set, catch)]
7821 pub fn set_u32(
7822 target: &JsValue,
7823 property_key: u32,
7824 value: &JsValue,
7825 ) -> Result<bool, JsValue>;
7826
7827 /// The static `Reflect.set()` method works like setting a
7828 /// property on an object.
7829 ///
7830 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
7831 #[wasm_bindgen(js_namespace = Reflect, js_name = set, catch)]
7832 pub fn set_with_receiver(
7833 target: &JsValue,
7834 property_key: &JsValue,
7835 value: &JsValue,
7836 receiver: &JsValue,
7837 ) -> Result<bool, JsValue>;
7838
7839 /// The static `Reflect.setPrototypeOf()` method is the same
7840 /// method as `Object.setPrototypeOf()`. It sets the prototype
7841 /// (i.e., the internal `[[Prototype]]` property) of a specified
7842 /// object to another object or to null.
7843 ///
7844 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/setPrototypeOf)
7845 #[wasm_bindgen(js_namespace = Reflect, js_name = setPrototypeOf, catch)]
7846 pub fn set_prototype_of<T>(
7847 target: &Object<T>,
7848 prototype: &JsValue,
7849 ) -> Result<bool, JsValue>;
7850 }
7851}
7852
7853// RegExp
7854#[wasm_bindgen]
7855extern "C" {
7856 #[wasm_bindgen(extends = Object, typescript_type = "RegExp")]
7857 #[derive(Clone, Debug, PartialEq, Eq)]
7858 pub type RegExp;
7859
7860 /// The `exec()` method executes a search for a match in a specified
7861 /// string. Returns a result array, or null.
7862 ///
7863 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec)
7864 #[cfg(not(js_sys_unstable_apis))]
7865 #[wasm_bindgen(method)]
7866 pub fn exec(this: &RegExp, text: &str) -> Option<Array<JsString>>;
7867
7868 /// The `exec()` method executes a search for a match in a specified
7869 /// string. Returns a result array, or null.
7870 ///
7871 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec)
7872 #[cfg(js_sys_unstable_apis)]
7873 #[wasm_bindgen(method)]
7874 pub fn exec(this: &RegExp, text: &str) -> Option<RegExpMatchArray>;
7875
7876 /// The flags property returns a string consisting of the flags of
7877 /// the current regular expression object.
7878 ///
7879 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/flags)
7880 #[wasm_bindgen(method, getter)]
7881 pub fn flags(this: &RegExp) -> JsString;
7882
7883 /// The global property indicates whether or not the "g" flag is
7884 /// used with the regular expression. global is a read-only
7885 /// property of an individual regular expression instance.
7886 ///
7887 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/global)
7888 #[wasm_bindgen(method, getter)]
7889 pub fn global(this: &RegExp) -> bool;
7890
7891 /// The ignoreCase property indicates whether or not the "i" flag
7892 /// is used with the regular expression. ignoreCase is a read-only
7893 /// property of an individual regular expression instance.
7894 ///
7895 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/ignoreCase)
7896 #[wasm_bindgen(method, getter, js_name = ignoreCase)]
7897 pub fn ignore_case(this: &RegExp) -> bool;
7898
7899 /// The non-standard input property is a static property of
7900 /// regular expressions that contains the string against which a
7901 /// regular expression is matched. RegExp.$_ is an alias for this
7902 /// property.
7903 ///
7904 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/input)
7905 #[wasm_bindgen(static_method_of = RegExp, getter)]
7906 pub fn input() -> JsString;
7907
7908 /// The lastIndex is a read/write integer property of regular expression
7909 /// instances that specifies the index at which to start the next match.
7910 ///
7911 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex)
7912 #[wasm_bindgen(structural, getter = lastIndex, method)]
7913 pub fn last_index(this: &RegExp) -> u32;
7914
7915 /// The lastIndex is a read/write integer property of regular expression
7916 /// instances that specifies the index at which to start the next match.
7917 ///
7918 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex)
7919 #[wasm_bindgen(structural, setter = lastIndex, method)]
7920 pub fn set_last_index(this: &RegExp, index: u32);
7921
7922 /// The non-standard lastMatch property is a static and read-only
7923 /// property of regular expressions that contains the last matched
7924 /// characters. `RegExp.$&` is an alias for this property.
7925 ///
7926 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastMatch)
7927 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = lastMatch)]
7928 pub fn last_match() -> JsString;
7929
7930 /// The non-standard lastParen property is a static and read-only
7931 /// property of regular expressions that contains the last
7932 /// parenthesized substring match, if any. `RegExp.$+` is an alias
7933 /// for this property.
7934 ///
7935 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastParen)
7936 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = lastParen)]
7937 pub fn last_paren() -> JsString;
7938
7939 /// The non-standard leftContext property is a static and
7940 /// read-only property of regular expressions that contains the
7941 /// substring preceding the most recent match. `RegExp.$`` is an
7942 /// alias for this property.
7943 ///
7944 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/leftContext)
7945 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = leftContext)]
7946 pub fn left_context() -> JsString;
7947
7948 /// The multiline property indicates whether or not the "m" flag
7949 /// is used with the regular expression. multiline is a read-only
7950 /// property of an individual regular expression instance.
7951 ///
7952 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/multiline)
7953 #[wasm_bindgen(method, getter)]
7954 pub fn multiline(this: &RegExp) -> bool;
7955
7956 /// The non-standard $1, $2, $3, $4, $5, $6, $7, $8, $9 properties
7957 /// are static and read-only properties of regular expressions
7958 /// that contain parenthesized substring matches.
7959 ///
7960 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/n)
7961 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$1")]
7962 pub fn n1() -> JsString;
7963 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$2")]
7964 pub fn n2() -> JsString;
7965 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$3")]
7966 pub fn n3() -> JsString;
7967 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$4")]
7968 pub fn n4() -> JsString;
7969 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$5")]
7970 pub fn n5() -> JsString;
7971 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$6")]
7972 pub fn n6() -> JsString;
7973 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$7")]
7974 pub fn n7() -> JsString;
7975 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$8")]
7976 pub fn n8() -> JsString;
7977 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$9")]
7978 pub fn n9() -> JsString;
7979
7980 /// The `RegExp` constructor creates a regular expression object for matching text with a pattern.
7981 ///
7982 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp)
7983 #[wasm_bindgen(constructor)]
7984 pub fn new(pattern: &str, flags: &str) -> RegExp;
7985 #[wasm_bindgen(constructor)]
7986 pub fn new_regexp(pattern: &RegExp, flags: &str) -> RegExp;
7987
7988 /// The non-standard rightContext property is a static and
7989 /// read-only property of regular expressions that contains the
7990 /// substring following the most recent match. `RegExp.$'` is an
7991 /// alias for this property.
7992 ///
7993 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/rightContext)
7994 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = rightContext)]
7995 pub fn right_context() -> JsString;
7996
7997 /// The source property returns a String containing the source
7998 /// text of the regexp object, and it doesn't contain the two
7999 /// forward slashes on both sides and any flags.
8000 ///
8001 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/source)
8002 #[wasm_bindgen(method, getter)]
8003 pub fn source(this: &RegExp) -> JsString;
8004
8005 /// The sticky property reflects whether or not the search is
8006 /// sticky (searches in strings only from the index indicated by
8007 /// the lastIndex property of this regular expression). sticky is
8008 /// a read-only property of an individual regular expression
8009 /// object.
8010 ///
8011 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/sticky)
8012 #[wasm_bindgen(method, getter)]
8013 pub fn sticky(this: &RegExp) -> bool;
8014
8015 /// The `test()` method executes a search for a match between a
8016 /// regular expression and a specified string. Returns true or
8017 /// false.
8018 ///
8019 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/test)
8020 #[wasm_bindgen(method)]
8021 pub fn test(this: &RegExp, text: &str) -> bool;
8022
8023 /// The `toString()` method returns a string representing the
8024 /// regular expression.
8025 ///
8026 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/toString)
8027 #[cfg(not(js_sys_unstable_apis))]
8028 #[wasm_bindgen(method, js_name = toString)]
8029 pub fn to_string(this: &RegExp) -> JsString;
8030
8031 /// The unicode property indicates whether or not the "u" flag is
8032 /// used with a regular expression. unicode is a read-only
8033 /// property of an individual regular expression instance.
8034 ///
8035 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/unicode)
8036 #[wasm_bindgen(method, getter)]
8037 pub fn unicode(this: &RegExp) -> bool;
8038}
8039
8040// RegExpMatchArray
8041#[wasm_bindgen]
8042extern "C" {
8043 /// The result array from `RegExp.exec()` or `String.matchAll()`.
8044 ///
8045 /// This is an array of strings with additional properties `index`, `input`, and `groups`.
8046 ///
8047 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec#return_value)
8048 #[wasm_bindgen(extends = Object, extends = Array, typescript_type = "RegExpMatchArray")]
8049 #[derive(Clone, Debug, PartialEq, Eq)]
8050 pub type RegExpMatchArray;
8051
8052 /// The 0-based index of the match in the string.
8053 #[wasm_bindgen(method, getter)]
8054 pub fn index(this: &RegExpMatchArray) -> u32;
8055
8056 /// The original string that was matched against.
8057 #[wasm_bindgen(method, getter)]
8058 pub fn input(this: &RegExpMatchArray) -> JsString;
8059
8060 /// An object of named capturing groups whose keys are the names and valuestype Array
8061 /// are the capturing groups, or `undefined` if no named capturing groups were defined.
8062 #[wasm_bindgen(method, getter)]
8063 pub fn groups(this: &RegExpMatchArray) -> Option<Object>;
8064
8065 /// The number of elements in the match array (full match + capture groups).
8066 #[wasm_bindgen(method, getter)]
8067 pub fn length(this: &RegExpMatchArray) -> u32;
8068
8069 /// Gets the matched string or capture group at the given index.
8070 /// Index 0 is the full match, indices 1+ are capture groups.
8071 #[wasm_bindgen(method, indexing_getter)]
8072 pub fn get(this: &RegExpMatchArray, index: u32) -> Option<JsString>;
8073}
8074
8075// Set
8076#[wasm_bindgen]
8077extern "C" {
8078 #[wasm_bindgen(extends = Object, typescript_type = "Set<any>")]
8079 #[derive(Clone, Debug, PartialEq, Eq)]
8080 pub type Set<T = JsValue>;
8081
8082 /// The [`Set`] object lets you store unique values of any type, whether
8083 /// primitive values or object references.
8084 ///
8085 /// **Note:** Consider using [`Set::new_typed`] to support typing.
8086 ///
8087 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
8088 #[cfg(not(js_sys_unstable_apis))]
8089 #[wasm_bindgen(constructor)]
8090 pub fn new(init: &JsValue) -> Set;
8091
8092 /// The [`Set`] object lets you store unique values of any type, whether
8093 /// primitive values or object references.
8094 ///
8095 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
8096 #[cfg(js_sys_unstable_apis)]
8097 #[wasm_bindgen(constructor)]
8098 pub fn new<T>() -> Set<T>;
8099
8100 // Next major: deprecate
8101 /// The [`Set`] object lets you store unique values of any type, whether
8102 /// primitive values or object references.
8103 ///
8104 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
8105 #[wasm_bindgen(constructor)]
8106 pub fn new_typed<T>() -> Set<T>;
8107
8108 /// The [`Set`] object lets you store unique values of any type, whether
8109 /// primitive values or object references.
8110 ///
8111 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
8112 #[wasm_bindgen(constructor, js_name = new)]
8113 pub fn new_empty<T>() -> Set<T>;
8114
8115 /// The [`Set`] object lets you store unique values of any type, whether
8116 /// primitive values or object references.
8117 ///
8118 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
8119 #[wasm_bindgen(constructor, js_name = new)]
8120 pub fn new_from_items<T>(items: &[T]) -> Set<T>;
8121
8122 /// The [`Set`] object lets you store unique values of any type, whether
8123 /// primitive values or object references.
8124 ///
8125 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
8126 #[wasm_bindgen(constructor, js_name = new, catch)]
8127 pub fn new_from_iterable<T, I: Iterable<Item = T>>(iterable: I) -> Result<Set<T>, JsValue>;
8128
8129 /// The `add()` method appends a new element with a specified value to the
8130 /// end of a [`Set`] object.
8131 ///
8132 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/add)
8133 #[wasm_bindgen(method)]
8134 pub fn add<T>(this: &Set<T>, value: &T) -> Set<T>;
8135
8136 /// The `clear()` method removes all elements from a [`Set`] object.
8137 ///
8138 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/clear)
8139 #[wasm_bindgen(method)]
8140 pub fn clear<T>(this: &Set<T>);
8141
8142 /// The `delete()` method removes the specified element from a [`Set`]
8143 /// object.
8144 ///
8145 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/delete)
8146 #[wasm_bindgen(method)]
8147 pub fn delete<T>(this: &Set<T>, value: &T) -> bool;
8148
8149 /// The `forEach()` method executes a provided function once for each value
8150 /// in the Set object, in insertion order.
8151 ///
8152 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/forEach)
8153 #[cfg(not(js_sys_unstable_apis))]
8154 #[wasm_bindgen(method, js_name = forEach)]
8155 pub fn for_each<T>(this: &Set<T>, callback: &mut dyn FnMut(T, T, Set<T>));
8156
8157 /// The `forEach()` method executes a provided function once for each value
8158 /// in the Set object, in insertion order.
8159 ///
8160 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/forEach)
8161 #[cfg(js_sys_unstable_apis)]
8162 #[wasm_bindgen(method, js_name = forEach)]
8163 pub fn for_each<T>(this: &Set<T>, callback: &mut dyn FnMut(T));
8164
8165 /// The `forEach()` method executes a provided function once for each value
8166 /// in the Set object, in insertion order.
8167 ///
8168 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/forEach)
8169 #[wasm_bindgen(method, js_name = forEach, catch)]
8170 pub fn try_for_each<T>(
8171 this: &Set<T>,
8172 callback: &mut dyn FnMut(T) -> Result<(), JsError>,
8173 ) -> Result<(), JsValue>;
8174
8175 /// The `has()` method returns a boolean indicating whether an element with
8176 /// the specified value exists in a [`Set`] object or not.
8177 ///
8178 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/has)
8179 #[wasm_bindgen(method)]
8180 pub fn has<T>(this: &Set<T>, value: &T) -> bool;
8181
8182 /// The size accessor property returns the number of elements in a [`Set`]
8183 /// object.
8184 ///
8185 /// [MDN documentation](https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Set/size)
8186 #[wasm_bindgen(method, getter)]
8187 pub fn size<T>(this: &Set<T>) -> u32;
8188
8189 /// The `union()` method returns a new set containing elements which are in
8190 /// either or both of this set and the given set.
8191 ///
8192 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/union)
8193 #[wasm_bindgen(method)]
8194 pub fn union<T>(this: &Set<T>, other: &Set<T>) -> Set<T>;
8195
8196 /// The `intersection()` method returns a new set containing elements which are
8197 /// in both this set and the given set.
8198 ///
8199 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/intersection)
8200 #[wasm_bindgen(method)]
8201 pub fn intersection<T>(this: &Set<T>, other: &Set<T>) -> Set<T>;
8202
8203 /// The `difference()` method returns a new set containing elements which are
8204 /// in this set but not in the given set.
8205 ///
8206 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/difference)
8207 #[wasm_bindgen(method)]
8208 pub fn difference<T>(this: &Set<T>, other: &Set<T>) -> Set<T>;
8209
8210 /// The `symmetricDifference()` method returns a new set containing elements
8211 /// which are in either this set or the given set, but not in both.
8212 ///
8213 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/symmetricDifference)
8214 #[wasm_bindgen(method, js_name = symmetricDifference)]
8215 pub fn symmetric_difference<T>(this: &Set<T>, other: &Set<T>) -> Set<T>;
8216
8217 /// The `isSubsetOf()` method returns a boolean indicating whether all elements
8218 /// of this set are in the given set.
8219 ///
8220 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/isSubsetOf)
8221 #[wasm_bindgen(method, js_name = isSubsetOf)]
8222 pub fn is_subset_of<T>(this: &Set<T>, other: &Set<T>) -> bool;
8223
8224 /// The `isSupersetOf()` method returns a boolean indicating whether all elements
8225 /// of the given set are in this set.
8226 ///
8227 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/isSupersetOf)
8228 #[wasm_bindgen(method, js_name = isSupersetOf)]
8229 pub fn is_superset_of<T>(this: &Set<T>, other: &Set<T>) -> bool;
8230
8231 /// The `isDisjointFrom()` method returns a boolean indicating whether this set
8232 /// has no elements in common with the given set.
8233 ///
8234 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/isDisjointFrom)
8235 #[wasm_bindgen(method, js_name = isDisjointFrom)]
8236 pub fn is_disjoint_from<T>(this: &Set<T>, other: &Set<T>) -> bool;
8237}
8238
8239impl Default for Set<JsValue> {
8240 fn default() -> Self {
8241 Self::new_typed()
8242 }
8243}
8244
8245impl<T> Iterable for Set<T> {
8246 type Item = T;
8247}
8248
8249// SetIterator
8250#[wasm_bindgen]
8251extern "C" {
8252 /// The `entries()` method returns a new Iterator object that contains an
8253 /// array of [value, value] for each element in the Set object, in insertion
8254 /// order. For Set objects there is no key like in Map objects. However, to
8255 /// keep the API similar to the Map object, each entry has the same value
8256 /// for its key and value here, so that an array [value, value] is returned.
8257 ///
8258 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/entries)
8259 #[cfg(not(js_sys_unstable_apis))]
8260 #[wasm_bindgen(method)]
8261 pub fn entries<T>(set: &Set<T>) -> Iterator;
8262
8263 /// The `entries()` method returns a new Iterator object that contains an
8264 /// array of [value, value] for each element in the Set object, in insertion
8265 /// order. For Set objects there is no key like in Map objects. However, to
8266 /// keep the API similar to the Map object, each entry has the same value
8267 /// for its key and value here, so that an array [value, value] is returned.
8268 ///
8269 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/entries)
8270 #[cfg(js_sys_unstable_apis)]
8271 #[wasm_bindgen(method, js_name = entries)]
8272 pub fn entries<T: JsGeneric>(set: &Set<T>) -> Iterator<ArrayTuple<(T, T)>>;
8273
8274 // Next major: deprecate
8275 /// The `entries()` method returns a new Iterator object that contains an
8276 /// array of [value, value] for each element in the Set object, in insertion
8277 /// order. For Set objects there is no key like in Map objects. However, to
8278 /// keep the API similar to the Map object, each entry has the same value
8279 /// for its key and value here, so that an array [value, value] is returned.
8280 ///
8281 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/entries)
8282 #[wasm_bindgen(method, js_name = entries)]
8283 pub fn entries_typed<T: JsGeneric>(set: &Set<T>) -> Iterator<ArrayTuple<(T, T)>>;
8284
8285 /// The `keys()` method is an alias for this method (for similarity with
8286 /// Map objects); it behaves exactly the same and returns values
8287 /// of Set elements.
8288 ///
8289 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/values)
8290 #[wasm_bindgen(method)]
8291 pub fn keys<T>(set: &Set<T>) -> Iterator<T>;
8292
8293 /// The `values()` method returns a new Iterator object that contains the
8294 /// values for each element in the Set object in insertion order.
8295 ///
8296 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/values)
8297 #[wasm_bindgen(method)]
8298 pub fn values<T>(set: &Set<T>) -> Iterator<T>;
8299}
8300
8301// SyntaxError
8302#[wasm_bindgen]
8303extern "C" {
8304 /// A `SyntaxError` is thrown when the JavaScript engine encounters tokens or
8305 /// token order that does not conform to the syntax of the language when
8306 /// parsing code.
8307 ///
8308 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError)
8309 #[wasm_bindgen(extends = Error, extends = Object, typescript_type = "SyntaxError")]
8310 #[derive(Clone, Debug, PartialEq, Eq)]
8311 pub type SyntaxError;
8312
8313 /// A `SyntaxError` is thrown when the JavaScript engine encounters tokens or
8314 /// token order that does not conform to the syntax of the language when
8315 /// parsing code.
8316 ///
8317 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError)
8318 #[wasm_bindgen(constructor)]
8319 pub fn new(message: &str) -> SyntaxError;
8320
8321 /// Creates a new `SyntaxError` with the given message and a typed
8322 /// [`ErrorOptions`] dictionary whose `cause` property indicates the
8323 /// original cause of the error.
8324 ///
8325 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError/SyntaxError)
8326 #[wasm_bindgen(constructor)]
8327 pub fn new_with_options(message: &str, options: &ErrorOptions) -> SyntaxError;
8328}
8329
8330// TypeError
8331#[wasm_bindgen]
8332extern "C" {
8333 /// The `TypeError` object represents an error when a value is not of the
8334 /// expected type.
8335 ///
8336 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError)
8337 #[wasm_bindgen(extends = Error, extends = Object, typescript_type = "TypeError")]
8338 #[derive(Clone, Debug, PartialEq, Eq)]
8339 pub type TypeError;
8340
8341 /// The `TypeError` object represents an error when a value is not of the
8342 /// expected type.
8343 ///
8344 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError)
8345 #[wasm_bindgen(constructor)]
8346 pub fn new(message: &str) -> TypeError;
8347
8348 /// Creates a new `TypeError` with the given message and a typed
8349 /// [`ErrorOptions`] dictionary whose `cause` property indicates the
8350 /// original cause of the error.
8351 ///
8352 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError/TypeError)
8353 #[wasm_bindgen(constructor)]
8354 pub fn new_with_options(message: &str, options: &ErrorOptions) -> TypeError;
8355}
8356
8357// URIError
8358#[wasm_bindgen]
8359extern "C" {
8360 /// The `URIError` object represents an error when a global URI handling
8361 /// function was used in a wrong way.
8362 ///
8363 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError)
8364 #[wasm_bindgen(extends = Error, extends = Object, js_name = URIError, typescript_type = "URIError")]
8365 #[derive(Clone, Debug, PartialEq, Eq)]
8366 pub type UriError;
8367
8368 /// The `URIError` object represents an error when a global URI handling
8369 /// function was used in a wrong way.
8370 ///
8371 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError)
8372 #[wasm_bindgen(constructor, js_class = "URIError")]
8373 pub fn new(message: &str) -> UriError;
8374
8375 /// Creates a new `URIError` with the given message and a typed
8376 /// [`ErrorOptions`] dictionary whose `cause` property indicates the
8377 /// original cause of the error.
8378 ///
8379 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError/URIError)
8380 #[wasm_bindgen(constructor, js_class = "URIError")]
8381 pub fn new_with_options(message: &str, options: &ErrorOptions) -> UriError;
8382}
8383
8384// WeakMap
8385#[wasm_bindgen]
8386extern "C" {
8387 #[wasm_bindgen(extends = Object, typescript_type = "WeakMap<object, any>")]
8388 #[derive(Clone, Debug, PartialEq, Eq)]
8389 pub type WeakMap<K = Object, V = JsValue>;
8390
8391 /// The [`WeakMap`] object is a collection of key/value pairs in which the
8392 /// keys are weakly referenced. The keys must be objects and the values can
8393 /// be arbitrary values.
8394 ///
8395 /// **Note:** Consider using [`WeakMap::new_typed`] to support typing.
8396 ///
8397 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap)
8398 #[cfg(not(js_sys_unstable_apis))]
8399 #[wasm_bindgen(constructor)]
8400 pub fn new() -> WeakMap;
8401
8402 /// The [`WeakMap`] object is a collection of key/value pairs in which the
8403 /// keys are weakly referenced. The keys must be objects and the values can
8404 /// be arbitrary values.
8405 ///
8406 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap)
8407 #[cfg(js_sys_unstable_apis)]
8408 #[wasm_bindgen(constructor)]
8409 pub fn new<K: JsGeneric = Object, V: JsGeneric = Object>() -> WeakMap<K, V>;
8410
8411 // Next major: deprecate
8412 /// The [`WeakMap`] object is a collection of key/value pairs in which the
8413 /// keys are weakly referenced. The keys must be objects and the values can
8414 /// be arbitrary values.
8415 ///
8416 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap)
8417 #[wasm_bindgen(constructor)]
8418 pub fn new_typed<K: JsGeneric = Object, V: JsGeneric = Object>() -> WeakMap<K, V>;
8419
8420 /// The `set()` method sets the value for the key in the [`WeakMap`] object.
8421 /// Returns the [`WeakMap`] object.
8422 ///
8423 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/set)
8424 #[wasm_bindgen(method, js_class = "WeakMap")]
8425 pub fn set<K, V>(this: &WeakMap<K, V>, key: &K, value: &V) -> WeakMap<K, V>;
8426
8427 /// The `get()` method returns a specified by key element
8428 /// from a [`WeakMap`] object. Returns `undefined` if the key is not found.
8429 ///
8430 /// **Note:** Consider using [`WeakMap::get_checked`] to get an `Option<V>` instead.
8431 ///
8432 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/get)
8433 #[cfg(not(js_sys_unstable_apis))]
8434 #[wasm_bindgen(method)]
8435 pub fn get<K, V>(this: &WeakMap<K, V>, key: &K) -> V;
8436
8437 /// The `get()` method returns a specified by key element
8438 /// from a [`WeakMap`] object. Returns `None` if the key is not found.
8439 ///
8440 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/get)
8441 #[cfg(js_sys_unstable_apis)]
8442 #[wasm_bindgen(method)]
8443 pub fn get<K, V>(this: &WeakMap<K, V>, key: &K) -> Option<V>;
8444
8445 /// The `get()` method returns a specified by key element
8446 /// from a [`WeakMap`] object. Returns `None` if the key is not found.
8447 ///
8448 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/get)
8449 #[wasm_bindgen(method, js_name = get)]
8450 pub fn get_checked<K, V>(this: &WeakMap<K, V>, key: &K) -> Option<V>;
8451
8452 /// The `has()` method returns a boolean indicating whether an element with
8453 /// the specified key exists in the [`WeakMap`] object or not.
8454 ///
8455 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/has)
8456 #[wasm_bindgen(method)]
8457 pub fn has<K, V>(this: &WeakMap<K, V>, key: &K) -> bool;
8458
8459 /// The `delete()` method removes the specified element from a [`WeakMap`]
8460 /// object.
8461 ///
8462 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/delete)
8463 #[wasm_bindgen(method)]
8464 pub fn delete<K, V>(this: &WeakMap<K, V>, key: &K) -> bool;
8465}
8466
8467impl Default for WeakMap {
8468 fn default() -> Self {
8469 Self::new()
8470 }
8471}
8472
8473// WeakSet
8474#[wasm_bindgen]
8475extern "C" {
8476 #[wasm_bindgen(extends = Object, typescript_type = "WeakSet<object>")]
8477 #[derive(Clone, Debug, PartialEq, Eq)]
8478 pub type WeakSet<T = Object>;
8479
8480 /// The `WeakSet` object lets you store weakly held objects in a collection.
8481 ///
8482 /// **Note:** Consider using [`WeakSet::new_typed`] for typed sets.
8483 ///
8484 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet)
8485 #[cfg(not(js_sys_unstable_apis))]
8486 #[wasm_bindgen(constructor)]
8487 pub fn new() -> WeakSet;
8488
8489 /// The `WeakSet` object lets you store weakly held objects in a collection.
8490 ///
8491 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet)
8492 #[cfg(js_sys_unstable_apis)]
8493 #[wasm_bindgen(constructor)]
8494 pub fn new<T = Object>() -> WeakSet<T>;
8495
8496 // Next major: deprecate
8497 /// The `WeakSet` object lets you store weakly held objects in a collection.
8498 ///
8499 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet)
8500 #[wasm_bindgen(constructor)]
8501 pub fn new_typed<T = Object>() -> WeakSet<T>;
8502
8503 /// The `has()` method returns a boolean indicating whether an object exists
8504 /// in a WeakSet or not.
8505 ///
8506 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet/has)
8507 #[wasm_bindgen(method)]
8508 pub fn has<T>(this: &WeakSet<T>, value: &T) -> bool;
8509
8510 /// The `add()` method appends a new object to the end of a WeakSet object.
8511 ///
8512 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet/add)
8513 #[wasm_bindgen(method)]
8514 pub fn add<T>(this: &WeakSet<T>, value: &T) -> WeakSet<T>;
8515
8516 /// The `delete()` method removes the specified element from a WeakSet
8517 /// object.
8518 ///
8519 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet/delete)
8520 #[wasm_bindgen(method)]
8521 pub fn delete<T>(this: &WeakSet<T>, value: &T) -> bool;
8522}
8523
8524impl Default for WeakSet {
8525 fn default() -> Self {
8526 Self::new()
8527 }
8528}
8529
8530// WeakRef
8531#[wasm_bindgen]
8532extern "C" {
8533 #[wasm_bindgen(extends = Object, typescript_type = "WeakRef<object>")]
8534 #[derive(Clone, Debug, PartialEq, Eq)]
8535 pub type WeakRef<T = Object>;
8536
8537 /// The `WeakRef` object contains a weak reference to an object. A weak
8538 /// reference to an object is a reference that does not prevent the object
8539 /// from being reclaimed by the garbage collector.
8540 ///
8541 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef)
8542 #[wasm_bindgen(constructor)]
8543 pub fn new<T = Object>(target: &T) -> WeakRef<T>;
8544
8545 /// Returns the `Object` this `WeakRef` points to, or `None` if the
8546 /// object has been garbage collected.
8547 ///
8548 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef/deref)
8549 #[wasm_bindgen(method)]
8550 pub fn deref<T>(this: &WeakRef<T>) -> Option<T>;
8551}
8552
8553#[cfg(js_sys_unstable_apis)]
8554#[allow(non_snake_case)]
8555pub mod Temporal;
8556
8557#[allow(non_snake_case)]
8558pub mod WebAssembly {
8559 use super::*;
8560
8561 // WebAssembly
8562 #[wasm_bindgen]
8563 extern "C" {
8564 /// The `WebAssembly.compile()` function compiles a `WebAssembly.Module`
8565 /// from WebAssembly binary code. This function is useful if it is
8566 /// necessary to a compile a module before it can be instantiated
8567 /// (otherwise, the `WebAssembly.instantiate()` function should be used).
8568 ///
8569 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compile)
8570 #[cfg(not(js_sys_unstable_apis))]
8571 #[wasm_bindgen(js_namespace = WebAssembly)]
8572 pub fn compile(buffer_source: &JsValue) -> Promise<JsValue>;
8573
8574 /// The `WebAssembly.compile()` function compiles a `WebAssembly.Module`
8575 /// from WebAssembly binary code. This function is useful if it is
8576 /// necessary to a compile a module before it can be instantiated
8577 /// (otherwise, the `WebAssembly.instantiate()` function should be used).
8578 ///
8579 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compile)
8580 #[cfg(js_sys_unstable_apis)]
8581 #[wasm_bindgen(js_namespace = WebAssembly)]
8582 pub fn compile(buffer_source: &JsValue) -> Promise<Module>;
8583
8584 /// The `WebAssembly.compileStreaming()` function compiles a
8585 /// `WebAssembly.Module` module directly from a streamed underlying
8586 /// source. This function is useful if it is necessary to a compile a
8587 /// module before it can be instantiated (otherwise, the
8588 /// `WebAssembly.instantiateStreaming()` function should be used).
8589 ///
8590 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compileStreaming)
8591 #[cfg(not(js_sys_unstable_apis))]
8592 #[wasm_bindgen(js_namespace = WebAssembly, js_name = compileStreaming)]
8593 pub fn compile_streaming(response: &Promise) -> Promise<JsValue>;
8594
8595 /// The `WebAssembly.compileStreaming()` function compiles a
8596 /// `WebAssembly.Module` module directly from a streamed underlying
8597 /// source. This function is useful if it is necessary to a compile a
8598 /// module before it can be instantiated (otherwise, the
8599 /// `WebAssembly.instantiateStreaming()` function should be used).
8600 ///
8601 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compileStreaming)
8602 #[cfg(js_sys_unstable_apis)]
8603 #[wasm_bindgen(js_namespace = WebAssembly, js_name = compileStreaming)]
8604 pub fn compile_streaming(response: &Promise) -> Promise<Module>;
8605
8606 /// The `WebAssembly.instantiate()` function allows you to compile and
8607 /// instantiate WebAssembly code.
8608 ///
8609 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate)
8610 #[cfg(not(js_sys_unstable_apis))]
8611 #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiate)]
8612 pub fn instantiate_buffer(buffer: &[u8], imports: &Object) -> Promise<JsValue>;
8613
8614 /// The `WebAssembly.instantiate()` function allows you to compile and
8615 /// instantiate WebAssembly code.
8616 ///
8617 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate)
8618 #[cfg(js_sys_unstable_apis)]
8619 #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiate)]
8620 pub fn instantiate_buffer(buffer: &[u8], imports: &Object) -> Promise<Instance>;
8621
8622 /// The `WebAssembly.instantiate()` function allows you to compile and
8623 /// instantiate WebAssembly code.
8624 ///
8625 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate)
8626 #[cfg(not(js_sys_unstable_apis))]
8627 #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiate)]
8628 pub fn instantiate_module(module: &Module, imports: &Object) -> Promise<JsValue>;
8629
8630 /// The `WebAssembly.instantiate()` function allows you to compile and
8631 /// instantiate WebAssembly code.
8632 ///
8633 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate)
8634 #[cfg(js_sys_unstable_apis)]
8635 #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiate)]
8636 pub fn instantiate_module(module: &Module, imports: &Object) -> Promise<Instance>;
8637
8638 /// The `WebAssembly.instantiateStreaming()` function compiles and
8639 /// instantiates a WebAssembly module directly from a streamed
8640 /// underlying source. This is the most efficient, optimized way to load
8641 /// Wasm code.
8642 ///
8643 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiateStreaming)
8644 #[cfg(not(js_sys_unstable_apis))]
8645 #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiateStreaming)]
8646 pub fn instantiate_streaming(response: &JsValue, imports: &Object) -> Promise<JsValue>;
8647
8648 /// The `WebAssembly.instantiateStreaming()` function compiles and
8649 /// instantiates a WebAssembly module directly from a streamed
8650 /// underlying source. This is the most efficient, optimized way to load
8651 /// Wasm code.
8652 ///
8653 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiateStreaming)
8654 #[cfg(js_sys_unstable_apis)]
8655 #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiateStreaming)]
8656 pub fn instantiate_streaming(response: &JsValue, imports: &Object) -> Promise<Instance>;
8657
8658 /// The `WebAssembly.validate()` function validates a given typed
8659 /// array of WebAssembly binary code, returning whether the bytes
8660 /// form a valid Wasm module (`true`) or not (`false`).
8661 ///
8662 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/validate)
8663 #[wasm_bindgen(js_namespace = WebAssembly, catch)]
8664 pub fn validate(buffer_source: &JsValue) -> Result<bool, JsValue>;
8665 }
8666
8667 // WebAssembly.CompileError
8668 #[wasm_bindgen]
8669 extern "C" {
8670 /// The `WebAssembly.CompileError()` constructor creates a new
8671 /// WebAssembly `CompileError` object, which indicates an error during
8672 /// WebAssembly decoding or validation.
8673 ///
8674 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/CompileError)
8675 #[wasm_bindgen(extends = Error, js_namespace = WebAssembly, typescript_type = "WebAssembly.CompileError")]
8676 #[derive(Clone, Debug, PartialEq, Eq)]
8677 pub type CompileError;
8678
8679 /// The `WebAssembly.CompileError()` constructor creates a new
8680 /// WebAssembly `CompileError` object, which indicates an error during
8681 /// WebAssembly decoding or validation.
8682 ///
8683 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/CompileError)
8684 #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
8685 pub fn new(message: &str) -> CompileError;
8686
8687 /// Creates a new `WebAssembly.CompileError` with the given message and
8688 /// a typed [`ErrorOptions`] dictionary whose `cause` property
8689 /// indicates the original cause of the error.
8690 ///
8691 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/CompileError/CompileError)
8692 #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
8693 pub fn new_with_options(message: &str, options: &ErrorOptions) -> CompileError;
8694 }
8695
8696 // WebAssembly.Instance
8697 #[wasm_bindgen]
8698 extern "C" {
8699 /// A `WebAssembly.Instance` object is a stateful, executable instance
8700 /// of a `WebAssembly.Module`. Instance objects contain all the exported
8701 /// WebAssembly functions that allow calling into WebAssembly code from
8702 /// JavaScript.
8703 ///
8704 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance)
8705 #[wasm_bindgen(extends = Object, js_namespace = WebAssembly, typescript_type = "WebAssembly.Instance")]
8706 #[derive(Clone, Debug, PartialEq, Eq)]
8707 pub type Instance;
8708
8709 /// The `WebAssembly.Instance()` constructor function can be called to
8710 /// synchronously instantiate a given `WebAssembly.Module`
8711 /// object. However, the primary way to get an `Instance` is through the
8712 /// asynchronous `WebAssembly.instantiateStreaming()` function.
8713 ///
8714 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance)
8715 #[wasm_bindgen(catch, constructor, js_namespace = WebAssembly)]
8716 pub fn new(module: &Module, imports: &Object) -> Result<Instance, JsValue>;
8717
8718 /// The `exports` readonly property of the `WebAssembly.Instance` object
8719 /// prototype returns an object containing as its members all the
8720 /// functions exported from the WebAssembly module instance, to allow
8721 /// them to be accessed and used by JavaScript.
8722 ///
8723 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance/exports)
8724 #[wasm_bindgen(getter, method, js_namespace = WebAssembly)]
8725 pub fn exports(this: &Instance) -> Object;
8726 }
8727
8728 // WebAssembly.LinkError
8729 #[wasm_bindgen]
8730 extern "C" {
8731 /// The `WebAssembly.LinkError()` constructor creates a new WebAssembly
8732 /// LinkError object, which indicates an error during module
8733 /// instantiation (besides traps from the start function).
8734 ///
8735 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/LinkError)
8736 #[wasm_bindgen(extends = Error, js_namespace = WebAssembly, typescript_type = "WebAssembly.LinkError")]
8737 #[derive(Clone, Debug, PartialEq, Eq)]
8738 pub type LinkError;
8739
8740 /// The `WebAssembly.LinkError()` constructor creates a new WebAssembly
8741 /// LinkError object, which indicates an error during module
8742 /// instantiation (besides traps from the start function).
8743 ///
8744 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/LinkError)
8745 #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
8746 pub fn new(message: &str) -> LinkError;
8747
8748 /// Creates a new `WebAssembly.LinkError` with the given message and a
8749 /// typed [`ErrorOptions`] dictionary whose `cause` property indicates
8750 /// the original cause of the error.
8751 ///
8752 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/LinkError/LinkError)
8753 #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
8754 pub fn new_with_options(message: &str, options: &ErrorOptions) -> LinkError;
8755 }
8756
8757 // WebAssembly.RuntimeError
8758 #[wasm_bindgen]
8759 extern "C" {
8760 /// The `WebAssembly.RuntimeError()` constructor creates a new WebAssembly
8761 /// `RuntimeError` object — the type that is thrown whenever WebAssembly
8762 /// specifies a trap.
8763 ///
8764 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/RuntimeError)
8765 #[wasm_bindgen(extends = Error, js_namespace = WebAssembly, typescript_type = "WebAssembly.RuntimeError")]
8766 #[derive(Clone, Debug, PartialEq, Eq)]
8767 pub type RuntimeError;
8768
8769 /// The `WebAssembly.RuntimeError()` constructor creates a new WebAssembly
8770 /// `RuntimeError` object — the type that is thrown whenever WebAssembly
8771 /// specifies a trap.
8772 ///
8773 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/RuntimeError)
8774 #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
8775 pub fn new(message: &str) -> RuntimeError;
8776
8777 /// Creates a new `WebAssembly.RuntimeError` with the given message
8778 /// and a typed [`ErrorOptions`] dictionary whose `cause` property
8779 /// indicates the original cause of the error.
8780 ///
8781 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/RuntimeError/RuntimeError)
8782 #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
8783 pub fn new_with_options(message: &str, options: &ErrorOptions) -> RuntimeError;
8784 }
8785
8786 // WebAssembly.Module
8787 #[wasm_bindgen]
8788 extern "C" {
8789 /// A `WebAssembly.Module` object contains stateless WebAssembly code
8790 /// that has already been compiled by the browser and can be
8791 /// efficiently shared with Workers, and instantiated multiple times.
8792 ///
8793 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module)
8794 #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Module")]
8795 #[derive(Clone, Debug, PartialEq, Eq)]
8796 pub type Module;
8797
8798 /// A `WebAssembly.Module` object contains stateless WebAssembly code
8799 /// that has already been compiled by the browser and can be
8800 /// efficiently shared with Workers, and instantiated multiple times.
8801 ///
8802 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module)
8803 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
8804 pub fn new(buffer_source: &JsValue) -> Result<Module, JsValue>;
8805
8806 /// The `WebAssembly.customSections()` function returns a copy of the
8807 /// contents of all custom sections in the given module with the given
8808 /// string name.
8809 ///
8810 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/customSections)
8811 #[wasm_bindgen(static_method_of = Module, js_namespace = WebAssembly, js_name = customSections)]
8812 pub fn custom_sections(module: &Module, sectionName: &str) -> Array;
8813
8814 /// The `WebAssembly.exports()` function returns an array containing
8815 /// descriptions of all the declared exports of the given `Module`.
8816 ///
8817 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/exports)
8818 #[wasm_bindgen(static_method_of = Module, js_namespace = WebAssembly)]
8819 pub fn exports(module: &Module) -> Array;
8820
8821 /// The `WebAssembly.imports()` function returns an array containing
8822 /// descriptions of all the declared imports of the given `Module`.
8823 ///
8824 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/imports)
8825 #[wasm_bindgen(static_method_of = Module, js_namespace = WebAssembly)]
8826 pub fn imports(module: &Module) -> Array;
8827 }
8828
8829 // WebAssembly.Table
8830 #[wasm_bindgen]
8831 extern "C" {
8832 /// The `WebAssembly.Table()` constructor creates a new `Table` object
8833 /// of the given size and element type.
8834 ///
8835 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table)
8836 #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Table")]
8837 #[derive(Clone, Debug, PartialEq, Eq)]
8838 pub type Table;
8839
8840 /// The `WebAssembly.Table()` constructor creates a new `Table` object
8841 /// of the given size and element type.
8842 ///
8843 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table)
8844 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
8845 pub fn new(table_descriptor: &Object) -> Result<Table, JsValue>;
8846
8847 /// The `WebAssembly.Table()` constructor creates a new `Table` object
8848 /// of the given size and element type.
8849 ///
8850 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table)
8851 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
8852 pub fn new_with_value(table_descriptor: &Object, value: JsValue) -> Result<Table, JsValue>;
8853
8854 /// The length prototype property of the `WebAssembly.Table` object
8855 /// returns the length of the table, i.e. the number of elements in the
8856 /// table.
8857 ///
8858 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/length)
8859 #[wasm_bindgen(method, getter, js_namespace = WebAssembly)]
8860 pub fn length(this: &Table) -> u32;
8861
8862 /// The `get()` prototype method of the `WebAssembly.Table()` object
8863 /// retrieves a function reference stored at a given index.
8864 ///
8865 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/get)
8866 #[wasm_bindgen(method, catch, js_namespace = WebAssembly)]
8867 pub fn get(this: &Table, index: u32) -> Result<Function, JsValue>;
8868
8869 /// The `get()` prototype method of the `WebAssembly.Table()` object
8870 /// retrieves a function reference stored at a given index.
8871 ///
8872 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/get)
8873 #[wasm_bindgen(method, catch, js_namespace = WebAssembly, js_name = get)]
8874 pub fn get_raw(this: &Table, index: u32) -> Result<JsValue, JsValue>;
8875
8876 /// The `grow()` prototype method of the `WebAssembly.Table` object
8877 /// increases the size of the `Table` instance by a specified number of
8878 /// elements.
8879 ///
8880 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/grow)
8881 #[wasm_bindgen(method, catch, js_namespace = WebAssembly)]
8882 pub fn grow(this: &Table, additional_capacity: u32) -> Result<u32, JsValue>;
8883
8884 /// The `grow()` prototype method of the `WebAssembly.Table` object
8885 /// increases the size of the `Table` instance by a specified number of
8886 /// elements.
8887 ///
8888 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/grow)
8889 #[wasm_bindgen(method, catch, js_namespace = WebAssembly, js_name = grow)]
8890 pub fn grow_with_value(
8891 this: &Table,
8892 additional_capacity: u32,
8893 value: JsValue,
8894 ) -> Result<u32, JsValue>;
8895
8896 /// The `set()` prototype method of the `WebAssembly.Table` object mutates a
8897 /// reference stored at a given index to a different value.
8898 ///
8899 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/set)
8900 #[wasm_bindgen(method, catch, js_namespace = WebAssembly)]
8901 pub fn set(this: &Table, index: u32, function: &Function) -> Result<(), JsValue>;
8902
8903 /// The `set()` prototype method of the `WebAssembly.Table` object mutates a
8904 /// reference stored at a given index to a different value.
8905 ///
8906 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/set)
8907 #[wasm_bindgen(method, catch, js_namespace = WebAssembly, js_name = set)]
8908 pub fn set_raw(this: &Table, index: u32, value: &JsValue) -> Result<(), JsValue>;
8909 }
8910
8911 // WebAssembly.Tag
8912 #[wasm_bindgen]
8913 extern "C" {
8914 /// The `WebAssembly.Tag()` constructor creates a new `Tag` object
8915 ///
8916 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Tag)
8917 #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Tag")]
8918 #[derive(Clone, Debug, PartialEq, Eq)]
8919 pub type Tag;
8920
8921 /// The `WebAssembly.Tag()` constructor creates a new `Tag` object
8922 ///
8923 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Tag)
8924 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
8925 pub fn new(tag_descriptor: &Object) -> Result<Tag, JsValue>;
8926 }
8927
8928 // WebAssembly.Exception
8929 #[wasm_bindgen]
8930 extern "C" {
8931 /// The `WebAssembly.Exception()` constructor creates a new `Exception` object
8932 ///
8933 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception)
8934 #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Exception")]
8935 #[derive(Clone, Debug, PartialEq, Eq)]
8936 pub type Exception;
8937
8938 /// The `WebAssembly.Exception()` constructor creates a new `Exception` object
8939 ///
8940 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception)
8941 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
8942 pub fn new(tag: &Tag, payload: &Array) -> Result<Exception, JsValue>;
8943
8944 /// The `WebAssembly.Exception()` constructor creates a new `Exception` object
8945 ///
8946 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception)
8947 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
8948 pub fn new_with_options(
8949 tag: &Tag,
8950 payload: &Array,
8951 options: &Object,
8952 ) -> Result<Exception, JsValue>;
8953
8954 /// The `is()` prototype method of the `WebAssembly.Exception` can be used to
8955 /// test if the Exception matches a given tag.
8956 ///
8957 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception/is)
8958 #[wasm_bindgen(method, js_namespace = WebAssembly)]
8959 pub fn is(this: &Exception, tag: &Tag) -> bool;
8960
8961 /// The `getArg()` prototype method of the `WebAssembly.Exception` can be used
8962 /// to get the value of a specified item in the exception's data arguments
8963 ///
8964 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception/getArg)
8965 #[wasm_bindgen(method, js_namespace = WebAssembly, js_name = getArg, catch)]
8966 pub fn get_arg(this: &Exception, tag: &Tag, index: u32) -> Result<JsValue, JsValue>;
8967 }
8968
8969 // WebAssembly.Global
8970 #[wasm_bindgen]
8971 extern "C" {
8972 /// The `WebAssembly.Global()` constructor creates a new `Global` object
8973 /// of the given type and value.
8974 ///
8975 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global)
8976 #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Global")]
8977 #[derive(Clone, Debug, PartialEq, Eq)]
8978 pub type Global;
8979
8980 /// The `WebAssembly.Global()` constructor creates a new `Global` object
8981 /// of the given type and value.
8982 ///
8983 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global)
8984 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
8985 pub fn new(global_descriptor: &Object, value: &JsValue) -> Result<Global, JsValue>;
8986
8987 /// The value prototype property of the `WebAssembly.Global` object
8988 /// returns the value of the global.
8989 ///
8990 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global)
8991 #[wasm_bindgen(method, getter, js_namespace = WebAssembly)]
8992 pub fn value(this: &Global) -> JsValue;
8993 #[wasm_bindgen(method, setter = value, js_namespace = WebAssembly)]
8994 pub fn set_value(this: &Global, value: &JsValue);
8995 }
8996
8997 // WebAssembly.Memory
8998 #[wasm_bindgen]
8999 extern "C" {
9000 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory)
9001 #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Memory")]
9002 #[derive(Clone, Debug, PartialEq, Eq)]
9003 pub type Memory;
9004
9005 /// The `WebAssembly.Memory()` constructor creates a new `Memory` object
9006 /// which is a resizable `ArrayBuffer` that holds the raw bytes of
9007 /// memory accessed by a WebAssembly `Instance`.
9008 ///
9009 /// A memory created by JavaScript or in WebAssembly code will be
9010 /// accessible and mutable from both JavaScript and WebAssembly.
9011 ///
9012 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory)
9013 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
9014 pub fn new(descriptor: &Object) -> Result<Memory, JsValue>;
9015
9016 /// An accessor property that returns the buffer contained in the
9017 /// memory.
9018 ///
9019 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory/buffer)
9020 #[wasm_bindgen(method, getter, js_namespace = WebAssembly)]
9021 pub fn buffer(this: &Memory) -> JsValue;
9022
9023 /// The `grow()` prototype method of the `Memory` object increases the
9024 /// size of the memory instance by a specified number of WebAssembly
9025 /// pages.
9026 ///
9027 /// Takes the number of pages to grow (64KiB in size) and returns the
9028 /// previous size of memory, in pages.
9029 ///
9030 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory/grow)
9031 #[wasm_bindgen(method, js_namespace = WebAssembly)]
9032 pub fn grow(this: &Memory, pages: u32) -> u32;
9033 }
9034}
9035
9036/// The `JSON` object contains methods for parsing [JavaScript Object
9037/// Notation (JSON)](https://json.org/) and converting values to JSON. It
9038/// can't be called or constructed, and aside from its two method
9039/// properties, it has no interesting functionality of its own.
9040#[allow(non_snake_case)]
9041pub mod JSON {
9042 use super::*;
9043
9044 // JSON
9045 #[wasm_bindgen]
9046 extern "C" {
9047 /// The `JSON.parse()` method parses a JSON string, constructing the
9048 /// JavaScript value or object described by the string.
9049 ///
9050 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse)
9051 #[wasm_bindgen(catch, js_namespace = JSON)]
9052 pub fn parse(text: &str) -> Result<JsValue, JsValue>;
9053
9054 /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
9055 ///
9056 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
9057 #[wasm_bindgen(catch, js_namespace = JSON)]
9058 pub fn stringify(obj: &JsValue) -> Result<JsString, JsValue>;
9059
9060 /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
9061 ///
9062 /// The `replacer` argument is a function that alters the behavior of the stringification
9063 /// process, or an array of String and Number objects that serve as a whitelist
9064 /// for selecting/filtering the properties of the value object to be included
9065 /// in the JSON string. If this value is null or not provided, all properties
9066 /// of the object are included in the resulting JSON string.
9067 ///
9068 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
9069 #[cfg(not(js_sys_unstable_apis))]
9070 #[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
9071 pub fn stringify_with_replacer(
9072 obj: &JsValue,
9073 replacer: &JsValue,
9074 ) -> Result<JsString, JsValue>;
9075
9076 /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
9077 ///
9078 /// The `replacer` argument is a function that alters the behavior of the stringification
9079 /// process, or an array of String and Number objects that serve as a whitelist
9080 /// for selecting/filtering the properties of the value object to be included
9081 /// in the JSON string. If this value is null or not provided, all properties
9082 /// of the object are included in the resulting JSON string.
9083 ///
9084 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
9085 #[cfg(js_sys_unstable_apis)]
9086 #[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
9087 pub fn stringify_with_replacer<'a>(
9088 obj: &JsValue,
9089 replacer: &mut dyn FnMut(JsString, JsValue) -> Result<Option<JsValue>, JsError>,
9090 space: Option<u32>,
9091 ) -> Result<JsString, JsValue>;
9092
9093 // Next major: deprecate
9094 /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
9095 ///
9096 /// The `replacer` argument is a function that alters the behavior of the stringification
9097 /// process, or an array of String and Number objects that serve as a whitelist
9098 /// for selecting/filtering the properties of the value object to be included
9099 /// in the JSON string. If this value is null or not provided, all properties
9100 /// of the object are included in the resulting JSON string.
9101 ///
9102 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
9103 #[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
9104 pub fn stringify_with_replacer_func<'a>(
9105 obj: &JsValue,
9106 replacer: &mut dyn FnMut(JsString, JsValue) -> Result<Option<JsValue>, JsError>,
9107 space: Option<u32>,
9108 ) -> Result<JsString, JsValue>;
9109
9110 /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
9111 ///
9112 /// The `replacer` argument is a function that alters the behavior of the stringification
9113 /// process, or an array of String and Number objects that serve as a whitelist
9114 /// for selecting/filtering the properties of the value object to be included
9115 /// in the JSON string. If this value is null or not provided, all properties
9116 /// of the object are included in the resulting JSON string.
9117 ///
9118 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
9119 #[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
9120 pub fn stringify_with_replacer_list(
9121 obj: &JsValue,
9122 replacer: Vec<String>,
9123 space: Option<u32>,
9124 ) -> Result<JsString, JsValue>;
9125
9126 // Next major: deprecate
9127 /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
9128 ///
9129 /// The `replacer` argument is a function that alters the behavior of the stringification
9130 /// process, or an array of String and Number objects that serve as a whitelist
9131 /// for selecting/filtering the properties of the value object to be included
9132 /// in the JSON string. If this value is null or not provided, all properties
9133 /// of the object are included in the resulting JSON string.
9134 ///
9135 /// The `space` argument is a String or Number object that's used to insert white space into
9136 /// the output JSON string for readability purposes. If this is a Number, it
9137 /// indicates the number of space characters to use as white space; this number
9138 /// is capped at 10 (if it is greater, the value is just 10). Values less than
9139 /// 1 indicate that no space should be used. If this is a String, the string
9140 /// (or the first 10 characters of the string, if it's longer than that) is
9141 /// used as white space. If this parameter is not provided (or is null), no
9142 /// white space is used.
9143 ///
9144 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
9145 #[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
9146 pub fn stringify_with_replacer_and_space(
9147 obj: &JsValue,
9148 replacer: &JsValue,
9149 space: &JsValue,
9150 ) -> Result<JsString, JsValue>;
9151 }
9152}
9153// JsString
9154#[wasm_bindgen]
9155extern "C" {
9156 #[wasm_bindgen(js_name = String, extends = Object, is_type_of = JsValue::is_string, typescript_type = "string")]
9157 #[derive(Clone, PartialEq, Eq)]
9158 pub type JsString;
9159
9160 /// The length property of a String object indicates the length of a string,
9161 /// in UTF-16 code units.
9162 ///
9163 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/length)
9164 #[wasm_bindgen(method, getter)]
9165 pub fn length(this: &JsString) -> u32;
9166
9167 /// The 'at()' method returns a new string consisting of the single UTF-16
9168 /// code unit located at the specified offset into the string, counting from
9169 /// the end if it's negative.
9170 ///
9171 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/at)
9172 #[wasm_bindgen(method, js_class = "String")]
9173 pub fn at(this: &JsString, index: i32) -> Option<JsString>;
9174
9175 /// The String object's `charAt()` method returns a new string consisting of
9176 /// the single UTF-16 code unit located at the specified offset into the
9177 /// string.
9178 ///
9179 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charAt)
9180 #[wasm_bindgen(method, js_class = "String", js_name = charAt)]
9181 pub fn char_at(this: &JsString, index: u32) -> JsString;
9182
9183 /// The `charCodeAt()` method returns an integer between 0 and 65535
9184 /// representing the UTF-16 code unit at the given index (the UTF-16 code
9185 /// unit matches the Unicode code point for code points representable in a
9186 /// single UTF-16 code unit, but might also be the first code unit of a
9187 /// surrogate pair for code points not representable in a single UTF-16 code
9188 /// unit, e.g. Unicode code points > 0x10000). If you want the entire code
9189 /// point value, use `codePointAt()`.
9190 ///
9191 /// Returns `NaN` if index is out of range.
9192 ///
9193 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charCodeAt)
9194 #[wasm_bindgen(method, js_class = "String", js_name = charCodeAt)]
9195 pub fn char_code_at(this: &JsString, index: u32) -> f64;
9196
9197 /// The `codePointAt()` method returns a non-negative integer that is the
9198 /// Unicode code point value.
9199 ///
9200 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/codePointAt)
9201 #[cfg(not(js_sys_unstable_apis))]
9202 #[wasm_bindgen(method, js_class = "String", js_name = codePointAt)]
9203 pub fn code_point_at(this: &JsString, pos: u32) -> JsValue;
9204
9205 /// The `codePointAt()` method returns a non-negative integer that is the
9206 /// Unicode code point value.
9207 ///
9208 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/codePointAt)
9209 #[cfg(js_sys_unstable_apis)]
9210 #[wasm_bindgen(method, js_class = "String", js_name = codePointAt)]
9211 pub fn code_point_at(this: &JsString, pos: u32) -> Option<u32>;
9212
9213 // Next major: deprecate
9214 /// The `codePointAt()` method returns a non-negative integer that is the
9215 /// Unicode code point value.
9216 ///
9217 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/codePointAt)
9218 #[wasm_bindgen(method, js_class = "String", js_name = codePointAt)]
9219 pub fn try_code_point_at(this: &JsString, pos: u32) -> Option<u16>;
9220
9221 /// The `concat()` method concatenates the string arguments to the calling
9222 /// string and returns a new string.
9223 ///
9224 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/concat)
9225 #[cfg(not(js_sys_unstable_apis))]
9226 #[wasm_bindgen(method, js_class = "String")]
9227 pub fn concat(this: &JsString, string_2: &JsValue) -> JsString;
9228
9229 /// The `concat()` method concatenates the string arguments to the calling
9230 /// string and returns a new string.
9231 ///
9232 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/concat)
9233 #[cfg(js_sys_unstable_apis)]
9234 #[wasm_bindgen(method, js_class = "String")]
9235 pub fn concat(this: &JsString, string: &JsString) -> JsString;
9236
9237 /// The `concat()` method concatenates the string arguments to the calling
9238 /// string and returns a new string.
9239 ///
9240 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/concat)
9241 #[wasm_bindgen(method, js_class = "String")]
9242 pub fn concat_many(this: &JsString, strings: &[JsString]) -> JsString;
9243
9244 /// The `endsWith()` method determines whether a string ends with the characters of a
9245 /// specified string, returning true or false as appropriate.
9246 ///
9247 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith)
9248 #[cfg(not(js_sys_unstable_apis))]
9249 #[wasm_bindgen(method, js_class = "String", js_name = endsWith)]
9250 pub fn ends_with(this: &JsString, search_string: &str, length: i32) -> bool;
9251
9252 /// The `endsWith()` method determines whether a string ends with the characters of a
9253 /// specified string, returning true or false as appropriate.
9254 ///
9255 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith)
9256 #[cfg(js_sys_unstable_apis)]
9257 #[wasm_bindgen(method, js_class = "String", js_name = endsWith)]
9258 pub fn ends_with(this: &JsString, search_string: &str) -> bool;
9259
9260 /// The static `String.fromCharCode()` method returns a string created from
9261 /// the specified sequence of UTF-16 code units.
9262 ///
9263 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
9264 ///
9265 /// # Notes
9266 ///
9267 /// There are a few bindings to `from_char_code` in `js-sys`: `from_char_code1`, `from_char_code2`, etc...
9268 /// with different arities.
9269 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode, variadic)]
9270 pub fn from_char_code(char_codes: &[u16]) -> JsString;
9271
9272 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
9273 #[cfg(not(js_sys_unstable_apis))]
9274 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
9275 pub fn from_char_code1(a: u32) -> JsString;
9276
9277 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
9278 #[cfg(js_sys_unstable_apis)]
9279 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
9280 pub fn from_char_code1(a: u16) -> JsString;
9281
9282 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
9283 #[cfg(not(js_sys_unstable_apis))]
9284 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
9285 pub fn from_char_code2(a: u32, b: u32) -> JsString;
9286
9287 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
9288 #[cfg(js_sys_unstable_apis)]
9289 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
9290 pub fn from_char_code2(a: u16, b: u16) -> JsString;
9291
9292 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
9293 #[cfg(not(js_sys_unstable_apis))]
9294 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
9295 pub fn from_char_code3(a: u32, b: u32, c: u32) -> JsString;
9296
9297 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
9298 #[cfg(js_sys_unstable_apis)]
9299 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
9300 pub fn from_char_code3(a: u16, b: u16, c: u16) -> JsString;
9301
9302 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
9303 #[cfg(not(js_sys_unstable_apis))]
9304 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
9305 pub fn from_char_code4(a: u32, b: u32, c: u32, d: u32) -> JsString;
9306
9307 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
9308 #[cfg(js_sys_unstable_apis)]
9309 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
9310 pub fn from_char_code4(a: u16, b: u16, c: u16, d: u16) -> JsString;
9311
9312 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
9313 #[cfg(not(js_sys_unstable_apis))]
9314 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
9315 pub fn from_char_code5(a: u32, b: u32, c: u32, d: u32, e: u32) -> JsString;
9316
9317 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
9318 #[cfg(js_sys_unstable_apis)]
9319 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
9320 pub fn from_char_code5(a: u16, b: u16, c: u16, d: u16, e: u16) -> JsString;
9321
9322 /// The static `String.fromCodePoint()` method returns a string created by
9323 /// using the specified sequence of code points.
9324 ///
9325 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
9326 ///
9327 /// # Exceptions
9328 ///
9329 /// A RangeError is thrown if an invalid Unicode code point is given
9330 ///
9331 /// # Notes
9332 ///
9333 /// There are a few bindings to `from_code_point` in `js-sys`: `from_code_point1`, `from_code_point2`, etc...
9334 /// with different arities.
9335 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint, variadic)]
9336 pub fn from_code_point(code_points: &[u32]) -> Result<JsString, JsValue>;
9337
9338 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
9339 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
9340 pub fn from_code_point1(a: u32) -> Result<JsString, JsValue>;
9341
9342 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
9343 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
9344 pub fn from_code_point2(a: u32, b: u32) -> Result<JsString, JsValue>;
9345
9346 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
9347 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
9348 pub fn from_code_point3(a: u32, b: u32, c: u32) -> Result<JsString, JsValue>;
9349
9350 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
9351 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
9352 pub fn from_code_point4(a: u32, b: u32, c: u32, d: u32) -> Result<JsString, JsValue>;
9353
9354 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
9355 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
9356 pub fn from_code_point5(a: u32, b: u32, c: u32, d: u32, e: u32) -> Result<JsString, JsValue>;
9357
9358 /// The `includes()` method determines whether one string may be found
9359 /// within another string, returning true or false as appropriate.
9360 ///
9361 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes)
9362 #[wasm_bindgen(method, js_class = "String")]
9363 pub fn includes(this: &JsString, search_string: &str, position: i32) -> bool;
9364
9365 /// The `indexOf()` method returns the index within the calling String
9366 /// object of the first occurrence of the specified value, starting the
9367 /// search at fromIndex. Returns -1 if the value is not found.
9368 ///
9369 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf)
9370 #[wasm_bindgen(method, js_class = "String", js_name = indexOf)]
9371 pub fn index_of(this: &JsString, search_value: &str, from_index: i32) -> i32;
9372
9373 /// The `lastIndexOf()` method returns the index within the calling String
9374 /// object of the last occurrence of the specified value, searching
9375 /// backwards from fromIndex. Returns -1 if the value is not found.
9376 ///
9377 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/lastIndexOf)
9378 #[wasm_bindgen(method, js_class = "String", js_name = lastIndexOf)]
9379 pub fn last_index_of(this: &JsString, search_value: &str, from_index: i32) -> i32;
9380
9381 /// The `localeCompare()` method returns a number indicating whether
9382 /// a reference string comes before or after or is the same as
9383 /// the given string in sort order.
9384 ///
9385 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare)
9386 #[cfg(not(js_sys_unstable_apis))]
9387 #[wasm_bindgen(method, js_class = "String", js_name = localeCompare)]
9388 pub fn locale_compare(
9389 this: &JsString,
9390 compare_string: &str,
9391 locales: &Array,
9392 options: &Object,
9393 ) -> i32;
9394
9395 /// The `localeCompare()` method returns a number indicating whether
9396 /// a reference string comes before or after or is the same as
9397 /// the given string in sort order.
9398 ///
9399 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare)
9400 #[cfg(js_sys_unstable_apis)]
9401 #[wasm_bindgen(method, js_class = "String", js_name = localeCompare)]
9402 pub fn locale_compare(
9403 this: &JsString,
9404 compare_string: &str,
9405 locales: &[JsString],
9406 options: &Intl::CollatorOptions,
9407 ) -> i32;
9408
9409 /// The `match()` method retrieves the matches when matching a string against a regular expression.
9410 ///
9411 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match)
9412 #[wasm_bindgen(method, js_class = "String", js_name = match)]
9413 pub fn match_(this: &JsString, pattern: &RegExp) -> Option<Object>;
9414
9415 /// The `match_all()` method is similar to `match()`, but gives an iterator of `exec()` arrays, which preserve capture groups.
9416 ///
9417 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/matchAll)
9418 #[cfg(not(js_sys_unstable_apis))]
9419 #[wasm_bindgen(method, js_class = "String", js_name = matchAll)]
9420 pub fn match_all(this: &JsString, pattern: &RegExp) -> Iterator;
9421
9422 /// The `match_all()` method is similar to `match()`, but gives an iterator of `exec()` arrays, which preserve capture groups.
9423 ///
9424 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/matchAll)
9425 #[cfg(js_sys_unstable_apis)]
9426 #[wasm_bindgen(method, js_class = "String", js_name = matchAll)]
9427 pub fn match_all(this: &JsString, pattern: &RegExp) -> Iterator<RegExpMatchArray>;
9428
9429 /// The `normalize()` method returns the Unicode Normalization Form
9430 /// of a given string (if the value isn't a string, it will be converted to one first).
9431 ///
9432 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize)
9433 #[wasm_bindgen(method, js_class = "String")]
9434 pub fn normalize(this: &JsString, form: &str) -> JsString;
9435
9436 /// The `padEnd()` method pads the current string with a given string
9437 /// (repeated, if needed) so that the resulting string reaches a given
9438 /// length. The padding is applied from the end (right) of the current
9439 /// string.
9440 ///
9441 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padEnd)
9442 #[wasm_bindgen(method, js_class = "String", js_name = padEnd)]
9443 pub fn pad_end(this: &JsString, target_length: u32, pad_string: &str) -> JsString;
9444
9445 /// The `padStart()` method pads the current string with another string
9446 /// (repeated, if needed) so that the resulting string reaches the given
9447 /// length. The padding is applied from the start (left) of the current
9448 /// string.
9449 ///
9450 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padStart)
9451 #[wasm_bindgen(method, js_class = "String", js_name = padStart)]
9452 pub fn pad_start(this: &JsString, target_length: u32, pad_string: &str) -> JsString;
9453
9454 /// The `repeat()` method constructs and returns a new string which contains the specified
9455 /// number of copies of the string on which it was called, concatenated together.
9456 ///
9457 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat)
9458 #[wasm_bindgen(method, js_class = "String")]
9459 pub fn repeat(this: &JsString, count: i32) -> JsString;
9460
9461 /// The `replace()` method returns a new string with some or all matches of a pattern
9462 /// replaced by a replacement. The pattern can be a string or a RegExp, and
9463 /// the replacement can be a string or a function to be called for each match.
9464 ///
9465 /// Note: The original string will remain unchanged.
9466 ///
9467 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
9468 #[wasm_bindgen(method, js_class = "String")]
9469 pub fn replace(this: &JsString, pattern: &str, replacement: &str) -> JsString;
9470
9471 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
9472 #[cfg(not(js_sys_unstable_apis))]
9473 #[wasm_bindgen(method, js_class = "String", js_name = replace)]
9474 pub fn replace_with_function(
9475 this: &JsString,
9476 pattern: &str,
9477 replacement: &Function,
9478 ) -> JsString;
9479
9480 /// The replacer function signature is `(match, offset, string) -> replacement`
9481 /// for patterns without capture groups, or `(match, p1, p2, ..., pN, offset, string, groups) -> replacement`
9482 /// when capture groups are present.
9483 ///
9484 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
9485 #[cfg(js_sys_unstable_apis)]
9486 #[wasm_bindgen(method, js_class = "String", js_name = replace)]
9487 pub fn replace_with_function(
9488 this: &JsString,
9489 pattern: &str,
9490 replacement: &Function<fn(JsString) -> JsString>,
9491 ) -> JsString;
9492
9493 #[wasm_bindgen(method, js_class = "String", js_name = replace)]
9494 pub fn replace_by_pattern(this: &JsString, pattern: &RegExp, replacement: &str) -> JsString;
9495
9496 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
9497 #[cfg(not(js_sys_unstable_apis))]
9498 #[wasm_bindgen(method, js_class = "String", js_name = replace)]
9499 pub fn replace_by_pattern_with_function(
9500 this: &JsString,
9501 pattern: &RegExp,
9502 replacement: &Function,
9503 ) -> JsString;
9504
9505 /// The replacer function signature is `(match, offset, string) -> replacement`
9506 /// for patterns without capture groups, or `(match, p1, p2, ..., pN, offset, string, groups) -> replacement`
9507 /// when capture groups are present.
9508 ///
9509 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
9510 #[cfg(js_sys_unstable_apis)]
9511 #[wasm_bindgen(method, js_class = "String", js_name = replace)]
9512 pub fn replace_by_pattern_with_function(
9513 this: &JsString,
9514 pattern: &RegExp,
9515 replacement: &Function<fn(JsString) -> JsString>,
9516 ) -> JsString;
9517
9518 /// The `replace_all()` method returns a new string with all matches of a pattern
9519 /// replaced by a replacement. The pattern can be a string or a global RegExp, and
9520 /// the replacement can be a string or a function to be called for each match.
9521 ///
9522 /// Note: The original string will remain unchanged.
9523 ///
9524 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)
9525 #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
9526 pub fn replace_all(this: &JsString, pattern: &str, replacement: &str) -> JsString;
9527
9528 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)
9529 #[cfg(not(js_sys_unstable_apis))]
9530 #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
9531 pub fn replace_all_with_function(
9532 this: &JsString,
9533 pattern: &str,
9534 replacement: &Function,
9535 ) -> JsString;
9536
9537 /// The replacer function signature is `(match, offset, string) -> replacement`
9538 /// for patterns without capture groups, or `(match, p1, p2, ..., pN, offset, string, groups) -> replacement`
9539 /// when capture groups are present.
9540 ///
9541 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)
9542 #[cfg(js_sys_unstable_apis)]
9543 #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
9544 pub fn replace_all_with_function(
9545 this: &JsString,
9546 pattern: &str,
9547 replacement: &Function<fn(JsString) -> JsString>,
9548 ) -> JsString;
9549
9550 #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
9551 pub fn replace_all_by_pattern(this: &JsString, pattern: &RegExp, replacement: &str)
9552 -> JsString;
9553
9554 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)
9555 #[cfg(not(js_sys_unstable_apis))]
9556 #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
9557 pub fn replace_all_by_pattern_with_function(
9558 this: &JsString,
9559 pattern: &RegExp,
9560 replacement: &Function,
9561 ) -> JsString;
9562
9563 /// The replacer function signature is `(match, offset, string) -> replacement`
9564 /// for patterns without capture groups, or `(match, p1, p2, ..., pN, offset, string, groups) -> replacement`
9565 /// when capture groups are present.
9566 ///
9567 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)
9568 #[cfg(js_sys_unstable_apis)]
9569 #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
9570 pub fn replace_all_by_pattern_with_function(
9571 this: &JsString,
9572 pattern: &RegExp,
9573 replacement: &Function<fn(JsString) -> JsString>,
9574 ) -> JsString;
9575
9576 /// The `search()` method executes a search for a match between
9577 /// a regular expression and this String object.
9578 ///
9579 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/search)
9580 #[wasm_bindgen(method, js_class = "String")]
9581 pub fn search(this: &JsString, pattern: &RegExp) -> i32;
9582
9583 /// The `slice()` method extracts a section of a string and returns it as a
9584 /// new string, without modifying the original string.
9585 ///
9586 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice)
9587 #[wasm_bindgen(method, js_class = "String")]
9588 pub fn slice(this: &JsString, start: u32, end: u32) -> JsString;
9589
9590 /// The `split()` method splits a String object into an array of strings by separating the string
9591 /// into substrings, using a specified separator string to determine where to make each split.
9592 ///
9593 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)
9594 #[wasm_bindgen(method, js_class = "String")]
9595 pub fn split(this: &JsString, separator: &str) -> Array;
9596
9597 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)
9598 #[wasm_bindgen(method, js_class = "String", js_name = split)]
9599 pub fn split_limit(this: &JsString, separator: &str, limit: u32) -> Array;
9600
9601 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)
9602 #[wasm_bindgen(method, js_class = "String", js_name = split)]
9603 pub fn split_by_pattern(this: &JsString, pattern: &RegExp) -> Array;
9604
9605 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)
9606 #[wasm_bindgen(method, js_class = "String", js_name = split)]
9607 pub fn split_by_pattern_limit(this: &JsString, pattern: &RegExp, limit: u32) -> Array;
9608
9609 /// The `startsWith()` method determines whether a string begins with the
9610 /// characters of a specified string, returning true or false as
9611 /// appropriate.
9612 ///
9613 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith)
9614 #[wasm_bindgen(method, js_class = "String", js_name = startsWith)]
9615 pub fn starts_with(this: &JsString, search_string: &str, position: u32) -> bool;
9616
9617 /// The `substring()` method returns the part of the string between the
9618 /// start and end indexes, or to the end of the string.
9619 ///
9620 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring)
9621 #[wasm_bindgen(method, js_class = "String")]
9622 pub fn substring(this: &JsString, index_start: u32, index_end: u32) -> JsString;
9623
9624 /// The `substr()` method returns the part of a string between
9625 /// the start index and a number of characters after it.
9626 ///
9627 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr)
9628 #[wasm_bindgen(method, js_class = "String")]
9629 pub fn substr(this: &JsString, start: i32, length: i32) -> JsString;
9630
9631 /// The `toLocaleLowerCase()` method returns the calling string value converted to lower case,
9632 /// according to any locale-specific case mappings.
9633 ///
9634 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLocaleLowerCase)
9635 #[wasm_bindgen(method, js_class = "String", js_name = toLocaleLowerCase)]
9636 pub fn to_locale_lower_case(this: &JsString, locale: Option<&str>) -> JsString;
9637
9638 /// The `toLocaleUpperCase()` method returns the calling string value converted to upper case,
9639 /// according to any locale-specific case mappings.
9640 ///
9641 /// [MDN documentation](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/String/toLocaleUpperCase)
9642 #[wasm_bindgen(method, js_class = "String", js_name = toLocaleUpperCase)]
9643 pub fn to_locale_upper_case(this: &JsString, locale: Option<&str>) -> JsString;
9644
9645 /// The `toLowerCase()` method returns the calling string value
9646 /// converted to lower case.
9647 ///
9648 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLowerCase)
9649 #[wasm_bindgen(method, js_class = "String", js_name = toLowerCase)]
9650 pub fn to_lower_case(this: &JsString) -> JsString;
9651
9652 /// The `toString()` method returns a string representing the specified
9653 /// object.
9654 ///
9655 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toString)
9656 #[cfg(not(js_sys_unstable_apis))]
9657 #[wasm_bindgen(method, js_class = "String", js_name = toString)]
9658 pub fn to_string(this: &JsString) -> JsString;
9659
9660 /// The `toUpperCase()` method returns the calling string value converted to
9661 /// uppercase (the value will be converted to a string if it isn't one).
9662 ///
9663 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase)
9664 #[wasm_bindgen(method, js_class = "String", js_name = toUpperCase)]
9665 pub fn to_upper_case(this: &JsString) -> JsString;
9666
9667 /// The `trim()` method removes whitespace from both ends of a string.
9668 /// Whitespace in this context is all the whitespace characters (space, tab,
9669 /// no-break space, etc.) and all the line terminator characters (LF, CR,
9670 /// etc.).
9671 ///
9672 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trim)
9673 #[wasm_bindgen(method, js_class = "String")]
9674 pub fn trim(this: &JsString) -> JsString;
9675
9676 /// The `trimEnd()` method removes whitespace from the end of a string.
9677 /// `trimRight()` is an alias of this method.
9678 ///
9679 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimEnd)
9680 #[wasm_bindgen(method, js_class = "String", js_name = trimEnd)]
9681 pub fn trim_end(this: &JsString) -> JsString;
9682
9683 /// The `trimEnd()` method removes whitespace from the end of a string.
9684 /// `trimRight()` is an alias of this method.
9685 ///
9686 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimEnd)
9687 #[wasm_bindgen(method, js_class = "String", js_name = trimRight)]
9688 pub fn trim_right(this: &JsString) -> JsString;
9689
9690 /// The `trimStart()` method removes whitespace from the beginning of a
9691 /// string. `trimLeft()` is an alias of this method.
9692 ///
9693 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimStart)
9694 #[wasm_bindgen(method, js_class = "String", js_name = trimStart)]
9695 pub fn trim_start(this: &JsString) -> JsString;
9696
9697 /// The `trimStart()` method removes whitespace from the beginning of a
9698 /// string. `trimLeft()` is an alias of this method.
9699 ///
9700 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimStart)
9701 #[wasm_bindgen(method, js_class = "String", js_name = trimLeft)]
9702 pub fn trim_left(this: &JsString) -> JsString;
9703
9704 /// The `valueOf()` method returns the primitive value of a `String` object.
9705 ///
9706 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/valueOf)
9707 #[wasm_bindgen(method, js_class = "String", js_name = valueOf)]
9708 pub fn value_of(this: &JsString) -> JsString;
9709
9710 /// The static `raw()` method is a tag function of template literals,
9711 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9712 ///
9713 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9714 #[wasm_bindgen(catch, variadic, static_method_of = JsString, js_class = "String")]
9715 pub fn raw(call_site: &Object, substitutions: &Array) -> Result<JsString, JsValue>;
9716
9717 /// The static `raw()` method is a tag function of template literals,
9718 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9719 ///
9720 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9721 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9722 pub fn raw_0(call_site: &Object) -> Result<JsString, JsValue>;
9723
9724 /// The static `raw()` method is a tag function of template literals,
9725 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9726 ///
9727 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9728 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9729 pub fn raw_1(call_site: &Object, substitutions_1: &str) -> Result<JsString, JsValue>;
9730
9731 /// The static `raw()` method is a tag function of template literals,
9732 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9733 ///
9734 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9735 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9736 pub fn raw_2(
9737 call_site: &Object,
9738 substitutions1: &str,
9739 substitutions2: &str,
9740 ) -> Result<JsString, JsValue>;
9741
9742 /// The static `raw()` method is a tag function of template literals,
9743 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9744 ///
9745 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9746 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9747 pub fn raw_3(
9748 call_site: &Object,
9749 substitutions1: &str,
9750 substitutions2: &str,
9751 substitutions3: &str,
9752 ) -> Result<JsString, JsValue>;
9753
9754 /// The static `raw()` method is a tag function of template literals,
9755 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9756 ///
9757 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9758 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9759 pub fn raw_4(
9760 call_site: &Object,
9761 substitutions1: &str,
9762 substitutions2: &str,
9763 substitutions3: &str,
9764 substitutions4: &str,
9765 ) -> Result<JsString, JsValue>;
9766
9767 /// The static `raw()` method is a tag function of template literals,
9768 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9769 ///
9770 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9771 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9772 pub fn raw_5(
9773 call_site: &Object,
9774 substitutions1: &str,
9775 substitutions2: &str,
9776 substitutions3: &str,
9777 substitutions4: &str,
9778 substitutions5: &str,
9779 ) -> Result<JsString, JsValue>;
9780
9781 /// The static `raw()` method is a tag function of template literals,
9782 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9783 ///
9784 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9785 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9786 pub fn raw_6(
9787 call_site: &Object,
9788 substitutions1: &str,
9789 substitutions2: &str,
9790 substitutions3: &str,
9791 substitutions4: &str,
9792 substitutions5: &str,
9793 substitutions6: &str,
9794 ) -> Result<JsString, JsValue>;
9795
9796 /// The static `raw()` method is a tag function of template literals,
9797 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9798 ///
9799 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9800 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9801 pub fn raw_7(
9802 call_site: &Object,
9803 substitutions1: &str,
9804 substitutions2: &str,
9805 substitutions3: &str,
9806 substitutions4: &str,
9807 substitutions5: &str,
9808 substitutions6: &str,
9809 substitutions7: &str,
9810 ) -> Result<JsString, JsValue>;
9811}
9812
9813// These upcasts are non-castable due to the constraints on the function
9814// but the UpcastFrom covariance must still extend through closure types.
9815// (impl UpcastFrom really just means CovariantGeneric relation)
9816impl UpcastFrom<String> for JsString {}
9817impl UpcastFrom<JsString> for String {}
9818
9819impl UpcastFrom<&str> for JsString {}
9820impl UpcastFrom<JsString> for &str {}
9821
9822impl UpcastFrom<char> for JsString {}
9823impl UpcastFrom<JsString> for char {}
9824
9825impl JsString {
9826 /// Returns the `JsString` value of this JS value if it's an instance of a
9827 /// string.
9828 ///
9829 /// If this JS value is not an instance of a string then this returns
9830 /// `None`.
9831 #[cfg(not(js_sys_unstable_apis))]
9832 #[deprecated(note = "recommended to use dyn_ref instead which is now equivalent")]
9833 pub fn try_from(val: &JsValue) -> Option<&JsString> {
9834 val.dyn_ref()
9835 }
9836
9837 /// Returns whether this string is a valid UTF-16 string.
9838 ///
9839 /// This is useful for learning whether `String::from(..)` will return a
9840 /// lossless representation of the JS string. If this string contains
9841 /// unpaired surrogates then `String::from` will succeed but it will be a
9842 /// lossy representation of the JS string because unpaired surrogates will
9843 /// become replacement characters.
9844 ///
9845 /// If this function returns `false` then to get a lossless representation
9846 /// of the string you'll need to manually use the `iter` method (or the
9847 /// `char_code_at` accessor) to view the raw character codes.
9848 ///
9849 /// For more information, see the documentation on [JS strings vs Rust
9850 /// strings][docs]
9851 ///
9852 /// [docs]: https://wasm-bindgen.github.io/wasm-bindgen/reference/types/str.html
9853 pub fn is_valid_utf16(&self) -> bool {
9854 core::char::decode_utf16(self.iter()).all(|i| i.is_ok())
9855 }
9856
9857 /// Returns an iterator over the `u16` character codes that make up this JS
9858 /// string.
9859 ///
9860 /// This method will call `char_code_at` for each code in this JS string,
9861 /// returning an iterator of the codes in sequence.
9862 pub fn iter(
9863 &self,
9864 ) -> impl ExactSizeIterator<Item = u16> + DoubleEndedIterator<Item = u16> + '_ {
9865 (0..self.length()).map(move |i| self.char_code_at(i) as u16)
9866 }
9867
9868 /// If this string consists of a single Unicode code point, then this method
9869 /// converts it into a Rust `char` without doing any allocations.
9870 ///
9871 /// If this JS value is not a valid UTF-8 or consists of more than a single
9872 /// codepoint, then this returns `None`.
9873 ///
9874 /// Note that a single Unicode code point might be represented as more than
9875 /// one code unit on the JavaScript side. For example, a JavaScript string
9876 /// `"\uD801\uDC37"` is actually a single Unicode code point U+10437 which
9877 /// corresponds to a character '𐐷'.
9878 pub fn as_char(&self) -> Option<char> {
9879 let len = self.length();
9880
9881 if len == 0 || len > 2 {
9882 return None;
9883 }
9884
9885 #[cfg(not(js_sys_unstable_apis))]
9886 let cp = self.code_point_at(0).as_f64().unwrap_throw() as u32;
9887 #[cfg(js_sys_unstable_apis)]
9888 let cp = self.code_point_at(0)?;
9889
9890 let c = core::char::from_u32(cp)?;
9891
9892 if c.len_utf16() as u32 == len {
9893 Some(c)
9894 } else {
9895 None
9896 }
9897 }
9898}
9899
9900impl PartialEq<str> for JsString {
9901 #[allow(clippy::cmp_owned)] // prevent infinite recursion
9902 fn eq(&self, other: &str) -> bool {
9903 String::from(self) == other
9904 }
9905}
9906
9907impl<'a> PartialEq<&'a str> for JsString {
9908 fn eq(&self, other: &&'a str) -> bool {
9909 <JsString as PartialEq<str>>::eq(self, other)
9910 }
9911}
9912
9913impl PartialEq<String> for JsString {
9914 fn eq(&self, other: &String) -> bool {
9915 <JsString as PartialEq<str>>::eq(self, other)
9916 }
9917}
9918
9919impl<'a> PartialEq<&'a String> for JsString {
9920 fn eq(&self, other: &&'a String) -> bool {
9921 <JsString as PartialEq<str>>::eq(self, other)
9922 }
9923}
9924
9925impl Default for JsString {
9926 fn default() -> Self {
9927 Self::from("")
9928 }
9929}
9930
9931impl<'a> From<&'a str> for JsString {
9932 fn from(s: &'a str) -> Self {
9933 JsString::unchecked_from_js(JsValue::from_str(s))
9934 }
9935}
9936
9937impl From<String> for JsString {
9938 fn from(s: String) -> Self {
9939 From::from(&*s)
9940 }
9941}
9942
9943impl From<char> for JsString {
9944 #[inline]
9945 fn from(c: char) -> Self {
9946 JsString::from_code_point1(c as u32).unwrap_throw()
9947 }
9948}
9949
9950impl<'a> From<&'a JsString> for String {
9951 fn from(s: &'a JsString) -> Self {
9952 s.obj.as_string().unwrap_throw()
9953 }
9954}
9955
9956impl From<JsString> for String {
9957 fn from(s: JsString) -> Self {
9958 From::from(&s)
9959 }
9960}
9961
9962impl fmt::Debug for JsString {
9963 #[inline]
9964 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9965 fmt::Debug::fmt(&String::from(self), f)
9966 }
9967}
9968
9969impl fmt::Display for JsString {
9970 #[inline]
9971 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9972 fmt::Display::fmt(&String::from(self), f)
9973 }
9974}
9975
9976impl str::FromStr for JsString {
9977 type Err = convert::Infallible;
9978 fn from_str(s: &str) -> Result<Self, Self::Err> {
9979 Ok(JsString::from(s))
9980 }
9981}
9982
9983// Symbol
9984#[wasm_bindgen]
9985extern "C" {
9986 #[wasm_bindgen(is_type_of = JsValue::is_symbol, typescript_type = "Symbol")]
9987 #[derive(Clone, Debug)]
9988 pub type Symbol;
9989
9990 /// The `Symbol.hasInstance` well-known symbol is used to determine
9991 /// if a constructor object recognizes an object as its instance.
9992 /// The `instanceof` operator's behavior can be customized by this symbol.
9993 ///
9994 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/hasInstance)
9995 #[wasm_bindgen(static_method_of = Symbol, getter, js_name = hasInstance)]
9996 pub fn has_instance() -> Symbol;
9997
9998 /// The `Symbol.isConcatSpreadable` well-known symbol is used to configure
9999 /// if an object should be flattened to its array elements when using the
10000 /// `Array.prototype.concat()` method.
10001 ///
10002 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/isConcatSpreadable)
10003 #[wasm_bindgen(static_method_of = Symbol, getter, js_name = isConcatSpreadable)]
10004 pub fn is_concat_spreadable() -> Symbol;
10005
10006 /// The `Symbol.asyncIterator` well-known symbol specifies the default AsyncIterator for an object.
10007 /// If this property is set on an object, it is an async iterable and can be used in a `for await...of` loop.
10008 ///
10009 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/asyncIterator)
10010 #[wasm_bindgen(static_method_of = Symbol, getter, js_name = asyncIterator)]
10011 pub fn async_iterator() -> Symbol;
10012
10013 /// The `Symbol.iterator` well-known symbol specifies the default iterator
10014 /// for an object. Used by `for...of`.
10015 ///
10016 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/iterator)
10017 #[wasm_bindgen(static_method_of = Symbol, getter)]
10018 pub fn iterator() -> Symbol;
10019
10020 /// The `Symbol.match` well-known symbol specifies the matching of a regular
10021 /// expression against a string. This function is called by the
10022 /// `String.prototype.match()` method.
10023 ///
10024 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/match)
10025 #[wasm_bindgen(static_method_of = Symbol, getter, js_name = match)]
10026 pub fn match_() -> Symbol;
10027
10028 /// The `Symbol.replace` well-known symbol specifies the method that
10029 /// replaces matched substrings of a string. This function is called by the
10030 /// `String.prototype.replace()` method.
10031 ///
10032 /// For more information, see `RegExp.prototype[@@replace]()` and
10033 /// `String.prototype.replace()`.
10034 ///
10035 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/replace)
10036 #[wasm_bindgen(static_method_of = Symbol, getter)]
10037 pub fn replace() -> Symbol;
10038
10039 /// The `Symbol.search` well-known symbol specifies the method that returns
10040 /// the index within a string that matches the regular expression. This
10041 /// function is called by the `String.prototype.search()` method.
10042 ///
10043 /// For more information, see `RegExp.prototype[@@search]()` and
10044 /// `String.prototype.search()`.
10045 ///
10046 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/search)
10047 #[wasm_bindgen(static_method_of = Symbol, getter)]
10048 pub fn search() -> Symbol;
10049
10050 /// The well-known symbol `Symbol.species` specifies a function-valued
10051 /// property that the constructor function uses to create derived objects.
10052 ///
10053 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/species)
10054 #[wasm_bindgen(static_method_of = Symbol, getter)]
10055 pub fn species() -> Symbol;
10056
10057 /// The `Symbol.split` well-known symbol specifies the method that splits a
10058 /// string at the indices that match a regular expression. This function is
10059 /// called by the `String.prototype.split()` method.
10060 ///
10061 /// For more information, see `RegExp.prototype[@@split]()` and
10062 /// `String.prototype.split()`.
10063 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/split)
10064 #[wasm_bindgen(static_method_of = Symbol, getter)]
10065 pub fn split() -> Symbol;
10066
10067 /// The `Symbol.toPrimitive` is a symbol that specifies a function valued
10068 /// property that is called to convert an object to a corresponding
10069 /// primitive value.
10070 ///
10071 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toPrimitive)
10072 #[wasm_bindgen(static_method_of = Symbol, getter, js_name = toPrimitive)]
10073 pub fn to_primitive() -> Symbol;
10074
10075 /// The `Symbol.toStringTag` well-known symbol is a string valued property
10076 /// that is used in the creation of the default string description of an
10077 /// object. It is accessed internally by the `Object.prototype.toString()`
10078 /// method.
10079 ///
10080 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toString)
10081 #[wasm_bindgen(static_method_of = Symbol, getter, js_name = toStringTag)]
10082 pub fn to_string_tag() -> Symbol;
10083
10084 /// The `Symbol.for(key)` method searches for existing symbols in a runtime-wide symbol registry with
10085 /// the given key and returns it if found.
10086 /// Otherwise a new symbol gets created in the global symbol registry with this key.
10087 ///
10088 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/for)
10089 #[wasm_bindgen(static_method_of = Symbol, js_name = for)]
10090 pub fn for_(key: &str) -> Symbol;
10091
10092 /// The `Symbol.keyFor(sym)` method retrieves a shared symbol key from the global symbol registry for the given symbol.
10093 ///
10094 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/keyFor)
10095 #[wasm_bindgen(static_method_of = Symbol, js_name = keyFor)]
10096 pub fn key_for(sym: &Symbol) -> JsValue;
10097
10098 // Next major: deprecate
10099 /// The `toString()` method returns a string representing the specified Symbol object.
10100 ///
10101 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toString)
10102 #[wasm_bindgen(method, js_name = toString)]
10103 pub fn to_string(this: &Symbol) -> JsString;
10104
10105 /// The `toString()` method returns a string representing the specified Symbol object.
10106 ///
10107 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toString)
10108 #[wasm_bindgen(method, js_name = toString)]
10109 pub fn to_js_string(this: &Symbol) -> JsString;
10110
10111 /// The `Symbol.unscopables` well-known symbol is used to specify an object
10112 /// value of whose own and inherited property names are excluded from the
10113 /// with environment bindings of the associated object.
10114 ///
10115 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/unscopables)
10116 #[wasm_bindgen(static_method_of = Symbol, getter)]
10117 pub fn unscopables() -> Symbol;
10118
10119 /// The `valueOf()` method returns the primitive value of a Symbol object.
10120 ///
10121 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/valueOf)
10122 #[wasm_bindgen(method, js_name = valueOf)]
10123 pub fn value_of(this: &Symbol) -> Symbol;
10124}
10125
10126#[allow(non_snake_case)]
10127pub mod Intl {
10128 use super::*;
10129
10130 // Intl
10131 #[wasm_bindgen]
10132 extern "C" {
10133 /// The `Intl.getCanonicalLocales()` method returns an array containing
10134 /// the canonical locale names. Duplicates will be omitted and elements
10135 /// will be validated as structurally valid language tags.
10136 ///
10137 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/getCanonicalLocales)
10138 #[cfg(not(js_sys_unstable_apis))]
10139 #[wasm_bindgen(js_name = getCanonicalLocales, js_namespace = Intl)]
10140 pub fn get_canonical_locales(s: &JsValue) -> Array;
10141
10142 /// The `Intl.getCanonicalLocales()` method returns an array containing
10143 /// the canonical locale names. Duplicates will be omitted and elements
10144 /// will be validated as structurally valid language tags.
10145 ///
10146 /// Throws a `RangeError` if any of the strings are not valid locale identifiers.
10147 ///
10148 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/getCanonicalLocales)
10149 #[cfg(js_sys_unstable_apis)]
10150 #[wasm_bindgen(js_name = getCanonicalLocales, js_namespace = Intl, catch)]
10151 pub fn get_canonical_locales(s: &[JsString]) -> Result<Array<JsString>, JsValue>;
10152
10153 /// The `Intl.supportedValuesOf()` method returns an array containing the
10154 /// supported calendar, collation, currency, numbering system, or unit values
10155 /// supported by the implementation.
10156 ///
10157 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/supportedValuesOf)
10158 #[wasm_bindgen(js_name = supportedValuesOf, js_namespace = Intl)]
10159 pub fn supported_values_of(key: SupportedValuesKey) -> Array<JsString>;
10160 }
10161
10162 // Intl string enums
10163
10164 /// Key for `Intl.supportedValuesOf()`.
10165 #[wasm_bindgen]
10166 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10167 pub enum SupportedValuesKey {
10168 Calendar = "calendar",
10169 Collation = "collation",
10170 Currency = "currency",
10171 NumberingSystem = "numberingSystem",
10172 TimeZone = "timeZone",
10173 Unit = "unit",
10174 }
10175
10176 /// Locale matching algorithm for Intl constructors.
10177 #[wasm_bindgen]
10178 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10179 pub enum LocaleMatcher {
10180 Lookup = "lookup",
10181 BestFit = "best fit",
10182 }
10183
10184 /// Usage for `Intl.Collator`.
10185 #[wasm_bindgen]
10186 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10187 pub enum CollatorUsage {
10188 Sort = "sort",
10189 Search = "search",
10190 }
10191
10192 /// Sensitivity for `Intl.Collator`.
10193 #[wasm_bindgen]
10194 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10195 pub enum CollatorSensitivity {
10196 Base = "base",
10197 Accent = "accent",
10198 Case = "case",
10199 Variant = "variant",
10200 }
10201
10202 /// Case first option for `Intl.Collator`.
10203 #[wasm_bindgen]
10204 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10205 pub enum CollatorCaseFirst {
10206 Upper = "upper",
10207 Lower = "lower",
10208 False = "false",
10209 }
10210
10211 /// Style for `Intl.NumberFormat`.
10212 #[wasm_bindgen]
10213 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10214 pub enum NumberFormatStyle {
10215 Decimal = "decimal",
10216 Currency = "currency",
10217 Percent = "percent",
10218 Unit = "unit",
10219 }
10220
10221 /// Currency display for `Intl.NumberFormat`.
10222 #[wasm_bindgen]
10223 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10224 pub enum CurrencyDisplay {
10225 Code = "code",
10226 Symbol = "symbol",
10227 NarrowSymbol = "narrowSymbol",
10228 Name = "name",
10229 }
10230
10231 /// Currency sign for `Intl.NumberFormat`.
10232 #[wasm_bindgen]
10233 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10234 pub enum CurrencySign {
10235 Standard = "standard",
10236 Accounting = "accounting",
10237 }
10238
10239 /// Unit display for `Intl.NumberFormat`.
10240 #[wasm_bindgen]
10241 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10242 pub enum UnitDisplay {
10243 Short = "short",
10244 Narrow = "narrow",
10245 Long = "long",
10246 }
10247
10248 /// Notation for `Intl.NumberFormat`.
10249 #[wasm_bindgen]
10250 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10251 pub enum NumberFormatNotation {
10252 Standard = "standard",
10253 Scientific = "scientific",
10254 Engineering = "engineering",
10255 Compact = "compact",
10256 }
10257
10258 /// Compact display for `Intl.NumberFormat`.
10259 #[wasm_bindgen]
10260 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10261 pub enum CompactDisplay {
10262 Short = "short",
10263 Long = "long",
10264 }
10265
10266 /// Sign display for `Intl.NumberFormat`.
10267 #[wasm_bindgen]
10268 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10269 pub enum SignDisplay {
10270 Auto = "auto",
10271 Never = "never",
10272 Always = "always",
10273 ExceptZero = "exceptZero",
10274 }
10275
10276 /// Rounding mode for `Intl.NumberFormat`.
10277 #[wasm_bindgen]
10278 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10279 pub enum RoundingMode {
10280 Ceil = "ceil",
10281 Floor = "floor",
10282 Expand = "expand",
10283 Trunc = "trunc",
10284 HalfCeil = "halfCeil",
10285 HalfFloor = "halfFloor",
10286 HalfExpand = "halfExpand",
10287 HalfTrunc = "halfTrunc",
10288 HalfEven = "halfEven",
10289 }
10290
10291 /// Rounding priority for `Intl.NumberFormat`.
10292 #[wasm_bindgen]
10293 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10294 pub enum RoundingPriority {
10295 Auto = "auto",
10296 MorePrecision = "morePrecision",
10297 LessPrecision = "lessPrecision",
10298 }
10299
10300 /// Trailing zero display for `Intl.NumberFormat`.
10301 #[wasm_bindgen]
10302 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10303 pub enum TrailingZeroDisplay {
10304 Auto = "auto",
10305 StripIfInteger = "stripIfInteger",
10306 }
10307
10308 /// Use grouping option for `Intl.NumberFormat`.
10309 ///
10310 /// Determines whether to use grouping separators, such as thousands
10311 /// separators or thousand/lakh/crore separators.
10312 ///
10313 /// The default is `Min2` if notation is "compact", and `Auto` otherwise.
10314 ///
10315 /// Note: The string values `"true"` and `"false"` are accepted by JavaScript
10316 /// but are always converted to the default value. Use `True` and `False`
10317 /// variants for the boolean behavior.
10318 ///
10319 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#usegrouping)
10320 #[wasm_bindgen]
10321 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10322 pub enum UseGrouping {
10323 /// Display grouping separators even if the locale prefers otherwise.
10324 Always = "always",
10325 /// Display grouping separators based on the locale preference,
10326 /// which may also be dependent on the currency.
10327 Auto = "auto",
10328 /// Display grouping separators when there are at least 2 digits in a group.
10329 Min2 = "min2",
10330 /// Same as `Always`. Display grouping separators even if the locale prefers otherwise.
10331 True = "true",
10332 /// Display no grouping separators.
10333 False = "false",
10334 }
10335
10336 /// Date/time style for `Intl.DateTimeFormat`.
10337 #[wasm_bindgen]
10338 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10339 pub enum DateTimeStyle {
10340 Full = "full",
10341 Long = "long",
10342 Medium = "medium",
10343 Short = "short",
10344 }
10345
10346 /// Hour cycle for `Intl.DateTimeFormat`.
10347 #[wasm_bindgen]
10348 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10349 pub enum HourCycle {
10350 H11 = "h11",
10351 H12 = "h12",
10352 H23 = "h23",
10353 H24 = "h24",
10354 }
10355
10356 /// Weekday format for `Intl.DateTimeFormat`.
10357 #[wasm_bindgen]
10358 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10359 pub enum WeekdayFormat {
10360 Narrow = "narrow",
10361 Short = "short",
10362 Long = "long",
10363 }
10364
10365 /// Era format for `Intl.DateTimeFormat`.
10366 #[wasm_bindgen]
10367 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10368 pub enum EraFormat {
10369 Narrow = "narrow",
10370 Short = "short",
10371 Long = "long",
10372 }
10373
10374 /// Year format for `Intl.DateTimeFormat`.
10375 #[wasm_bindgen]
10376 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10377 pub enum YearFormat {
10378 Numeric = "numeric",
10379 TwoDigit = "2-digit",
10380 }
10381
10382 /// Month format for `Intl.DateTimeFormat`.
10383 #[wasm_bindgen]
10384 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10385 pub enum MonthFormat {
10386 #[wasm_bindgen]
10387 Numeric = "numeric",
10388 #[wasm_bindgen]
10389 TwoDigit = "2-digit",
10390 #[wasm_bindgen]
10391 Narrow = "narrow",
10392 #[wasm_bindgen]
10393 Short = "short",
10394 #[wasm_bindgen]
10395 Long = "long",
10396 }
10397
10398 /// Day format for `Intl.DateTimeFormat`.
10399 #[wasm_bindgen]
10400 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10401 pub enum DayFormat {
10402 #[wasm_bindgen]
10403 Numeric = "numeric",
10404 #[wasm_bindgen]
10405 TwoDigit = "2-digit",
10406 }
10407
10408 /// Hour/minute/second format for `Intl.DateTimeFormat`.
10409 #[wasm_bindgen]
10410 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10411 pub enum NumericFormat {
10412 #[wasm_bindgen]
10413 Numeric = "numeric",
10414 #[wasm_bindgen]
10415 TwoDigit = "2-digit",
10416 }
10417
10418 /// Time zone name format for `Intl.DateTimeFormat`.
10419 #[wasm_bindgen]
10420 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10421 pub enum TimeZoneNameFormat {
10422 Short = "short",
10423 Long = "long",
10424 ShortOffset = "shortOffset",
10425 LongOffset = "longOffset",
10426 ShortGeneric = "shortGeneric",
10427 LongGeneric = "longGeneric",
10428 }
10429
10430 /// Day period format for `Intl.DateTimeFormat`.
10431 #[wasm_bindgen]
10432 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10433 pub enum DayPeriodFormat {
10434 Narrow = "narrow",
10435 Short = "short",
10436 Long = "long",
10437 }
10438
10439 /// Part type for `DateTimeFormat.formatToParts()`.
10440 #[wasm_bindgen]
10441 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10442 pub enum DateTimeFormatPartType {
10443 Day = "day",
10444 DayPeriod = "dayPeriod",
10445 Era = "era",
10446 FractionalSecond = "fractionalSecond",
10447 Hour = "hour",
10448 Literal = "literal",
10449 Minute = "minute",
10450 Month = "month",
10451 RelatedYear = "relatedYear",
10452 Second = "second",
10453 TimeZoneName = "timeZoneName",
10454 Weekday = "weekday",
10455 Year = "year",
10456 YearName = "yearName",
10457 }
10458
10459 /// Part type for `NumberFormat.formatToParts()`.
10460 #[wasm_bindgen]
10461 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10462 pub enum NumberFormatPartType {
10463 Compact = "compact",
10464 Currency = "currency",
10465 Decimal = "decimal",
10466 ExponentInteger = "exponentInteger",
10467 ExponentMinusSign = "exponentMinusSign",
10468 ExponentSeparator = "exponentSeparator",
10469 Fraction = "fraction",
10470 Group = "group",
10471 Infinity = "infinity",
10472 Integer = "integer",
10473 Literal = "literal",
10474 MinusSign = "minusSign",
10475 Nan = "nan",
10476 PercentSign = "percentSign",
10477 PlusSign = "plusSign",
10478 Unit = "unit",
10479 Unknown = "unknown",
10480 }
10481
10482 /// Type for `Intl.PluralRules` (cardinal or ordinal).
10483 #[wasm_bindgen]
10484 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10485 pub enum PluralRulesType {
10486 Cardinal = "cardinal",
10487 Ordinal = "ordinal",
10488 }
10489
10490 /// Plural category returned by `PluralRules.select()`.
10491 #[wasm_bindgen]
10492 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10493 pub enum PluralCategory {
10494 Zero = "zero",
10495 One = "one",
10496 Two = "two",
10497 Few = "few",
10498 Many = "many",
10499 Other = "other",
10500 }
10501
10502 /// Numeric option for `Intl.RelativeTimeFormat`.
10503 #[wasm_bindgen]
10504 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10505 pub enum RelativeTimeFormatNumeric {
10506 Always = "always",
10507 Auto = "auto",
10508 }
10509
10510 /// Style for `Intl.RelativeTimeFormat`.
10511 #[wasm_bindgen]
10512 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10513 pub enum RelativeTimeFormatStyle {
10514 Long = "long",
10515 Short = "short",
10516 Narrow = "narrow",
10517 }
10518
10519 /// Unit for `RelativeTimeFormat.format()`.
10520 #[wasm_bindgen]
10521 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10522 pub enum RelativeTimeFormatUnit {
10523 Year = "year",
10524 Years = "years",
10525 Quarter = "quarter",
10526 Quarters = "quarters",
10527 Month = "month",
10528 Months = "months",
10529 Week = "week",
10530 Weeks = "weeks",
10531 Day = "day",
10532 Days = "days",
10533 Hour = "hour",
10534 Hours = "hours",
10535 Minute = "minute",
10536 Minutes = "minutes",
10537 Second = "second",
10538 Seconds = "seconds",
10539 }
10540
10541 /// Part type for `RelativeTimeFormat.formatToParts()`.
10542 #[wasm_bindgen]
10543 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10544 pub enum RelativeTimeFormatPartType {
10545 Literal = "literal",
10546 Integer = "integer",
10547 Decimal = "decimal",
10548 Fraction = "fraction",
10549 }
10550
10551 /// Source indicator for range format parts.
10552 ///
10553 /// Indicates which part of the range (start, end, or shared) a formatted
10554 /// part belongs to when using `formatRangeToParts()`.
10555 ///
10556 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatRangeToParts#description)
10557 #[wasm_bindgen]
10558 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10559 pub enum RangeSource {
10560 /// The part is from the start of the range.
10561 StartRange = "startRange",
10562 /// The part is from the end of the range.
10563 EndRange = "endRange",
10564 /// The part is shared between start and end (e.g., a separator or common element).
10565 Shared = "shared",
10566 }
10567
10568 /// Type for `Intl.ListFormat`.
10569 #[wasm_bindgen]
10570 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10571 pub enum ListFormatType {
10572 /// For lists of standalone items (default).
10573 Conjunction = "conjunction",
10574 /// For lists representing alternatives.
10575 Disjunction = "disjunction",
10576 /// For lists of values with units.
10577 Unit = "unit",
10578 }
10579
10580 /// Style for `Intl.ListFormat`.
10581 #[wasm_bindgen]
10582 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10583 pub enum ListFormatStyle {
10584 /// "A, B, and C" (default).
10585 Long = "long",
10586 /// "A, B, C".
10587 Short = "short",
10588 /// "A B C".
10589 Narrow = "narrow",
10590 }
10591
10592 /// Part type for `Intl.ListFormat.formatToParts()`.
10593 #[wasm_bindgen]
10594 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10595 pub enum ListFormatPartType {
10596 /// A value from the list.
10597 Element = "element",
10598 /// A linguistic construct (e.g., ", ", " and ").
10599 Literal = "literal",
10600 }
10601
10602 /// Type for `Intl.Segmenter`.
10603 #[wasm_bindgen]
10604 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10605 pub enum SegmenterGranularity {
10606 /// Segment by grapheme clusters (user-perceived characters).
10607 Grapheme = "grapheme",
10608 /// Segment by words.
10609 Word = "word",
10610 /// Segment by sentences.
10611 Sentence = "sentence",
10612 }
10613
10614 /// Type for `Intl.DisplayNames`.
10615 #[wasm_bindgen]
10616 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10617 pub enum DisplayNamesType {
10618 /// Language display names.
10619 Language = "language",
10620 /// Region display names.
10621 Region = "region",
10622 /// Script display names.
10623 Script = "script",
10624 /// Currency display names.
10625 Currency = "currency",
10626 /// Calendar display names.
10627 Calendar = "calendar",
10628 /// Date/time field display names.
10629 DateTimeField = "dateTimeField",
10630 }
10631
10632 /// Style for `Intl.DisplayNames`.
10633 #[wasm_bindgen]
10634 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10635 pub enum DisplayNamesStyle {
10636 /// Full display name (default).
10637 Long = "long",
10638 /// Abbreviated display name.
10639 Short = "short",
10640 /// Minimal display name.
10641 Narrow = "narrow",
10642 }
10643
10644 /// Fallback for `Intl.DisplayNames`.
10645 #[wasm_bindgen]
10646 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10647 pub enum DisplayNamesFallback {
10648 /// Return the input code if no display name is available (default).
10649 Code = "code",
10650 /// Return undefined if no display name is available.
10651 None = "none",
10652 }
10653
10654 /// Language display for `Intl.DisplayNames`.
10655 #[wasm_bindgen]
10656 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10657 pub enum DisplayNamesLanguageDisplay {
10658 /// Use dialect names (e.g., "British English").
10659 Dialect = "dialect",
10660 /// Use standard names (e.g., "English (United Kingdom)").
10661 Standard = "standard",
10662 }
10663
10664 // Intl.RelativeTimeFormatOptions
10665 #[wasm_bindgen]
10666 extern "C" {
10667 /// Options for `Intl.RelativeTimeFormat` constructor.
10668 ///
10669 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/RelativeTimeFormat#options)
10670 #[wasm_bindgen(extends = Object)]
10671 #[derive(Clone, Debug)]
10672 pub type RelativeTimeFormatOptions;
10673
10674 #[wasm_bindgen(method, getter = localeMatcher)]
10675 pub fn get_locale_matcher(this: &RelativeTimeFormatOptions) -> Option<LocaleMatcher>;
10676 #[wasm_bindgen(method, setter = localeMatcher)]
10677 pub fn set_locale_matcher(this: &RelativeTimeFormatOptions, value: LocaleMatcher);
10678
10679 #[wasm_bindgen(method, getter = numeric)]
10680 pub fn get_numeric(this: &RelativeTimeFormatOptions) -> Option<RelativeTimeFormatNumeric>;
10681 #[wasm_bindgen(method, setter = numeric)]
10682 pub fn set_numeric(this: &RelativeTimeFormatOptions, value: RelativeTimeFormatNumeric);
10683
10684 #[wasm_bindgen(method, getter = style)]
10685 pub fn get_style(this: &RelativeTimeFormatOptions) -> Option<RelativeTimeFormatStyle>;
10686 #[wasm_bindgen(method, setter = style)]
10687 pub fn set_style(this: &RelativeTimeFormatOptions, value: RelativeTimeFormatStyle);
10688 }
10689
10690 impl RelativeTimeFormatOptions {
10691 pub fn new() -> RelativeTimeFormatOptions {
10692 JsCast::unchecked_into(Object::new())
10693 }
10694 }
10695
10696 impl Default for RelativeTimeFormatOptions {
10697 fn default() -> Self {
10698 RelativeTimeFormatOptions::new()
10699 }
10700 }
10701
10702 // Intl.ResolvedRelativeTimeFormatOptions
10703 #[wasm_bindgen]
10704 extern "C" {
10705 /// Resolved options returned by `Intl.RelativeTimeFormat.prototype.resolvedOptions()`.
10706 ///
10707 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/resolvedOptions)
10708 #[wasm_bindgen(extends = RelativeTimeFormatOptions)]
10709 #[derive(Clone, Debug)]
10710 pub type ResolvedRelativeTimeFormatOptions;
10711
10712 /// The resolved locale string.
10713 #[wasm_bindgen(method, getter = locale)]
10714 pub fn get_locale(this: &ResolvedRelativeTimeFormatOptions) -> JsString;
10715
10716 /// The numbering system used.
10717 #[wasm_bindgen(method, getter = numberingSystem)]
10718 pub fn get_numbering_system(this: &ResolvedRelativeTimeFormatOptions) -> JsString;
10719 }
10720
10721 // Intl.RelativeTimeFormatPart
10722 #[wasm_bindgen]
10723 extern "C" {
10724 /// A part of the formatted relative time returned by `formatToParts()`.
10725 ///
10726 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/formatToParts)
10727 #[wasm_bindgen(extends = Object)]
10728 #[derive(Clone, Debug)]
10729 pub type RelativeTimeFormatPart;
10730
10731 /// The type of this part.
10732 #[wasm_bindgen(method, getter = type)]
10733 pub fn type_(this: &RelativeTimeFormatPart) -> RelativeTimeFormatPartType;
10734
10735 /// The string value of this part.
10736 #[wasm_bindgen(method, getter = value)]
10737 pub fn value(this: &RelativeTimeFormatPart) -> JsString;
10738
10739 /// The unit used in this part (only for integer parts).
10740 #[wasm_bindgen(method, getter = unit)]
10741 pub fn unit(this: &RelativeTimeFormatPart) -> Option<JsString>;
10742 }
10743
10744 // Intl.LocaleMatcherOptions
10745 #[wasm_bindgen]
10746 extern "C" {
10747 /// Options for `supportedLocalesOf` methods.
10748 #[wasm_bindgen(extends = Object)]
10749 #[derive(Clone, Debug)]
10750 pub type LocaleMatcherOptions;
10751
10752 #[wasm_bindgen(method, getter = localeMatcher)]
10753 pub fn get_locale_matcher(this: &LocaleMatcherOptions) -> Option<LocaleMatcher>;
10754
10755 #[wasm_bindgen(method, setter = localeMatcher)]
10756 pub fn set_locale_matcher(this: &LocaleMatcherOptions, value: LocaleMatcher);
10757 }
10758
10759 impl LocaleMatcherOptions {
10760 pub fn new() -> LocaleMatcherOptions {
10761 JsCast::unchecked_into(Object::new())
10762 }
10763 }
10764
10765 impl Default for LocaleMatcherOptions {
10766 fn default() -> Self {
10767 LocaleMatcherOptions::new()
10768 }
10769 }
10770
10771 // Intl.Collator Options
10772 #[wasm_bindgen]
10773 extern "C" {
10774 /// Options for `Intl.Collator` and `String.prototype.localeCompare`.
10775 ///
10776 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Collator/Collator#options)
10777 #[wasm_bindgen(extends = Object)]
10778 #[derive(Clone, Debug)]
10779 pub type CollatorOptions;
10780
10781 #[wasm_bindgen(method, getter = localeMatcher)]
10782 pub fn get_locale_matcher(this: &CollatorOptions) -> Option<LocaleMatcher>;
10783 #[wasm_bindgen(method, setter = localeMatcher)]
10784 pub fn set_locale_matcher(this: &CollatorOptions, value: LocaleMatcher);
10785
10786 #[wasm_bindgen(method, getter = usage)]
10787 pub fn get_usage(this: &CollatorOptions) -> Option<CollatorUsage>;
10788 #[wasm_bindgen(method, setter = usage)]
10789 pub fn set_usage(this: &CollatorOptions, value: CollatorUsage);
10790
10791 #[wasm_bindgen(method, getter = sensitivity)]
10792 pub fn get_sensitivity(this: &CollatorOptions) -> Option<CollatorSensitivity>;
10793 #[wasm_bindgen(method, setter = sensitivity)]
10794 pub fn set_sensitivity(this: &CollatorOptions, value: CollatorSensitivity);
10795
10796 #[wasm_bindgen(method, getter = ignorePunctuation)]
10797 pub fn get_ignore_punctuation(this: &CollatorOptions) -> Option<bool>;
10798 #[wasm_bindgen(method, setter = ignorePunctuation)]
10799 pub fn set_ignore_punctuation(this: &CollatorOptions, value: bool);
10800
10801 #[wasm_bindgen(method, getter = numeric)]
10802 pub fn get_numeric(this: &CollatorOptions) -> Option<bool>;
10803 #[wasm_bindgen(method, setter = numeric)]
10804 pub fn set_numeric(this: &CollatorOptions, value: bool);
10805
10806 #[wasm_bindgen(method, getter = caseFirst)]
10807 pub fn get_case_first(this: &CollatorOptions) -> Option<CollatorCaseFirst>;
10808 #[wasm_bindgen(method, setter = caseFirst)]
10809 pub fn set_case_first(this: &CollatorOptions, value: CollatorCaseFirst);
10810 }
10811 impl CollatorOptions {
10812 pub fn new() -> CollatorOptions {
10813 JsCast::unchecked_into(Object::new())
10814 }
10815 }
10816 impl Default for CollatorOptions {
10817 fn default() -> Self {
10818 CollatorOptions::new()
10819 }
10820 }
10821
10822 // Intl.Collator ResolvedCollatorOptions
10823 #[wasm_bindgen]
10824 extern "C" {
10825 #[wasm_bindgen(extends = CollatorOptions)]
10826 #[derive(Clone, Debug)]
10827 pub type ResolvedCollatorOptions;
10828
10829 #[wasm_bindgen(method, getter = locale)]
10830 pub fn get_locale(this: &ResolvedCollatorOptions) -> JsString; // not Option, always present
10831 #[wasm_bindgen(method, getter = collation)]
10832 pub fn get_collation(this: &ResolvedCollatorOptions) -> JsString;
10833 }
10834
10835 // Intl.Collator
10836 #[wasm_bindgen]
10837 extern "C" {
10838 /// The `Intl.Collator` object is a constructor for collators, objects
10839 /// that enable language sensitive string comparison.
10840 ///
10841 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator)
10842 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.Collator")]
10843 #[derive(Clone, Debug)]
10844 pub type Collator;
10845
10846 /// The `Intl.Collator` object is a constructor for collators, objects
10847 /// that enable language sensitive string comparison.
10848 ///
10849 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator)
10850 #[cfg(not(js_sys_unstable_apis))]
10851 #[wasm_bindgen(constructor, js_namespace = Intl)]
10852 pub fn new(locales: &Array, options: &Object) -> Collator;
10853
10854 /// The `Intl.Collator` object is a constructor for collators, objects
10855 /// that enable language sensitive string comparison.
10856 ///
10857 /// Throws a `RangeError` if locales contain invalid values.
10858 ///
10859 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator)
10860 #[cfg(js_sys_unstable_apis)]
10861 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
10862 pub fn new(locales: &[JsString], options: &CollatorOptions) -> Result<Collator, JsValue>;
10863
10864 /// The Intl.Collator.prototype.compare property returns a function that
10865 /// compares two strings according to the sort order of this Collator
10866 /// object.
10867 ///
10868 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/compare)
10869 #[cfg(not(js_sys_unstable_apis))]
10870 #[wasm_bindgen(method, getter, js_class = "Intl.Collator")]
10871 pub fn compare(this: &Collator) -> Function;
10872
10873 /// Compares two strings according to the sort order of this Collator.
10874 ///
10875 /// Returns a negative value if `a` comes before `b`, positive if `a` comes
10876 /// after `b`, and zero if they are equal.
10877 ///
10878 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Collator/compare)
10879 #[cfg(js_sys_unstable_apis)]
10880 #[wasm_bindgen(method, js_class = "Intl.Collator")]
10881 pub fn compare(this: &Collator, a: &str, b: &str) -> i32;
10882
10883 /// The `Intl.Collator.prototype.resolvedOptions()` method returns a new
10884 /// object with properties reflecting the locale and collation options
10885 /// computed during initialization of this Collator object.
10886 ///
10887 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/resolvedOptions)
10888 #[cfg(not(js_sys_unstable_apis))]
10889 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
10890 pub fn resolved_options(this: &Collator) -> Object;
10891
10892 /// The `Intl.Collator.prototype.resolvedOptions()` method returns a new
10893 /// object with properties reflecting the locale and collation options
10894 /// computed during initialization of this Collator object.
10895 ///
10896 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/resolvedOptions)
10897 #[cfg(js_sys_unstable_apis)]
10898 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
10899 pub fn resolved_options(this: &Collator) -> ResolvedCollatorOptions;
10900
10901 /// The `Intl.Collator.supportedLocalesOf()` method returns an array
10902 /// containing those of the provided locales that are supported in
10903 /// collation without having to fall back to the runtime's default
10904 /// locale.
10905 ///
10906 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/supportedLocalesOf)
10907 #[cfg(not(js_sys_unstable_apis))]
10908 #[wasm_bindgen(static_method_of = Collator, js_namespace = Intl, js_name = supportedLocalesOf)]
10909 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
10910
10911 /// The `Intl.Collator.supportedLocalesOf()` method returns an array
10912 /// containing those of the provided locales that are supported in
10913 /// collation without having to fall back to the runtime's default
10914 /// locale.
10915 ///
10916 /// Throws a `RangeError` if locales contain invalid values.
10917 ///
10918 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/supportedLocalesOf)
10919 #[cfg(js_sys_unstable_apis)]
10920 #[wasm_bindgen(static_method_of = Collator, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
10921 pub fn supported_locales_of(
10922 locales: &[JsString],
10923 options: &LocaleMatcherOptions,
10924 ) -> Result<Array<JsString>, JsValue>;
10925 }
10926
10927 #[cfg(not(js_sys_unstable_apis))]
10928 impl Default for Collator {
10929 fn default() -> Self {
10930 Self::new(
10931 &JsValue::UNDEFINED.unchecked_into(),
10932 &JsValue::UNDEFINED.unchecked_into(),
10933 )
10934 }
10935 }
10936
10937 #[cfg(js_sys_unstable_apis)]
10938 impl Default for Collator {
10939 fn default() -> Self {
10940 Self::new(&[], &Default::default()).unwrap()
10941 }
10942 }
10943
10944 // Intl.DateTimeFormatOptions
10945 #[wasm_bindgen]
10946 extern "C" {
10947 /// Options for `Intl.DateTimeFormat` constructor.
10948 ///
10949 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat#options)
10950 #[wasm_bindgen(extends = Object)]
10951 #[derive(Clone, Debug)]
10952 pub type DateTimeFormatOptions;
10953
10954 // Locale matching
10955 #[wasm_bindgen(method, getter = localeMatcher)]
10956 pub fn get_locale_matcher(this: &DateTimeFormatOptions) -> Option<LocaleMatcher>;
10957 #[wasm_bindgen(method, setter = localeMatcher)]
10958 pub fn set_locale_matcher(this: &DateTimeFormatOptions, value: LocaleMatcher);
10959
10960 // Calendar/numbering (free-form strings, no enum)
10961 #[wasm_bindgen(method, getter = calendar)]
10962 pub fn get_calendar(this: &DateTimeFormatOptions) -> Option<JsString>;
10963 #[wasm_bindgen(method, setter = calendar)]
10964 pub fn set_calendar(this: &DateTimeFormatOptions, value: &str);
10965
10966 #[wasm_bindgen(method, getter = numberingSystem)]
10967 pub fn get_numbering_system(this: &DateTimeFormatOptions) -> Option<JsString>;
10968 #[wasm_bindgen(method, setter = numberingSystem)]
10969 pub fn set_numbering_system(this: &DateTimeFormatOptions, value: &str);
10970
10971 // Timezone (free-form string)
10972 #[wasm_bindgen(method, getter = timeZone)]
10973 pub fn get_time_zone(this: &DateTimeFormatOptions) -> Option<JsString>;
10974 #[wasm_bindgen(method, setter = timeZone)]
10975 pub fn set_time_zone(this: &DateTimeFormatOptions, value: &str);
10976
10977 // Hour cycle
10978 #[wasm_bindgen(method, getter = hour12)]
10979 pub fn get_hour12(this: &DateTimeFormatOptions) -> Option<bool>;
10980 #[wasm_bindgen(method, setter = hour12)]
10981 pub fn set_hour12(this: &DateTimeFormatOptions, value: bool);
10982
10983 #[wasm_bindgen(method, getter = hourCycle)]
10984 pub fn get_hour_cycle(this: &DateTimeFormatOptions) -> Option<HourCycle>;
10985 #[wasm_bindgen(method, setter = hourCycle)]
10986 pub fn set_hour_cycle(this: &DateTimeFormatOptions, value: HourCycle);
10987
10988 // Style shortcuts
10989 #[wasm_bindgen(method, getter = dateStyle)]
10990 pub fn get_date_style(this: &DateTimeFormatOptions) -> Option<DateTimeStyle>;
10991 #[wasm_bindgen(method, setter = dateStyle)]
10992 pub fn set_date_style(this: &DateTimeFormatOptions, value: DateTimeStyle);
10993
10994 #[wasm_bindgen(method, getter = timeStyle)]
10995 pub fn get_time_style(this: &DateTimeFormatOptions) -> Option<DateTimeStyle>;
10996 #[wasm_bindgen(method, setter = timeStyle)]
10997 pub fn set_time_style(this: &DateTimeFormatOptions, value: DateTimeStyle);
10998
10999 // Component options
11000 #[wasm_bindgen(method, getter = weekday)]
11001 pub fn get_weekday(this: &DateTimeFormatOptions) -> Option<WeekdayFormat>;
11002 #[wasm_bindgen(method, setter = weekday)]
11003 pub fn set_weekday(this: &DateTimeFormatOptions, value: WeekdayFormat);
11004
11005 #[wasm_bindgen(method, getter = era)]
11006 pub fn get_era(this: &DateTimeFormatOptions) -> Option<EraFormat>;
11007 #[wasm_bindgen(method, setter = era)]
11008 pub fn set_era(this: &DateTimeFormatOptions, value: EraFormat);
11009
11010 #[wasm_bindgen(method, getter = year)]
11011 pub fn get_year(this: &DateTimeFormatOptions) -> Option<YearFormat>;
11012 #[wasm_bindgen(method, setter = year)]
11013 pub fn set_year(this: &DateTimeFormatOptions, value: YearFormat);
11014
11015 #[wasm_bindgen(method, getter = month)]
11016 pub fn get_month(this: &DateTimeFormatOptions) -> Option<MonthFormat>;
11017 #[wasm_bindgen(method, setter = month)]
11018 pub fn set_month(this: &DateTimeFormatOptions, value: MonthFormat);
11019
11020 #[wasm_bindgen(method, getter = day)]
11021 pub fn get_day(this: &DateTimeFormatOptions) -> Option<DayFormat>;
11022 #[wasm_bindgen(method, setter = day)]
11023 pub fn set_day(this: &DateTimeFormatOptions, value: DayFormat);
11024
11025 #[wasm_bindgen(method, getter = hour)]
11026 pub fn get_hour(this: &DateTimeFormatOptions) -> Option<NumericFormat>;
11027 #[wasm_bindgen(method, setter = hour)]
11028 pub fn set_hour(this: &DateTimeFormatOptions, value: NumericFormat);
11029
11030 #[wasm_bindgen(method, getter = minute)]
11031 pub fn get_minute(this: &DateTimeFormatOptions) -> Option<NumericFormat>;
11032 #[wasm_bindgen(method, setter = minute)]
11033 pub fn set_minute(this: &DateTimeFormatOptions, value: NumericFormat);
11034
11035 #[wasm_bindgen(method, getter = second)]
11036 pub fn get_second(this: &DateTimeFormatOptions) -> Option<NumericFormat>;
11037 #[wasm_bindgen(method, setter = second)]
11038 pub fn set_second(this: &DateTimeFormatOptions, value: NumericFormat);
11039
11040 #[wasm_bindgen(method, getter = fractionalSecondDigits)]
11041 pub fn get_fractional_second_digits(this: &DateTimeFormatOptions) -> Option<u8>;
11042 #[wasm_bindgen(method, setter = fractionalSecondDigits)]
11043 pub fn set_fractional_second_digits(this: &DateTimeFormatOptions, value: u8);
11044
11045 #[wasm_bindgen(method, getter = timeZoneName)]
11046 pub fn get_time_zone_name(this: &DateTimeFormatOptions) -> Option<TimeZoneNameFormat>;
11047 #[wasm_bindgen(method, setter = timeZoneName)]
11048 pub fn set_time_zone_name(this: &DateTimeFormatOptions, value: TimeZoneNameFormat);
11049
11050 #[wasm_bindgen(method, getter = dayPeriod)]
11051 pub fn get_day_period(this: &DateTimeFormatOptions) -> Option<DayPeriodFormat>;
11052 #[wasm_bindgen(method, setter = dayPeriod)]
11053 pub fn set_day_period(this: &DateTimeFormatOptions, value: DayPeriodFormat);
11054 }
11055
11056 impl DateTimeFormatOptions {
11057 pub fn new() -> DateTimeFormatOptions {
11058 JsCast::unchecked_into(Object::new())
11059 }
11060 }
11061
11062 impl Default for DateTimeFormatOptions {
11063 fn default() -> Self {
11064 DateTimeFormatOptions::new()
11065 }
11066 }
11067
11068 // Intl.ResolvedDateTimeFormatOptions
11069 #[wasm_bindgen]
11070 extern "C" {
11071 /// Resolved options returned by `Intl.DateTimeFormat.prototype.resolvedOptions()`.
11072 ///
11073 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/resolvedOptions)
11074 #[wasm_bindgen(extends = DateTimeFormatOptions)]
11075 #[derive(Clone, Debug)]
11076 pub type ResolvedDateTimeFormatOptions;
11077
11078 /// The resolved locale string.
11079 #[wasm_bindgen(method, getter = locale)]
11080 pub fn get_locale(this: &ResolvedDateTimeFormatOptions) -> JsString;
11081 }
11082
11083 // Intl.DateTimeFormatPart
11084 #[wasm_bindgen]
11085 extern "C" {
11086 /// A part of the formatted date returned by `formatToParts()`.
11087 ///
11088 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatToParts)
11089 #[wasm_bindgen(extends = Object)]
11090 #[derive(Clone, Debug)]
11091 pub type DateTimeFormatPart;
11092
11093 /// The type of the part (e.g., "day", "month", "year", "literal", etc.)
11094 #[wasm_bindgen(method, getter = type)]
11095 pub fn type_(this: &DateTimeFormatPart) -> DateTimeFormatPartType;
11096
11097 /// The value of the part.
11098 #[wasm_bindgen(method, getter)]
11099 pub fn value(this: &DateTimeFormatPart) -> JsString;
11100 }
11101
11102 // Intl.DateTimeRangeFormatPart
11103 #[wasm_bindgen]
11104 extern "C" {
11105 /// A part of the formatted date range returned by `formatRangeToParts()`.
11106 ///
11107 /// Extends `DateTimeFormatPart` with a `source` property indicating whether
11108 /// the part is from the start date, end date, or shared between them.
11109 ///
11110 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatRangeToParts)
11111 #[wasm_bindgen(extends = DateTimeFormatPart)]
11112 #[derive(Clone, Debug)]
11113 pub type DateTimeRangeFormatPart;
11114
11115 /// The source of the part: "startRange", "endRange", or "shared".
11116 #[wasm_bindgen(method, getter)]
11117 pub fn source(this: &DateTimeRangeFormatPart) -> RangeSource;
11118 }
11119
11120 // Intl.DateTimeFormat
11121 #[wasm_bindgen]
11122 extern "C" {
11123 /// The `Intl.DateTimeFormat` object is a constructor for objects
11124 /// that enable language-sensitive date and time formatting.
11125 ///
11126 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat)
11127 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.DateTimeFormat")]
11128 #[derive(Clone, Debug)]
11129 pub type DateTimeFormat;
11130
11131 /// The `Intl.DateTimeFormat` object is a constructor for objects
11132 /// that enable language-sensitive date and time formatting.
11133 ///
11134 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat)
11135 #[cfg(not(js_sys_unstable_apis))]
11136 #[wasm_bindgen(constructor, js_namespace = Intl)]
11137 pub fn new(locales: &Array, options: &Object) -> DateTimeFormat;
11138
11139 /// The `Intl.DateTimeFormat` object is a constructor for objects
11140 /// that enable language-sensitive date and time formatting.
11141 ///
11142 /// Throws a `RangeError` if locales contain invalid values.
11143 ///
11144 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat)
11145 #[cfg(js_sys_unstable_apis)]
11146 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
11147 pub fn new(
11148 locales: &[JsString],
11149 options: &DateTimeFormatOptions,
11150 ) -> Result<DateTimeFormat, JsValue>;
11151
11152 /// The Intl.DateTimeFormat.prototype.format property returns a getter function that
11153 /// formats a date according to the locale and formatting options of this
11154 /// Intl.DateTimeFormat object.
11155 ///
11156 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/format)
11157 #[cfg(not(js_sys_unstable_apis))]
11158 #[wasm_bindgen(method, getter, js_class = "Intl.DateTimeFormat")]
11159 pub fn format(this: &DateTimeFormat) -> Function;
11160
11161 /// Formats a date according to the locale and formatting options of this
11162 /// `Intl.DateTimeFormat` object.
11163 ///
11164 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/format)
11165 #[cfg(js_sys_unstable_apis)]
11166 #[wasm_bindgen(method, js_class = "Intl.DateTimeFormat")]
11167 pub fn format(this: &DateTimeFormat, date: &Date) -> JsString;
11168
11169 /// The `Intl.DateTimeFormat.prototype.formatToParts()` method allows locale-aware
11170 /// formatting of strings produced by DateTimeFormat formatters.
11171 ///
11172 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/formatToParts)
11173 #[cfg(not(js_sys_unstable_apis))]
11174 #[wasm_bindgen(method, js_class = "Intl.DateTimeFormat", js_name = formatToParts)]
11175 pub fn format_to_parts(this: &DateTimeFormat, date: &Date) -> Array;
11176
11177 /// The `Intl.DateTimeFormat.prototype.formatToParts()` method allows locale-aware
11178 /// formatting of strings produced by DateTimeFormat formatters.
11179 ///
11180 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/formatToParts)
11181 #[cfg(js_sys_unstable_apis)]
11182 #[wasm_bindgen(method, js_class = "Intl.DateTimeFormat", js_name = formatToParts)]
11183 pub fn format_to_parts(this: &DateTimeFormat, date: &Date) -> Array<DateTimeFormatPart>;
11184
11185 /// The `Intl.DateTimeFormat.prototype.formatRange()` method formats a date range
11186 /// in the most concise way based on the locales and options provided when
11187 /// instantiating this `Intl.DateTimeFormat` object.
11188 ///
11189 /// Throws a `TypeError` if the dates are invalid.
11190 ///
11191 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatRange)
11192 #[wasm_bindgen(method, js_class = "Intl.DateTimeFormat", js_name = formatRange, catch)]
11193 pub fn format_range(
11194 this: &DateTimeFormat,
11195 start_date: &Date,
11196 end_date: &Date,
11197 ) -> Result<JsString, JsValue>;
11198
11199 /// The `Intl.DateTimeFormat.prototype.formatRangeToParts()` method returns an array
11200 /// of locale-specific tokens representing each part of the formatted date range
11201 /// produced by `Intl.DateTimeFormat` formatters.
11202 ///
11203 /// Throws a `TypeError` if the dates are invalid.
11204 ///
11205 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatRangeToParts)
11206 #[wasm_bindgen(method, js_class = "Intl.DateTimeFormat", js_name = formatRangeToParts, catch)]
11207 pub fn format_range_to_parts(
11208 this: &DateTimeFormat,
11209 start_date: &Date,
11210 end_date: &Date,
11211 ) -> Result<Array<DateTimeRangeFormatPart>, JsValue>;
11212
11213 /// The `Intl.DateTimeFormat.prototype.resolvedOptions()` method returns a new
11214 /// object with properties reflecting the locale and date and time formatting
11215 /// options computed during initialization of this DateTimeFormat object.
11216 ///
11217 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/resolvedOptions)
11218 #[cfg(not(js_sys_unstable_apis))]
11219 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11220 pub fn resolved_options(this: &DateTimeFormat) -> Object;
11221
11222 /// The `Intl.DateTimeFormat.prototype.resolvedOptions()` method returns a new
11223 /// object with properties reflecting the locale and date and time formatting
11224 /// options computed during initialization of this DateTimeFormat object.
11225 ///
11226 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/resolvedOptions)
11227 #[cfg(js_sys_unstable_apis)]
11228 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11229 pub fn resolved_options(this: &DateTimeFormat) -> ResolvedDateTimeFormatOptions;
11230
11231 /// The `Intl.DateTimeFormat.supportedLocalesOf()` method returns an array
11232 /// containing those of the provided locales that are supported in date
11233 /// and time formatting without having to fall back to the runtime's default
11234 /// locale.
11235 ///
11236 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/supportedLocalesOf)
11237 #[cfg(not(js_sys_unstable_apis))]
11238 #[wasm_bindgen(static_method_of = DateTimeFormat, js_namespace = Intl, js_name = supportedLocalesOf)]
11239 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
11240
11241 /// The `Intl.DateTimeFormat.supportedLocalesOf()` method returns an array
11242 /// containing those of the provided locales that are supported in date
11243 /// and time formatting without having to fall back to the runtime's default
11244 /// locale.
11245 ///
11246 /// Throws a `RangeError` if locales contain invalid values.
11247 ///
11248 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/supportedLocalesOf)
11249 #[cfg(js_sys_unstable_apis)]
11250 #[wasm_bindgen(static_method_of = DateTimeFormat, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
11251 pub fn supported_locales_of(
11252 locales: &[JsString],
11253 options: &LocaleMatcherOptions,
11254 ) -> Result<Array<JsString>, JsValue>;
11255 }
11256
11257 #[cfg(not(js_sys_unstable_apis))]
11258 impl Default for DateTimeFormat {
11259 fn default() -> Self {
11260 Self::new(
11261 &JsValue::UNDEFINED.unchecked_into(),
11262 &JsValue::UNDEFINED.unchecked_into(),
11263 )
11264 }
11265 }
11266
11267 #[cfg(js_sys_unstable_apis)]
11268 impl Default for DateTimeFormat {
11269 fn default() -> Self {
11270 Self::new(&[], &Default::default()).unwrap()
11271 }
11272 }
11273
11274 // Intl.NumberFormatOptions
11275 #[wasm_bindgen]
11276 extern "C" {
11277 /// Options for `Intl.NumberFormat` constructor.
11278 ///
11279 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#options)
11280 #[wasm_bindgen(extends = Object)]
11281 #[derive(Clone, Debug)]
11282 pub type NumberFormatOptions;
11283
11284 // Locale matching
11285 #[wasm_bindgen(method, getter = localeMatcher)]
11286 pub fn get_locale_matcher(this: &NumberFormatOptions) -> Option<LocaleMatcher>;
11287 #[wasm_bindgen(method, setter = localeMatcher)]
11288 pub fn set_locale_matcher(this: &NumberFormatOptions, value: LocaleMatcher);
11289
11290 // Numbering system (free-form string)
11291 #[wasm_bindgen(method, getter = numberingSystem)]
11292 pub fn get_numbering_system(this: &NumberFormatOptions) -> Option<JsString>;
11293 #[wasm_bindgen(method, setter = numberingSystem)]
11294 pub fn set_numbering_system(this: &NumberFormatOptions, value: &str);
11295
11296 // Style
11297 #[wasm_bindgen(method, getter = style)]
11298 pub fn get_style(this: &NumberFormatOptions) -> Option<NumberFormatStyle>;
11299 #[wasm_bindgen(method, setter = style)]
11300 pub fn set_style(this: &NumberFormatOptions, value: NumberFormatStyle);
11301
11302 // Currency options (currency code is free-form ISO 4217 string)
11303 #[wasm_bindgen(method, getter = currency)]
11304 pub fn get_currency(this: &NumberFormatOptions) -> Option<JsString>;
11305 #[wasm_bindgen(method, setter = currency)]
11306 pub fn set_currency(this: &NumberFormatOptions, value: &str);
11307
11308 #[wasm_bindgen(method, getter = currencyDisplay)]
11309 pub fn get_currency_display(this: &NumberFormatOptions) -> Option<CurrencyDisplay>;
11310 #[wasm_bindgen(method, setter = currencyDisplay)]
11311 pub fn set_currency_display(this: &NumberFormatOptions, value: CurrencyDisplay);
11312
11313 #[wasm_bindgen(method, getter = currencySign)]
11314 pub fn get_currency_sign(this: &NumberFormatOptions) -> Option<CurrencySign>;
11315 #[wasm_bindgen(method, setter = currencySign)]
11316 pub fn set_currency_sign(this: &NumberFormatOptions, value: CurrencySign);
11317
11318 // Unit options (unit name is free-form string)
11319 #[wasm_bindgen(method, getter = unit)]
11320 pub fn get_unit(this: &NumberFormatOptions) -> Option<JsString>;
11321 #[wasm_bindgen(method, setter = unit)]
11322 pub fn set_unit(this: &NumberFormatOptions, value: &str);
11323
11324 #[wasm_bindgen(method, getter = unitDisplay)]
11325 pub fn get_unit_display(this: &NumberFormatOptions) -> Option<UnitDisplay>;
11326 #[wasm_bindgen(method, setter = unitDisplay)]
11327 pub fn set_unit_display(this: &NumberFormatOptions, value: UnitDisplay);
11328
11329 // Notation
11330 #[wasm_bindgen(method, getter = notation)]
11331 pub fn get_notation(this: &NumberFormatOptions) -> Option<NumberFormatNotation>;
11332 #[wasm_bindgen(method, setter = notation)]
11333 pub fn set_notation(this: &NumberFormatOptions, value: NumberFormatNotation);
11334
11335 #[wasm_bindgen(method, getter = compactDisplay)]
11336 pub fn get_compact_display(this: &NumberFormatOptions) -> Option<CompactDisplay>;
11337 #[wasm_bindgen(method, setter = compactDisplay)]
11338 pub fn set_compact_display(this: &NumberFormatOptions, value: CompactDisplay);
11339
11340 // Sign display
11341 #[wasm_bindgen(method, getter = signDisplay)]
11342 pub fn get_sign_display(this: &NumberFormatOptions) -> Option<SignDisplay>;
11343 #[wasm_bindgen(method, setter = signDisplay)]
11344 pub fn set_sign_display(this: &NumberFormatOptions, value: SignDisplay);
11345
11346 // Digit options
11347 #[wasm_bindgen(method, getter = minimumIntegerDigits)]
11348 pub fn get_minimum_integer_digits(this: &NumberFormatOptions) -> Option<u8>;
11349 #[wasm_bindgen(method, setter = minimumIntegerDigits)]
11350 pub fn set_minimum_integer_digits(this: &NumberFormatOptions, value: u8);
11351
11352 #[wasm_bindgen(method, getter = minimumFractionDigits)]
11353 pub fn get_minimum_fraction_digits(this: &NumberFormatOptions) -> Option<u8>;
11354 #[wasm_bindgen(method, setter = minimumFractionDigits)]
11355 pub fn set_minimum_fraction_digits(this: &NumberFormatOptions, value: u8);
11356
11357 #[wasm_bindgen(method, getter = maximumFractionDigits)]
11358 pub fn get_maximum_fraction_digits(this: &NumberFormatOptions) -> Option<u8>;
11359 #[wasm_bindgen(method, setter = maximumFractionDigits)]
11360 pub fn set_maximum_fraction_digits(this: &NumberFormatOptions, value: u8);
11361
11362 #[wasm_bindgen(method, getter = minimumSignificantDigits)]
11363 pub fn get_minimum_significant_digits(this: &NumberFormatOptions) -> Option<u8>;
11364 #[wasm_bindgen(method, setter = minimumSignificantDigits)]
11365 pub fn set_minimum_significant_digits(this: &NumberFormatOptions, value: u8);
11366
11367 #[wasm_bindgen(method, getter = maximumSignificantDigits)]
11368 pub fn get_maximum_significant_digits(this: &NumberFormatOptions) -> Option<u8>;
11369 #[wasm_bindgen(method, setter = maximumSignificantDigits)]
11370 pub fn set_maximum_significant_digits(this: &NumberFormatOptions, value: u8);
11371
11372 // Grouping
11373 #[wasm_bindgen(method, getter = useGrouping)]
11374 pub fn get_use_grouping(this: &NumberFormatOptions) -> Option<UseGrouping>;
11375 #[wasm_bindgen(method, setter = useGrouping)]
11376 pub fn set_use_grouping(this: &NumberFormatOptions, value: UseGrouping);
11377
11378 // Rounding
11379 #[wasm_bindgen(method, getter = roundingMode)]
11380 pub fn get_rounding_mode(this: &NumberFormatOptions) -> Option<RoundingMode>;
11381 #[wasm_bindgen(method, setter = roundingMode)]
11382 pub fn set_rounding_mode(this: &NumberFormatOptions, value: RoundingMode);
11383
11384 #[wasm_bindgen(method, getter = roundingPriority)]
11385 pub fn get_rounding_priority(this: &NumberFormatOptions) -> Option<RoundingPriority>;
11386 #[wasm_bindgen(method, setter = roundingPriority)]
11387 pub fn set_rounding_priority(this: &NumberFormatOptions, value: RoundingPriority);
11388
11389 #[wasm_bindgen(method, getter = roundingIncrement)]
11390 pub fn get_rounding_increment(this: &NumberFormatOptions) -> Option<u32>;
11391 #[wasm_bindgen(method, setter = roundingIncrement)]
11392 pub fn set_rounding_increment(this: &NumberFormatOptions, value: u32);
11393
11394 #[wasm_bindgen(method, getter = trailingZeroDisplay)]
11395 pub fn get_trailing_zero_display(this: &NumberFormatOptions)
11396 -> Option<TrailingZeroDisplay>;
11397 #[wasm_bindgen(method, setter = trailingZeroDisplay)]
11398 pub fn set_trailing_zero_display(this: &NumberFormatOptions, value: TrailingZeroDisplay);
11399 }
11400
11401 impl NumberFormatOptions {
11402 pub fn new() -> NumberFormatOptions {
11403 JsCast::unchecked_into(Object::new())
11404 }
11405 }
11406
11407 impl Default for NumberFormatOptions {
11408 fn default() -> Self {
11409 NumberFormatOptions::new()
11410 }
11411 }
11412
11413 // Intl.ResolvedNumberFormatOptions
11414 #[wasm_bindgen]
11415 extern "C" {
11416 /// Resolved options returned by `Intl.NumberFormat.prototype.resolvedOptions()`.
11417 ///
11418 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/resolvedOptions)
11419 #[wasm_bindgen(extends = NumberFormatOptions)]
11420 #[derive(Clone, Debug)]
11421 pub type ResolvedNumberFormatOptions;
11422
11423 /// The resolved locale string.
11424 #[wasm_bindgen(method, getter = locale)]
11425 pub fn get_locale(this: &ResolvedNumberFormatOptions) -> JsString;
11426 }
11427
11428 // Intl.NumberFormatPart
11429 #[wasm_bindgen]
11430 extern "C" {
11431 /// A part of the formatted number returned by `formatToParts()`.
11432 ///
11433 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatToParts)
11434 #[wasm_bindgen(extends = Object)]
11435 #[derive(Clone, Debug)]
11436 pub type NumberFormatPart;
11437
11438 /// The type of the part (e.g., "integer", "decimal", "fraction", "currency", etc.)
11439 #[wasm_bindgen(method, getter = type)]
11440 pub fn type_(this: &NumberFormatPart) -> NumberFormatPartType;
11441
11442 /// The value of the part.
11443 #[wasm_bindgen(method, getter)]
11444 pub fn value(this: &NumberFormatPart) -> JsString;
11445 }
11446
11447 // Intl.NumberRangeFormatPart
11448 #[wasm_bindgen]
11449 extern "C" {
11450 /// A part of the formatted number range returned by `formatRangeToParts()`.
11451 ///
11452 /// Extends `NumberFormatPart` with a `source` property indicating whether
11453 /// the part is from the start number, end number, or shared between them.
11454 ///
11455 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatRangeToParts)
11456 #[wasm_bindgen(extends = NumberFormatPart)]
11457 #[derive(Clone, Debug)]
11458 pub type NumberRangeFormatPart;
11459
11460 /// The source of the part: "startRange", "endRange", or "shared".
11461 #[wasm_bindgen(method, getter)]
11462 pub fn source(this: &NumberRangeFormatPart) -> RangeSource;
11463 }
11464
11465 // Intl.NumberFormat
11466 #[wasm_bindgen]
11467 extern "C" {
11468 /// The `Intl.NumberFormat` object is a constructor for objects
11469 /// that enable language sensitive number formatting.
11470 ///
11471 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat)
11472 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.NumberFormat")]
11473 #[derive(Clone, Debug)]
11474 pub type NumberFormat;
11475
11476 /// The `Intl.NumberFormat` object is a constructor for objects
11477 /// that enable language sensitive number formatting.
11478 ///
11479 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat)
11480 #[cfg(not(js_sys_unstable_apis))]
11481 #[wasm_bindgen(constructor, js_namespace = Intl)]
11482 pub fn new(locales: &Array, options: &Object) -> NumberFormat;
11483
11484 /// The `Intl.NumberFormat` object is a constructor for objects
11485 /// that enable language sensitive number formatting.
11486 ///
11487 /// Throws a `RangeError` if locales contain invalid values.
11488 ///
11489 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat)
11490 #[cfg(js_sys_unstable_apis)]
11491 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
11492 pub fn new(
11493 locales: &[JsString],
11494 options: &NumberFormatOptions,
11495 ) -> Result<NumberFormat, JsValue>;
11496
11497 /// The Intl.NumberFormat.prototype.format property returns a getter function that
11498 /// formats a number according to the locale and formatting options of this
11499 /// NumberFormat object.
11500 ///
11501 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/format)
11502 #[cfg(not(js_sys_unstable_apis))]
11503 #[wasm_bindgen(method, getter, js_class = "Intl.NumberFormat")]
11504 pub fn format(this: &NumberFormat) -> Function;
11505
11506 /// Formats a number according to the locale and formatting options of this
11507 /// `Intl.NumberFormat` object.
11508 ///
11509 /// Accepts numeric strings for BigInt/arbitrary precision (e.g., `"123n"` → `"123"`,
11510 /// or use E notation: `"1000000E-6"` → `"1"`).
11511 ///
11512 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/format)
11513 #[cfg(js_sys_unstable_apis)]
11514 #[wasm_bindgen(method, js_class = "Intl.NumberFormat")]
11515 pub fn format(this: &NumberFormat, value: &JsString) -> JsString;
11516
11517 /// The `Intl.Numberformat.prototype.formatToParts()` method allows locale-aware
11518 /// formatting of strings produced by NumberTimeFormat formatters.
11519 ///
11520 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/formatToParts)
11521 #[cfg(not(js_sys_unstable_apis))]
11522 #[wasm_bindgen(method, js_class = "Intl.NumberFormat", js_name = formatToParts)]
11523 pub fn format_to_parts(this: &NumberFormat, number: f64) -> Array;
11524
11525 /// The `Intl.NumberFormat.prototype.formatToParts()` method allows locale-aware
11526 /// formatting of strings produced by `Intl.NumberFormat` formatters.
11527 ///
11528 /// Accepts numeric strings for BigInt/arbitrary precision (e.g., `"123n"` → `"123"`,
11529 /// or use E notation: `"1000000E-6"` → `"1"`).
11530 ///
11531 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatToParts)
11532 #[cfg(js_sys_unstable_apis)]
11533 #[wasm_bindgen(method, js_class = "Intl.NumberFormat", js_name = formatToParts)]
11534 pub fn format_to_parts(this: &NumberFormat, value: &JsString) -> Array<NumberFormatPart>;
11535
11536 /// Formats a range of numbers according to the locale and formatting options
11537 /// of this `Intl.NumberFormat` object.
11538 ///
11539 /// Accepts numeric strings for BigInt/arbitrary precision (e.g., `"123n"` → `"123"`,
11540 /// or use E notation: `"1000000E-6"` → `"1"`).
11541 ///
11542 /// Throws a `TypeError` if the values are invalid.
11543 ///
11544 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatRange)
11545 #[wasm_bindgen(method, js_class = "Intl.NumberFormat", js_name = formatRange, catch)]
11546 pub fn format_range(
11547 this: &NumberFormat,
11548 start: &JsString,
11549 end: &JsString,
11550 ) -> Result<JsString, JsValue>;
11551
11552 /// Returns an array of locale-specific tokens representing each part of
11553 /// the formatted number range.
11554 ///
11555 /// Accepts numeric strings for BigInt/arbitrary precision (e.g., `"123n"` → `"123"`,
11556 /// or use E notation: `"1000000E-6"` → `"1"`).
11557 ///
11558 /// Throws a `TypeError` if the values are invalid.
11559 ///
11560 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatRangeToParts)
11561 #[wasm_bindgen(method, js_class = "Intl.NumberFormat", js_name = formatRangeToParts, catch)]
11562 pub fn format_range_to_parts(
11563 this: &NumberFormat,
11564 start: &JsString,
11565 end: &JsString,
11566 ) -> Result<Array<NumberRangeFormatPart>, JsValue>;
11567
11568 /// The `Intl.NumberFormat.prototype.resolvedOptions()` method returns a new
11569 /// object with properties reflecting the locale and number formatting
11570 /// options computed during initialization of this NumberFormat object.
11571 ///
11572 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/resolvedOptions)
11573 #[cfg(not(js_sys_unstable_apis))]
11574 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11575 pub fn resolved_options(this: &NumberFormat) -> Object;
11576
11577 /// The `Intl.NumberFormat.prototype.resolvedOptions()` method returns a new
11578 /// object with properties reflecting the locale and number formatting
11579 /// options computed during initialization of this NumberFormat object.
11580 ///
11581 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/resolvedOptions)
11582 #[cfg(js_sys_unstable_apis)]
11583 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11584 pub fn resolved_options(this: &NumberFormat) -> ResolvedNumberFormatOptions;
11585
11586 /// The `Intl.NumberFormat.supportedLocalesOf()` method returns an array
11587 /// containing those of the provided locales that are supported in number
11588 /// formatting without having to fall back to the runtime's default locale.
11589 ///
11590 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/supportedLocalesOf)
11591 #[cfg(not(js_sys_unstable_apis))]
11592 #[wasm_bindgen(static_method_of = NumberFormat, js_namespace = Intl, js_name = supportedLocalesOf)]
11593 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
11594
11595 /// The `Intl.NumberFormat.supportedLocalesOf()` method returns an array
11596 /// containing those of the provided locales that are supported in number
11597 /// formatting without having to fall back to the runtime's default locale.
11598 ///
11599 /// Throws a `RangeError` if locales contain invalid values.
11600 ///
11601 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/supportedLocalesOf)
11602 #[cfg(js_sys_unstable_apis)]
11603 #[wasm_bindgen(static_method_of = NumberFormat, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
11604 pub fn supported_locales_of(
11605 locales: &[JsString],
11606 options: &LocaleMatcherOptions,
11607 ) -> Result<Array<JsString>, JsValue>;
11608 }
11609
11610 #[cfg(not(js_sys_unstable_apis))]
11611 impl Default for NumberFormat {
11612 fn default() -> Self {
11613 Self::new(
11614 &JsValue::UNDEFINED.unchecked_into(),
11615 &JsValue::UNDEFINED.unchecked_into(),
11616 )
11617 }
11618 }
11619
11620 #[cfg(js_sys_unstable_apis)]
11621 impl Default for NumberFormat {
11622 fn default() -> Self {
11623 Self::new(&[], &Default::default()).unwrap()
11624 }
11625 }
11626
11627 // Intl.PluralRulesOptions
11628 #[wasm_bindgen]
11629 extern "C" {
11630 /// Options for `Intl.PluralRules` constructor.
11631 ///
11632 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules/PluralRules#options)
11633 #[wasm_bindgen(extends = Object)]
11634 #[derive(Clone, Debug)]
11635 pub type PluralRulesOptions;
11636
11637 #[wasm_bindgen(method, getter = localeMatcher)]
11638 pub fn get_locale_matcher(this: &PluralRulesOptions) -> Option<LocaleMatcher>;
11639 #[wasm_bindgen(method, setter = localeMatcher)]
11640 pub fn set_locale_matcher(this: &PluralRulesOptions, value: LocaleMatcher);
11641
11642 #[wasm_bindgen(method, getter = type)]
11643 pub fn get_type(this: &PluralRulesOptions) -> Option<PluralRulesType>;
11644 #[wasm_bindgen(method, setter = type)]
11645 pub fn set_type(this: &PluralRulesOptions, value: PluralRulesType);
11646
11647 #[wasm_bindgen(method, getter = minimumIntegerDigits)]
11648 pub fn get_minimum_integer_digits(this: &PluralRulesOptions) -> Option<u8>;
11649 #[wasm_bindgen(method, setter = minimumIntegerDigits)]
11650 pub fn set_minimum_integer_digits(this: &PluralRulesOptions, value: u8);
11651
11652 #[wasm_bindgen(method, getter = minimumFractionDigits)]
11653 pub fn get_minimum_fraction_digits(this: &PluralRulesOptions) -> Option<u8>;
11654 #[wasm_bindgen(method, setter = minimumFractionDigits)]
11655 pub fn set_minimum_fraction_digits(this: &PluralRulesOptions, value: u8);
11656
11657 #[wasm_bindgen(method, getter = maximumFractionDigits)]
11658 pub fn get_maximum_fraction_digits(this: &PluralRulesOptions) -> Option<u8>;
11659 #[wasm_bindgen(method, setter = maximumFractionDigits)]
11660 pub fn set_maximum_fraction_digits(this: &PluralRulesOptions, value: u8);
11661
11662 #[wasm_bindgen(method, getter = minimumSignificantDigits)]
11663 pub fn get_minimum_significant_digits(this: &PluralRulesOptions) -> Option<u8>;
11664 #[wasm_bindgen(method, setter = minimumSignificantDigits)]
11665 pub fn set_minimum_significant_digits(this: &PluralRulesOptions, value: u8);
11666
11667 #[wasm_bindgen(method, getter = maximumSignificantDigits)]
11668 pub fn get_maximum_significant_digits(this: &PluralRulesOptions) -> Option<u8>;
11669 #[wasm_bindgen(method, setter = maximumSignificantDigits)]
11670 pub fn set_maximum_significant_digits(this: &PluralRulesOptions, value: u8);
11671
11672 #[wasm_bindgen(method, getter = roundingPriority)]
11673 pub fn get_rounding_priority(this: &PluralRulesOptions) -> Option<RoundingPriority>;
11674 #[wasm_bindgen(method, setter = roundingPriority)]
11675 pub fn set_rounding_priority(this: &PluralRulesOptions, value: RoundingPriority);
11676
11677 #[wasm_bindgen(method, getter = roundingIncrement)]
11678 pub fn get_rounding_increment(this: &PluralRulesOptions) -> Option<u32>;
11679 #[wasm_bindgen(method, setter = roundingIncrement)]
11680 pub fn set_rounding_increment(this: &PluralRulesOptions, value: u32);
11681
11682 #[wasm_bindgen(method, getter = roundingMode)]
11683 pub fn get_rounding_mode(this: &PluralRulesOptions) -> Option<RoundingMode>;
11684 #[wasm_bindgen(method, setter = roundingMode)]
11685 pub fn set_rounding_mode(this: &PluralRulesOptions, value: RoundingMode);
11686
11687 #[wasm_bindgen(method, getter = trailingZeroDisplay)]
11688 pub fn get_trailing_zero_display(this: &PluralRulesOptions) -> Option<TrailingZeroDisplay>;
11689 #[wasm_bindgen(method, setter = trailingZeroDisplay)]
11690 pub fn set_trailing_zero_display(this: &PluralRulesOptions, value: TrailingZeroDisplay);
11691 }
11692
11693 impl PluralRulesOptions {
11694 pub fn new() -> PluralRulesOptions {
11695 JsCast::unchecked_into(Object::new())
11696 }
11697 }
11698
11699 impl Default for PluralRulesOptions {
11700 fn default() -> Self {
11701 PluralRulesOptions::new()
11702 }
11703 }
11704
11705 // Intl.ResolvedPluralRulesOptions
11706 #[wasm_bindgen]
11707 extern "C" {
11708 /// Resolved options returned by `Intl.PluralRules.prototype.resolvedOptions()`.
11709 ///
11710 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules/resolvedOptions)
11711 #[wasm_bindgen(extends = PluralRulesOptions)]
11712 #[derive(Clone, Debug)]
11713 pub type ResolvedPluralRulesOptions;
11714
11715 /// The resolved locale string.
11716 #[wasm_bindgen(method, getter = locale)]
11717 pub fn get_locale(this: &ResolvedPluralRulesOptions) -> JsString;
11718
11719 /// The plural categories used by the locale.
11720 #[wasm_bindgen(method, getter = pluralCategories)]
11721 pub fn get_plural_categories(this: &ResolvedPluralRulesOptions) -> Array<JsString>;
11722 }
11723
11724 // Intl.PluralRules
11725 #[wasm_bindgen]
11726 extern "C" {
11727 /// The `Intl.PluralRules` object is a constructor for objects
11728 /// that enable plural sensitive formatting and plural language rules.
11729 ///
11730 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules)
11731 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.PluralRules")]
11732 #[derive(Clone, Debug)]
11733 pub type PluralRules;
11734
11735 /// The `Intl.PluralRules` object is a constructor for objects
11736 /// that enable plural sensitive formatting and plural language rules.
11737 ///
11738 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules)
11739 #[cfg(not(js_sys_unstable_apis))]
11740 #[wasm_bindgen(constructor, js_namespace = Intl)]
11741 pub fn new(locales: &Array, options: &Object) -> PluralRules;
11742
11743 /// The `Intl.PluralRules` object is a constructor for objects
11744 /// that enable plural sensitive formatting and plural language rules.
11745 ///
11746 /// Throws a `RangeError` if locales contain invalid values.
11747 ///
11748 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules)
11749 #[cfg(js_sys_unstable_apis)]
11750 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
11751 pub fn new(
11752 locales: &[JsString],
11753 options: &PluralRulesOptions,
11754 ) -> Result<PluralRules, JsValue>;
11755
11756 /// The `Intl.PluralRules.prototype.resolvedOptions()` method returns a new
11757 /// object with properties reflecting the locale and plural formatting
11758 /// options computed during initialization of this PluralRules object.
11759 ///
11760 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/resolvedOptions)
11761 #[cfg(not(js_sys_unstable_apis))]
11762 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11763 pub fn resolved_options(this: &PluralRules) -> Object;
11764
11765 /// The `Intl.PluralRules.prototype.resolvedOptions()` method returns a new
11766 /// object with properties reflecting the locale and plural formatting
11767 /// options computed during initialization of this PluralRules object.
11768 ///
11769 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/resolvedOptions)
11770 #[cfg(js_sys_unstable_apis)]
11771 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11772 pub fn resolved_options(this: &PluralRules) -> ResolvedPluralRulesOptions;
11773
11774 /// The `Intl.PluralRules.prototype.select()` method returns a String indicating
11775 /// which plural rule to use for locale-aware formatting.
11776 ///
11777 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/select)
11778 #[cfg(not(js_sys_unstable_apis))]
11779 #[wasm_bindgen(method, js_namespace = Intl)]
11780 pub fn select(this: &PluralRules, number: f64) -> JsString;
11781
11782 /// The `Intl.PluralRules.prototype.select()` method returns a String indicating
11783 /// which plural rule to use for locale-aware formatting.
11784 ///
11785 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/select)
11786 #[cfg(js_sys_unstable_apis)]
11787 #[wasm_bindgen(method, js_namespace = Intl)]
11788 pub fn select(this: &PluralRules, number: f64) -> PluralCategory;
11789
11790 /// The `Intl.PluralRules.prototype.selectRange()` method returns a string indicating
11791 /// which plural rule to use for locale-aware formatting of a range of numbers.
11792 ///
11793 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules/selectRange)
11794 #[cfg(not(js_sys_unstable_apis))]
11795 #[wasm_bindgen(method, js_namespace = Intl, js_name = selectRange)]
11796 pub fn select_range(this: &PluralRules, start: f64, end: f64) -> JsString;
11797
11798 /// The `Intl.PluralRules.prototype.selectRange()` method returns a string indicating
11799 /// which plural rule to use for locale-aware formatting of a range of numbers.
11800 ///
11801 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules/selectRange)
11802 #[cfg(js_sys_unstable_apis)]
11803 #[wasm_bindgen(method, js_namespace = Intl, js_name = selectRange)]
11804 pub fn select_range(this: &PluralRules, start: f64, end: f64) -> PluralCategory;
11805
11806 /// The `Intl.PluralRules.supportedLocalesOf()` method returns an array
11807 /// containing those of the provided locales that are supported in plural
11808 /// formatting without having to fall back to the runtime's default locale.
11809 ///
11810 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/supportedLocalesOf)
11811 #[cfg(not(js_sys_unstable_apis))]
11812 #[wasm_bindgen(static_method_of = PluralRules, js_namespace = Intl, js_name = supportedLocalesOf)]
11813 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
11814
11815 /// The `Intl.PluralRules.supportedLocalesOf()` method returns an array
11816 /// containing those of the provided locales that are supported in plural
11817 /// formatting without having to fall back to the runtime's default locale.
11818 ///
11819 /// Throws a `RangeError` if locales contain invalid values.
11820 ///
11821 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/supportedLocalesOf)
11822 #[cfg(js_sys_unstable_apis)]
11823 #[wasm_bindgen(static_method_of = PluralRules, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
11824 pub fn supported_locales_of(
11825 locales: &[JsString],
11826 options: &LocaleMatcherOptions,
11827 ) -> Result<Array<JsString>, JsValue>;
11828 }
11829
11830 #[cfg(not(js_sys_unstable_apis))]
11831 impl Default for PluralRules {
11832 fn default() -> Self {
11833 Self::new(
11834 &JsValue::UNDEFINED.unchecked_into(),
11835 &JsValue::UNDEFINED.unchecked_into(),
11836 )
11837 }
11838 }
11839
11840 #[cfg(js_sys_unstable_apis)]
11841 impl Default for PluralRules {
11842 fn default() -> Self {
11843 Self::new(&[], &Default::default()).unwrap()
11844 }
11845 }
11846
11847 // Intl.RelativeTimeFormat
11848 #[wasm_bindgen]
11849 extern "C" {
11850 /// The `Intl.RelativeTimeFormat` object is a constructor for objects
11851 /// that enable language-sensitive relative time formatting.
11852 ///
11853 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat)
11854 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.RelativeTimeFormat")]
11855 #[derive(Clone, Debug)]
11856 pub type RelativeTimeFormat;
11857
11858 /// The `Intl.RelativeTimeFormat` object is a constructor for objects
11859 /// that enable language-sensitive relative time formatting.
11860 ///
11861 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat)
11862 #[cfg(not(js_sys_unstable_apis))]
11863 #[wasm_bindgen(constructor, js_namespace = Intl)]
11864 pub fn new(locales: &Array, options: &Object) -> RelativeTimeFormat;
11865
11866 /// The `Intl.RelativeTimeFormat` object is a constructor for objects
11867 /// that enable language-sensitive relative time formatting.
11868 ///
11869 /// Throws a `RangeError` if locales contain invalid values.
11870 ///
11871 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat)
11872 #[cfg(js_sys_unstable_apis)]
11873 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
11874 pub fn new(locales: &[JsString]) -> Result<RelativeTimeFormat, JsValue>;
11875
11876 /// The `Intl.RelativeTimeFormat` object is a constructor for objects
11877 /// that enable language-sensitive relative time formatting.
11878 ///
11879 /// Throws a `RangeError` if locales or options contain invalid values.
11880 ///
11881 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat)
11882 #[cfg(js_sys_unstable_apis)]
11883 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
11884 pub fn new_with_options(
11885 locales: &[JsString],
11886 options: &RelativeTimeFormatOptions,
11887 ) -> Result<RelativeTimeFormat, JsValue>;
11888
11889 /// The `Intl.RelativeTimeFormat.prototype.format` method formats a `value` and `unit`
11890 /// according to the locale and formatting options of this Intl.RelativeTimeFormat object.
11891 ///
11892 /// Throws a `RangeError` if unit is invalid.
11893 ///
11894 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/format)
11895 #[cfg(not(js_sys_unstable_apis))]
11896 #[wasm_bindgen(method, js_class = "Intl.RelativeTimeFormat")]
11897 pub fn format(this: &RelativeTimeFormat, value: f64, unit: &str) -> JsString;
11898
11899 /// The `Intl.RelativeTimeFormat.prototype.format` method formats a `value` and `unit`
11900 /// according to the locale and formatting options of this Intl.RelativeTimeFormat object.
11901 ///
11902 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/format)
11903 #[cfg(js_sys_unstable_apis)]
11904 #[wasm_bindgen(method, js_class = "Intl.RelativeTimeFormat")]
11905 pub fn format(
11906 this: &RelativeTimeFormat,
11907 value: f64,
11908 unit: RelativeTimeFormatUnit,
11909 ) -> JsString;
11910
11911 /// The `Intl.RelativeTimeFormat.prototype.formatToParts()` method returns an array of
11912 /// objects representing the relative time format in parts that can be used for custom locale-aware formatting.
11913 ///
11914 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/formatToParts)
11915 #[cfg(not(js_sys_unstable_apis))]
11916 #[wasm_bindgen(method, js_class = "Intl.RelativeTimeFormat", js_name = formatToParts)]
11917 pub fn format_to_parts(this: &RelativeTimeFormat, value: f64, unit: &str) -> Array;
11918
11919 /// The `Intl.RelativeTimeFormat.prototype.formatToParts()` method returns an array of
11920 /// objects representing the relative time format in parts that can be used for custom locale-aware formatting.
11921 ///
11922 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/formatToParts)
11923 #[cfg(js_sys_unstable_apis)]
11924 #[wasm_bindgen(method, js_class = "Intl.RelativeTimeFormat", js_name = formatToParts)]
11925 pub fn format_to_parts(
11926 this: &RelativeTimeFormat,
11927 value: f64,
11928 unit: RelativeTimeFormatUnit,
11929 ) -> Array<RelativeTimeFormatPart>;
11930
11931 /// The `Intl.RelativeTimeFormat.prototype.resolvedOptions()` method returns a new
11932 /// object with properties reflecting the locale and relative time formatting
11933 /// options computed during initialization of this RelativeTimeFormat object.
11934 ///
11935 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/resolvedOptions)
11936 #[cfg(not(js_sys_unstable_apis))]
11937 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11938 pub fn resolved_options(this: &RelativeTimeFormat) -> Object;
11939
11940 /// The `Intl.RelativeTimeFormat.prototype.resolvedOptions()` method returns a new
11941 /// object with properties reflecting the locale and relative time formatting
11942 /// options computed during initialization of this RelativeTimeFormat object.
11943 ///
11944 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/resolvedOptions)
11945 #[cfg(js_sys_unstable_apis)]
11946 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11947 pub fn resolved_options(this: &RelativeTimeFormat) -> ResolvedRelativeTimeFormatOptions;
11948
11949 /// The `Intl.RelativeTimeFormat.supportedLocalesOf()` method returns an array
11950 /// containing those of the provided locales that are supported in date and time
11951 /// formatting without having to fall back to the runtime's default locale.
11952 ///
11953 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RelativeTimeFormat/supportedLocalesOf)
11954 #[cfg(not(js_sys_unstable_apis))]
11955 #[wasm_bindgen(static_method_of = RelativeTimeFormat, js_namespace = Intl, js_name = supportedLocalesOf)]
11956 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
11957
11958 /// The `Intl.RelativeTimeFormat.supportedLocalesOf()` method returns an array
11959 /// containing those of the provided locales that are supported in date and time
11960 /// formatting without having to fall back to the runtime's default locale.
11961 ///
11962 /// Throws a `RangeError` if locales contain invalid values.
11963 ///
11964 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RelativeTimeFormat/supportedLocalesOf)
11965 #[cfg(js_sys_unstable_apis)]
11966 #[wasm_bindgen(static_method_of = RelativeTimeFormat, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
11967 pub fn supported_locales_of(
11968 locales: &[JsString],
11969 options: &LocaleMatcherOptions,
11970 ) -> Result<Array<JsString>, JsValue>;
11971 }
11972
11973 #[cfg(not(js_sys_unstable_apis))]
11974 impl Default for RelativeTimeFormat {
11975 fn default() -> Self {
11976 Self::new(
11977 &JsValue::UNDEFINED.unchecked_into(),
11978 &JsValue::UNDEFINED.unchecked_into(),
11979 )
11980 }
11981 }
11982
11983 #[cfg(js_sys_unstable_apis)]
11984 impl Default for RelativeTimeFormat {
11985 fn default() -> Self {
11986 Self::new(&[]).unwrap()
11987 }
11988 }
11989
11990 // Intl.ListFormatOptions
11991 #[wasm_bindgen]
11992 extern "C" {
11993 /// Options for `Intl.ListFormat` constructor.
11994 ///
11995 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/ListFormat#options)
11996 #[wasm_bindgen(extends = Object)]
11997 #[derive(Clone, Debug)]
11998 pub type ListFormatOptions;
11999
12000 #[wasm_bindgen(method, getter = localeMatcher)]
12001 pub fn get_locale_matcher(this: &ListFormatOptions) -> Option<LocaleMatcher>;
12002 #[wasm_bindgen(method, setter = localeMatcher)]
12003 pub fn set_locale_matcher(this: &ListFormatOptions, value: LocaleMatcher);
12004
12005 #[wasm_bindgen(method, getter = type)]
12006 pub fn get_type(this: &ListFormatOptions) -> Option<ListFormatType>;
12007 #[wasm_bindgen(method, setter = type)]
12008 pub fn set_type(this: &ListFormatOptions, value: ListFormatType);
12009
12010 #[wasm_bindgen(method, getter = style)]
12011 pub fn get_style(this: &ListFormatOptions) -> Option<ListFormatStyle>;
12012 #[wasm_bindgen(method, setter = style)]
12013 pub fn set_style(this: &ListFormatOptions, value: ListFormatStyle);
12014 }
12015
12016 impl ListFormatOptions {
12017 pub fn new() -> ListFormatOptions {
12018 JsCast::unchecked_into(Object::new())
12019 }
12020 }
12021
12022 impl Default for ListFormatOptions {
12023 fn default() -> Self {
12024 ListFormatOptions::new()
12025 }
12026 }
12027
12028 // Intl.ResolvedListFormatOptions
12029 #[wasm_bindgen]
12030 extern "C" {
12031 /// Resolved options returned by `Intl.ListFormat.prototype.resolvedOptions()`.
12032 ///
12033 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/resolvedOptions)
12034 #[wasm_bindgen(extends = ListFormatOptions)]
12035 #[derive(Clone, Debug)]
12036 pub type ResolvedListFormatOptions;
12037
12038 /// The resolved locale string.
12039 #[wasm_bindgen(method, getter = locale)]
12040 pub fn get_locale(this: &ResolvedListFormatOptions) -> JsString;
12041 }
12042
12043 // Intl.ListFormatPart
12044 #[wasm_bindgen]
12045 extern "C" {
12046 /// A part of the formatted list returned by `formatToParts()`.
12047 ///
12048 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/formatToParts)
12049 #[wasm_bindgen(extends = Object)]
12050 #[derive(Clone, Debug)]
12051 pub type ListFormatPart;
12052
12053 /// The type of the part ("element" or "literal").
12054 #[wasm_bindgen(method, getter = type)]
12055 pub fn type_(this: &ListFormatPart) -> ListFormatPartType;
12056
12057 /// The value of the part.
12058 #[wasm_bindgen(method, getter)]
12059 pub fn value(this: &ListFormatPart) -> JsString;
12060 }
12061
12062 // Intl.ListFormat
12063 #[wasm_bindgen]
12064 extern "C" {
12065 /// The `Intl.ListFormat` object enables language-sensitive list formatting.
12066 ///
12067 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat)
12068 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.ListFormat")]
12069 #[derive(Clone, Debug)]
12070 pub type ListFormat;
12071
12072 /// Creates a new `Intl.ListFormat` object.
12073 ///
12074 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/ListFormat)
12075 #[cfg(not(js_sys_unstable_apis))]
12076 #[wasm_bindgen(constructor, js_namespace = Intl)]
12077 pub fn new(locales: &Array, options: &Object) -> ListFormat;
12078
12079 /// Creates a new `Intl.ListFormat` object.
12080 ///
12081 /// Throws a `RangeError` if locales or options contain invalid values.
12082 ///
12083 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/ListFormat)
12084 #[cfg(js_sys_unstable_apis)]
12085 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
12086 pub fn new(
12087 locales: &[JsString],
12088 options: &ListFormatOptions,
12089 ) -> Result<ListFormat, JsValue>;
12090
12091 /// Formats a list of strings according to the locale and options.
12092 ///
12093 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/format)
12094 #[cfg(not(js_sys_unstable_apis))]
12095 #[wasm_bindgen(method, js_class = "Intl.ListFormat")]
12096 pub fn format(this: &ListFormat, list: &Array) -> JsString;
12097
12098 /// Formats a list of strings according to the locale and options.
12099 ///
12100 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/format)
12101 #[cfg(js_sys_unstable_apis)]
12102 #[wasm_bindgen(method, js_class = "Intl.ListFormat")]
12103 pub fn format(this: &ListFormat, list: &[JsString]) -> JsString;
12104
12105 /// Returns an array of objects representing the list in parts.
12106 ///
12107 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/formatToParts)
12108 #[cfg(not(js_sys_unstable_apis))]
12109 #[wasm_bindgen(method, js_class = "Intl.ListFormat", js_name = formatToParts)]
12110 pub fn format_to_parts(this: &ListFormat, list: &Array) -> Array;
12111
12112 /// Returns an array of objects representing the list in parts.
12113 ///
12114 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/formatToParts)
12115 #[cfg(js_sys_unstable_apis)]
12116 #[wasm_bindgen(method, js_class = "Intl.ListFormat", js_name = formatToParts)]
12117 pub fn format_to_parts(this: &ListFormat, list: &[JsString]) -> Array<ListFormatPart>;
12118
12119 /// Returns an object with properties reflecting the options used.
12120 ///
12121 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/resolvedOptions)
12122 #[cfg(not(js_sys_unstable_apis))]
12123 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
12124 pub fn resolved_options(this: &ListFormat) -> Object;
12125
12126 /// Returns an object with properties reflecting the options used.
12127 ///
12128 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/resolvedOptions)
12129 #[cfg(js_sys_unstable_apis)]
12130 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
12131 pub fn resolved_options(this: &ListFormat) -> ResolvedListFormatOptions;
12132
12133 /// Returns an array of supported locales.
12134 ///
12135 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/supportedLocalesOf)
12136 #[cfg(not(js_sys_unstable_apis))]
12137 #[wasm_bindgen(static_method_of = ListFormat, js_namespace = Intl, js_name = supportedLocalesOf)]
12138 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
12139
12140 /// Returns an array of supported locales.
12141 ///
12142 /// Throws a `RangeError` if locales contain invalid values.
12143 ///
12144 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/supportedLocalesOf)
12145 #[cfg(js_sys_unstable_apis)]
12146 #[wasm_bindgen(static_method_of = ListFormat, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
12147 pub fn supported_locales_of(
12148 locales: &[JsString],
12149 options: &LocaleMatcherOptions,
12150 ) -> Result<Array<JsString>, JsValue>;
12151 }
12152
12153 #[cfg(not(js_sys_unstable_apis))]
12154 impl Default for ListFormat {
12155 fn default() -> Self {
12156 Self::new(
12157 &JsValue::UNDEFINED.unchecked_into(),
12158 &JsValue::UNDEFINED.unchecked_into(),
12159 )
12160 }
12161 }
12162
12163 #[cfg(js_sys_unstable_apis)]
12164 impl Default for ListFormat {
12165 fn default() -> Self {
12166 Self::new(&[], &Default::default()).unwrap()
12167 }
12168 }
12169
12170 // Intl.SegmenterOptions
12171 #[wasm_bindgen]
12172 extern "C" {
12173 /// Options for `Intl.Segmenter` constructor.
12174 ///
12175 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/Segmenter#options)
12176 #[wasm_bindgen(extends = Object)]
12177 #[derive(Clone, Debug)]
12178 pub type SegmenterOptions;
12179
12180 #[wasm_bindgen(method, getter = localeMatcher)]
12181 pub fn get_locale_matcher(this: &SegmenterOptions) -> Option<LocaleMatcher>;
12182 #[wasm_bindgen(method, setter = localeMatcher)]
12183 pub fn set_locale_matcher(this: &SegmenterOptions, value: LocaleMatcher);
12184
12185 #[wasm_bindgen(method, getter = granularity)]
12186 pub fn get_granularity(this: &SegmenterOptions) -> Option<SegmenterGranularity>;
12187 #[wasm_bindgen(method, setter = granularity)]
12188 pub fn set_granularity(this: &SegmenterOptions, value: SegmenterGranularity);
12189 }
12190
12191 impl SegmenterOptions {
12192 pub fn new() -> SegmenterOptions {
12193 JsCast::unchecked_into(Object::new())
12194 }
12195 }
12196
12197 impl Default for SegmenterOptions {
12198 fn default() -> Self {
12199 SegmenterOptions::new()
12200 }
12201 }
12202
12203 // Intl.ResolvedSegmenterOptions
12204 #[wasm_bindgen]
12205 extern "C" {
12206 /// Resolved options returned by `Intl.Segmenter.prototype.resolvedOptions()`.
12207 ///
12208 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/resolvedOptions)
12209 #[wasm_bindgen(extends = SegmenterOptions)]
12210 #[derive(Clone, Debug)]
12211 pub type ResolvedSegmenterOptions;
12212
12213 /// The resolved locale string.
12214 #[wasm_bindgen(method, getter = locale)]
12215 pub fn get_locale(this: &ResolvedSegmenterOptions) -> JsString;
12216 }
12217
12218 // Intl.SegmentData
12219 #[wasm_bindgen]
12220 extern "C" {
12221 /// Data about a segment returned by the Segments iterator.
12222 ///
12223 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/segment/Segments#segment_data)
12224 #[wasm_bindgen(extends = Object)]
12225 #[derive(Clone, Debug)]
12226 pub type SegmentData;
12227
12228 /// The segment string.
12229 #[wasm_bindgen(method, getter)]
12230 pub fn segment(this: &SegmentData) -> JsString;
12231
12232 /// The index of the segment in the original string.
12233 #[wasm_bindgen(method, getter)]
12234 pub fn index(this: &SegmentData) -> u32;
12235
12236 /// The original input string.
12237 #[wasm_bindgen(method, getter)]
12238 pub fn input(this: &SegmentData) -> JsString;
12239
12240 /// Whether the segment is word-like (only for word granularity).
12241 #[wasm_bindgen(method, getter = isWordLike)]
12242 pub fn is_word_like(this: &SegmentData) -> Option<bool>;
12243 }
12244
12245 // Intl.Segments
12246 #[wasm_bindgen]
12247 extern "C" {
12248 /// The Segments object is an iterable collection of segments of a string.
12249 ///
12250 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/segment/Segments)
12251 #[wasm_bindgen(extends = Object)]
12252 #[derive(Clone, Debug)]
12253 pub type Segments;
12254
12255 /// Returns segment data for the segment containing the character at the given index.
12256 ///
12257 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/segment/Segments/containing)
12258 #[wasm_bindgen(method)]
12259 pub fn containing(this: &Segments, index: u32) -> Option<SegmentData>;
12260 }
12261
12262 // Intl.Segmenter
12263 #[wasm_bindgen]
12264 extern "C" {
12265 /// The `Intl.Segmenter` object enables locale-sensitive text segmentation.
12266 ///
12267 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter)
12268 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.Segmenter")]
12269 #[derive(Clone, Debug)]
12270 pub type Segmenter;
12271
12272 /// Creates a new `Intl.Segmenter` object.
12273 ///
12274 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/Segmenter)
12275 #[cfg(not(js_sys_unstable_apis))]
12276 #[wasm_bindgen(constructor, js_namespace = Intl)]
12277 pub fn new(locales: &Array, options: &Object) -> Segmenter;
12278
12279 /// Creates a new `Intl.Segmenter` object.
12280 ///
12281 /// Throws a `RangeError` if locales or options contain invalid values.
12282 ///
12283 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/Segmenter)
12284 #[cfg(js_sys_unstable_apis)]
12285 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
12286 pub fn new(locales: &[JsString], options: &SegmenterOptions) -> Result<Segmenter, JsValue>;
12287
12288 /// Returns a Segments object containing the segments of the input string.
12289 ///
12290 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/segment)
12291 #[wasm_bindgen(method, js_class = "Intl.Segmenter")]
12292 pub fn segment(this: &Segmenter, input: &str) -> Segments;
12293
12294 /// Returns an object with properties reflecting the options used.
12295 ///
12296 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/resolvedOptions)
12297 #[cfg(not(js_sys_unstable_apis))]
12298 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
12299 pub fn resolved_options(this: &Segmenter) -> Object;
12300
12301 /// Returns an object with properties reflecting the options used.
12302 ///
12303 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/resolvedOptions)
12304 #[cfg(js_sys_unstable_apis)]
12305 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
12306 pub fn resolved_options(this: &Segmenter) -> ResolvedSegmenterOptions;
12307
12308 /// Returns an array of supported locales.
12309 ///
12310 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/supportedLocalesOf)
12311 #[cfg(not(js_sys_unstable_apis))]
12312 #[wasm_bindgen(static_method_of = Segmenter, js_namespace = Intl, js_name = supportedLocalesOf)]
12313 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
12314
12315 /// Returns an array of supported locales.
12316 ///
12317 /// Throws a `RangeError` if locales contain invalid values.
12318 ///
12319 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/supportedLocalesOf)
12320 #[cfg(js_sys_unstable_apis)]
12321 #[wasm_bindgen(static_method_of = Segmenter, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
12322 pub fn supported_locales_of(
12323 locales: &[JsString],
12324 options: &LocaleMatcherOptions,
12325 ) -> Result<Array<JsString>, JsValue>;
12326 }
12327
12328 #[cfg(not(js_sys_unstable_apis))]
12329 impl Default for Segmenter {
12330 fn default() -> Self {
12331 Self::new(
12332 &JsValue::UNDEFINED.unchecked_into(),
12333 &JsValue::UNDEFINED.unchecked_into(),
12334 )
12335 }
12336 }
12337
12338 #[cfg(js_sys_unstable_apis)]
12339 impl Default for Segmenter {
12340 fn default() -> Self {
12341 Self::new(&[], &Default::default()).unwrap()
12342 }
12343 }
12344
12345 // Intl.DisplayNamesOptions
12346 #[wasm_bindgen]
12347 extern "C" {
12348 /// Options for `Intl.DisplayNames` constructor.
12349 ///
12350 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/DisplayNames#options)
12351 #[wasm_bindgen(extends = Object)]
12352 #[derive(Clone, Debug)]
12353 pub type DisplayNamesOptions;
12354
12355 #[wasm_bindgen(method, getter = localeMatcher)]
12356 pub fn get_locale_matcher(this: &DisplayNamesOptions) -> Option<LocaleMatcher>;
12357 #[wasm_bindgen(method, setter = localeMatcher)]
12358 pub fn set_locale_matcher(this: &DisplayNamesOptions, value: LocaleMatcher);
12359
12360 #[wasm_bindgen(method, getter = type)]
12361 pub fn get_type(this: &DisplayNamesOptions) -> Option<DisplayNamesType>;
12362 #[wasm_bindgen(method, setter = type)]
12363 pub fn set_type(this: &DisplayNamesOptions, value: DisplayNamesType);
12364
12365 #[wasm_bindgen(method, getter = style)]
12366 pub fn get_style(this: &DisplayNamesOptions) -> Option<DisplayNamesStyle>;
12367 #[wasm_bindgen(method, setter = style)]
12368 pub fn set_style(this: &DisplayNamesOptions, value: DisplayNamesStyle);
12369
12370 #[wasm_bindgen(method, getter = fallback)]
12371 pub fn get_fallback(this: &DisplayNamesOptions) -> Option<DisplayNamesFallback>;
12372 #[wasm_bindgen(method, setter = fallback)]
12373 pub fn set_fallback(this: &DisplayNamesOptions, value: DisplayNamesFallback);
12374
12375 #[wasm_bindgen(method, getter = languageDisplay)]
12376 pub fn get_language_display(
12377 this: &DisplayNamesOptions,
12378 ) -> Option<DisplayNamesLanguageDisplay>;
12379 #[wasm_bindgen(method, setter = languageDisplay)]
12380 pub fn set_language_display(this: &DisplayNamesOptions, value: DisplayNamesLanguageDisplay);
12381 }
12382
12383 impl DisplayNamesOptions {
12384 pub fn new() -> DisplayNamesOptions {
12385 JsCast::unchecked_into(Object::new())
12386 }
12387 }
12388
12389 impl Default for DisplayNamesOptions {
12390 fn default() -> Self {
12391 DisplayNamesOptions::new()
12392 }
12393 }
12394
12395 // Intl.ResolvedDisplayNamesOptions
12396 #[wasm_bindgen]
12397 extern "C" {
12398 /// Resolved options returned by `Intl.DisplayNames.prototype.resolvedOptions()`.
12399 ///
12400 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/resolvedOptions)
12401 #[wasm_bindgen(extends = DisplayNamesOptions)]
12402 #[derive(Clone, Debug)]
12403 pub type ResolvedDisplayNamesOptions;
12404
12405 /// The resolved locale string.
12406 #[wasm_bindgen(method, getter = locale)]
12407 pub fn get_locale(this: &ResolvedDisplayNamesOptions) -> JsString;
12408 }
12409
12410 // Intl.DisplayNames
12411 #[wasm_bindgen]
12412 extern "C" {
12413 /// The `Intl.DisplayNames` object enables the consistent translation of
12414 /// language, region, and script display names.
12415 ///
12416 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames)
12417 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.DisplayNames")]
12418 #[derive(Clone, Debug)]
12419 pub type DisplayNames;
12420
12421 /// Creates a new `Intl.DisplayNames` object.
12422 ///
12423 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/DisplayNames)
12424 #[cfg(not(js_sys_unstable_apis))]
12425 #[wasm_bindgen(constructor, js_namespace = Intl)]
12426 pub fn new(locales: &Array, options: &Object) -> DisplayNames;
12427
12428 /// Creates a new `Intl.DisplayNames` object.
12429 ///
12430 /// Throws a `RangeError` if locales or options contain invalid values.
12431 ///
12432 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/DisplayNames)
12433 #[cfg(js_sys_unstable_apis)]
12434 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
12435 pub fn new(
12436 locales: &[JsString],
12437 options: &DisplayNamesOptions,
12438 ) -> Result<DisplayNames, JsValue>;
12439
12440 /// Returns the display name for the given code.
12441 ///
12442 /// Returns `undefined` if fallback is "none" and no name is available.
12443 ///
12444 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/of)
12445 #[wasm_bindgen(method, js_class = "Intl.DisplayNames")]
12446 pub fn of(this: &DisplayNames, code: &str) -> Option<JsString>;
12447
12448 /// Returns an object with properties reflecting the options used.
12449 ///
12450 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/resolvedOptions)
12451 #[cfg(not(js_sys_unstable_apis))]
12452 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
12453 pub fn resolved_options(this: &DisplayNames) -> Object;
12454
12455 /// Returns an object with properties reflecting the options used.
12456 ///
12457 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/resolvedOptions)
12458 #[cfg(js_sys_unstable_apis)]
12459 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
12460 pub fn resolved_options(this: &DisplayNames) -> ResolvedDisplayNamesOptions;
12461
12462 /// Returns an array of supported locales.
12463 ///
12464 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/supportedLocalesOf)
12465 #[cfg(not(js_sys_unstable_apis))]
12466 #[wasm_bindgen(static_method_of = DisplayNames, js_namespace = Intl, js_name = supportedLocalesOf)]
12467 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
12468
12469 /// Returns an array of supported locales.
12470 ///
12471 /// Throws a `RangeError` if locales contain invalid values.
12472 ///
12473 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/supportedLocalesOf)
12474 #[cfg(js_sys_unstable_apis)]
12475 #[wasm_bindgen(static_method_of = DisplayNames, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
12476 pub fn supported_locales_of(
12477 locales: &[JsString],
12478 options: &LocaleMatcherOptions,
12479 ) -> Result<Array<JsString>, JsValue>;
12480 }
12481
12482 // Intl.Locale
12483 #[wasm_bindgen]
12484 extern "C" {
12485 /// The `Intl.Locale` object is a standard built-in property of the Intl object
12486 /// that represents a Unicode locale identifier.
12487 ///
12488 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale)
12489 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.Locale")]
12490 #[derive(Clone, Debug)]
12491 pub type Locale;
12492
12493 /// Creates a new `Intl.Locale` object.
12494 ///
12495 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/Locale)
12496 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
12497 pub fn new(tag: &str) -> Result<Locale, JsValue>;
12498
12499 /// Creates a new `Intl.Locale` object with options.
12500 ///
12501 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/Locale)
12502 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
12503 pub fn new_with_options(tag: &str, options: &Object) -> Result<Locale, JsValue>;
12504
12505 /// The base name of the locale (language + region + script).
12506 ///
12507 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/baseName)
12508 #[wasm_bindgen(method, getter = baseName)]
12509 pub fn base_name(this: &Locale) -> JsString;
12510
12511 /// The calendar type for the locale.
12512 ///
12513 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/calendar)
12514 #[wasm_bindgen(method, getter)]
12515 pub fn calendar(this: &Locale) -> Option<JsString>;
12516
12517 /// The case first sorting option.
12518 ///
12519 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/caseFirst)
12520 #[wasm_bindgen(method, getter = caseFirst)]
12521 pub fn case_first(this: &Locale) -> Option<JsString>;
12522
12523 /// The collation type for the locale.
12524 ///
12525 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/collation)
12526 #[wasm_bindgen(method, getter)]
12527 pub fn collation(this: &Locale) -> Option<JsString>;
12528
12529 /// The hour cycle for the locale.
12530 ///
12531 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/hourCycle)
12532 #[wasm_bindgen(method, getter = hourCycle)]
12533 pub fn hour_cycle(this: &Locale) -> Option<JsString>;
12534
12535 /// The language code for the locale.
12536 ///
12537 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/language)
12538 #[wasm_bindgen(method, getter)]
12539 pub fn language(this: &Locale) -> JsString;
12540
12541 /// The numbering system for the locale.
12542 ///
12543 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/numberingSystem)
12544 #[wasm_bindgen(method, getter = numberingSystem)]
12545 pub fn numbering_system(this: &Locale) -> Option<JsString>;
12546
12547 /// Whether the locale uses numeric collation.
12548 ///
12549 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/numeric)
12550 #[wasm_bindgen(method, getter)]
12551 pub fn numeric(this: &Locale) -> bool;
12552
12553 /// The region code for the locale.
12554 ///
12555 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/region)
12556 #[wasm_bindgen(method, getter)]
12557 pub fn region(this: &Locale) -> Option<JsString>;
12558
12559 /// The script code for the locale.
12560 ///
12561 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/script)
12562 #[wasm_bindgen(method, getter)]
12563 pub fn script(this: &Locale) -> Option<JsString>;
12564
12565 /// Returns an array of available calendars for the locale.
12566 ///
12567 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getCalendars)
12568 #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getCalendars)]
12569 pub fn get_calendars(this: &Locale) -> Array<JsString>;
12570
12571 /// Returns an array of available collations for the locale.
12572 ///
12573 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getCollations)
12574 #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getCollations)]
12575 pub fn get_collations(this: &Locale) -> Array<JsString>;
12576
12577 /// Returns an array of available hour cycles for the locale.
12578 ///
12579 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getHourCycles)
12580 #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getHourCycles)]
12581 pub fn get_hour_cycles(this: &Locale) -> Array<JsString>;
12582
12583 /// Returns an array of available numbering systems for the locale.
12584 ///
12585 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getNumberingSystems)
12586 #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getNumberingSystems)]
12587 pub fn get_numbering_systems(this: &Locale) -> Array<JsString>;
12588
12589 /// Returns an array of available time zones for the locale's region.
12590 ///
12591 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getTimeZones)
12592 #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getTimeZones)]
12593 pub fn get_time_zones(this: &Locale) -> Option<Array<JsString>>;
12594
12595 /// Returns week information for the locale.
12596 ///
12597 /// May not be available in all environments.
12598 ///
12599 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getWeekInfo)
12600 #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getWeekInfo, catch)]
12601 pub fn get_week_info(this: &Locale) -> Result<WeekInfo, JsValue>;
12602
12603 /// Returns text layout information for the locale.
12604 ///
12605 /// May not be available in all environments.
12606 ///
12607 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getTextInfo)
12608 #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getTextInfo, catch)]
12609 pub fn get_text_info(this: &Locale) -> Result<TextInfo, JsValue>;
12610
12611 /// Returns a new Locale with the specified calendar.
12612 ///
12613 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/maximize)
12614 #[wasm_bindgen(method, js_class = "Intl.Locale")]
12615 pub fn maximize(this: &Locale) -> Locale;
12616
12617 /// Returns a new Locale with the minimal subtags.
12618 ///
12619 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/minimize)
12620 #[wasm_bindgen(method, js_class = "Intl.Locale")]
12621 pub fn minimize(this: &Locale) -> Locale;
12622 }
12623
12624 // Intl.Locale WeekInfo
12625 #[wasm_bindgen]
12626 extern "C" {
12627 /// Week information for a locale.
12628 ///
12629 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getWeekInfo)
12630 #[wasm_bindgen(extends = Object)]
12631 #[derive(Clone, Debug)]
12632 pub type WeekInfo;
12633
12634 /// The first day of the week (1 = Monday, 7 = Sunday).
12635 #[wasm_bindgen(method, getter = firstDay)]
12636 pub fn first_day(this: &WeekInfo) -> u8;
12637
12638 /// Array of weekend days.
12639 #[wasm_bindgen(method, getter)]
12640 pub fn weekend(this: &WeekInfo) -> Array<Number>;
12641
12642 /// Minimal days in the first week of the year.
12643 #[wasm_bindgen(method, getter = minimalDays)]
12644 pub fn minimal_days(this: &WeekInfo) -> u8;
12645 }
12646
12647 // Intl.Locale TextInfo
12648 #[wasm_bindgen]
12649 extern "C" {
12650 /// Text layout information for a locale.
12651 ///
12652 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getTextInfo)
12653 #[wasm_bindgen(extends = Object)]
12654 #[derive(Clone, Debug)]
12655 pub type TextInfo;
12656
12657 /// The text direction ("ltr" or "rtl").
12658 #[wasm_bindgen(method, getter)]
12659 pub fn direction(this: &TextInfo) -> JsString;
12660 }
12661
12662 // Intl.DurationFormat enums
12663
12664 /// The style for duration formatting.
12665 ///
12666 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat#style)
12667 #[wasm_bindgen]
12668 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
12669 pub enum DurationFormatStyle {
12670 Long = "long",
12671 Short = "short",
12672 Narrow = "narrow",
12673 Digital = "digital",
12674 }
12675
12676 /// The display style for individual duration units.
12677 ///
12678 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat#years)
12679 #[wasm_bindgen]
12680 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
12681 pub enum DurationUnitStyle {
12682 Long = "long",
12683 Short = "short",
12684 Narrow = "narrow",
12685 }
12686
12687 /// The display style for time duration units (hours, minutes, seconds).
12688 ///
12689 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat#hours)
12690 #[wasm_bindgen]
12691 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
12692 pub enum DurationTimeUnitStyle {
12693 Long = "long",
12694 Short = "short",
12695 Narrow = "narrow",
12696 Numeric = "numeric",
12697 #[wasm_bindgen(js_name = "2-digit")]
12698 TwoDigit = "2-digit",
12699 }
12700
12701 /// The display option for duration units.
12702 ///
12703 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat#yearsdisplay)
12704 #[wasm_bindgen]
12705 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
12706 pub enum DurationUnitDisplay {
12707 Auto = "auto",
12708 Always = "always",
12709 }
12710
12711 /// The type of a duration format part.
12712 ///
12713 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/formatToParts#type)
12714 #[wasm_bindgen]
12715 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
12716 pub enum DurationFormatPartType {
12717 Years = "years",
12718 Months = "months",
12719 Weeks = "weeks",
12720 Days = "days",
12721 Hours = "hours",
12722 Minutes = "minutes",
12723 Seconds = "seconds",
12724 Milliseconds = "milliseconds",
12725 Microseconds = "microseconds",
12726 Nanoseconds = "nanoseconds",
12727 Literal = "literal",
12728 Integer = "integer",
12729 Decimal = "decimal",
12730 Fraction = "fraction",
12731 }
12732
12733 // Intl.DurationFormatOptions
12734 #[wasm_bindgen]
12735 extern "C" {
12736 /// Options for `Intl.DurationFormat` constructor.
12737 ///
12738 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat#options)
12739 #[wasm_bindgen(extends = Object)]
12740 #[derive(Clone, Debug)]
12741 pub type DurationFormatOptions;
12742
12743 #[wasm_bindgen(method, getter = localeMatcher)]
12744 pub fn get_locale_matcher(this: &DurationFormatOptions) -> Option<LocaleMatcher>;
12745 #[wasm_bindgen(method, setter = localeMatcher)]
12746 pub fn set_locale_matcher(this: &DurationFormatOptions, value: LocaleMatcher);
12747
12748 #[wasm_bindgen(method, getter = style)]
12749 pub fn get_style(this: &DurationFormatOptions) -> Option<DurationFormatStyle>;
12750 #[wasm_bindgen(method, setter = style)]
12751 pub fn set_style(this: &DurationFormatOptions, value: DurationFormatStyle);
12752
12753 #[wasm_bindgen(method, getter = years)]
12754 pub fn get_years(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
12755 #[wasm_bindgen(method, setter = years)]
12756 pub fn set_years(this: &DurationFormatOptions, value: DurationUnitStyle);
12757
12758 #[wasm_bindgen(method, getter = yearsDisplay)]
12759 pub fn get_years_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
12760 #[wasm_bindgen(method, setter = yearsDisplay)]
12761 pub fn set_years_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12762
12763 #[wasm_bindgen(method, getter = months)]
12764 pub fn get_months(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
12765 #[wasm_bindgen(method, setter = months)]
12766 pub fn set_months(this: &DurationFormatOptions, value: DurationUnitStyle);
12767
12768 #[wasm_bindgen(method, getter = monthsDisplay)]
12769 pub fn get_months_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
12770 #[wasm_bindgen(method, setter = monthsDisplay)]
12771 pub fn set_months_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12772
12773 #[wasm_bindgen(method, getter = weeks)]
12774 pub fn get_weeks(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
12775 #[wasm_bindgen(method, setter = weeks)]
12776 pub fn set_weeks(this: &DurationFormatOptions, value: DurationUnitStyle);
12777
12778 #[wasm_bindgen(method, getter = weeksDisplay)]
12779 pub fn get_weeks_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
12780 #[wasm_bindgen(method, setter = weeksDisplay)]
12781 pub fn set_weeks_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12782
12783 #[wasm_bindgen(method, getter = days)]
12784 pub fn get_days(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
12785 #[wasm_bindgen(method, setter = days)]
12786 pub fn set_days(this: &DurationFormatOptions, value: DurationUnitStyle);
12787
12788 #[wasm_bindgen(method, getter = daysDisplay)]
12789 pub fn get_days_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
12790 #[wasm_bindgen(method, setter = daysDisplay)]
12791 pub fn set_days_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12792
12793 #[wasm_bindgen(method, getter = hours)]
12794 pub fn get_hours(this: &DurationFormatOptions) -> Option<DurationTimeUnitStyle>;
12795 #[wasm_bindgen(method, setter = hours)]
12796 pub fn set_hours(this: &DurationFormatOptions, value: DurationTimeUnitStyle);
12797
12798 #[wasm_bindgen(method, getter = hoursDisplay)]
12799 pub fn get_hours_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
12800 #[wasm_bindgen(method, setter = hoursDisplay)]
12801 pub fn set_hours_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12802
12803 #[wasm_bindgen(method, getter = minutes)]
12804 pub fn get_minutes(this: &DurationFormatOptions) -> Option<DurationTimeUnitStyle>;
12805 #[wasm_bindgen(method, setter = minutes)]
12806 pub fn set_minutes(this: &DurationFormatOptions, value: DurationTimeUnitStyle);
12807
12808 #[wasm_bindgen(method, getter = minutesDisplay)]
12809 pub fn get_minutes_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
12810 #[wasm_bindgen(method, setter = minutesDisplay)]
12811 pub fn set_minutes_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12812
12813 #[wasm_bindgen(method, getter = seconds)]
12814 pub fn get_seconds(this: &DurationFormatOptions) -> Option<DurationTimeUnitStyle>;
12815 #[wasm_bindgen(method, setter = seconds)]
12816 pub fn set_seconds(this: &DurationFormatOptions, value: DurationTimeUnitStyle);
12817
12818 #[wasm_bindgen(method, getter = secondsDisplay)]
12819 pub fn get_seconds_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
12820 #[wasm_bindgen(method, setter = secondsDisplay)]
12821 pub fn set_seconds_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12822
12823 #[wasm_bindgen(method, getter = milliseconds)]
12824 pub fn get_milliseconds(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
12825 #[wasm_bindgen(method, setter = milliseconds)]
12826 pub fn set_milliseconds(this: &DurationFormatOptions, value: DurationUnitStyle);
12827
12828 #[wasm_bindgen(method, getter = millisecondsDisplay)]
12829 pub fn get_milliseconds_display(
12830 this: &DurationFormatOptions,
12831 ) -> Option<DurationUnitDisplay>;
12832 #[wasm_bindgen(method, setter = millisecondsDisplay)]
12833 pub fn set_milliseconds_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12834
12835 #[wasm_bindgen(method, getter = microseconds)]
12836 pub fn get_microseconds(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
12837 #[wasm_bindgen(method, setter = microseconds)]
12838 pub fn set_microseconds(this: &DurationFormatOptions, value: DurationUnitStyle);
12839
12840 #[wasm_bindgen(method, getter = microsecondsDisplay)]
12841 pub fn get_microseconds_display(
12842 this: &DurationFormatOptions,
12843 ) -> Option<DurationUnitDisplay>;
12844 #[wasm_bindgen(method, setter = microsecondsDisplay)]
12845 pub fn set_microseconds_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12846
12847 #[wasm_bindgen(method, getter = nanoseconds)]
12848 pub fn get_nanoseconds(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
12849 #[wasm_bindgen(method, setter = nanoseconds)]
12850 pub fn set_nanoseconds(this: &DurationFormatOptions, value: DurationUnitStyle);
12851
12852 #[wasm_bindgen(method, getter = nanosecondsDisplay)]
12853 pub fn get_nanoseconds_display(this: &DurationFormatOptions)
12854 -> Option<DurationUnitDisplay>;
12855 #[wasm_bindgen(method, setter = nanosecondsDisplay)]
12856 pub fn set_nanoseconds_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12857
12858 #[wasm_bindgen(method, getter = fractionalDigits)]
12859 pub fn get_fractional_digits(this: &DurationFormatOptions) -> Option<u8>;
12860 #[wasm_bindgen(method, setter = fractionalDigits)]
12861 pub fn set_fractional_digits(this: &DurationFormatOptions, value: u8);
12862 }
12863
12864 impl DurationFormatOptions {
12865 pub fn new() -> DurationFormatOptions {
12866 JsCast::unchecked_into(Object::new())
12867 }
12868 }
12869
12870 impl Default for DurationFormatOptions {
12871 fn default() -> Self {
12872 DurationFormatOptions::new()
12873 }
12874 }
12875
12876 // Intl.ResolvedDurationFormatOptions
12877 #[wasm_bindgen]
12878 extern "C" {
12879 /// Resolved options returned by `Intl.DurationFormat.prototype.resolvedOptions()`.
12880 ///
12881 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/resolvedOptions)
12882 #[wasm_bindgen(extends = DurationFormatOptions)]
12883 #[derive(Clone, Debug)]
12884 pub type ResolvedDurationFormatOptions;
12885
12886 /// The resolved locale string.
12887 #[wasm_bindgen(method, getter = locale)]
12888 pub fn get_locale(this: &ResolvedDurationFormatOptions) -> JsString;
12889
12890 /// The resolved numbering system.
12891 #[wasm_bindgen(method, getter = numberingSystem)]
12892 pub fn get_numbering_system(this: &ResolvedDurationFormatOptions) -> JsString;
12893 }
12894
12895 // Intl.Duration (input object for DurationFormat)
12896 #[wasm_bindgen]
12897 extern "C" {
12898 /// A duration object used as input to `Intl.DurationFormat.format()`.
12899 ///
12900 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/format#duration)
12901 #[wasm_bindgen(extends = Object)]
12902 #[derive(Clone, Debug)]
12903 pub type Duration;
12904
12905 #[wasm_bindgen(method, getter)]
12906 pub fn years(this: &Duration) -> Option<f64>;
12907 #[wasm_bindgen(method, setter)]
12908 pub fn set_years(this: &Duration, value: f64);
12909
12910 #[wasm_bindgen(method, getter)]
12911 pub fn months(this: &Duration) -> Option<f64>;
12912 #[wasm_bindgen(method, setter)]
12913 pub fn set_months(this: &Duration, value: f64);
12914
12915 #[wasm_bindgen(method, getter)]
12916 pub fn weeks(this: &Duration) -> Option<f64>;
12917 #[wasm_bindgen(method, setter)]
12918 pub fn set_weeks(this: &Duration, value: f64);
12919
12920 #[wasm_bindgen(method, getter)]
12921 pub fn days(this: &Duration) -> Option<f64>;
12922 #[wasm_bindgen(method, setter)]
12923 pub fn set_days(this: &Duration, value: f64);
12924
12925 #[wasm_bindgen(method, getter)]
12926 pub fn hours(this: &Duration) -> Option<f64>;
12927 #[wasm_bindgen(method, setter)]
12928 pub fn set_hours(this: &Duration, value: f64);
12929
12930 #[wasm_bindgen(method, getter)]
12931 pub fn minutes(this: &Duration) -> Option<f64>;
12932 #[wasm_bindgen(method, setter)]
12933 pub fn set_minutes(this: &Duration, value: f64);
12934
12935 #[wasm_bindgen(method, getter)]
12936 pub fn seconds(this: &Duration) -> Option<f64>;
12937 #[wasm_bindgen(method, setter)]
12938 pub fn set_seconds(this: &Duration, value: f64);
12939
12940 #[wasm_bindgen(method, getter)]
12941 pub fn milliseconds(this: &Duration) -> Option<f64>;
12942 #[wasm_bindgen(method, setter)]
12943 pub fn set_milliseconds(this: &Duration, value: f64);
12944
12945 #[wasm_bindgen(method, getter)]
12946 pub fn microseconds(this: &Duration) -> Option<f64>;
12947 #[wasm_bindgen(method, setter)]
12948 pub fn set_microseconds(this: &Duration, value: f64);
12949
12950 #[wasm_bindgen(method, getter)]
12951 pub fn nanoseconds(this: &Duration) -> Option<f64>;
12952 #[wasm_bindgen(method, setter)]
12953 pub fn set_nanoseconds(this: &Duration, value: f64);
12954 }
12955
12956 impl Duration {
12957 pub fn new() -> Duration {
12958 JsCast::unchecked_into(Object::new())
12959 }
12960 }
12961
12962 impl Default for Duration {
12963 fn default() -> Self {
12964 Duration::new()
12965 }
12966 }
12967
12968 // Intl.DurationFormatPart
12969 #[wasm_bindgen]
12970 extern "C" {
12971 /// A part of the formatted duration returned by `formatToParts()`.
12972 ///
12973 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/formatToParts)
12974 #[wasm_bindgen(extends = Object)]
12975 #[derive(Clone, Debug)]
12976 pub type DurationFormatPart;
12977
12978 /// The type of the part.
12979 #[wasm_bindgen(method, getter = type)]
12980 pub fn type_(this: &DurationFormatPart) -> DurationFormatPartType;
12981
12982 /// The value of the part.
12983 #[wasm_bindgen(method, getter)]
12984 pub fn value(this: &DurationFormatPart) -> JsString;
12985
12986 /// The unit this part represents (if applicable).
12987 #[wasm_bindgen(method, getter)]
12988 pub fn unit(this: &DurationFormatPart) -> Option<JsString>;
12989 }
12990
12991 // Intl.DurationFormat
12992 #[wasm_bindgen]
12993 extern "C" {
12994 /// The `Intl.DurationFormat` object enables language-sensitive duration formatting.
12995 ///
12996 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat)
12997 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.DurationFormat")]
12998 #[derive(Clone, Debug)]
12999 pub type DurationFormat;
13000
13001 /// Creates a new `Intl.DurationFormat` object.
13002 ///
13003 /// Throws a `RangeError` if locales or options contain invalid values.
13004 ///
13005 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat)
13006 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
13007 pub fn new(
13008 locales: &[JsString],
13009 options: &DurationFormatOptions,
13010 ) -> Result<DurationFormat, JsValue>;
13011
13012 /// Formats a duration according to the locale and formatting options.
13013 ///
13014 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/format)
13015 #[wasm_bindgen(method, js_class = "Intl.DurationFormat")]
13016 pub fn format(this: &DurationFormat, duration: &Duration) -> JsString;
13017
13018 /// Returns an array of objects representing the formatted duration in parts.
13019 ///
13020 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/formatToParts)
13021 #[wasm_bindgen(method, js_class = "Intl.DurationFormat", js_name = formatToParts)]
13022 pub fn format_to_parts(
13023 this: &DurationFormat,
13024 duration: &Duration,
13025 ) -> Array<DurationFormatPart>;
13026
13027 /// Returns an object with properties reflecting the options used.
13028 ///
13029 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/resolvedOptions)
13030 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
13031 pub fn resolved_options(this: &DurationFormat) -> ResolvedDurationFormatOptions;
13032
13033 /// Returns an array of supported locales.
13034 ///
13035 /// Throws a `RangeError` if locales contain invalid values.
13036 ///
13037 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/supportedLocalesOf)
13038 #[wasm_bindgen(static_method_of = DurationFormat, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
13039 pub fn supported_locales_of(
13040 locales: &[JsString],
13041 options: &LocaleMatcherOptions,
13042 ) -> Result<Array<JsString>, JsValue>;
13043 }
13044
13045 impl Default for DurationFormat {
13046 fn default() -> Self {
13047 Self::new(&[], &Default::default()).unwrap()
13048 }
13049 }
13050}
13051
13052#[wasm_bindgen]
13053extern "C" {
13054 /// The `PromiseState` object represents the the status of the promise,
13055 /// as used in `allSettled`.
13056 ///
13057 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled)
13058 #[must_use]
13059 #[wasm_bindgen(extends = Object, typescript_type = "any")]
13060 #[derive(Clone, Debug)]
13061 pub type PromiseState<T = JsValue>;
13062
13063 /// A string, either "fulfilled" or "rejected", indicating the eventual state of the promise.
13064 #[wasm_bindgen(method, getter = status)]
13065 pub fn get_status<T>(this: &PromiseState<T>) -> String;
13066
13067 /// Only present if status is "fulfilled". The value that the promise was fulfilled with.
13068 #[wasm_bindgen(method, getter = value)]
13069 pub fn get_value<T>(this: &PromiseState<T>) -> Option<T>;
13070
13071 /// Only present if status is "rejected". The reason that the promise was rejected with.
13072 #[wasm_bindgen(method, getter = reason)]
13073 pub fn get_reason<T>(this: &PromiseState<T>) -> Option<JsValue>;
13074}
13075
13076impl<T> PromiseState<T> {
13077 pub fn is_fulfilled(&self) -> bool {
13078 self.get_status() == "fulfilled"
13079 }
13080
13081 pub fn is_rejected(&self) -> bool {
13082 self.get_status() == "rejected"
13083 }
13084}
13085
13086/// Converts a `PromiseState<T>` into a `Result<T, JsValue>`, matching the
13087/// spec invariant that exactly one of the fulfilled value or the rejection
13088/// reason is populated per slot.
13089impl<T: JsGeneric + FromWasmAbi> From<PromiseState<T>> for Result<T, JsValue> {
13090 fn from(state: PromiseState<T>) -> Result<T, JsValue> {
13091 if state.is_fulfilled() {
13092 Ok(state.get_value().unwrap())
13093 } else {
13094 Err(state.get_reason().unwrap())
13095 }
13096 }
13097}
13098
13099// Promise
13100#[wasm_bindgen]
13101extern "C" {
13102 /// The `Promise` object represents the eventual completion (or failure) of
13103 /// an asynchronous operation, and its resulting value.
13104 ///
13105 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
13106 #[must_use]
13107 #[wasm_bindgen(extends = Object, typescript_type = "Promise<any>", no_promising)]
13108 #[derive(Clone, Debug)]
13109 pub type Promise<T = JsValue>;
13110
13111 /// Creates a new `Promise` with the provided executor `cb`
13112 ///
13113 /// The `cb` is a function that is passed with the arguments `resolve` and
13114 /// `reject`. The `cb` function is executed immediately by the `Promise`
13115 /// implementation, passing `resolve` and `reject` functions (the executor
13116 /// is called before the `Promise` constructor even returns the created
13117 /// object). The `resolve` and `reject` functions, when called, resolve or
13118 /// reject the promise, respectively. The executor normally initiates
13119 /// some asynchronous work, and then, once that completes, either calls
13120 /// the `resolve` function to resolve the promise or else rejects it if an
13121 /// error occurred.
13122 ///
13123 /// If an error is thrown in the executor function, the promise is rejected.
13124 /// The return value of the executor is ignored.
13125 ///
13126 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
13127 #[cfg(not(js_sys_unstable_apis))]
13128 #[wasm_bindgen(constructor)]
13129 pub fn new(cb: &mut dyn FnMut(Function, Function)) -> Promise;
13130
13131 /// Creates a new `Promise` with the provided executor `cb`
13132 ///
13133 /// The `cb` is a function that is passed with the arguments `resolve` and
13134 /// `reject`. The `cb` function is executed immediately by the `Promise`
13135 /// implementation, passing `resolve` and `reject` functions (the executor
13136 /// is called before the `Promise` constructor even returns the created
13137 /// object). The `resolve` and `reject` functions, when called, resolve or
13138 /// reject the promise, respectively. The executor normally initiates
13139 /// some asynchronous work, and then, once that completes, either calls
13140 /// the `resolve` function to resolve the promise or else rejects it if an
13141 /// error occurred.
13142 ///
13143 /// If an error is thrown in the executor function, the promise is rejected.
13144 /// The return value of the executor is ignored.
13145 ///
13146 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
13147 #[cfg(js_sys_unstable_apis)]
13148 #[wasm_bindgen(constructor)]
13149 pub fn new<T: JsGeneric>(
13150 cb: &mut dyn FnMut(Function<fn(T) -> Undefined>, Function<fn(JsValue) -> Undefined>),
13151 ) -> Promise<T>;
13152
13153 // Next major: deprecate
13154 /// Creates a new `Promise` with the provided executor `cb`
13155 ///
13156 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
13157 #[wasm_bindgen(constructor)]
13158 pub fn new_typed<T: Promising + JsGeneric>(
13159 cb: &mut dyn FnMut(Function<fn(T) -> Undefined>, Function<fn(JsValue) -> Undefined>),
13160 ) -> Promise<<T as Promising>::Resolution>;
13161
13162 /// The `Promise.all(iterable)` method returns a single `Promise` that
13163 /// resolves when all of the promises in the iterable argument have resolved
13164 /// or when the iterable argument contains no promises. It rejects with the
13165 /// reason of the first promise that rejects.
13166 ///
13167 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all)
13168 #[cfg(not(js_sys_unstable_apis))]
13169 #[wasm_bindgen(static_method_of = Promise)]
13170 pub fn all(obj: &JsValue) -> Promise;
13171
13172 /// The `Promise.all(iterable)` method returns a single `Promise` that
13173 /// resolves when all of the promises in the iterable argument have resolved
13174 /// or when the iterable argument contains no promises. It rejects with the
13175 /// reason of the first promise that rejects.
13176 ///
13177 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all)
13178 #[cfg(js_sys_unstable_apis)]
13179 #[wasm_bindgen(static_method_of = Promise, js_name = all)]
13180 pub fn all<I: Iterable>(obj: &I) -> Promise<Array<<I::Item as Promising>::Resolution>>
13181 where
13182 I::Item: Promising;
13183
13184 // Next major: deprecate
13185 /// The `Promise.all(iterable)` method returns a single `Promise` that
13186 /// resolves when all of the promises in the iterable argument have resolved
13187 /// or when the iterable argument contains no promises. It rejects with the
13188 /// reason of the first promise that rejects.
13189 ///
13190 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all)
13191 #[wasm_bindgen(static_method_of = Promise, js_name = all)]
13192 pub fn all_iterable<I: Iterable>(obj: &I) -> Promise<Array<<I::Item as Promising>::Resolution>>
13193 where
13194 I::Item: Promising;
13195
13196 /// The `Promise.allSettled(iterable)` method returns a single `Promise` that
13197 /// resolves when all of the promises in the iterable argument have either
13198 /// fulfilled or rejected or when the iterable argument contains no promises.
13199 ///
13200 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled)
13201 #[cfg(not(js_sys_unstable_apis))]
13202 #[wasm_bindgen(static_method_of = Promise, js_name = allSettled)]
13203 pub fn all_settled(obj: &JsValue) -> Promise;
13204
13205 /// The `Promise.allSettled(iterable)` method returns a single `Promise` that
13206 /// resolves when all of the promises in the iterable argument have either
13207 /// fulfilled or rejected or when the iterable argument contains no promises.
13208 ///
13209 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled)
13210 #[cfg(js_sys_unstable_apis)]
13211 #[wasm_bindgen(static_method_of = Promise, js_name = allSettled)]
13212 pub fn all_settled<I: Iterable>(
13213 obj: &I,
13214 ) -> Promise<Array<PromiseState<<I::Item as Promising>::Resolution>>>
13215 where
13216 I::Item: Promising;
13217
13218 // Next major: deprecate
13219 /// The `Promise.allSettled(iterable)` method returns a single `Promise` that
13220 /// resolves when all of the promises in the iterable argument have either
13221 /// fulfilled or rejected or when the iterable argument contains no promises.
13222 ///
13223 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled)
13224 #[wasm_bindgen(static_method_of = Promise, js_name = allSettled)]
13225 pub fn all_settled_iterable<I: Iterable>(
13226 obj: &I,
13227 ) -> Promise<Array<PromiseState<<I::Item as Promising>::Resolution>>>
13228 where
13229 I::Item: Promising;
13230
13231 /// The `Promise.any(iterable)` method returns a single `Promise` that
13232 /// resolves when any of the promises in the iterable argument have resolved
13233 /// or when the iterable argument contains no promises. It rejects with an
13234 /// `AggregateError` if all promises in the iterable rejected.
13235 ///
13236 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/any)
13237 #[cfg(not(js_sys_unstable_apis))]
13238 #[wasm_bindgen(static_method_of = Promise)]
13239 pub fn any(obj: &JsValue) -> Promise;
13240
13241 /// The `Promise.any(iterable)` method returns a single `Promise` that
13242 /// resolves when any of the promises in the iterable argument have resolved
13243 /// or when the iterable argument contains no promises. It rejects with an
13244 /// `AggregateError` if all promises in the iterable rejected.
13245 ///
13246 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/any)
13247 #[cfg(js_sys_unstable_apis)]
13248 #[wasm_bindgen(static_method_of = Promise, js_name = any)]
13249 pub fn any<I: Iterable>(obj: &I) -> Promise<<I::Item as Promising>::Resolution>
13250 where
13251 I::Item: Promising;
13252
13253 // Next major: deprecate
13254 /// The `Promise.any(iterable)` method returns a single `Promise` that
13255 /// resolves when any of the promises in the iterable argument have resolved
13256 /// or when the iterable argument contains no promises. It rejects with an
13257 /// `AggregateError` if all promises in the iterable rejected.
13258 ///
13259 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/any)
13260 #[wasm_bindgen(static_method_of = Promise, js_name = any)]
13261 pub fn any_iterable<I: Iterable>(obj: &I) -> Promise<<I::Item as Promising>::Resolution>
13262 where
13263 I::Item: Promising;
13264
13265 /// The `Promise.race(iterable)` method returns a promise that resolves or
13266 /// rejects as soon as one of the promises in the iterable resolves or
13267 /// rejects, with the value or reason from that promise.
13268 ///
13269 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/race)
13270 #[cfg(not(js_sys_unstable_apis))]
13271 #[wasm_bindgen(static_method_of = Promise)]
13272 pub fn race(obj: &JsValue) -> Promise;
13273
13274 /// The `Promise.race(iterable)` method returns a promise that resolves or
13275 /// rejects as soon as one of the promises in the iterable resolves or
13276 /// rejects, with the value or reason from that promise.
13277 ///
13278 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/race)
13279 #[cfg(js_sys_unstable_apis)]
13280 #[wasm_bindgen(static_method_of = Promise, js_name = race)]
13281 pub fn race<I: Iterable>(obj: &I) -> Promise<<I::Item as Promising>::Resolution>
13282 where
13283 I::Item: Promising;
13284
13285 // Next major: deprecate
13286 /// The `Promise.race(iterable)` method returns a promise that resolves or
13287 /// rejects as soon as one of the promises in the iterable resolves or
13288 /// rejects, with the value or reason from that promise.
13289 ///
13290 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/race)
13291 #[wasm_bindgen(static_method_of = Promise, js_name = race)]
13292 pub fn race_iterable<I: Iterable>(obj: &I) -> Promise<<I::Item as Promising>::Resolution>
13293 where
13294 I::Item: Promising;
13295
13296 /// The `Promise.reject(reason)` method returns a `Promise` object that is
13297 /// rejected with the given reason.
13298 ///
13299 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/reject)
13300 #[cfg(not(js_sys_unstable_apis))]
13301 #[wasm_bindgen(static_method_of = Promise)]
13302 pub fn reject(obj: &JsValue) -> Promise;
13303
13304 /// The `Promise.reject(reason)` method returns a `Promise` object that is
13305 /// rejected with the given reason.
13306 ///
13307 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/reject)
13308 #[cfg(js_sys_unstable_apis)]
13309 #[wasm_bindgen(static_method_of = Promise, js_name = reject)]
13310 pub fn reject<T>(obj: &JsValue) -> Promise<T>;
13311
13312 // Next major: deprecate
13313 /// The `Promise.reject(reason)` method returns a `Promise` object that is
13314 /// rejected with the given reason.
13315 ///
13316 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/reject)
13317 #[wasm_bindgen(static_method_of = Promise, js_name = reject)]
13318 pub fn reject_typed<T>(obj: &JsValue) -> Promise<T>;
13319
13320 /// The `Promise.resolve(value)` method returns a `Promise` object that is
13321 /// resolved with the given value. If the value is a promise, that promise
13322 /// is returned; if the value is a thenable (i.e. has a "then" method), the
13323 /// returned promise will "follow" that thenable, adopting its eventual
13324 /// state; otherwise the returned promise will be fulfilled with the value.
13325 ///
13326 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/resolve)
13327 #[wasm_bindgen(static_method_of = Promise, js_name = resolve)]
13328 pub fn resolve<U: Promising>(obj: &U) -> Promise<U::Resolution>;
13329
13330 /// The `catch()` method returns a `Promise` and deals with rejected cases
13331 /// only. It behaves the same as calling `Promise.prototype.then(undefined,
13332 /// onRejected)` (in fact, calling `obj.catch(onRejected)` internally calls
13333 /// `obj.then(undefined, onRejected)`).
13334 ///
13335 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch)
13336 #[cfg(not(js_sys_unstable_apis))]
13337 #[wasm_bindgen(method)]
13338 pub fn catch<T>(this: &Promise<T>, cb: &ScopedClosure<dyn FnMut(JsValue)>) -> Promise<JsValue>;
13339
13340 /// The `catch()` method returns a `Promise` and deals with rejected cases
13341 /// only. It behaves the same as calling `Promise.prototype.then(undefined,
13342 /// onRejected)` (in fact, calling `obj.catch(onRejected)` internally calls
13343 /// `obj.then(undefined, onRejected)`).
13344 ///
13345 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch)
13346 #[cfg(js_sys_unstable_apis)]
13347 #[wasm_bindgen(method, js_name = catch)]
13348 pub fn catch<'a, T, R: Promising>(
13349 this: &Promise<T>,
13350 cb: &ScopedClosure<'a, dyn FnMut(T) -> Result<R, JsError>>,
13351 ) -> Promise<R::Resolution>;
13352
13353 // Next major: deprecate
13354 /// Same as `catch`, but returning a result to become the new Promise value.
13355 #[wasm_bindgen(method, js_name = catch)]
13356 pub fn catch_map<'a, T, R: Promising>(
13357 this: &Promise<T>,
13358 cb: &ScopedClosure<'a, dyn FnMut(T) -> Result<R, JsError>>,
13359 ) -> Promise<R::Resolution>;
13360
13361 /// The `then()` method returns a `Promise`. It takes up to two arguments:
13362 /// callback functions for the success and failure cases of the `Promise`.
13363 ///
13364 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then)
13365 #[cfg(not(js_sys_unstable_apis))]
13366 #[wasm_bindgen(method)]
13367 pub fn then<'a, T>(this: &Promise<T>, cb: &ScopedClosure<'a, dyn FnMut(T)>)
13368 -> Promise<JsValue>;
13369
13370 /// The `then()` method returns a `Promise`. It takes up to two arguments:
13371 /// callback functions for the success and failure cases of the `Promise`.
13372 ///
13373 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then)
13374 #[cfg(js_sys_unstable_apis)]
13375 #[wasm_bindgen(method, js_name = then)]
13376 pub fn then<'a, T, R: Promising>(
13377 this: &Promise<T>,
13378 cb: &ScopedClosure<'a, dyn FnMut(T) -> Result<R, JsError>>,
13379 ) -> Promise<R::Resolution>;
13380
13381 /// The `then()` method returns a `Promise`. It takes up to two arguments:
13382 /// callback functions for the success and failure cases of the `Promise`.
13383 ///
13384 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then)
13385 #[wasm_bindgen(method, js_name = then)]
13386 pub fn then_with_reject<'a, T, R: Promising>(
13387 this: &Promise<T>,
13388 resolve: &ScopedClosure<'a, dyn FnMut(T) -> Result<R, JsError>>,
13389 reject: &ScopedClosure<'a, dyn FnMut(JsValue) -> Result<R, JsError>>,
13390 ) -> Promise<R::Resolution>;
13391
13392 // Next major: deprecate
13393 /// Alias for `then()` with a return value.
13394 /// The `then()` method returns a `Promise`. It takes up to two arguments:
13395 /// callback functions for the success and failure cases of the `Promise`.
13396 ///
13397 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then)
13398 #[wasm_bindgen(method, js_name = then)]
13399 pub fn then_map<'a, T, R: Promising>(
13400 this: &Promise<T>,
13401 cb: &ScopedClosure<'a, dyn FnMut(T) -> Result<R, JsError>>,
13402 ) -> Promise<R::Resolution>;
13403
13404 /// Same as `then`, only with both arguments provided.
13405 ///
13406 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then)
13407 #[wasm_bindgen(method, js_name = then)]
13408 pub fn then2(
13409 this: &Promise,
13410 resolve: &ScopedClosure<dyn FnMut(JsValue)>,
13411 reject: &ScopedClosure<dyn FnMut(JsValue)>,
13412 ) -> Promise;
13413
13414 /// The `finally()` method returns a `Promise`. When the promise is settled,
13415 /// whether fulfilled or rejected, the specified callback function is
13416 /// executed. This provides a way for code that must be executed once the
13417 /// `Promise` has been dealt with to be run whether the promise was
13418 /// fulfilled successfully or rejected.
13419 ///
13420 /// This lets you avoid duplicating code in both the promise's `then()` and
13421 /// `catch()` handlers.
13422 ///
13423 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/finally)
13424 #[wasm_bindgen(method)]
13425 pub fn finally<T>(this: &Promise<T>, cb: &ScopedClosure<dyn FnMut()>) -> Promise<JsValue>;
13426}
13427
13428impl<T: JsGeneric> Promising for Promise<T> {
13429 type Resolution = T;
13430}
13431
13432/// Internal: maps a tuple of `Promise<T_i>` to the result shapes of
13433/// [`Promise::all_tuple`] and [`Promise::all_settled_tuple`].
13434///
13435/// Implemented for every tuple arity 1..=8 of `Promise<T: JsGeneric>`. The
13436/// associated `Joined` / `Settled` types pin down the [`ArrayTuple`] shape
13437/// of the result so the one [`JsCast::unchecked_into`] needed to reinterpret
13438/// the [`Array<JsValue>`] returned by `Promise.all` / `Promise.allSettled`
13439/// is encapsulated inside each impl — the caller sees a fully-typed
13440/// `Promise<ArrayTuple<...>>`.
13441///
13442/// The soundness of the `unchecked_into`s here rests on `Promise.all` and
13443/// `Promise.allSettled` preserving input order and arity, which they do by
13444/// spec.
13445///
13446/// You normally call [`Promise::all_tuple`] / [`Promise::all_settled_tuple`]
13447/// rather than using this trait directly.
13448#[doc(hidden)]
13449pub trait PromiseTuple {
13450 /// The typed `ArrayTuple` shape the joined promise resolves to.
13451 ///
13452 /// For a tuple `(Promise<T1>, Promise<T2>, ...)` this is
13453 /// `ArrayTuple<(T1, T2, ...)>`.
13454 type Joined: JsGeneric;
13455
13456 /// The typed `ArrayTuple` shape the all-settled promise resolves to.
13457 ///
13458 /// For a tuple `(Promise<T1>, Promise<T2>, ...)` this is
13459 /// `ArrayTuple<(PromiseState<T1>, PromiseState<T2>, ...)>`.
13460 type Settled: JsGeneric;
13461
13462 /// Join via `Promise.all`, returning a typed `Promise`.
13463 fn all(self) -> Promise<Self::Joined>;
13464
13465 /// Settle via `Promise.allSettled`, returning a typed `Promise`.
13466 fn all_settled(self) -> Promise<Self::Settled>;
13467}
13468
13469macro_rules! impl_promise_tuple {
13470 ([$($T:ident)+] [$($idx:tt)+]) => {
13471 // Rust tuple of `Promise<T_i>`. Builds the heterogeneous
13472 // `ArrayTuple` of promises via the existing `From<(...)>` impl
13473 // (each element upcasts through `JsGeneric`), then delegates to
13474 // the `ArrayTuple` impl below.
13475 impl<$($T: JsGeneric),+> PromiseTuple for ($(Promise<$T>,)+) {
13476 type Joined = ArrayTuple<($($T,)+)>;
13477 type Settled = ArrayTuple<($(PromiseState<$T>,)+)>;
13478
13479 fn all(self) -> Promise<Self::Joined> {
13480 let tuple: ArrayTuple<($(Promise<$T>,)+)> = ($(self.$idx,)+).into();
13481 tuple.all()
13482 }
13483
13484 fn all_settled(self) -> Promise<Self::Settled> {
13485 let tuple: ArrayTuple<($(Promise<$T>,)+)> = ($(self.$idx,)+).into();
13486 tuple.all_settled()
13487 }
13488 }
13489
13490 // `ArrayTuple<(Promise<T_1>, ..., Promise<T_n>)>` — callers who
13491 // already have an `ArrayTuple` (e.g. from a binding that returns
13492 // one, or built via `.into()` earlier in a pipeline) can pass it
13493 // directly without unpacking into a Rust tuple.
13494 //
13495 // Hands the `ArrayTuple` straight to `Promise.all_iterable` /
13496 // `Promise.allSettled_iterable` and reinterprets the result
13497 // `Array<JsValue>` as the intended typed `ArrayTuple`. Safe because
13498 // `Promise.all` / `Promise.allSettled` preserve input order and
13499 // arity by spec.
13500 impl<$($T: JsGeneric),+> PromiseTuple for ArrayTuple<($(Promise<$T>,)+)> {
13501 type Joined = ArrayTuple<($($T,)+)>;
13502 type Settled = ArrayTuple<($(PromiseState<$T>,)+)>;
13503
13504 fn all(self) -> Promise<Self::Joined> {
13505 use wasm_bindgen::JsCast;
13506 Promise::all_iterable(&self).unchecked_into()
13507 }
13508
13509 fn all_settled(self) -> Promise<Self::Settled> {
13510 use wasm_bindgen::JsCast;
13511 Promise::all_settled_iterable(&self).unchecked_into()
13512 }
13513 }
13514 };
13515}
13516
13517impl_promise_tuple!([T1][0]);
13518impl_promise_tuple!([T1 T2] [0 1]);
13519impl_promise_tuple!([T1 T2 T3] [0 1 2]);
13520impl_promise_tuple!([T1 T2 T3 T4] [0 1 2 3]);
13521impl_promise_tuple!([T1 T2 T3 T4 T5] [0 1 2 3 4]);
13522impl_promise_tuple!([T1 T2 T3 T4 T5 T6] [0 1 2 3 4 5]);
13523impl_promise_tuple!([T1 T2 T3 T4 T5 T6 T7] [0 1 2 3 4 5 6]);
13524impl_promise_tuple!([T1 T2 T3 T4 T5 T6 T7 T8] [0 1 2 3 4 5 6 7]);
13525
13526impl Promise {
13527 /// Heterogeneous counterpart to [`Promise::all_iterable`]: accepts a Rust
13528 /// tuple of `Promise<T_i>` and returns a single [`Promise`] resolving to a
13529 /// typed [`ArrayTuple<(T_1, T_2, ..., T_n)>`].
13530 ///
13531 /// Destructure the awaited result via [`ArrayTuple::into_tuple`] to get
13532 /// the individual values back as a native Rust tuple. Implemented for
13533 /// arity 1..=8.
13534 ///
13535 /// Rejects with the first rejection, matching `Promise.all` semantics.
13536 ///
13537 /// # Example
13538 ///
13539 /// ```ignore
13540 /// use js_sys::Promise;
13541 ///
13542 /// let (response, buffer) = Promise::all_tuple((fetch_promise, buffer_promise))
13543 /// .await?
13544 /// .into_tuple();
13545 /// ```
13546 #[inline]
13547 pub fn all_tuple<T: PromiseTuple>(promises: T) -> Promise<T::Joined> {
13548 promises.all()
13549 }
13550
13551 /// Heterogeneous counterpart to [`Promise::all_settled_iterable`]: accepts
13552 /// a Rust tuple of `Promise<T_i>` and returns a single [`Promise`]
13553 /// resolving to a typed
13554 /// `ArrayTuple<(PromiseState<T_1>, ..., PromiseState<T_n>)>`.
13555 ///
13556 /// Unlike [`Promise::all_tuple`], this never rejects early: every input
13557 /// settles (fulfills or rejects) and is reflected by its [`PromiseState`]
13558 /// slot in the result tuple. Implemented for arity 1..=8.
13559 ///
13560 /// # Example
13561 ///
13562 /// ```ignore
13563 /// use js_sys::Promise;
13564 ///
13565 /// let results = Promise::all_settled_tuple((fetch_promise, buffer_promise)).await?;
13566 /// let (response_state, buffer_state) = results.into_tuple();
13567 /// ```
13568 #[inline]
13569 pub fn all_settled_tuple<T: PromiseTuple>(promises: T) -> Promise<T::Settled> {
13570 promises.all_settled()
13571 }
13572}
13573
13574/// Returns a handle to the global scope object.
13575///
13576/// This allows access to the global properties and global names by accessing
13577/// the `Object` returned.
13578pub fn global() -> Object {
13579 use once_cell::unsync::Lazy;
13580
13581 struct Wrapper<T>(Lazy<T>);
13582
13583 #[cfg(not(target_feature = "atomics"))]
13584 unsafe impl<T> Sync for Wrapper<T> {}
13585
13586 #[cfg(not(target_feature = "atomics"))]
13587 unsafe impl<T> Send for Wrapper<T> {}
13588
13589 #[cfg_attr(target_feature = "atomics", thread_local)]
13590 static GLOBAL: Wrapper<Object> = Wrapper(Lazy::new(get_global_object));
13591
13592 return GLOBAL.0.clone();
13593
13594 fn get_global_object() -> Object {
13595 // Accessing the global object is not an easy thing to do, and what we
13596 // basically want is `globalThis` but we can't rely on that existing
13597 // everywhere. In the meantime we've got the fallbacks mentioned in:
13598 //
13599 // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis
13600 //
13601 // Note that this is pretty heavy code-size wise but it at least gets
13602 // the job largely done for now and avoids the `Function` constructor at
13603 // the end which triggers CSP errors.
13604 #[wasm_bindgen]
13605 extern "C" {
13606 #[derive(Clone, Debug)]
13607 type Global;
13608
13609 #[wasm_bindgen(thread_local_v2, js_name = globalThis)]
13610 static GLOBAL_THIS: Option<Object>;
13611
13612 #[wasm_bindgen(thread_local_v2, js_name = self)]
13613 static SELF: Option<Object>;
13614
13615 #[wasm_bindgen(thread_local_v2, js_name = window)]
13616 static WINDOW: Option<Object>;
13617
13618 #[wasm_bindgen(thread_local_v2, js_name = global)]
13619 static GLOBAL: Option<Object>;
13620 }
13621
13622 // The order is important: in Firefox Extension Content Scripts `globalThis`
13623 // is a Sandbox (not Window), so `globalThis` must be checked after `window`.
13624 let static_object = SELF
13625 .with(Option::clone)
13626 .or_else(|| WINDOW.with(Option::clone))
13627 .or_else(|| GLOBAL_THIS.with(Option::clone))
13628 .or_else(|| GLOBAL.with(Option::clone));
13629 if let Some(obj) = static_object {
13630 if !obj.is_undefined() {
13631 return obj;
13632 }
13633 }
13634
13635 // Global object not found
13636 JsValue::undefined().unchecked_into()
13637 }
13638}
13639
13640// Float16Array
13641//
13642// Rust does not yet have a stable builtin `f16`, so the raw JS bindings live
13643// here and any Rust-side helper APIs use explicit `u16` / `f32` naming. The
13644// unsuffixed float APIs are reserved for a future native `f16` binding.
13645#[wasm_bindgen]
13646extern "C" {
13647 #[wasm_bindgen(extends = Object, typescript_type = "Float16Array")]
13648 #[derive(Clone, Debug)]
13649 pub type Float16Array;
13650
13651 /// The `Float16Array()` constructor creates a new array.
13652 ///
13653 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float16Array)
13654 #[wasm_bindgen(constructor)]
13655 pub fn new(constructor_arg: &JsValue) -> Float16Array;
13656
13657 /// The `Float16Array()` constructor creates an array with an internal
13658 /// buffer large enough for `length` elements.
13659 ///
13660 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float16Array)
13661 #[wasm_bindgen(constructor)]
13662 pub fn new_with_length(length: u32) -> Float16Array;
13663
13664 /// The `Float16Array()` constructor creates an array with the given
13665 /// buffer but is a view starting at `byte_offset`.
13666 ///
13667 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float16Array)
13668 #[wasm_bindgen(constructor)]
13669 pub fn new_with_byte_offset(buffer: &JsValue, byte_offset: u32) -> Float16Array;
13670
13671 /// The `Float16Array()` constructor creates an array with the given
13672 /// buffer but is a view starting at `byte_offset` for `length` elements.
13673 ///
13674 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float16Array)
13675 #[wasm_bindgen(constructor)]
13676 pub fn new_with_byte_offset_and_length(
13677 buffer: &JsValue,
13678 byte_offset: u32,
13679 length: u32,
13680 ) -> Float16Array;
13681
13682 /// The `fill()` method fills all elements from a start index to an end
13683 /// index with a static `f32` value.
13684 ///
13685 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/fill)
13686 #[wasm_bindgen(method, js_name = fill)]
13687 pub fn fill_with_f32(this: &Float16Array, value: f32, start: u32, end: u32) -> Float16Array;
13688
13689 /// The buffer accessor property represents the `ArrayBuffer` referenced
13690 /// by a `TypedArray` at construction time.
13691 #[wasm_bindgen(getter, method)]
13692 pub fn buffer(this: &Float16Array) -> ArrayBuffer;
13693
13694 /// The `subarray()` method returns a new `TypedArray` on the same
13695 /// `ArrayBuffer` store and with the same element types as this array.
13696 #[wasm_bindgen(method)]
13697 pub fn subarray(this: &Float16Array, begin: u32, end: u32) -> Float16Array;
13698
13699 /// The `slice()` method returns a shallow copy of a portion of a typed
13700 /// array into a new typed array object.
13701 #[wasm_bindgen(method)]
13702 pub fn slice(this: &Float16Array, begin: u32, end: u32) -> Float16Array;
13703
13704 /// The `forEach()` method executes a provided function once per array
13705 /// element, passing values as `f32`.
13706 #[wasm_bindgen(method, js_name = forEach)]
13707 pub fn for_each_as_f32(this: &Float16Array, callback: &mut dyn FnMut(f32, u32, Float16Array));
13708
13709 /// The `forEach()` method executes a provided function once per array
13710 /// element, passing values as `f32`.
13711 #[wasm_bindgen(method, js_name = forEach, catch)]
13712 pub fn try_for_each_as_f32(
13713 this: &Float16Array,
13714 callback: &mut dyn FnMut(f32, u32, Float16Array) -> Result<(), JsError>,
13715 ) -> Result<(), JsValue>;
13716
13717 /// The length accessor property represents the length (in elements) of a
13718 /// typed array.
13719 #[wasm_bindgen(method, getter)]
13720 pub fn length(this: &Float16Array) -> u32;
13721
13722 /// The byteLength accessor property represents the length (in bytes) of a
13723 /// typed array.
13724 #[wasm_bindgen(method, getter, js_name = byteLength)]
13725 pub fn byte_length(this: &Float16Array) -> u32;
13726
13727 /// The byteOffset accessor property represents the offset (in bytes) of a
13728 /// typed array from the start of its `ArrayBuffer`.
13729 #[wasm_bindgen(method, getter, js_name = byteOffset)]
13730 pub fn byte_offset(this: &Float16Array) -> u32;
13731
13732 /// The `set()` method stores multiple values in the typed array, reading
13733 /// input values from a specified array.
13734 #[wasm_bindgen(method)]
13735 pub fn set(this: &Float16Array, src: &JsValue, offset: u32);
13736
13737 /// Gets the value at `idx` as an `f32`, counting from the end if negative.
13738 #[wasm_bindgen(method, js_name = at)]
13739 pub fn at_as_f32(this: &Float16Array, idx: i32) -> Option<f32>;
13740
13741 /// The `copyWithin()` method shallow copies part of a typed array to another
13742 /// location in the same typed array and returns it, without modifying its size.
13743 ///
13744 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin)
13745 #[wasm_bindgen(method, js_name = copyWithin)]
13746 pub fn copy_within(this: &Float16Array, target: i32, start: i32, end: i32) -> Float16Array;
13747
13748 /// Gets the value at `idx` as an `f32`, equivalent to JavaScript
13749 /// `arr[idx]`.
13750 #[wasm_bindgen(method, indexing_getter)]
13751 pub fn get_index_as_f32(this: &Float16Array, idx: u32) -> f32;
13752
13753 /// Sets the value at `idx` from an `f32`, equivalent to JavaScript
13754 /// `arr[idx] = value`.
13755 #[wasm_bindgen(method, indexing_setter)]
13756 pub fn set_index_from_f32(this: &Float16Array, idx: u32, value: f32);
13757}
13758
13759impl Default for Float16Array {
13760 fn default() -> Self {
13761 Self::new(&JsValue::UNDEFINED.unchecked_into())
13762 }
13763}
13764
13765impl TypedArray for Float16Array {}
13766
13767impl Float16Array {
13768 fn as_uint16_view(&self) -> Uint16Array {
13769 let buffer = self.buffer();
13770 Uint16Array::new_with_byte_offset_and_length(
13771 buffer.as_ref(),
13772 self.byte_offset(),
13773 self.length(),
13774 )
13775 }
13776
13777 /// Creates an array from raw IEEE 754 binary16 bit patterns.
13778 ///
13779 /// This pairs naturally with the optional `half` crate:
13780 ///
13781 /// ```rust
13782 /// use half::f16;
13783 /// use js_sys::Float16Array;
13784 ///
13785 /// let values = [f16::from_f32(1.0), f16::from_f32(-2.0)];
13786 /// let bits = values.map(f16::to_bits);
13787 /// let array = Float16Array::new_from_u16_slice(&bits);
13788 /// ```
13789 pub fn new_from_u16_slice(slice: &[u16]) -> Float16Array {
13790 let array = Float16Array::new_with_length(slice.len() as u32);
13791 array.copy_from_u16_slice(slice);
13792 array
13793 }
13794
13795 /// Copy the raw IEEE 754 binary16 bit patterns from this JS typed array
13796 /// into the destination Rust slice.
13797 ///
13798 /// # Panics
13799 ///
13800 /// This function will panic if this typed array's length is different than
13801 /// the length of the provided `dst` array.
13802 ///
13803 /// Values copied into `dst` can be converted back into `half::f16` with
13804 /// `half::f16::from_bits`.
13805 pub fn copy_to_u16_slice(&self, dst: &mut [u16]) {
13806 self.as_uint16_view().copy_to(dst);
13807 }
13808
13809 /// Copy raw IEEE 754 binary16 bit patterns from the source Rust slice into
13810 /// this JS typed array.
13811 ///
13812 /// # Panics
13813 ///
13814 /// This function will panic if this typed array's length is different than
13815 /// the length of the provided `src` array.
13816 ///
13817 /// When using the optional `half` crate, populate `src` with
13818 /// `half::f16::to_bits()`.
13819 pub fn copy_from_u16_slice(&self, src: &[u16]) {
13820 self.as_uint16_view().copy_from(src);
13821 }
13822
13823 /// Efficiently copies the contents of this JS typed array into a new Vec of
13824 /// raw IEEE 754 binary16 bit patterns.
13825 ///
13826 /// This makes it easy to round-trip through the optional `half` crate:
13827 ///
13828 /// ```rust
13829 /// use half::f16;
13830 ///
13831 /// let bits = array.to_u16_vec();
13832 /// let values: Vec<f16> = bits.into_iter().map(f16::from_bits).collect();
13833 /// ```
13834 pub fn to_u16_vec(&self) -> Vec<u16> {
13835 self.as_uint16_view().to_vec()
13836 }
13837}
13838
13839macro_rules! arrays {
13840 ($(#[doc = $ctor:literal] #[doc = $mdn:literal] $name:ident: $ty:ident,)*) => ($(
13841 #[wasm_bindgen]
13842 extern "C" {
13843 #[wasm_bindgen(extends = Object, typescript_type = $name)]
13844 #[derive(Clone, Debug)]
13845 pub type $name;
13846
13847 /// The
13848 #[doc = $ctor]
13849 /// constructor creates a new array.
13850 ///
13851 /// [MDN documentation](
13852 #[doc = $mdn]
13853 /// )
13854 #[wasm_bindgen(constructor)]
13855 pub fn new(constructor_arg: &JsValue) -> $name;
13856
13857 /// An
13858 #[doc = $ctor]
13859 /// which creates an array with an internal buffer large
13860 /// enough for `length` elements.
13861 ///
13862 /// [MDN documentation](
13863 #[doc = $mdn]
13864 /// )
13865 #[wasm_bindgen(constructor)]
13866 pub fn new_with_length(length: u32) -> $name;
13867
13868 /// An
13869 #[doc = $ctor]
13870 /// which creates an array from a Rust slice.
13871 ///
13872 /// [MDN documentation](
13873 #[doc = $mdn]
13874 /// )
13875 #[wasm_bindgen(constructor)]
13876 pub fn new_from_slice(slice: &[$ty]) -> $name;
13877
13878 /// An
13879 #[doc = $ctor]
13880 /// which creates an array with the given buffer but is a
13881 /// view starting at `byte_offset`.
13882 ///
13883 /// [MDN documentation](
13884 #[doc = $mdn]
13885 /// )
13886 #[wasm_bindgen(constructor)]
13887 pub fn new_with_byte_offset(buffer: &JsValue, byte_offset: u32) -> $name;
13888
13889 /// An
13890 #[doc = $ctor]
13891 /// which creates an array with the given buffer but is a
13892 /// view starting at `byte_offset` for `length` elements.
13893 ///
13894 /// [MDN documentation](
13895 #[doc = $mdn]
13896 /// )
13897 #[wasm_bindgen(constructor)]
13898 pub fn new_with_byte_offset_and_length(
13899 buffer: &JsValue,
13900 byte_offset: u32,
13901 length: u32,
13902 ) -> $name;
13903
13904 /// The `fill()` method fills all the elements of an array from a start index
13905 /// to an end index with a static value. The end index is not included.
13906 ///
13907 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/fill)
13908 #[wasm_bindgen(method)]
13909 pub fn fill(this: &$name, value: $ty, start: u32, end: u32) -> $name;
13910
13911 /// The buffer accessor property represents the `ArrayBuffer` referenced
13912 /// by a `TypedArray` at construction time.
13913 #[wasm_bindgen(getter, method)]
13914 pub fn buffer(this: &$name) -> ArrayBuffer;
13915
13916 /// The `subarray()` method returns a new `TypedArray` on the same
13917 /// `ArrayBuffer` store and with the same element types as for this
13918 /// `TypedArray` object.
13919 #[wasm_bindgen(method)]
13920 pub fn subarray(this: &$name, begin: u32, end: u32) -> $name;
13921
13922 /// The `slice()` method returns a shallow copy of a portion of a typed
13923 /// array into a new typed array object. This method has the same algorithm
13924 /// as `Array.prototype.slice()`.
13925 #[wasm_bindgen(method)]
13926 pub fn slice(this: &$name, begin: u32, end: u32) -> $name;
13927
13928 /// The `forEach()` method executes a provided function once per array
13929 /// element. This method has the same algorithm as
13930 /// `Array.prototype.forEach()`. `TypedArray` is one of the typed array
13931 /// types here.
13932 #[wasm_bindgen(method, js_name = forEach)]
13933 pub fn for_each(this: &$name, callback: &mut dyn FnMut($ty, u32, $name));
13934
13935 /// The `forEach()` method executes a provided function once per array
13936 /// element. This method has the same algorithm as
13937 /// `Array.prototype.forEach()`. `TypedArray` is one of the typed array
13938 /// types here.
13939 #[wasm_bindgen(method, js_name = forEach, catch)]
13940 pub fn try_for_each(this: &$name, callback: &mut dyn FnMut($ty, u32, $name) -> Result<(), JsError>) -> Result<(), JsValue>;
13941
13942 /// The length accessor property represents the length (in elements) of a
13943 /// typed array.
13944 #[wasm_bindgen(method, getter)]
13945 pub fn length(this: &$name) -> u32;
13946
13947 /// The byteLength accessor property represents the length (in bytes) of a
13948 /// typed array.
13949 #[wasm_bindgen(method, getter, js_name = byteLength)]
13950 pub fn byte_length(this: &$name) -> u32;
13951
13952 /// The byteOffset accessor property represents the offset (in bytes) of a
13953 /// typed array from the start of its `ArrayBuffer`.
13954 #[wasm_bindgen(method, getter, js_name = byteOffset)]
13955 pub fn byte_offset(this: &$name) -> u32;
13956
13957 /// The `set()` method stores multiple values in the typed array, reading
13958 /// input values from a specified array.
13959 #[wasm_bindgen(method)]
13960 pub fn set(this: &$name, src: &JsValue, offset: u32);
13961
13962 /// Gets the value at `idx`, counting from the end if negative.
13963 #[wasm_bindgen(method)]
13964 pub fn at(this: &$name, idx: i32) -> Option<$ty>;
13965
13966 /// The `copyWithin()` method shallow copies part of a typed array to another
13967 /// location in the same typed array and returns it, without modifying its size.
13968 ///
13969 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin)
13970 #[wasm_bindgen(method, js_name = copyWithin)]
13971 pub fn copy_within(this: &$name, target: i32, start: i32, end: i32) -> $name;
13972
13973 /// Gets the value at `idx`, equivalent to the javascript `my_var = arr[idx]`.
13974 #[wasm_bindgen(method, indexing_getter)]
13975 pub fn get_index(this: &$name, idx: u32) -> $ty;
13976
13977 /// Sets the value at `idx`, equivalent to the javascript `arr[idx] = value`.
13978 #[wasm_bindgen(method, indexing_setter)]
13979 pub fn set_index(this: &$name, idx: u32, value: $ty);
13980
13981 /// Copies the Rust slice's data to self.
13982 ///
13983 /// This method is not expected to be public. It requires the length of the
13984 /// TypedArray to be the same as the slice, use `self.copy_from(slice)` instead.
13985 #[wasm_bindgen(method, js_name = set)]
13986 fn copy_from_slice(this: &$name, slice: &[$ty]);
13987
13988 /// Copies this TypedArray's data to Rust slice;
13989 ///
13990 /// This method is not expected to be public. It requires the length of the
13991 /// TypedArray to be the same as the slice, use `self.copy_to(slice)` instead.
13992 ///
13993 /// # Workaround
13994 ///
13995 /// We actually need `slice.set(typed_array)` here, but since slice cannot be treated as
13996 /// `Uint8Array` on the Rust side, we use `Uint8Array.prototype.set.call`, which allows
13997 /// us to specify the `this` value inside the function.
13998 ///
13999 /// Therefore, `Uint8Array.prototype.set.call(slice, typed_array)` is equivalent to
14000 /// `slice.set(typed_array)`.
14001 #[wasm_bindgen(js_namespace = $name, js_name = "prototype.set.call")]
14002 fn copy_to_slice(slice: &mut [$ty], this: &$name);
14003 }
14004
14005 impl $name {
14006 /// Creates a JS typed array which is a view into wasm's linear
14007 /// memory at the slice specified.
14008 ///
14009 /// This function returns a new typed array which is a view into
14010 /// wasm's memory. This view does not copy the underlying data.
14011 ///
14012 /// # Safety
14013 ///
14014 /// Views into WebAssembly memory are only valid so long as the
14015 /// backing buffer isn't resized in JS. Once this function is called
14016 /// any future calls to `Box::new` (or malloc of any form) may cause
14017 /// the returned value here to be invalidated. Use with caution!
14018 ///
14019 /// Additionally the returned object can be safely mutated but the
14020 /// input slice isn't guaranteed to be mutable.
14021 ///
14022 /// Finally, the returned object is disconnected from the input
14023 /// slice's lifetime, so there's no guarantee that the data is read
14024 /// at the right time.
14025 pub unsafe fn view(rust: &[$ty]) -> $name {
14026 wasm_bindgen::__rt::wbg_cast(rust)
14027 }
14028
14029 /// Creates a JS typed array which is a view into wasm's linear
14030 /// memory at the specified pointer with specified length.
14031 ///
14032 /// This function returns a new typed array which is a view into
14033 /// wasm's memory. This view does not copy the underlying data.
14034 ///
14035 /// # Safety
14036 ///
14037 /// Views into WebAssembly memory are only valid so long as the
14038 /// backing buffer isn't resized in JS. Once this function is called
14039 /// any future calls to `Box::new` (or malloc of any form) may cause
14040 /// the returned value here to be invalidated. Use with caution!
14041 ///
14042 /// Additionally the returned object can be safely mutated,
14043 /// the changes are guaranteed to be reflected in the input array.
14044 pub unsafe fn view_mut_raw(ptr: *mut $ty, length: usize) -> $name {
14045 let slice = core::slice::from_raw_parts_mut(ptr, length);
14046 Self::view(slice)
14047 }
14048
14049 /// Copy the contents of this JS typed array into the destination
14050 /// Rust pointer.
14051 ///
14052 /// This function will efficiently copy the memory from a typed
14053 /// array into this Wasm module's own linear memory, initializing
14054 /// the memory destination provided.
14055 ///
14056 /// # Safety
14057 ///
14058 /// This function requires `dst` to point to a buffer
14059 /// large enough to fit this array's contents.
14060 pub unsafe fn raw_copy_to_ptr(&self, dst: *mut $ty) {
14061 let slice = core::slice::from_raw_parts_mut(dst, self.length() as usize);
14062 self.copy_to(slice);
14063 }
14064
14065 /// Copy the contents of this JS typed array into the destination
14066 /// Rust slice.
14067 ///
14068 /// This function will efficiently copy the memory from a typed
14069 /// array into this Wasm module's own linear memory, initializing
14070 /// the memory destination provided.
14071 ///
14072 /// # Panics
14073 ///
14074 /// This function will panic if this typed array's length is
14075 /// different than the length of the provided `dst` array.
14076 pub fn copy_to(&self, dst: &mut [$ty]) {
14077 core::assert_eq!(self.length() as usize, dst.len());
14078 $name::copy_to_slice(dst, self);
14079 }
14080
14081 /// Copy the contents of this JS typed array into the destination
14082 /// Rust slice.
14083 ///
14084 /// This function will efficiently copy the memory from a typed
14085 /// array into this Wasm module's own linear memory, initializing
14086 /// the memory destination provided.
14087 ///
14088 /// # Panics
14089 ///
14090 /// This function will panic if this typed array's length is
14091 /// different than the length of the provided `dst` array.
14092 pub fn copy_to_uninit<'dst>(&self, dst: &'dst mut [MaybeUninit<$ty>]) -> &'dst mut [$ty] {
14093 core::assert_eq!(self.length() as usize, dst.len());
14094 let dst = unsafe { &mut *(dst as *mut [MaybeUninit<$ty>] as *mut [$ty]) };
14095 self.copy_to(dst);
14096 dst
14097 }
14098
14099 /// Copy the contents of the source Rust slice into this
14100 /// JS typed array.
14101 ///
14102 /// This function will efficiently copy the memory from within
14103 /// the Wasm module's own linear memory to this typed array.
14104 ///
14105 /// # Panics
14106 ///
14107 /// This function will panic if this typed array's length is
14108 /// different than the length of the provided `src` array.
14109 pub fn copy_from(&self, src: &[$ty]) {
14110 core::assert_eq!(self.length() as usize, src.len());
14111 self.copy_from_slice(src);
14112 }
14113
14114 /// Efficiently copies the contents of this JS typed array into a new Vec.
14115 pub fn to_vec(&self) -> Vec<$ty> {
14116 let len = self.length() as usize;
14117 let mut output = Vec::with_capacity(len);
14118 // Safety: the capacity has been set
14119 unsafe {
14120 self.raw_copy_to_ptr(output.as_mut_ptr());
14121 output.set_len(len);
14122 }
14123 output
14124 }
14125 }
14126
14127 impl<'a> From<&'a [$ty]> for $name {
14128 #[inline]
14129 fn from(slice: &'a [$ty]) -> $name {
14130 // This is safe because the `new` function makes a copy if its argument is a TypedArray
14131 $name::new_from_slice(slice)
14132 }
14133 }
14134
14135 impl Default for $name {
14136 fn default() -> Self {
14137 Self::new(&JsValue::UNDEFINED.unchecked_into())
14138 }
14139 }
14140
14141 impl TypedArray for $name {}
14142
14143
14144 )*);
14145}
14146
14147arrays! {
14148 /// `Int8Array()`
14149 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int8Array
14150 Int8Array: i8,
14151
14152 /// `Int16Array()`
14153 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int16Array
14154 Int16Array: i16,
14155
14156 /// `Int32Array()`
14157 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int32Array
14158 Int32Array: i32,
14159
14160 /// `Uint8Array()`
14161 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array
14162 Uint8Array: u8,
14163
14164 /// `Uint8ClampedArray()`
14165 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8ClampedArray
14166 Uint8ClampedArray: u8,
14167
14168 /// `Uint16Array()`
14169 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint16Array
14170 Uint16Array: u16,
14171
14172 /// `Uint32Array()`
14173 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint32Array
14174 Uint32Array: u32,
14175
14176 /// `Float32Array()`
14177 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array
14178 Float32Array: f32,
14179
14180 /// `Float64Array()`
14181 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float64Array
14182 Float64Array: f64,
14183
14184 /// `BigInt64Array()`
14185 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt64Array
14186 BigInt64Array: i64,
14187
14188 /// `BigUint64Array()`
14189 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigUint64Array
14190 BigUint64Array: u64,
14191}
14192
14193/// Bridging between JavaScript `Promise`s and Rust `Future`s.
14194///
14195/// Enables `promise.await` directly on any [`Promise`].
14196/// This module is also re-exported by `wasm-bindgen-futures` for backwards compatibility.
14197pub mod futures;