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::{JsNullable, 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)+]) => {
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 impl<$($T,)+ Target> UpcastFrom<ArrayTuple<($($T,)+)>> for JsNullable<Array<Target>>
1820 where
1821 $(Target: UpcastFrom<$T>,)+
1822 {}
1823 };
1824}
1825
1826impl_tuple_covariance!([T1][Target1]);
1827impl_tuple_covariance!([T1 T2] [Target1 Target2]);
1828impl_tuple_covariance!([T1 T2 T3] [Target1 Target2 Target3]);
1829impl_tuple_covariance!([T1 T2 T3 T4] [Target1 Target2 Target3 Target4]);
1830impl_tuple_covariance!([T1 T2 T3 T4 T5] [Target1 Target2 Target3 Target4 Target5]);
1831impl_tuple_covariance!([T1 T2 T3 T4 T5 T6] [Target1 Target2 Target3 Target4 Target5 Target6]);
1832impl_tuple_covariance!([T1 T2 T3 T4 T5 T6 T7] [Target1 Target2 Target3 Target4 Target5 Target6 Target7]);
1833impl_tuple_covariance!([T1 T2 T3 T4 T5 T6 T7 T8] [Target1 Target2 Target3 Target4 Target5 Target6 Target7 Target8]);
1834
1835// Tuple casting is implemented in core
1836impl<T: JsTuple, U: JsTuple> UpcastFrom<ArrayTuple<T>> for ArrayTuple<U> where U: UpcastFrom<T> {}
1837impl<T: JsTuple> UpcastFrom<ArrayTuple<T>> for JsValue {}
1838impl<T: JsTuple> UpcastFrom<ArrayTuple<T>> for JsOption<JsValue> {}
1839impl<T: JsTuple> UpcastFrom<ArrayTuple<T>> for JsNullable<JsValue> {}
1840
1841/// Iterator returned by `Array::into_iter`
1842#[derive(Debug, Clone)]
1843pub struct ArrayIntoIter<T: JsGeneric = JsValue> {
1844 range: core::ops::Range<u32>,
1845 array: Array<T>,
1846}
1847
1848#[cfg(not(js_sys_unstable_apis))]
1849impl<T: JsGeneric> core::iter::Iterator for ArrayIntoIter<T> {
1850 type Item = T;
1851
1852 fn next(&mut self) -> Option<Self::Item> {
1853 let index = self.range.next()?;
1854 Some(self.array.get(index))
1855 }
1856
1857 #[inline]
1858 fn size_hint(&self) -> (usize, Option<usize>) {
1859 self.range.size_hint()
1860 }
1861
1862 #[inline]
1863 fn count(self) -> usize
1864 where
1865 Self: Sized,
1866 {
1867 self.range.count()
1868 }
1869
1870 #[inline]
1871 fn last(self) -> Option<Self::Item>
1872 where
1873 Self: Sized,
1874 {
1875 let Self { range, array } = self;
1876 range.last().map(|index| array.get(index))
1877 }
1878
1879 #[inline]
1880 fn nth(&mut self, n: usize) -> Option<Self::Item> {
1881 self.range.nth(n).map(|index| self.array.get(index))
1882 }
1883}
1884
1885#[cfg(js_sys_unstable_apis)]
1886impl<T: JsGeneric> core::iter::Iterator for ArrayIntoIter<T> {
1887 type Item = T;
1888
1889 fn next(&mut self) -> Option<Self::Item> {
1890 let index = self.range.next()?;
1891 self.array.get(index)
1892 }
1893
1894 #[inline]
1895 fn size_hint(&self) -> (usize, Option<usize>) {
1896 self.range.size_hint()
1897 }
1898
1899 #[inline]
1900 fn count(self) -> usize
1901 where
1902 Self: Sized,
1903 {
1904 self.range.count()
1905 }
1906
1907 #[inline]
1908 fn last(self) -> Option<Self::Item>
1909 where
1910 Self: Sized,
1911 {
1912 let Self { range, array } = self;
1913 range.last().and_then(|index| array.get(index))
1914 }
1915
1916 #[inline]
1917 fn nth(&mut self, n: usize) -> Option<Self::Item> {
1918 self.range.nth(n).and_then(|index| self.array.get(index))
1919 }
1920}
1921
1922#[cfg(not(js_sys_unstable_apis))]
1923impl<T: JsGeneric> core::iter::DoubleEndedIterator for ArrayIntoIter<T> {
1924 fn next_back(&mut self) -> Option<Self::Item> {
1925 let index = self.range.next_back()?;
1926 Some(self.array.get(index))
1927 }
1928
1929 fn nth_back(&mut self, n: usize) -> Option<Self::Item> {
1930 self.range.nth_back(n).map(|index| self.array.get(index))
1931 }
1932}
1933
1934#[cfg(js_sys_unstable_apis)]
1935impl<T: JsGeneric> core::iter::DoubleEndedIterator for ArrayIntoIter<T> {
1936 fn next_back(&mut self) -> Option<Self::Item> {
1937 let index = self.range.next_back()?;
1938 self.array.get(index)
1939 }
1940
1941 fn nth_back(&mut self, n: usize) -> Option<Self::Item> {
1942 self.range
1943 .nth_back(n)
1944 .and_then(|index| self.array.get(index))
1945 }
1946}
1947
1948impl<T: JsGeneric> core::iter::FusedIterator for ArrayIntoIter<T> {}
1949
1950impl<T: JsGeneric> core::iter::ExactSizeIterator for ArrayIntoIter<T> {}
1951
1952/// Iterator returned by `Array::iter`
1953#[derive(Debug, Clone)]
1954pub struct ArrayIter<'a, T: JsGeneric = JsValue> {
1955 range: core::ops::Range<u32>,
1956 array: &'a Array<T>,
1957}
1958
1959impl<T: JsGeneric> core::iter::Iterator for ArrayIter<'_, T> {
1960 type Item = T;
1961
1962 fn next(&mut self) -> Option<Self::Item> {
1963 let index = self.range.next()?;
1964 Some(self.array.get_unchecked(index))
1965 }
1966
1967 #[inline]
1968 fn size_hint(&self) -> (usize, Option<usize>) {
1969 self.range.size_hint()
1970 }
1971
1972 #[inline]
1973 fn count(self) -> usize
1974 where
1975 Self: Sized,
1976 {
1977 self.range.count()
1978 }
1979
1980 #[inline]
1981 fn last(self) -> Option<Self::Item>
1982 where
1983 Self: Sized,
1984 {
1985 let Self { range, array } = self;
1986 range.last().map(|index| array.get_unchecked(index))
1987 }
1988
1989 #[inline]
1990 fn nth(&mut self, n: usize) -> Option<Self::Item> {
1991 self.range
1992 .nth(n)
1993 .map(|index| self.array.get_unchecked(index))
1994 }
1995}
1996
1997impl<T: JsGeneric> core::iter::DoubleEndedIterator for ArrayIter<'_, T> {
1998 fn next_back(&mut self) -> Option<Self::Item> {
1999 let index = self.range.next_back()?;
2000 Some(self.array.get_unchecked(index))
2001 }
2002
2003 fn nth_back(&mut self, n: usize) -> Option<Self::Item> {
2004 self.range
2005 .nth_back(n)
2006 .map(|index| self.array.get_unchecked(index))
2007 }
2008}
2009
2010impl<T: JsGeneric> core::iter::FusedIterator for ArrayIter<'_, T> {}
2011
2012impl<T: JsGeneric> core::iter::ExactSizeIterator for ArrayIter<'_, T> {}
2013
2014impl<T: JsGeneric> Array<T> {
2015 /// Returns an iterator over the values of the JS array.
2016 pub fn iter(&self) -> ArrayIter<'_, T> {
2017 ArrayIter {
2018 range: 0..self.length(),
2019 array: self,
2020 }
2021 }
2022}
2023
2024impl<T: JsGeneric> core::iter::IntoIterator for Array<T> {
2025 type Item = T;
2026 type IntoIter = ArrayIntoIter<T>;
2027
2028 fn into_iter(self) -> Self::IntoIter {
2029 ArrayIntoIter {
2030 range: 0..self.length(),
2031 array: self,
2032 }
2033 }
2034}
2035
2036// `FromIterator` / `Extend` for `Array` (= `Array<JsValue>` via the default
2037// type parameter) preserve the long-standing stable behaviour: any iterator
2038// of items convertible to `&JsValue` collects into an erased `Array<JsValue>`.
2039//
2040// Typed collection (where the element type is inferred from the iterator
2041// item via [`IntoJsGeneric`]) is exposed as the inherent constructor
2042// [`Array::from_iter_typed`] rather than a second `FromIterator` impl. A
2043// blanket `impl<A: IntoJsGeneric> FromIterator<A> for Array<A::JsCanon>`
2044// would overlap with the stable `AsRef<JsValue>` impl on `Array<JsValue>`
2045// (since `JsValue: IntoJsGeneric` with `JsCanon = JsValue`), so the two
2046// cannot coexist as `FromIterator` impls without coherence violations.
2047//
2048// TODO(next major): deprecate this `FromIterator`/`Extend` pair in favour
2049// of a single `IntoJsGeneric`-based impl, and rename `from_iter_typed` to
2050// take its place. That migration is source-breaking for callers relying on
2051// `.collect::<Array>()` implicit erasure of typed items, so it is deferred.
2052
2053impl<A> core::iter::FromIterator<A> for Array
2054where
2055 A: AsRef<JsValue>,
2056{
2057 fn from_iter<I>(iter: I) -> Array
2058 where
2059 I: IntoIterator<Item = A>,
2060 {
2061 let mut out = Array::new();
2062 out.extend(iter);
2063 out
2064 }
2065}
2066
2067impl<A> core::iter::Extend<A> for Array
2068where
2069 A: AsRef<JsValue>,
2070{
2071 fn extend<I>(&mut self, iter: I)
2072 where
2073 I: IntoIterator<Item = A>,
2074 {
2075 for value in iter {
2076 self.push(value.as_ref());
2077 }
2078 }
2079}
2080
2081impl<T: JsGeneric> Array<T> {
2082 /// Collect an iterator into a typed `Array<T>`, projecting each item
2083 /// through its canonical [`JsGeneric`] via [`IntoJsGeneric`].
2084 ///
2085 /// This is the typed counterpart to the stable
2086 /// `impl FromIterator<A> for Array where A: AsRef<JsValue>`, which always
2087 /// produces an erased `Array<JsValue>`. Use `from_iter_typed` when you
2088 /// want the element type inferred from the iterator item:
2089 ///
2090 /// ```ignore
2091 /// use js_sys::{Array, Number};
2092 ///
2093 /// let arr = Array::from_iter_typed((0..10).map(Number::from));
2094 /// // arr: Array<Number>
2095 /// ```
2096 ///
2097 /// Reference iteration (`Item = &U`) is supported transparently via the
2098 /// `&U: IntoJsGeneric` blanket in `wasm-bindgen` core.
2099 //
2100 // TODO(next major): replace the stable `FromIterator` impl above with
2101 // this behaviour and remove `from_iter_typed`.
2102 pub fn from_iter_typed<A, I>(iter: I) -> Array<T>
2103 where
2104 A: IntoJsGeneric<JsCanon = T>,
2105 I: IntoIterator<Item = A>,
2106 {
2107 let mut out = Array::<T>::new_typed();
2108 out.extend_typed(iter);
2109 out
2110 }
2111
2112 /// Extend a typed `Array<T>` with an iterator of items convertible to
2113 /// `T` via [`IntoJsGeneric`]. Companion to [`Array::from_iter_typed`].
2114 //
2115 // TODO(next major): replace the stable `Extend` impl above with this
2116 // behaviour and remove `extend_typed`.
2117 pub fn extend_typed<A, I>(&mut self, iter: I)
2118 where
2119 A: IntoJsGeneric<JsCanon = T>,
2120 I: IntoIterator<Item = A>,
2121 {
2122 for value in iter {
2123 self.push(&value.to_js());
2124 }
2125 }
2126}
2127
2128impl Default for Array<JsValue> {
2129 fn default() -> Self {
2130 Self::new()
2131 }
2132}
2133
2134impl<T> Iterable for Array<T> {
2135 type Item = T;
2136}
2137
2138impl<T: JsTuple> Iterable for ArrayTuple<T> {
2139 type Item = JsValue;
2140}
2141
2142// ArrayBufferOptions
2143#[wasm_bindgen]
2144extern "C" {
2145 #[wasm_bindgen(extends = Object, typescript_type = "ArrayBufferOptions")]
2146 #[derive(Clone, Debug, PartialEq, Eq)]
2147 pub type ArrayBufferOptions;
2148
2149 /// The maximum size, in bytes, that the array buffer can be resized to.
2150 #[wasm_bindgen(method, setter, js_name = maxByteLength)]
2151 pub fn set_max_byte_length(this: &ArrayBufferOptions, max_byte_length: usize);
2152
2153 /// The maximum size, in bytes, that the array buffer can be resized to.
2154 #[wasm_bindgen(method, getter, js_name = maxByteLength)]
2155 pub fn get_max_byte_length(this: &ArrayBufferOptions) -> usize;
2156}
2157
2158impl ArrayBufferOptions {
2159 #[cfg(not(js_sys_unstable_apis))]
2160 pub fn new(max_byte_length: usize) -> ArrayBufferOptions {
2161 let options = JsCast::unchecked_into::<ArrayBufferOptions>(Object::new());
2162 options.set_max_byte_length(max_byte_length);
2163 options
2164 }
2165
2166 #[cfg(js_sys_unstable_apis)]
2167 pub fn new(max_byte_length: usize) -> ArrayBufferOptions {
2168 let options = JsCast::unchecked_into::<ArrayBufferOptions>(Object::<JsValue>::new());
2169 options.set_max_byte_length(max_byte_length);
2170 options
2171 }
2172}
2173
2174// ArrayBuffer
2175#[wasm_bindgen]
2176extern "C" {
2177 #[wasm_bindgen(extends = Object, typescript_type = "ArrayBuffer")]
2178 #[derive(Clone, Debug, PartialEq, Eq)]
2179 pub type ArrayBuffer;
2180
2181 /// The `ArrayBuffer` object is used to represent a generic,
2182 /// fixed-length raw binary data buffer. You cannot directly
2183 /// manipulate the contents of an `ArrayBuffer`; instead, you
2184 /// create one of the typed array objects or a `DataView` object
2185 /// which represents the buffer in a specific format, and use that
2186 /// to read and write the contents of the buffer.
2187 ///
2188 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer)
2189 #[cfg(not(js_sys_unstable_apis))]
2190 #[wasm_bindgen(constructor)]
2191 pub fn new(length: u32) -> ArrayBuffer;
2192
2193 /// The `ArrayBuffer` object is used to represent a generic,
2194 /// fixed-length raw binary data buffer. You cannot directly
2195 /// manipulate the contents of an `ArrayBuffer`; instead, you
2196 /// create one of the typed array objects or a `DataView` object
2197 /// which represents the buffer in a specific format, and use that
2198 /// to read and write the contents of the buffer.
2199 ///
2200 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer)
2201 #[cfg(js_sys_unstable_apis)]
2202 #[wasm_bindgen(constructor)]
2203 pub fn new(length: usize) -> ArrayBuffer;
2204
2205 /// The `ArrayBuffer` object is used to represent a generic,
2206 /// fixed-length raw binary data buffer. You cannot directly
2207 /// manipulate the contents of an `ArrayBuffer`; instead, you
2208 /// create one of the typed array objects or a `DataView` object
2209 /// which represents the buffer in a specific format, and use that
2210 /// to read and write the contents of the buffer.
2211 ///
2212 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer)
2213 #[wasm_bindgen(constructor)]
2214 pub fn new_with_options(length: usize, options: &ArrayBufferOptions) -> ArrayBuffer;
2215
2216 /// The `byteLength` property of an object which is an instance of type ArrayBuffer
2217 /// it's an accessor property whose set accessor function is undefined,
2218 /// meaning that you can only read this property.
2219 /// The value is established when the array is constructed and cannot be changed.
2220 /// This property returns 0 if this ArrayBuffer has been detached.
2221 ///
2222 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/byteLength)
2223 #[cfg(not(js_sys_unstable_apis))]
2224 #[wasm_bindgen(method, getter, js_name = byteLength)]
2225 pub fn byte_length(this: &ArrayBuffer) -> u32;
2226
2227 /// The `byteLength` property of an object which is an instance of type ArrayBuffer
2228 /// it's an accessor property whose set accessor function is undefined,
2229 /// meaning that you can only read this property.
2230 /// The value is established when the array is constructed and cannot be changed.
2231 /// This property returns 0 if this ArrayBuffer has been detached.
2232 ///
2233 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/byteLength)
2234 #[cfg(js_sys_unstable_apis)]
2235 #[wasm_bindgen(method, getter, js_name = byteLength)]
2236 pub fn byte_length(this: &ArrayBuffer) -> usize;
2237
2238 /// The `detached` accessor property of `ArrayBuffer` instances returns a boolean indicating
2239 /// whether or not this buffer has been detached (transferred).
2240 ///
2241 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/detached)
2242 #[wasm_bindgen(method, getter)]
2243 pub fn detached(this: &ArrayBuffer) -> bool;
2244
2245 /// The `isView()` method returns true if arg is one of the `ArrayBuffer`
2246 /// views, such as typed array objects or a DataView; false otherwise.
2247 ///
2248 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/isView)
2249 #[wasm_bindgen(static_method_of = ArrayBuffer, js_name = isView)]
2250 pub fn is_view(value: &JsValue) -> bool;
2251
2252 /// The `maxByteLength` accessor property of ArrayBuffer instances returns the maximum
2253 /// length (in bytes) that this array buffer can be resized to.
2254 ///
2255 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/maxByteLength)
2256 #[wasm_bindgen(method, getter, js_name = maxByteLength)]
2257 pub fn max_byte_length(this: &ArrayBuffer) -> usize;
2258
2259 /// The `resizable` accessor property of `ArrayBuffer` instances returns whether this array buffer
2260 /// can be resized or not.
2261 ///
2262 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/resizable)
2263 #[wasm_bindgen(method, getter)]
2264 pub fn resizable(this: &ArrayBuffer) -> bool;
2265
2266 /// The `resize()` method of ArrayBuffer instances resizes the ArrayBuffer to the
2267 /// specified size, in bytes.
2268 ///
2269 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/resize)
2270 #[wasm_bindgen(method, catch)]
2271 pub fn resize(this: &ArrayBuffer, new_len: usize) -> Result<(), JsValue>;
2272
2273 /// The `slice()` method returns a new `ArrayBuffer` whose contents
2274 /// are a copy of this `ArrayBuffer`'s bytes from begin, inclusive,
2275 /// up to end, exclusive.
2276 ///
2277 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/slice)
2278 #[cfg(not(js_sys_unstable_apis))]
2279 #[wasm_bindgen(method)]
2280 pub fn slice(this: &ArrayBuffer, begin: u32) -> ArrayBuffer;
2281
2282 /// The `slice()` method returns a new `ArrayBuffer` whose contents
2283 /// are a copy of this `ArrayBuffer`'s bytes from begin, inclusive,
2284 /// up to end, exclusive. Negative indices count from the end.
2285 ///
2286 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/slice)
2287 #[cfg(js_sys_unstable_apis)]
2288 #[wasm_bindgen(method)]
2289 pub fn slice(this: &ArrayBuffer, begin: isize, end: isize) -> ArrayBuffer;
2290
2291 /// The `slice()` method returns a new `ArrayBuffer` whose contents
2292 /// are a copy of this `ArrayBuffer`'s bytes from begin, inclusive,
2293 /// up to end, exclusive.
2294 ///
2295 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/slice)
2296 #[cfg(not(js_sys_unstable_apis))]
2297 #[wasm_bindgen(method, js_name = slice)]
2298 pub fn slice_from(this: &ArrayBuffer, begin: isize) -> ArrayBuffer;
2299
2300 /// The `slice()` method returns a new `ArrayBuffer` whose contents
2301 /// are a copy of this `ArrayBuffer`'s bytes from begin to the end.
2302 /// Negative indices count from the end.
2303 ///
2304 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/slice)
2305 #[cfg(js_sys_unstable_apis)]
2306 #[wasm_bindgen(method, js_name = slice)]
2307 pub fn slice_from(this: &ArrayBuffer, begin: isize) -> ArrayBuffer;
2308
2309 // Next major: deprecate
2310 /// Like `slice()` but with the `end` argument.
2311 ///
2312 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/slice)
2313 #[wasm_bindgen(method, js_name = slice)]
2314 pub fn slice_with_end(this: &ArrayBuffer, begin: u32, end: u32) -> ArrayBuffer;
2315
2316 /// The `transfer()` method of ArrayBuffer instances creates a new `ArrayBuffer`
2317 /// with the same byte content as this buffer, then detaches this buffer.
2318 ///
2319 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/transfer)
2320 #[wasm_bindgen(method, catch)]
2321 pub fn transfer(this: &ArrayBuffer) -> Result<ArrayBuffer, JsValue>;
2322
2323 /// The `transfer()` method of `ArrayBuffer` instances creates a new `ArrayBuffer`
2324 /// with the same byte content as this buffer, then detaches this buffer.
2325 ///
2326 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/transfer)
2327 #[wasm_bindgen(method, catch, js_name = transfer)]
2328 pub fn transfer_with_length(
2329 this: &ArrayBuffer,
2330 new_byte_length: usize,
2331 ) -> Result<ArrayBuffer, JsValue>;
2332
2333 /// The `transferToFixedLength()` method of `ArrayBuffer` instances creates a new non-resizable
2334 /// ArrayBuffer with the same byte content as this buffer, then detaches this buffer.
2335 ///
2336 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/transferToFixedLength)
2337 #[wasm_bindgen(method, catch, js_name = transferToFixedLength)]
2338 pub fn transfer_to_fixed_length(this: &ArrayBuffer) -> Result<ArrayBuffer, JsValue>;
2339
2340 /// The `transferToFixedLength()` method of `ArrayBuffer` instances creates a new non-resizable
2341 /// `ArrayBuffer` with the same byte content as this buffer, then detaches this buffer.
2342 ///
2343 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/transferToFixedLength)
2344 #[wasm_bindgen(method, catch, js_name = transferToFixedLength)]
2345 pub fn transfer_to_fixed_length_with_length(
2346 this: &ArrayBuffer,
2347 new_byte_length: usize,
2348 ) -> Result<ArrayBuffer, JsValue>;
2349}
2350
2351impl UpcastFrom<&[u8]> for ArrayBuffer {}
2352
2353// SharedArrayBuffer
2354#[wasm_bindgen]
2355extern "C" {
2356 #[wasm_bindgen(extends = Object, typescript_type = "SharedArrayBuffer")]
2357 #[derive(Clone, Debug)]
2358 pub type SharedArrayBuffer;
2359
2360 /// The `SharedArrayBuffer` object is used to represent a generic,
2361 /// fixed-length raw binary data buffer, similar to the `ArrayBuffer`
2362 /// object, but in a way that they can be used to create views
2363 /// on shared memory. Unlike an `ArrayBuffer`, a `SharedArrayBuffer`
2364 /// cannot become detached.
2365 ///
2366 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer)
2367 #[cfg(not(js_sys_unstable_apis))]
2368 #[wasm_bindgen(constructor)]
2369 pub fn new(length: u32) -> SharedArrayBuffer;
2370
2371 /// The `SharedArrayBuffer` object is used to represent a generic,
2372 /// fixed-length raw binary data buffer, similar to the `ArrayBuffer`
2373 /// object, but in a way that they can be used to create views
2374 /// on shared memory. Unlike an `ArrayBuffer`, a `SharedArrayBuffer`
2375 /// cannot become detached.
2376 ///
2377 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer)
2378 #[cfg(js_sys_unstable_apis)]
2379 #[wasm_bindgen(constructor)]
2380 pub fn new(length: usize) -> SharedArrayBuffer;
2381
2382 /// The `SharedArrayBuffer` object is used to represent a generic,
2383 /// fixed-length raw binary data buffer, similar to the `ArrayBuffer`
2384 /// object, but in a way that they can be used to create views
2385 /// on shared memory. Unlike an `ArrayBuffer`, a `SharedArrayBuffer`
2386 /// cannot become detached.
2387 ///
2388 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer)
2389 #[wasm_bindgen(constructor)]
2390 pub fn new_with_options(length: usize, options: &ArrayBufferOptions) -> SharedArrayBuffer;
2391
2392 /// The `byteLength` accessor property represents the length of
2393 /// an `SharedArrayBuffer` in bytes. This is established when
2394 /// the `SharedArrayBuffer` is constructed and cannot be changed.
2395 ///
2396 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/byteLength)
2397 #[cfg(not(js_sys_unstable_apis))]
2398 #[wasm_bindgen(method, getter, js_name = byteLength)]
2399 pub fn byte_length(this: &SharedArrayBuffer) -> u32;
2400
2401 /// The `byteLength` accessor property represents the length of
2402 /// an `SharedArrayBuffer` in bytes. This is established when
2403 /// the `SharedArrayBuffer` is constructed and cannot be changed.
2404 ///
2405 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/byteLength)
2406 #[cfg(js_sys_unstable_apis)]
2407 #[wasm_bindgen(method, getter, js_name = byteLength)]
2408 pub fn byte_length(this: &SharedArrayBuffer) -> usize;
2409
2410 /// The `growable` accessor property of `SharedArrayBuffer` instances returns whether
2411 /// this `SharedArrayBuffer` can be grown or not.
2412 ///
2413 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/growable)
2414 #[wasm_bindgen(method, getter)]
2415 pub fn growable(this: &SharedArrayBuffer) -> bool;
2416
2417 /// The `grow()` method of `SharedArrayBuffer` instances grows the
2418 /// `SharedArrayBuffer` to the specified size, in bytes.
2419 ///
2420 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/grow)
2421 #[wasm_bindgen(method, catch)]
2422 pub fn grow(this: &SharedArrayBuffer, new_byte_length: usize) -> Result<(), JsValue>;
2423
2424 /// The `maxByteLength` accessor property of `SharedArrayBuffer` instances returns the maximum
2425 /// length (in bytes) that this `SharedArrayBuffer` can be resized to.
2426 ///
2427 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/maxByteLength)
2428 #[wasm_bindgen(method, getter, js_name = maxByteLength)]
2429 pub fn max_byte_length(this: &SharedArrayBuffer) -> usize;
2430
2431 /// The `slice()` method returns a new `SharedArrayBuffer` whose contents
2432 /// are a copy of this `SharedArrayBuffer`'s bytes from begin, inclusive,
2433 /// up to end, exclusive.
2434 ///
2435 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/slice)
2436 #[cfg(not(js_sys_unstable_apis))]
2437 #[wasm_bindgen(method)]
2438 pub fn slice(this: &SharedArrayBuffer, begin: u32) -> SharedArrayBuffer;
2439
2440 /// The `slice()` method returns a new `SharedArrayBuffer` whose contents
2441 /// are a copy of this `SharedArrayBuffer`'s bytes from begin, inclusive,
2442 /// up to end, exclusive. Negative indices count from the end.
2443 ///
2444 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/slice)
2445 #[cfg(js_sys_unstable_apis)]
2446 #[wasm_bindgen(method)]
2447 pub fn slice(this: &SharedArrayBuffer, begin: isize, end: isize) -> SharedArrayBuffer;
2448
2449 /// The `slice()` method returns a new `SharedArrayBuffer` whose contents
2450 /// are a copy of this `SharedArrayBuffer`'s bytes from begin, inclusive,
2451 /// up to end, exclusive.
2452 ///
2453 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/slice)
2454 #[cfg(not(js_sys_unstable_apis))]
2455 #[wasm_bindgen(method)]
2456 pub fn slice_from(this: &SharedArrayBuffer, begin: isize) -> SharedArrayBuffer;
2457
2458 /// The `slice()` method returns a new `SharedArrayBuffer` whose contents
2459 /// are a copy of this `SharedArrayBuffer`'s bytes from begin to end.
2460 /// Negative indices count from the end.
2461 ///
2462 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/slice)
2463 #[cfg(js_sys_unstable_apis)]
2464 #[wasm_bindgen(method)]
2465 pub fn slice_from(this: &SharedArrayBuffer, begin: isize) -> SharedArrayBuffer;
2466
2467 // Next major: deprecate
2468 /// Like `slice()` but with the `end` argument.
2469 ///
2470 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/slice)
2471 #[wasm_bindgen(method, js_name = slice)]
2472 pub fn slice_with_end(this: &SharedArrayBuffer, begin: u32, end: u32) -> SharedArrayBuffer;
2473}
2474
2475// Array Iterator
2476#[wasm_bindgen]
2477extern "C" {
2478 /// The `keys()` method returns a new Array Iterator object that contains the
2479 /// keys for each index in the array.
2480 ///
2481 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/keys)
2482 #[wasm_bindgen(method)]
2483 pub fn keys<T>(this: &Array<T>) -> Iterator<T>;
2484
2485 /// The `entries()` method returns a new Array Iterator object that contains
2486 /// the key/value pairs for each index in the array.
2487 ///
2488 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries)
2489 #[cfg(not(js_sys_unstable_apis))]
2490 #[wasm_bindgen(method)]
2491 #[deprecated(note = "recommended to use `Array::entries_typed` instead for typing")]
2492 #[allow(deprecated)]
2493 pub fn entries<T>(this: &Array<T>) -> Iterator<T>;
2494
2495 /// The `entries()` method returns a new Array Iterator object that contains
2496 /// the key/value pairs for each index in the array.
2497 ///
2498 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries)
2499 #[cfg(js_sys_unstable_apis)]
2500 #[wasm_bindgen(method)]
2501 pub fn entries<T: JsGeneric>(this: &Array<T>) -> Iterator<ArrayTuple<(Number, T)>>;
2502
2503 // Next major: deprecate
2504 /// The `entries()` method returns a new Array Iterator object that contains
2505 /// the key/value pairs for each index in the array.
2506 ///
2507 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries)
2508 #[wasm_bindgen(method, js_name = entries)]
2509 pub fn entries_typed<T: JsGeneric>(this: &Array<T>) -> Iterator<ArrayTuple<(Number, T)>>;
2510
2511 /// The `values()` method returns a new Array Iterator object that
2512 /// contains the values for each index in the array.
2513 ///
2514 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/values)
2515 #[wasm_bindgen(method)]
2516 pub fn values<T>(this: &Array<T>) -> Iterator<T>;
2517}
2518
2519// FIXME(next-major): rename this trait to `ArrayBufferView`. The DOM/WebIDL
2520// spec name `ArrayBufferView` covers both `DataView` and the typed-array
2521// types, which more accurately reflects the set of types that implement this
2522// trait. The `TypedArray` name is kept for now to avoid a breaking change.
2523pub trait TypedArray: JsGeneric {}
2524
2525impl TypedArray for DataView {}
2526
2527// Next major: use usize/isize for indices
2528/// The `Atomics` object provides atomic operations as static methods.
2529/// They are used with `SharedArrayBuffer` objects.
2530///
2531/// The Atomic operations are installed on an `Atomics` module. Unlike
2532/// the other global objects, `Atomics` is not a constructor. You cannot
2533/// use it with a new operator or invoke the `Atomics` object as a
2534/// function. All properties and methods of `Atomics` are static
2535/// (as is the case with the Math object, for example).
2536/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics)
2537#[allow(non_snake_case)]
2538pub mod Atomics {
2539 use super::*;
2540
2541 #[wasm_bindgen]
2542 extern "C" {
2543 /// The static `Atomics.add()` method adds a given value at a given
2544 /// position in the array and returns the old value at that position.
2545 /// This atomic operation guarantees that no other write happens
2546 /// until the modified value is written back.
2547 ///
2548 /// You should use `add_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2549 ///
2550 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/add)
2551 #[wasm_bindgen(js_namespace = Atomics, catch)]
2552 pub fn add<T: TypedArray = Int32Array>(
2553 typed_array: &T,
2554 index: u32,
2555 value: i32,
2556 ) -> Result<i32, JsValue>;
2557
2558 /// The static `Atomics.add()` method adds a given value at a given
2559 /// position in the array and returns the old value at that position.
2560 /// This atomic operation guarantees that no other write happens
2561 /// until the modified value is written back.
2562 ///
2563 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2564 ///
2565 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/add)
2566 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = add)]
2567 pub fn add_bigint<T: TypedArray = Int32Array>(
2568 typed_array: &T,
2569 index: u32,
2570 value: i64,
2571 ) -> Result<i64, JsValue>;
2572
2573 /// The static `Atomics.and()` method computes a bitwise AND with a given
2574 /// value at a given position in the array, and returns the old value
2575 /// at that position.
2576 /// This atomic operation guarantees that no other write happens
2577 /// until the modified value is written back.
2578 ///
2579 /// You should use `and_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2580 ///
2581 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/and)
2582 #[wasm_bindgen(js_namespace = Atomics, catch)]
2583 pub fn and<T: TypedArray = Int32Array>(
2584 typed_array: &T,
2585 index: u32,
2586 value: i32,
2587 ) -> Result<i32, JsValue>;
2588
2589 /// The static `Atomics.and()` method computes a bitwise AND with a given
2590 /// value at a given position in the array, and returns the old value
2591 /// at that position.
2592 /// This atomic operation guarantees that no other write happens
2593 /// until the modified value is written back.
2594 ///
2595 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2596 ///
2597 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/and)
2598 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = and)]
2599 pub fn and_bigint<T: TypedArray = Int32Array>(
2600 typed_array: &T,
2601 index: u32,
2602 value: i64,
2603 ) -> Result<i64, JsValue>;
2604
2605 /// The static `Atomics.compareExchange()` method exchanges a given
2606 /// replacement value at a given position in the array, if a given expected
2607 /// value equals the old value. It returns the old value at that position
2608 /// whether it was equal to the expected value or not.
2609 /// This atomic operation guarantees that no other write happens
2610 /// until the modified value is written back.
2611 ///
2612 /// You should use `compare_exchange_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2613 ///
2614 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/compareExchange)
2615 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = compareExchange)]
2616 pub fn compare_exchange<T: TypedArray = Int32Array>(
2617 typed_array: &T,
2618 index: u32,
2619 expected_value: i32,
2620 replacement_value: i32,
2621 ) -> Result<i32, JsValue>;
2622
2623 /// The static `Atomics.compareExchange()` method exchanges a given
2624 /// replacement value at a given position in the array, if a given expected
2625 /// value equals the old value. It returns the old value at that position
2626 /// whether it was equal to the expected value or not.
2627 /// This atomic operation guarantees that no other write happens
2628 /// until the modified value is written back.
2629 ///
2630 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2631 ///
2632 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/compareExchange)
2633 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = compareExchange)]
2634 pub fn compare_exchange_bigint<T: TypedArray = Int32Array>(
2635 typed_array: &T,
2636 index: u32,
2637 expected_value: i64,
2638 replacement_value: i64,
2639 ) -> Result<i64, JsValue>;
2640
2641 /// The static `Atomics.exchange()` method stores a given value at a given
2642 /// position in the array and returns the old value at that position.
2643 /// This atomic operation guarantees that no other write happens
2644 /// until the modified value is written back.
2645 ///
2646 /// You should use `exchange_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2647 ///
2648 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/exchange)
2649 #[wasm_bindgen(js_namespace = Atomics, catch)]
2650 pub fn exchange<T: TypedArray = Int32Array>(
2651 typed_array: &T,
2652 index: u32,
2653 value: i32,
2654 ) -> Result<i32, JsValue>;
2655
2656 /// The static `Atomics.exchange()` method stores a given value at a given
2657 /// position in the array and returns the old value at that position.
2658 /// This atomic operation guarantees that no other write happens
2659 /// until the modified value is written back.
2660 ///
2661 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2662 ///
2663 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/exchange)
2664 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = exchange)]
2665 pub fn exchange_bigint<T: TypedArray = Int32Array>(
2666 typed_array: &T,
2667 index: u32,
2668 value: i64,
2669 ) -> Result<i64, JsValue>;
2670
2671 /// The static `Atomics.isLockFree()` method is used to determine
2672 /// whether to use locks or atomic operations. It returns true,
2673 /// if the given size is one of the `BYTES_PER_ELEMENT` property
2674 /// of integer `TypedArray` types.
2675 ///
2676 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/isLockFree)
2677 #[wasm_bindgen(js_namespace = Atomics, js_name = isLockFree)]
2678 pub fn is_lock_free(size: u32) -> bool;
2679
2680 /// The static `Atomics.load()` method returns a value at a given
2681 /// position in the array.
2682 ///
2683 /// You should use `load_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2684 ///
2685 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/load)
2686 #[wasm_bindgen(js_namespace = Atomics, catch)]
2687 pub fn load<T: TypedArray = Int32Array>(
2688 typed_array: &T,
2689 index: u32,
2690 ) -> Result<i32, JsValue>;
2691
2692 /// The static `Atomics.load()` method returns a value at a given
2693 /// position in the array.
2694 ///
2695 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2696 ///
2697 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/load)
2698 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = load)]
2699 pub fn load_bigint<T: TypedArray = Int32Array>(
2700 typed_array: &T,
2701 index: i64,
2702 ) -> Result<i64, JsValue>;
2703
2704 /// The static `Atomics.notify()` method notifies up some agents that
2705 /// are sleeping in the wait queue.
2706 /// Note: This operation works with a shared `Int32Array` only.
2707 /// If `count` is not provided, notifies all the agents in the queue.
2708 ///
2709 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/notify)
2710 #[wasm_bindgen(js_namespace = Atomics, catch)]
2711 pub fn notify(typed_array: &Int32Array, index: u32) -> Result<u32, JsValue>;
2712
2713 /// The static `Atomics.notify()` method notifies up some agents that
2714 /// are sleeping in the wait queue.
2715 /// Note: This operation works with a shared `Int32Array` only.
2716 /// If `count` is not provided, notifies all the agents in the queue.
2717 ///
2718 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/notify)
2719 #[wasm_bindgen(js_namespace = Atomics, catch)]
2720 pub fn notify_bigint(typed_array: &BigInt64Array, index: u32) -> Result<u32, JsValue>;
2721
2722 /// Notifies up to `count` agents in the wait queue.
2723 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = notify)]
2724 pub fn notify_with_count(
2725 typed_array: &Int32Array,
2726 index: u32,
2727 count: u32,
2728 ) -> Result<u32, JsValue>;
2729
2730 /// Notifies up to `count` agents in the wait queue.
2731 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = notify)]
2732 pub fn notify_bigint_with_count(
2733 typed_array: &BigInt64Array,
2734 index: u32,
2735 count: u32,
2736 ) -> Result<u32, JsValue>;
2737
2738 /// The static `Atomics.or()` method computes a bitwise OR with a given value
2739 /// at a given position in the array, and returns the old value at that position.
2740 /// This atomic operation guarantees that no other write happens
2741 /// until the modified value is written back.
2742 ///
2743 /// You should use `or_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2744 ///
2745 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/or)
2746 #[wasm_bindgen(js_namespace = Atomics, catch)]
2747 pub fn or<T: TypedArray = Int32Array>(
2748 typed_array: &T,
2749 index: u32,
2750 value: i32,
2751 ) -> Result<i32, JsValue>;
2752
2753 /// The static `Atomics.or()` method computes a bitwise OR with a given value
2754 /// at a given position in the array, and returns the old value at that position.
2755 /// This atomic operation guarantees that no other write happens
2756 /// until the modified value is written back.
2757 ///
2758 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2759 ///
2760 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/or)
2761 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = or)]
2762 pub fn or_bigint<T: TypedArray = Int32Array>(
2763 typed_array: &T,
2764 index: u32,
2765 value: i64,
2766 ) -> Result<i64, JsValue>;
2767
2768 /// The static `Atomics.pause()` static method provides a micro-wait primitive that hints to the CPU
2769 /// that the caller is spinning while waiting on access to a shared resource. This allows the system
2770 /// to reduce the resources allocated to the core (such as power) or thread, without yielding the
2771 /// current thread.
2772 ///
2773 /// `pause()` has no observable behavior other than timing. The exact behavior is dependent on the CPU
2774 /// architecture and the operating system. For example, in Intel x86, it may be a pause instruction as
2775 /// per Intel's optimization manual. It could be a no-op in certain platforms.
2776 ///
2777 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2778 ///
2779 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/xor)
2780 #[wasm_bindgen(js_namespace = Atomics)]
2781 pub fn pause();
2782
2783 /// The static `Atomics.pause()` static method provides a micro-wait primitive that hints to the CPU
2784 /// that the caller is spinning while waiting on access to a shared resource. This allows the system
2785 /// to reduce the resources allocated to the core (such as power) or thread, without yielding the
2786 /// current thread.
2787 ///
2788 /// `pause()` has no observable behavior other than timing. The exact behavior is dependent on the CPU
2789 /// architecture and the operating system. For example, in Intel x86, it may be a pause instruction as
2790 /// per Intel's optimization manual. It could be a no-op in certain platforms.
2791 ///
2792 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2793 ///
2794 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/xor)
2795 #[wasm_bindgen(js_namespace = Atomics)]
2796 pub fn pause_with_hint(duration_hint: u32);
2797
2798 /// The static `Atomics.store()` method stores a given value at the given
2799 /// position in the array and returns that value.
2800 ///
2801 /// You should use `store_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2802 ///
2803 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/store)
2804 #[wasm_bindgen(js_namespace = Atomics, catch)]
2805 pub fn store<T: TypedArray = Int32Array>(
2806 typed_array: &T,
2807 index: u32,
2808 value: i32,
2809 ) -> Result<i32, JsValue>;
2810
2811 /// The static `Atomics.store()` method stores a given value at the given
2812 /// position in the array and returns that value.
2813 ///
2814 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2815 ///
2816 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/store)
2817 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = store)]
2818 pub fn store_bigint<T: TypedArray = Int32Array>(
2819 typed_array: &T,
2820 index: u32,
2821 value: i64,
2822 ) -> Result<i64, JsValue>;
2823
2824 /// The static `Atomics.sub()` method subtracts a given value at a
2825 /// given position in the array and returns the old value at that position.
2826 /// This atomic operation guarantees that no other write happens
2827 /// until the modified value is written back.
2828 ///
2829 /// You should use `sub_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2830 ///
2831 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/sub)
2832 #[wasm_bindgen(js_namespace = Atomics, catch)]
2833 pub fn sub<T: TypedArray = Int32Array>(
2834 typed_array: &T,
2835 index: u32,
2836 value: i32,
2837 ) -> Result<i32, JsValue>;
2838
2839 /// The static `Atomics.sub()` method subtracts a given value at a
2840 /// given position in the array and returns the old value at that position.
2841 /// This atomic operation guarantees that no other write happens
2842 /// until the modified value is written back.
2843 ///
2844 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2845 ///
2846 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/sub)
2847 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = sub)]
2848 pub fn sub_bigint<T: TypedArray = Int32Array>(
2849 typed_array: &T,
2850 index: u32,
2851 value: i64,
2852 ) -> Result<i64, JsValue>;
2853
2854 /// The static `Atomics.wait()` method verifies that a given
2855 /// position in an `Int32Array` still contains a given value
2856 /// and if so sleeps, awaiting a wakeup or a timeout.
2857 /// It returns a string which is either "ok", "not-equal", or "timed-out".
2858 /// Note: This operation only works with a shared `Int32Array`
2859 /// and may not be allowed on the main thread.
2860 ///
2861 /// You should use `wait_bigint` to operate on a `BigInt64Array`.
2862 ///
2863 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait)
2864 #[wasm_bindgen(js_namespace = Atomics, catch)]
2865 pub fn wait(typed_array: &Int32Array, index: u32, value: i32) -> Result<JsString, JsValue>;
2866
2867 /// The static `Atomics.wait()` method verifies that a given
2868 /// position in an `BigInt64Array` still contains a given value
2869 /// and if so sleeps, awaiting a wakeup or a timeout.
2870 /// It returns a string which is either "ok", "not-equal", or "timed-out".
2871 /// Note: This operation only works with a shared `BigInt64Array`
2872 /// and may not be allowed on the main thread.
2873 ///
2874 /// You should use `wait` to operate on a `Int32Array`.
2875 ///
2876 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait)
2877 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = wait)]
2878 pub fn wait_bigint(
2879 typed_array: &BigInt64Array,
2880 index: u32,
2881 value: i64,
2882 ) -> Result<JsString, JsValue>;
2883
2884 /// Like `wait()`, but with timeout
2885 ///
2886 /// You should use `wait_with_timeout_bigint` to operate on a `BigInt64Array`.
2887 ///
2888 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait)
2889 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = wait)]
2890 pub fn wait_with_timeout(
2891 typed_array: &Int32Array,
2892 index: u32,
2893 value: i32,
2894 timeout: f64,
2895 ) -> Result<JsString, JsValue>;
2896
2897 /// Like `wait()`, but with timeout
2898 ///
2899 /// You should use `wait_with_timeout` to operate on a `Int32Array`.
2900 ///
2901 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait)
2902 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = wait)]
2903 pub fn wait_with_timeout_bigint(
2904 typed_array: &BigInt64Array,
2905 index: u32,
2906 value: i64,
2907 timeout: f64,
2908 ) -> Result<JsString, JsValue>;
2909
2910 /// The static `Atomics.waitAsync()` method verifies that a given position in an
2911 /// `Int32Array` still contains a given value and if so sleeps, awaiting a
2912 /// wakeup or a timeout. It returns an object with two properties. The first
2913 /// property `async` is a boolean which if true indicates that the second
2914 /// property `value` is a promise. If `async` is false then value is a string
2915 /// whether equal to either "not-equal" or "timed-out".
2916 /// Note: This operation only works with a shared `Int32Array` and may be used
2917 /// on the main thread.
2918 ///
2919 /// You should use `wait_async_bigint` to operate on a `BigInt64Array`.
2920 ///
2921 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/waitAsync)
2922 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = waitAsync)]
2923 pub fn wait_async(
2924 typed_array: &Int32Array,
2925 index: u32,
2926 value: i32,
2927 ) -> Result<Object, JsValue>;
2928
2929 /// The static `Atomics.waitAsync()` method verifies that a given position in an
2930 /// `Int32Array` still contains a given value and if so sleeps, awaiting a
2931 /// wakeup or a timeout. It returns an object with two properties. The first
2932 /// property `async` is a boolean which if true indicates that the second
2933 /// property `value` is a promise. If `async` is false then value is a string
2934 /// whether equal to either "not-equal" or "timed-out".
2935 /// Note: This operation only works with a shared `BigInt64Array` and may be used
2936 /// on the main thread.
2937 ///
2938 /// You should use `wait_async` to operate on a `Int32Array`.
2939 ///
2940 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/waitAsync)
2941 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = waitAsync)]
2942 pub fn wait_async_bigint(
2943 typed_array: &BigInt64Array,
2944 index: u32,
2945 value: i64,
2946 ) -> Result<Object, JsValue>;
2947
2948 /// Like `waitAsync()`, but with timeout
2949 ///
2950 /// You should use `wait_async_with_timeout_bigint` to operate on a `BigInt64Array`.
2951 ///
2952 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/waitAsync)
2953 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = waitAsync)]
2954 pub fn wait_async_with_timeout(
2955 typed_array: &Int32Array,
2956 index: u32,
2957 value: i32,
2958 timeout: f64,
2959 ) -> Result<Object, JsValue>;
2960
2961 /// Like `waitAsync()`, but with timeout
2962 ///
2963 /// You should use `wait_async_with_timeout` to operate on a `Int32Array`.
2964 ///
2965 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/waitAsync)
2966 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = waitAsync)]
2967 pub fn wait_async_with_timeout_bigint(
2968 typed_array: &BigInt64Array,
2969 index: u32,
2970 value: i64,
2971 timeout: f64,
2972 ) -> Result<Object, JsValue>;
2973
2974 /// The static `Atomics.xor()` method computes a bitwise XOR
2975 /// with a given value at a given position in the array,
2976 /// and returns the old value at that position.
2977 /// This atomic operation guarantees that no other write happens
2978 /// until the modified value is written back.
2979 ///
2980 /// You should use `xor_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2981 ///
2982 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/xor)
2983 #[wasm_bindgen(js_namespace = Atomics, catch)]
2984 pub fn xor<T: TypedArray = Int32Array>(
2985 typed_array: &T,
2986 index: u32,
2987 value: i32,
2988 ) -> Result<i32, JsValue>;
2989
2990 /// The static `Atomics.xor()` method computes a bitwise XOR
2991 /// with a given value at a given position in the array,
2992 /// and returns the old value at that position.
2993 /// This atomic operation guarantees that no other write happens
2994 /// until the modified value is written back.
2995 ///
2996 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2997 ///
2998 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/xor)
2999 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = xor)]
3000 pub fn xor_bigint<T: TypedArray = Int32Array>(
3001 typed_array: &T,
3002 index: u32,
3003 value: i64,
3004 ) -> Result<i64, JsValue>;
3005 }
3006}
3007
3008// BigInt
3009#[wasm_bindgen]
3010extern "C" {
3011 #[wasm_bindgen(extends = Object, is_type_of = |v| v.is_bigint(), typescript_type = "bigint")]
3012 #[derive(Clone, PartialEq, Eq)]
3013 pub type BigInt;
3014
3015 #[wasm_bindgen(catch, js_name = BigInt)]
3016 fn new_bigint(value: &JsValue) -> Result<BigInt, Error>;
3017
3018 #[wasm_bindgen(js_name = BigInt)]
3019 fn new_bigint_unchecked(value: &JsValue) -> BigInt;
3020
3021 /// Clamps a BigInt value to a signed integer value, and returns that value.
3022 ///
3023 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/asIntN)
3024 #[wasm_bindgen(static_method_of = BigInt, js_name = asIntN)]
3025 pub fn as_int_n(bits: f64, bigint: &BigInt) -> BigInt;
3026
3027 /// Clamps a BigInt value to an unsigned integer value, and returns that value.
3028 ///
3029 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/asUintN)
3030 #[wasm_bindgen(static_method_of = BigInt, js_name = asUintN)]
3031 pub fn as_uint_n(bits: f64, bigint: &BigInt) -> BigInt;
3032
3033 /// 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.
3034 ///
3035 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/toLocaleString)
3036 #[cfg(not(js_sys_unstable_apis))]
3037 #[wasm_bindgen(method, js_name = toLocaleString)]
3038 pub fn to_locale_string(this: &BigInt, locales: &JsValue, options: &JsValue) -> JsString;
3039
3040 /// 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.
3041 ///
3042 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/toLocaleString)
3043 #[cfg(js_sys_unstable_apis)]
3044 #[wasm_bindgen(method, js_name = toLocaleString)]
3045 pub fn to_locale_string(
3046 this: &BigInt,
3047 locales: &[JsString],
3048 options: &Intl::NumberFormatOptions,
3049 ) -> JsString;
3050
3051 // Next major: deprecate
3052 /// 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.
3053 ///
3054 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/toString)
3055 #[wasm_bindgen(catch, method, js_name = toString)]
3056 pub fn to_string(this: &BigInt, radix: u8) -> Result<JsString, RangeError>;
3057
3058 /// Returns a string representing this BigInt value in the specified radix (base).
3059 ///
3060 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/toString)
3061 #[cfg(js_sys_unstable_apis)]
3062 #[wasm_bindgen(catch, method, js_name = toString)]
3063 pub fn to_string_with_radix(this: &BigInt, radix: u8) -> Result<JsString, RangeError>;
3064
3065 #[wasm_bindgen(method, js_name = toString)]
3066 fn to_string_unchecked(this: &BigInt, radix: u8) -> String;
3067
3068 /// Returns this BigInt value. Overrides the [`Object.prototype.valueOf()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf) method.
3069 ///
3070 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/valueOf)
3071 #[wasm_bindgen(method, js_name = valueOf)]
3072 pub fn value_of(this: &BigInt, radix: u8) -> BigInt;
3073}
3074
3075impl BigInt {
3076 /// Creates a new BigInt value.
3077 ///
3078 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/BigInt)
3079 #[inline]
3080 pub fn new(value: &JsValue) -> Result<BigInt, Error> {
3081 new_bigint(value)
3082 }
3083
3084 /// Applies the binary `/` JS operator on two `BigInt`s, catching and returning any `RangeError` thrown.
3085 ///
3086 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Division)
3087 pub fn checked_div(&self, rhs: &Self) -> Result<Self, RangeError> {
3088 let result = JsValue::as_ref(self).checked_div(JsValue::as_ref(rhs));
3089
3090 if result.is_instance_of::<RangeError>() {
3091 Err(result.unchecked_into())
3092 } else {
3093 Ok(result.unchecked_into())
3094 }
3095 }
3096
3097 /// Applies the binary `**` JS operator on the two `BigInt`s.
3098 ///
3099 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Exponentiation)
3100 #[inline]
3101 pub fn pow(&self, rhs: &Self) -> Self {
3102 JsValue::as_ref(self)
3103 .pow(JsValue::as_ref(rhs))
3104 .unchecked_into()
3105 }
3106
3107 /// Returns a tuple of this [`BigInt`]'s absolute value along with a
3108 /// [`bool`] indicating whether the [`BigInt`] was negative.
3109 fn abs(&self) -> (Self, bool) {
3110 if self < &BigInt::from(0) {
3111 (-self, true)
3112 } else {
3113 (self.clone(), false)
3114 }
3115 }
3116}
3117
3118macro_rules! bigint_from {
3119 ($($x:ident)*) => ($(
3120 impl From<$x> for BigInt {
3121 #[inline]
3122 fn from(x: $x) -> BigInt {
3123 new_bigint_unchecked(&JsValue::from(x))
3124 }
3125 }
3126
3127 impl PartialEq<$x> for BigInt {
3128 #[inline]
3129 fn eq(&self, other: &$x) -> bool {
3130 JsValue::from(self) == JsValue::from(BigInt::from(*other))
3131 }
3132 }
3133 )*)
3134}
3135bigint_from!(i8 u8 i16 u16 i32 u32 isize usize);
3136
3137macro_rules! bigint_from_big {
3138 ($($x:ident)*) => ($(
3139 impl From<$x> for BigInt {
3140 #[inline]
3141 fn from(x: $x) -> BigInt {
3142 JsValue::from(x).unchecked_into()
3143 }
3144 }
3145
3146 impl PartialEq<$x> for BigInt {
3147 #[inline]
3148 fn eq(&self, other: &$x) -> bool {
3149 self == &BigInt::from(*other)
3150 }
3151 }
3152
3153 impl TryFrom<BigInt> for $x {
3154 type Error = BigInt;
3155
3156 #[inline]
3157 fn try_from(x: BigInt) -> Result<Self, BigInt> {
3158 Self::try_from(JsValue::from(x)).map_err(JsCast::unchecked_into)
3159 }
3160 }
3161 )*)
3162}
3163bigint_from_big!(i64 u64 i128 u128);
3164
3165impl PartialEq<Number> for BigInt {
3166 #[inline]
3167 fn eq(&self, other: &Number) -> bool {
3168 JsValue::as_ref(self).loose_eq(JsValue::as_ref(other))
3169 }
3170}
3171
3172impl Not for &BigInt {
3173 type Output = BigInt;
3174
3175 #[inline]
3176 fn not(self) -> Self::Output {
3177 JsValue::as_ref(self).bit_not().unchecked_into()
3178 }
3179}
3180
3181forward_deref_unop!(impl Not, not for BigInt);
3182forward_js_unop!(impl Neg, neg for BigInt);
3183forward_js_binop!(impl BitAnd, bitand for BigInt);
3184forward_js_binop!(impl BitOr, bitor for BigInt);
3185forward_js_binop!(impl BitXor, bitxor for BigInt);
3186forward_js_binop!(impl Shl, shl for BigInt);
3187forward_js_binop!(impl Shr, shr for BigInt);
3188forward_js_binop!(impl Add, add for BigInt);
3189forward_js_binop!(impl Sub, sub for BigInt);
3190forward_js_binop!(impl Div, div for BigInt);
3191forward_js_binop!(impl Mul, mul for BigInt);
3192forward_js_binop!(impl Rem, rem for BigInt);
3193sum_product!(BigInt);
3194
3195partialord_ord!(BigInt);
3196
3197impl Default for BigInt {
3198 fn default() -> Self {
3199 BigInt::from(i32::default())
3200 }
3201}
3202
3203impl FromStr for BigInt {
3204 type Err = Error;
3205
3206 #[inline]
3207 fn from_str(s: &str) -> Result<Self, Self::Err> {
3208 BigInt::new(&s.into())
3209 }
3210}
3211
3212impl fmt::Debug for BigInt {
3213 #[inline]
3214 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3215 fmt::Display::fmt(self, f)
3216 }
3217}
3218
3219impl fmt::Display for BigInt {
3220 #[inline]
3221 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3222 let (abs, is_neg) = self.abs();
3223 f.pad_integral(!is_neg, "", &abs.to_string_unchecked(10))
3224 }
3225}
3226
3227impl fmt::Binary for BigInt {
3228 #[inline]
3229 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3230 let (abs, is_neg) = self.abs();
3231 f.pad_integral(!is_neg, "0b", &abs.to_string_unchecked(2))
3232 }
3233}
3234
3235impl fmt::Octal for BigInt {
3236 #[inline]
3237 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3238 let (abs, is_neg) = self.abs();
3239 f.pad_integral(!is_neg, "0o", &abs.to_string_unchecked(8))
3240 }
3241}
3242
3243impl fmt::LowerHex for BigInt {
3244 #[inline]
3245 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3246 let (abs, is_neg) = self.abs();
3247 f.pad_integral(!is_neg, "0x", &abs.to_string_unchecked(16))
3248 }
3249}
3250
3251impl fmt::UpperHex for BigInt {
3252 #[inline]
3253 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3254 let (abs, is_neg) = self.abs();
3255 let mut s: String = abs.to_string_unchecked(16);
3256 s.make_ascii_uppercase();
3257 f.pad_integral(!is_neg, "0x", &s)
3258 }
3259}
3260
3261// Boolean
3262#[wasm_bindgen]
3263extern "C" {
3264 #[wasm_bindgen(extends = Object, is_type_of = |v| v.as_bool().is_some(), typescript_type = "boolean")]
3265 #[derive(Clone, PartialEq, Eq)]
3266 pub type Boolean;
3267
3268 /// The `Boolean()` constructor creates an object wrapper for a boolean value.
3269 ///
3270 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)
3271 #[cfg(not(js_sys_unstable_apis))]
3272 #[wasm_bindgen(constructor)]
3273 #[deprecated(note = "recommended to use `Boolean::from` instead")]
3274 #[allow(deprecated)]
3275 pub fn new(value: &JsValue) -> Boolean;
3276
3277 /// The `valueOf()` method returns the primitive value of a `Boolean` object.
3278 ///
3279 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean/valueOf)
3280 #[wasm_bindgen(method, js_name = valueOf)]
3281 pub fn value_of(this: &Boolean) -> bool;
3282}
3283
3284impl UpcastFrom<bool> for Boolean {}
3285impl UpcastFrom<Boolean> for bool {}
3286
3287impl Boolean {
3288 /// Typed Boolean true constant.
3289 pub const TRUE: Boolean = Self {
3290 obj: Object {
3291 obj: JsValue::TRUE,
3292 generics: PhantomData,
3293 },
3294 };
3295
3296 /// Typed Boolean false constant.
3297 pub const FALSE: Boolean = Self {
3298 obj: Object {
3299 obj: JsValue::FALSE,
3300 generics: PhantomData,
3301 },
3302 };
3303}
3304
3305impl From<bool> for Boolean {
3306 #[inline]
3307 fn from(b: bool) -> Boolean {
3308 Boolean::unchecked_from_js(JsValue::from(b))
3309 }
3310}
3311
3312impl From<Boolean> for bool {
3313 #[inline]
3314 fn from(b: Boolean) -> bool {
3315 b.value_of()
3316 }
3317}
3318
3319impl PartialEq<bool> for Boolean {
3320 #[inline]
3321 fn eq(&self, other: &bool) -> bool {
3322 self.value_of() == *other
3323 }
3324}
3325
3326impl fmt::Debug for Boolean {
3327 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3328 fmt::Debug::fmt(&self.value_of(), f)
3329 }
3330}
3331
3332impl fmt::Display for Boolean {
3333 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3334 fmt::Display::fmt(&self.value_of(), f)
3335 }
3336}
3337
3338impl Default for Boolean {
3339 fn default() -> Self {
3340 Self::from(bool::default())
3341 }
3342}
3343
3344impl Not for &Boolean {
3345 type Output = Boolean;
3346
3347 #[inline]
3348 fn not(self) -> Self::Output {
3349 (!JsValue::as_ref(self)).into()
3350 }
3351}
3352
3353forward_deref_unop!(impl Not, not for Boolean);
3354
3355partialord_ord!(Boolean);
3356
3357// DataView
3358#[wasm_bindgen]
3359extern "C" {
3360 #[wasm_bindgen(extends = Object, typescript_type = "DataView")]
3361 #[derive(Clone, Debug, PartialEq, Eq)]
3362 pub type DataView;
3363
3364 /// The `DataView` view provides a low-level interface for reading and
3365 /// writing multiple number types in an `ArrayBuffer` irrespective of the
3366 /// platform's endianness.
3367 ///
3368 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView)
3369 #[wasm_bindgen(constructor)]
3370 pub fn new(buffer: &ArrayBuffer, byteOffset: usize, byteLength: usize) -> DataView;
3371
3372 /// The `DataView` view provides a low-level interface for reading and
3373 /// writing multiple number types in an `ArrayBuffer` irrespective of the
3374 /// platform's endianness.
3375 ///
3376 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView)
3377 #[wasm_bindgen(constructor)]
3378 pub fn new_with_shared_array_buffer(
3379 buffer: &SharedArrayBuffer,
3380 byteOffset: usize,
3381 byteLength: usize,
3382 ) -> DataView;
3383
3384 /// The ArrayBuffer referenced by this view. Fixed at construction time and thus read only.
3385 ///
3386 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/buffer)
3387 #[wasm_bindgen(method, getter)]
3388 pub fn buffer(this: &DataView) -> ArrayBuffer;
3389
3390 /// The length (in bytes) of this view from the start of its ArrayBuffer.
3391 /// Fixed at construction time and thus read only.
3392 ///
3393 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/byteLength)
3394 #[wasm_bindgen(method, getter, js_name = byteLength)]
3395 pub fn byte_length(this: &DataView) -> usize;
3396
3397 /// The offset (in bytes) of this view from the start of its ArrayBuffer.
3398 /// Fixed at construction time and thus read only.
3399 ///
3400 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/byteOffset)
3401 #[wasm_bindgen(method, getter, js_name = byteOffset)]
3402 pub fn byte_offset(this: &DataView) -> usize;
3403
3404 /// The `getInt8()` method gets a signed 8-bit integer (byte) at the
3405 /// specified byte offset from the start of the DataView.
3406 ///
3407 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt8)
3408 #[wasm_bindgen(method, js_name = getInt8)]
3409 pub fn get_int8(this: &DataView, byte_offset: usize) -> i8;
3410
3411 /// The `getUint8()` method gets a unsigned 8-bit integer (byte) at the specified
3412 /// byte offset from the start of the DataView.
3413 ///
3414 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint8)
3415 #[wasm_bindgen(method, js_name = getUint8)]
3416 pub fn get_uint8(this: &DataView, byte_offset: usize) -> u8;
3417
3418 /// The `getInt16()` method gets a signed 16-bit integer (short) at the specified
3419 /// byte offset from the start of the DataView.
3420 ///
3421 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt16)
3422 #[wasm_bindgen(method, js_name = getInt16)]
3423 pub fn get_int16(this: &DataView, byte_offset: usize) -> i16;
3424
3425 /// The `getInt16()` method gets a signed 16-bit integer (short) at the specified
3426 /// byte offset from the start of the DataView.
3427 ///
3428 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt16)
3429 #[wasm_bindgen(method, js_name = getInt16)]
3430 pub fn get_int16_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> i16;
3431
3432 /// The `getUint16()` method gets an unsigned 16-bit integer (unsigned short) at the specified
3433 /// byte offset from the start of the view.
3434 ///
3435 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint16)
3436 #[wasm_bindgen(method, js_name = getUint16)]
3437 pub fn get_uint16(this: &DataView, byte_offset: usize) -> u16;
3438
3439 /// The `getUint16()` method gets an unsigned 16-bit integer (unsigned short) at the specified
3440 /// byte offset from the start of the view.
3441 ///
3442 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint16)
3443 #[wasm_bindgen(method, js_name = getUint16)]
3444 pub fn get_uint16_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> u16;
3445
3446 /// The `getInt32()` method gets a signed 32-bit integer (long) at the specified
3447 /// byte offset from the start of the DataView.
3448 ///
3449 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt32)
3450 #[wasm_bindgen(method, js_name = getInt32)]
3451 pub fn get_int32(this: &DataView, byte_offset: usize) -> i32;
3452
3453 /// The `getInt32()` method gets a signed 32-bit integer (long) at the specified
3454 /// byte offset from the start of the DataView.
3455 ///
3456 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt32)
3457 #[wasm_bindgen(method, js_name = getInt32)]
3458 pub fn get_int32_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> i32;
3459
3460 /// The `getUint32()` method gets an unsigned 32-bit integer (unsigned long) at the specified
3461 /// byte offset from the start of the view.
3462 ///
3463 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint32)
3464 #[wasm_bindgen(method, js_name = getUint32)]
3465 pub fn get_uint32(this: &DataView, byte_offset: usize) -> u32;
3466
3467 /// The `getUint32()` method gets an unsigned 32-bit integer (unsigned long) at the specified
3468 /// byte offset from the start of the view.
3469 ///
3470 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint32)
3471 #[wasm_bindgen(method, js_name = getUint32)]
3472 pub fn get_uint32_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> u32;
3473
3474 /// The `getFloat32()` method gets a signed 32-bit float (float) at the specified
3475 /// byte offset from the start of the DataView.
3476 ///
3477 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat32)
3478 #[wasm_bindgen(method, js_name = getFloat32)]
3479 pub fn get_float32(this: &DataView, byte_offset: usize) -> f32;
3480
3481 /// The `getFloat32()` method gets a signed 32-bit float (float) at the specified
3482 /// byte offset from the start of the DataView.
3483 ///
3484 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat32)
3485 #[wasm_bindgen(method, js_name = getFloat32)]
3486 pub fn get_float32_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> f32;
3487
3488 /// The `getFloat16()` method gets a signed 16-bit float at the specified
3489 /// byte offset from the start of the DataView as an `f32`.
3490 ///
3491 /// The unsuffixed `get_float16` name is reserved for a future native
3492 /// `f16` binding once Rust stabilizes the type.
3493 ///
3494 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat16)
3495 #[wasm_bindgen(method, js_name = getFloat16)]
3496 pub fn get_float16_as_f32(this: &DataView, byte_offset: usize) -> f32;
3497
3498 /// The `getFloat16()` method gets a signed 16-bit float at the specified
3499 /// byte offset from the start of the DataView as an `f32`.
3500 ///
3501 /// The unsuffixed `get_float16_endian` name is reserved for a future
3502 /// native `f16` binding once Rust stabilizes the type.
3503 ///
3504 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat16)
3505 #[wasm_bindgen(method, js_name = getFloat16)]
3506 pub fn get_float16_endian_as_f32(
3507 this: &DataView,
3508 byte_offset: usize,
3509 little_endian: bool,
3510 ) -> f32;
3511
3512 /// The `getFloat64()` method gets a signed 64-bit float (double) at the specified
3513 /// byte offset from the start of the DataView.
3514 ///
3515 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat64)
3516 #[wasm_bindgen(method, js_name = getFloat64)]
3517 pub fn get_float64(this: &DataView, byte_offset: usize) -> f64;
3518
3519 /// The `getFloat64()` method gets a signed 64-bit float (double) at the specified
3520 /// byte offset from the start of the DataView.
3521 ///
3522 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat64)
3523 #[wasm_bindgen(method, js_name = getFloat64)]
3524 pub fn get_float64_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> f64;
3525
3526 /// The `setInt8()` method stores a signed 8-bit integer (byte) value at the
3527 /// specified byte offset from the start of the DataView.
3528 ///
3529 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt8)
3530 #[wasm_bindgen(method, js_name = setInt8)]
3531 pub fn set_int8(this: &DataView, byte_offset: usize, value: i8);
3532
3533 /// The `setUint8()` method stores an unsigned 8-bit integer (byte) value at the
3534 /// specified byte offset from the start of the DataView.
3535 ///
3536 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint8)
3537 #[wasm_bindgen(method, js_name = setUint8)]
3538 pub fn set_uint8(this: &DataView, byte_offset: usize, value: u8);
3539
3540 /// The `setInt16()` method stores a signed 16-bit integer (short) value at the
3541 /// specified byte offset from the start of the DataView.
3542 ///
3543 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt16)
3544 #[wasm_bindgen(method, js_name = setInt16)]
3545 pub fn set_int16(this: &DataView, byte_offset: usize, value: i16);
3546
3547 /// The `setInt16()` method stores a signed 16-bit integer (short) value at the
3548 /// specified byte offset from the start of the DataView.
3549 ///
3550 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt16)
3551 #[wasm_bindgen(method, js_name = setInt16)]
3552 pub fn set_int16_endian(this: &DataView, byte_offset: usize, value: i16, little_endian: bool);
3553
3554 /// The `setUint16()` method stores an unsigned 16-bit integer (unsigned short) value at the
3555 /// specified byte offset from the start of the DataView.
3556 ///
3557 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint16)
3558 #[wasm_bindgen(method, js_name = setUint16)]
3559 pub fn set_uint16(this: &DataView, byte_offset: usize, value: u16);
3560
3561 /// The `setUint16()` method stores an unsigned 16-bit integer (unsigned short) value at the
3562 /// specified byte offset from the start of the DataView.
3563 ///
3564 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint16)
3565 #[wasm_bindgen(method, js_name = setUint16)]
3566 pub fn set_uint16_endian(this: &DataView, byte_offset: usize, value: u16, little_endian: bool);
3567
3568 /// The `setInt32()` method stores a signed 32-bit integer (long) value at the
3569 /// specified byte offset from the start of the DataView.
3570 ///
3571 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt32)
3572 #[wasm_bindgen(method, js_name = setInt32)]
3573 pub fn set_int32(this: &DataView, byte_offset: usize, value: i32);
3574
3575 /// The `setInt32()` method stores a signed 32-bit integer (long) value at the
3576 /// specified byte offset from the start of the DataView.
3577 ///
3578 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt32)
3579 #[wasm_bindgen(method, js_name = setInt32)]
3580 pub fn set_int32_endian(this: &DataView, byte_offset: usize, value: i32, little_endian: bool);
3581
3582 /// The `setUint32()` method stores an unsigned 32-bit integer (unsigned long) value at the
3583 /// specified byte offset from the start of the DataView.
3584 ///
3585 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint32)
3586 #[wasm_bindgen(method, js_name = setUint32)]
3587 pub fn set_uint32(this: &DataView, byte_offset: usize, value: u32);
3588
3589 /// The `setUint32()` method stores an unsigned 32-bit integer (unsigned long) value at the
3590 /// specified byte offset from the start of the DataView.
3591 ///
3592 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint32)
3593 #[wasm_bindgen(method, js_name = setUint32)]
3594 pub fn set_uint32_endian(this: &DataView, byte_offset: usize, value: u32, little_endian: bool);
3595
3596 /// The `setFloat32()` method stores a signed 32-bit float (float) value at the
3597 /// specified byte offset from the start of the DataView.
3598 ///
3599 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat32)
3600 #[wasm_bindgen(method, js_name = setFloat32)]
3601 pub fn set_float32(this: &DataView, byte_offset: usize, value: f32);
3602
3603 /// The `setFloat32()` method stores a signed 32-bit float (float) value at the
3604 /// specified byte offset from the start of the DataView.
3605 ///
3606 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat32)
3607 #[wasm_bindgen(method, js_name = setFloat32)]
3608 pub fn set_float32_endian(this: &DataView, byte_offset: usize, value: f32, little_endian: bool);
3609
3610 /// The `setFloat16()` method stores a signed 16-bit float value from an
3611 /// `f32` at the specified byte offset from the start of the DataView.
3612 ///
3613 /// The unsuffixed `set_float16` name is reserved for a future native
3614 /// `f16` binding once Rust stabilizes the type.
3615 ///
3616 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat16)
3617 #[wasm_bindgen(method, js_name = setFloat16)]
3618 pub fn set_float16_from_f32(this: &DataView, byte_offset: usize, value: f32);
3619
3620 /// The `setFloat16()` method stores a signed 16-bit float value from an
3621 /// `f32` at the specified byte offset from the start of the DataView.
3622 ///
3623 /// The unsuffixed `set_float16_endian` name is reserved for a future
3624 /// native `f16` binding once Rust stabilizes the type.
3625 ///
3626 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat16)
3627 #[wasm_bindgen(method, js_name = setFloat16)]
3628 pub fn set_float16_endian_from_f32(
3629 this: &DataView,
3630 byte_offset: usize,
3631 value: f32,
3632 little_endian: bool,
3633 );
3634
3635 /// The `setFloat64()` method stores a signed 64-bit float (double) value at the
3636 /// specified byte offset from the start of the DataView.
3637 ///
3638 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat64)
3639 #[wasm_bindgen(method, js_name = setFloat64)]
3640 pub fn set_float64(this: &DataView, byte_offset: usize, value: f64);
3641
3642 /// The `setFloat64()` method stores a signed 64-bit float (double) value at the
3643 /// specified byte offset from the start of the DataView.
3644 ///
3645 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat64)
3646 #[wasm_bindgen(method, js_name = setFloat64)]
3647 pub fn set_float64_endian(this: &DataView, byte_offset: usize, value: f64, little_endian: bool);
3648}
3649
3650// Error
3651#[wasm_bindgen]
3652extern "C" {
3653 #[wasm_bindgen(extends = Object, typescript_type = "Error")]
3654 #[derive(Clone, Debug, PartialEq, Eq)]
3655 pub type Error;
3656
3657 /// The Error constructor creates an error object.
3658 /// Instances of Error objects are thrown when runtime errors occur.
3659 /// The Error object can also be used as a base object for user-defined exceptions.
3660 /// See below for standard built-in error types.
3661 ///
3662 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)
3663 #[wasm_bindgen(constructor)]
3664 pub fn new(message: &str) -> Error;
3665
3666 /// Creates a new `Error` with the given message and an untyped options
3667 /// object whose `cause` property indicates the original cause of the
3668 /// error.
3669 ///
3670 /// New code should prefer [`Error::new_with_error_options`], which takes
3671 /// a typed [`ErrorOptions`] dictionary.
3672 ///
3673 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/Error)
3674 #[wasm_bindgen(constructor)]
3675 pub fn new_with_options(message: &str, options: &Object) -> Error;
3676
3677 /// Creates a new `Error` with the given message and a typed
3678 /// [`ErrorOptions`] dictionary whose `cause` property indicates the
3679 /// original cause of the error.
3680 ///
3681 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/Error)
3682 #[wasm_bindgen(constructor)]
3683 pub fn new_with_error_options(message: &str, options: &ErrorOptions) -> Error;
3684
3685 /// The cause property is the underlying cause of the error.
3686 /// Usually this is used to add context to re-thrown errors.
3687 ///
3688 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error#differentiate_between_similar_errors)
3689 #[wasm_bindgen(method, getter)]
3690 pub fn cause(this: &Error) -> JsValue;
3691 #[wasm_bindgen(method, setter)]
3692 pub fn set_cause(this: &Error, cause: &JsValue);
3693
3694 /// The message property is a human-readable description of the error.
3695 ///
3696 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/message)
3697 #[wasm_bindgen(method, getter)]
3698 pub fn message(this: &Error) -> JsString;
3699 #[wasm_bindgen(method, setter)]
3700 pub fn set_message(this: &Error, message: &str);
3701
3702 /// The name property represents a name for the type of error. The initial value is "Error".
3703 ///
3704 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/name)
3705 #[wasm_bindgen(method, getter)]
3706 pub fn name(this: &Error) -> JsString;
3707 #[wasm_bindgen(method, setter)]
3708 pub fn set_name(this: &Error, name: &str);
3709
3710 /// The `toString()` method returns a string representing the specified Error object
3711 ///
3712 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/toString)
3713 #[cfg(not(js_sys_unstable_apis))]
3714 #[wasm_bindgen(method, js_name = toString)]
3715 pub fn to_string(this: &Error) -> JsString;
3716
3717 /// The `Error.stackTraceLimit` property controls the number of stack
3718 /// frames collected by a stack trace.
3719 ///
3720 /// This is a non-standard V8/Node.js API.
3721 ///
3722 /// [V8 documentation](https://v8.dev/docs/stack-trace-api#stack-trace-collection-for-custom-exceptions)
3723 #[wasm_bindgen(static_method_of = Error, getter, js_name = stackTraceLimit)]
3724 pub fn stack_trace_limit() -> JsValue;
3725
3726 /// Set `Error.stackTraceLimit` to control the number of stack frames
3727 /// collected by a stack trace.
3728 ///
3729 /// This is a non-standard V8/Node.js API.
3730 ///
3731 /// [V8 documentation](https://v8.dev/docs/stack-trace-api#stack-trace-collection-for-custom-exceptions)
3732 #[wasm_bindgen(static_method_of = Error, setter, js_name = stackTraceLimit)]
3733 pub fn set_stack_trace_limit(value: &JsValue);
3734}
3735
3736partialord_ord!(JsString);
3737
3738// EvalError
3739#[wasm_bindgen]
3740extern "C" {
3741 #[wasm_bindgen(extends = Object, extends = Error, typescript_type = "EvalError")]
3742 #[derive(Clone, Debug, PartialEq, Eq)]
3743 pub type EvalError;
3744
3745 /// The `EvalError` object indicates an error regarding the global eval() function. This
3746 /// exception is not thrown by JavaScript anymore, however the EvalError object remains for
3747 /// compatibility.
3748 ///
3749 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/EvalError)
3750 #[wasm_bindgen(constructor)]
3751 pub fn new(message: &str) -> EvalError;
3752
3753 /// Creates a new `EvalError` with the given message and a typed
3754 /// [`ErrorOptions`] dictionary whose `cause` property indicates the
3755 /// original cause of the error.
3756 ///
3757 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/EvalError/EvalError)
3758 #[wasm_bindgen(constructor)]
3759 pub fn new_with_options(message: &str, options: &ErrorOptions) -> EvalError;
3760}
3761
3762#[wasm_bindgen]
3763extern "C" {
3764 #[wasm_bindgen(extends = Object, is_type_of = JsValue::is_function, no_upcast, typescript_type = "Function")]
3765 #[derive(Clone, Debug, PartialEq, Eq)]
3766 /// `Function` represents any generic Function in JS, by treating all arguments as `JsValue`.
3767 ///
3768 /// It takes a generic parameter of phantom type `fn (Arg1, ..., Argn) -> Ret` which
3769 /// is used to type the JS function. For example, `Function<fn () -> Number>` represents
3770 /// a function taking no arguments that returns a number.
3771 ///
3772 /// The 8 generic argument parameters (`Arg1` through `Arg8`) are the argument
3773 /// types. Arguments not provided enable strict arity checking at compile time.
3774 ///
3775 /// A void function is represented by `fn (Arg) -> Undefined`, and **not** the `()` unit
3776 /// type. This is because generics must be based on JS values in the JS generic type system.
3777 ///
3778 /// _The default without any parameters is as a void function - no arguments, `Undefined` return._
3779 ///
3780 /// _The default generic for `Function` is `fn (JsValue, JsValue, ...) -> JsValue`,
3781 /// representing any function, since all functions safely upcast into this function._
3782 ///
3783 /// ### Arity Enforcement
3784 ///
3785 /// It is not possible to use `call4` or `bind4` on a function that does not have
3786 /// at least 4 arguments — the compiler will reject this because only arguments that
3787 /// are not `None` support the trait bound for `ErasableGeneric`.
3788 ///
3789 /// ### Examples
3790 ///
3791 /// ```ignore
3792 /// // A function taking no args, returning Number
3793 /// let f: Function<Number> = get_some_fn();
3794 ///
3795 /// // A function taking (String, Number) and returning Boolean
3796 /// let f: Function<Boolean, String, Number> = get_some_fn();
3797 ///
3798 /// ### Upcasting
3799 ///
3800 /// To pass a typed `Function` where a different generic Function is expected, `upcast()` may be used
3801 /// to convert into any generic `Function` at zero cost with type-safety.
3802 ///
3803 /// MDN documentation (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
3804 pub type Function<
3805 T: JsFunction = fn(
3806 JsValue,
3807 JsValue,
3808 JsValue,
3809 JsValue,
3810 JsValue,
3811 JsValue,
3812 JsValue,
3813 JsValue,
3814 ) -> JsValue,
3815 >;
3816}
3817
3818#[wasm_bindgen]
3819extern "C" {
3820 /// The `Function` constructor creates a new `Function` object. Calling the
3821 /// constructor directly can create functions dynamically, but suffers from
3822 /// security and similar (but far less significant) performance issues
3823 /// similar to `eval`. However, unlike `eval`, the `Function` constructor
3824 /// allows executing code in the global scope, prompting better programming
3825 /// habits and allowing for more efficient code minification.
3826 ///
3827 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
3828 #[cfg(all(feature = "unsafe-eval", not(js_sys_unstable_apis)))]
3829 #[wasm_bindgen(constructor)]
3830 pub fn new_with_args(args: &str, body: &str) -> Function;
3831
3832 /// The `Function` constructor creates a new `Function` object. Calling the
3833 /// constructor directly can create functions dynamically, but suffers from
3834 /// security and similar (but far less significant) performance issues
3835 /// similar to `eval`. However, unlike `eval`, the `Function` constructor
3836 /// allows executing code in the global scope, prompting better programming
3837 /// habits and allowing for more efficient code minification.
3838 ///
3839 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
3840 #[cfg(all(feature = "unsafe-eval", js_sys_unstable_apis))]
3841 #[wasm_bindgen(constructor)]
3842 pub fn new_with_args<T: JsFunction = fn() -> JsValue>(args: &str, body: &str) -> Function<T>;
3843
3844 // Next major: deprecate
3845 /// The `Function` constructor creates a new `Function` object. Calling the
3846 /// constructor directly can create functions dynamically, but suffers from
3847 /// security and similar (but far less significant) performance issues
3848 /// similar to `eval`. However, unlike `eval`, the `Function` constructor
3849 /// allows executing code in the global scope, prompting better programming
3850 /// habits and allowing for more efficient code minification.
3851 ///
3852 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
3853 #[cfg(feature = "unsafe-eval")]
3854 #[wasm_bindgen(constructor)]
3855 pub fn new_with_args_typed<T: JsFunction = fn() -> JsValue>(
3856 args: &str,
3857 body: &str,
3858 ) -> Function<T>;
3859
3860 /// The `Function` constructor creates a new `Function` object. Calling the
3861 /// constructor directly can create functions dynamically, but suffers from
3862 /// security and similar (but far less significant) performance issues
3863 /// similar to `eval`. However, unlike `eval`, the `Function` constructor
3864 /// allows executing code in the global scope, prompting better programming
3865 /// habits and allowing for more efficient code minification.
3866 ///
3867 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
3868 #[cfg(all(feature = "unsafe-eval", not(js_sys_unstable_apis)))]
3869 #[wasm_bindgen(constructor)]
3870 pub fn new_no_args(body: &str) -> Function;
3871
3872 /// The `Function` constructor creates a new `Function` object. Calling the
3873 /// constructor directly can create functions dynamically, but suffers from
3874 /// security and similar (but far less significant) performance issues
3875 /// similar to `eval`. However, unlike `eval`, the `Function` constructor
3876 /// allows executing code in the global scope, prompting better programming
3877 /// habits and allowing for more efficient code minification.
3878 ///
3879 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
3880 #[cfg(all(feature = "unsafe-eval", js_sys_unstable_apis))]
3881 #[wasm_bindgen(constructor)]
3882 pub fn new_no_args<T: JsFunction = fn() -> JsValue>(body: &str) -> Function<T>;
3883
3884 // Next major: deprecate
3885 /// The `Function` constructor creates a new `Function` object.
3886 ///
3887 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
3888 #[cfg(feature = "unsafe-eval")]
3889 #[wasm_bindgen(constructor)]
3890 pub fn new_no_args_typed<T: JsFunction = fn() -> JsValue>(body: &str) -> Function<T>;
3891
3892 /// The `apply()` method calls a function with a given this value, and arguments provided as an array
3893 /// (or an array-like object).
3894 ///
3895 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply)
3896 #[wasm_bindgen(method, catch)]
3897 pub fn apply<T: JsFunction = fn() -> JsValue>(
3898 this: &Function<T>,
3899 context: &JsValue,
3900 args: &Array,
3901 ) -> Result<<T as JsFunction>::Ret, JsValue>;
3902
3903 // Next major: Deprecate, and separately provide provide impl
3904 /// The `call()` method calls a function with a given this value and
3905 /// arguments provided individually.
3906 ///
3907 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3908 ///
3909 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3910 #[wasm_bindgen(method, catch, js_name = call)]
3911 pub fn call0<Ret: JsGeneric, F: JsFunction<Ret = Ret> = fn() -> JsValue>(
3912 this: &Function<F>,
3913 context: &JsValue,
3914 ) -> Result<Ret, JsValue>;
3915
3916 // Next major: Deprecate, and separately provide provide impl
3917 /// The `call()` method calls a function with a given this value and
3918 /// arguments provided individually.
3919 ///
3920 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3921 ///
3922 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3923 #[wasm_bindgen(method, catch, js_name = call)]
3924 pub fn call1<
3925 Ret: JsGeneric,
3926 Arg1: JsGeneric,
3927 F: JsFunction<Ret = Ret> + JsFunction1<Arg1 = Arg1> = fn(JsValue) -> JsValue,
3928 >(
3929 this: &Function<F>,
3930 context: &JsValue,
3931 arg1: &Arg1,
3932 ) -> Result<Ret, JsValue>;
3933
3934 // Next major: Deprecate, and separately provide provide impl
3935 /// The `call()` method calls a function with a given this value and
3936 /// arguments provided individually.
3937 ///
3938 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3939 ///
3940 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3941 #[wasm_bindgen(method, catch, js_name = call)]
3942 pub fn call2<
3943 Ret: JsGeneric,
3944 Arg1: JsGeneric,
3945 Arg2: JsGeneric,
3946 F: JsFunction<Ret = Ret> + JsFunction1<Arg1 = Arg1> + JsFunction2<Arg2 = Arg2> = fn(
3947 JsValue,
3948 JsValue,
3949 ) -> JsValue,
3950 >(
3951 this: &Function<F>,
3952 context: &JsValue,
3953 arg1: &Arg1,
3954 arg2: &Arg2,
3955 ) -> Result<Ret, JsValue>;
3956
3957 // Next major: Deprecate, and separately provide provide impl
3958 /// The `call()` method calls a function with a given this value and
3959 /// arguments provided individually.
3960 ///
3961 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3962 ///
3963 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3964 #[wasm_bindgen(method, catch, js_name = call)]
3965 pub fn call3<
3966 Ret: JsGeneric,
3967 Arg1: JsGeneric,
3968 Arg2: JsGeneric,
3969 Arg3: JsGeneric,
3970 F: JsFunction<Ret = Ret> + JsFunction3<Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3> = fn(
3971 JsValue,
3972 JsValue,
3973 JsValue,
3974 ) -> JsValue,
3975 >(
3976 this: &Function<F>,
3977 context: &JsValue,
3978 arg1: &Arg1,
3979 arg2: &Arg2,
3980 arg3: &Arg3,
3981 ) -> Result<Ret, JsValue>;
3982
3983 // Next major: Deprecate, and separately provide provide impl
3984 /// The `call()` method calls a function with a given this value and
3985 /// arguments provided individually.
3986 ///
3987 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3988 ///
3989 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3990 #[wasm_bindgen(method, catch, js_name = call)]
3991 pub fn call4<
3992 Ret: JsGeneric,
3993 Arg1: JsGeneric,
3994 Arg2: JsGeneric,
3995 Arg3: JsGeneric,
3996 Arg4: JsGeneric,
3997 F: JsFunction<Ret = Ret> + JsFunction4<Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3, Arg4 = Arg4> = fn(
3998 JsValue,
3999 JsValue,
4000 JsValue,
4001 JsValue,
4002 ) -> JsValue,
4003 >(
4004 this: &Function<F>,
4005 context: &JsValue,
4006 arg1: &Arg1,
4007 arg2: &Arg2,
4008 arg3: &Arg3,
4009 arg4: &Arg4,
4010 ) -> Result<Ret, JsValue>;
4011
4012 // Next major: Deprecate, and separately provide provide impl
4013 /// The `call()` method calls a function with a given this value and
4014 /// arguments provided individually.
4015 ///
4016 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
4017 ///
4018 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
4019 #[wasm_bindgen(method, catch, js_name = call)]
4020 pub fn call5<
4021 Ret: JsGeneric,
4022 Arg1: JsGeneric,
4023 Arg2: JsGeneric,
4024 Arg3: JsGeneric,
4025 Arg4: JsGeneric,
4026 Arg5: JsGeneric,
4027 F: JsFunction<Ret = Ret>
4028 + JsFunction5<Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3, Arg4 = Arg4, Arg5 = Arg5> = fn(
4029 JsValue,
4030 JsValue,
4031 JsValue,
4032 JsValue,
4033 JsValue,
4034 ) -> JsValue,
4035 >(
4036 this: &Function<F>,
4037 context: &JsValue,
4038 arg1: &Arg1,
4039 arg2: &Arg2,
4040 arg3: &Arg3,
4041 arg4: &Arg4,
4042 arg5: &Arg5,
4043 ) -> Result<Ret, JsValue>;
4044
4045 // Next major: Deprecate, and separately provide provide impl
4046 /// The `call()` method calls a function with a given this value and
4047 /// arguments provided individually.
4048 ///
4049 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
4050 ///
4051 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
4052 #[wasm_bindgen(method, catch, js_name = call)]
4053 pub fn call6<
4054 Ret: JsGeneric,
4055 Arg1: JsGeneric,
4056 Arg2: JsGeneric,
4057 Arg3: JsGeneric,
4058 Arg4: JsGeneric,
4059 Arg5: JsGeneric,
4060 Arg6: JsGeneric,
4061 F: JsFunction<Ret = Ret>
4062 + JsFunction6<
4063 Arg1 = Arg1,
4064 Arg2 = Arg2,
4065 Arg3 = Arg3,
4066 Arg4 = Arg4,
4067 Arg5 = Arg5,
4068 Arg6 = Arg6,
4069 > = fn(JsValue, JsValue, JsValue, JsValue, JsValue, JsValue) -> JsValue,
4070 >(
4071 this: &Function<F>,
4072 context: &JsValue,
4073 arg1: &Arg1,
4074 arg2: &Arg2,
4075 arg3: &Arg3,
4076 arg4: &Arg4,
4077 arg5: &Arg5,
4078 arg6: &Arg6,
4079 ) -> Result<Ret, JsValue>;
4080
4081 // Next major: Deprecate, and separately provide provide impl
4082 /// The `call()` method calls a function with a given this value and
4083 /// arguments provided individually.
4084 ///
4085 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
4086 ///
4087 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
4088 #[wasm_bindgen(method, catch, js_name = call)]
4089 pub fn call7<
4090 Ret: JsGeneric,
4091 Arg1: JsGeneric,
4092 Arg2: JsGeneric,
4093 Arg3: JsGeneric,
4094 Arg4: JsGeneric,
4095 Arg5: JsGeneric,
4096 Arg6: JsGeneric,
4097 Arg7: JsGeneric,
4098 F: JsFunction<Ret = Ret>
4099 + JsFunction7<
4100 Arg1 = Arg1,
4101 Arg2 = Arg2,
4102 Arg3 = Arg3,
4103 Arg4 = Arg4,
4104 Arg5 = Arg5,
4105 Arg6 = Arg6,
4106 Arg7 = Arg7,
4107 > = fn(
4108 JsValue,
4109 JsValue,
4110 JsValue,
4111 JsValue,
4112 JsValue,
4113 JsValue,
4114 JsValue,
4115 ) -> JsValue,
4116 >(
4117 this: &Function<F>,
4118 context: &JsValue,
4119 arg1: &Arg1,
4120 arg2: &Arg2,
4121 arg3: &Arg3,
4122 arg4: &Arg4,
4123 arg5: &Arg5,
4124 arg6: &Arg6,
4125 arg7: &Arg7,
4126 ) -> Result<Ret, JsValue>;
4127
4128 // Next major: Deprecate, and separately provide provide impl
4129 /// The `call()` method calls a function with a given this value and
4130 /// arguments provided individually.
4131 ///
4132 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
4133 ///
4134 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
4135 #[wasm_bindgen(method, catch, js_name = call)]
4136 pub fn call8<
4137 Ret: JsGeneric,
4138 Arg1: JsGeneric,
4139 Arg2: JsGeneric,
4140 Arg3: JsGeneric,
4141 Arg4: JsGeneric,
4142 Arg5: JsGeneric,
4143 Arg6: JsGeneric,
4144 Arg7: JsGeneric,
4145 Arg8: JsGeneric,
4146 F: JsFunction8<
4147 Ret = Ret,
4148 Arg1 = Arg1,
4149 Arg2 = Arg2,
4150 Arg3 = Arg3,
4151 Arg4 = Arg4,
4152 Arg5 = Arg5,
4153 Arg6 = Arg6,
4154 Arg7 = Arg7,
4155 Arg8 = Arg8,
4156 > = fn(
4157 JsValue,
4158 JsValue,
4159 JsValue,
4160 JsValue,
4161 JsValue,
4162 JsValue,
4163 JsValue,
4164 JsValue,
4165 ) -> JsValue,
4166 >(
4167 this: &Function<F>,
4168 context: &JsValue,
4169 arg1: &Arg1,
4170 arg2: &Arg2,
4171 arg3: &Arg3,
4172 arg4: &Arg4,
4173 arg5: &Arg5,
4174 arg6: &Arg6,
4175 arg7: &Arg7,
4176 arg8: &Arg8,
4177 ) -> Result<Ret, JsValue>;
4178
4179 /// The `call()` method calls a function with a given this value and
4180 /// arguments provided individually.
4181 ///
4182 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
4183 ///
4184 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
4185 #[deprecated]
4186 #[allow(deprecated)]
4187 #[wasm_bindgen(method, catch, js_name = call)]
4188 pub fn call9<
4189 Ret: JsGeneric,
4190 Arg1: JsGeneric,
4191 Arg2: JsGeneric,
4192 Arg3: JsGeneric,
4193 Arg4: JsGeneric,
4194 Arg5: JsGeneric,
4195 Arg6: JsGeneric,
4196 Arg7: JsGeneric,
4197 Arg8: JsGeneric,
4198 F: JsFunction8<
4199 Ret = Ret,
4200 Arg1 = Arg1,
4201 Arg2 = Arg2,
4202 Arg3 = Arg3,
4203 Arg4 = Arg4,
4204 Arg5 = Arg5,
4205 Arg6 = Arg6,
4206 Arg7 = Arg7,
4207 Arg8 = Arg8,
4208 > = fn(
4209 JsValue,
4210 JsValue,
4211 JsValue,
4212 JsValue,
4213 JsValue,
4214 JsValue,
4215 JsValue,
4216 JsValue,
4217 ) -> JsValue,
4218 >(
4219 this: &Function<F>,
4220 context: &JsValue,
4221 arg1: &Arg1,
4222 arg2: &Arg2,
4223 arg3: &Arg3,
4224 arg4: &Arg4,
4225 arg5: &Arg5,
4226 arg6: &Arg6,
4227 arg7: &Arg7,
4228 arg8: &Arg8,
4229 arg9: &JsValue,
4230 ) -> Result<Ret, JsValue>;
4231
4232 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4233 /// with a given sequence of arguments preceding any provided when the new function is called.
4234 ///
4235 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4236 #[cfg(not(js_sys_unstable_apis))]
4237 #[deprecated(note = "Use `Function::bind0` instead.")]
4238 #[allow(deprecated)]
4239 #[wasm_bindgen(method, js_name = bind)]
4240 pub fn bind<T: JsFunction = fn() -> JsValue>(
4241 this: &Function<T>,
4242 context: &JsValue,
4243 ) -> Function<T>;
4244
4245 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4246 /// with a given sequence of arguments preceding any provided when the new function is called.
4247 ///
4248 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4249 ///
4250 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4251 #[wasm_bindgen(method, js_name = bind)]
4252 pub fn bind0<T: JsFunction = fn() -> JsValue>(
4253 this: &Function<T>,
4254 context: &JsValue,
4255 ) -> Function<T>;
4256
4257 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4258 /// with a given sequence of arguments preceding any provided when the new function is called.
4259 ///
4260 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4261 ///
4262 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4263 #[wasm_bindgen(method, js_name = bind)]
4264 pub fn bind1<
4265 Ret: JsGeneric,
4266 Arg1: JsGeneric,
4267 F: JsFunction1<Ret = Ret, Arg1 = Arg1> = fn(JsValue) -> JsValue,
4268 >(
4269 this: &Function<F>,
4270 context: &JsValue,
4271 arg1: &Arg1,
4272 ) -> Function<<F as JsFunction1>::Bind1>;
4273
4274 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4275 /// with a given sequence of arguments preceding any provided when the new function is called.
4276 ///
4277 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4278 ///
4279 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4280 #[wasm_bindgen(method, js_name = bind)]
4281 pub fn bind2<
4282 Ret: JsGeneric,
4283 Arg1: JsGeneric,
4284 Arg2: JsGeneric,
4285 F: JsFunction2<Ret = Ret, Arg1 = Arg1, Arg2 = Arg2> = fn(JsValue, JsValue) -> JsValue,
4286 >(
4287 this: &Function<F>,
4288 context: &JsValue,
4289 arg1: &Arg1,
4290 arg2: &Arg2,
4291 ) -> Function<<F as JsFunction2>::Bind2>;
4292
4293 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4294 /// with a given sequence of arguments preceding any provided when the new function is called.
4295 ///
4296 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4297 ///
4298 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4299 #[wasm_bindgen(method, js_name = bind)]
4300 pub fn bind3<
4301 Ret: JsGeneric,
4302 Arg1: JsGeneric,
4303 Arg2: JsGeneric,
4304 Arg3: JsGeneric,
4305 F: JsFunction3<Ret = Ret, Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3> = fn(
4306 JsValue,
4307 JsValue,
4308 JsValue,
4309 ) -> JsValue,
4310 >(
4311 this: &Function<F>,
4312 context: &JsValue,
4313 arg1: &Arg1,
4314 arg2: &Arg2,
4315 arg3: &Arg3,
4316 ) -> Function<<F as JsFunction3>::Bind3>;
4317
4318 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4319 /// with a given sequence of arguments preceding any provided when the new function is called.
4320 ///
4321 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4322 ///
4323 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4324 #[wasm_bindgen(method, js_name = bind)]
4325 pub fn bind4<
4326 Ret: JsGeneric,
4327 Arg1: JsGeneric,
4328 Arg2: JsGeneric,
4329 Arg3: JsGeneric,
4330 Arg4: JsGeneric,
4331 F: JsFunction4<Ret = Ret, Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3, Arg4 = Arg4> = fn(
4332 JsValue,
4333 JsValue,
4334 JsValue,
4335 JsValue,
4336 ) -> JsValue,
4337 >(
4338 this: &Function<F>,
4339 context: &JsValue,
4340 arg1: &Arg1,
4341 arg2: &Arg2,
4342 arg3: &Arg3,
4343 arg4: &Arg4,
4344 ) -> Function<<F as JsFunction4>::Bind4>;
4345
4346 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4347 /// with a given sequence of arguments preceding any provided when the new function is called.
4348 ///
4349 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4350 ///
4351 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4352 #[wasm_bindgen(method, js_name = bind)]
4353 pub fn bind5<
4354 Ret: JsGeneric,
4355 Arg1: JsGeneric,
4356 Arg2: JsGeneric,
4357 Arg3: JsGeneric,
4358 Arg4: JsGeneric,
4359 Arg5: JsGeneric,
4360 F: JsFunction5<Ret = Ret, Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3, Arg4 = Arg4, Arg5 = Arg5> = fn(
4361 JsValue,
4362 JsValue,
4363 JsValue,
4364 JsValue,
4365 JsValue,
4366 ) -> JsValue,
4367 >(
4368 this: &Function<F>,
4369 context: &JsValue,
4370 arg1: &Arg1,
4371 arg2: &Arg2,
4372 arg3: &Arg3,
4373 arg4: &Arg4,
4374 arg5: &Arg5,
4375 ) -> Function<<F as JsFunction5>::Bind5>;
4376
4377 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4378 /// with a given sequence of arguments preceding any provided when the new function is called.
4379 ///
4380 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4381 ///
4382 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4383 #[wasm_bindgen(method, js_name = bind)]
4384 pub fn bind6<
4385 Ret: JsGeneric,
4386 Arg1: JsGeneric,
4387 Arg2: JsGeneric,
4388 Arg3: JsGeneric,
4389 Arg4: JsGeneric,
4390 Arg5: JsGeneric,
4391 Arg6: JsGeneric,
4392 F: JsFunction6<
4393 Ret = Ret,
4394 Arg1 = Arg1,
4395 Arg2 = Arg2,
4396 Arg3 = Arg3,
4397 Arg4 = Arg4,
4398 Arg5 = Arg5,
4399 Arg6 = Arg6,
4400 > = fn(JsValue, JsValue, JsValue, JsValue, JsValue, JsValue) -> JsValue,
4401 >(
4402 this: &Function<F>,
4403 context: &JsValue,
4404 arg1: &Arg1,
4405 arg2: &Arg2,
4406 arg3: &Arg3,
4407 arg4: &Arg4,
4408 arg5: &Arg5,
4409 arg6: &Arg6,
4410 ) -> Function<<F as JsFunction6>::Bind6>;
4411
4412 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4413 /// with a given sequence of arguments preceding any provided when the new function is called.
4414 ///
4415 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4416 ///
4417 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4418 #[wasm_bindgen(method, js_name = bind)]
4419 pub fn bind7<
4420 Ret: JsGeneric,
4421 Arg1: JsGeneric,
4422 Arg2: JsGeneric,
4423 Arg3: JsGeneric,
4424 Arg4: JsGeneric,
4425 Arg5: JsGeneric,
4426 Arg6: JsGeneric,
4427 Arg7: JsGeneric,
4428 F: JsFunction7<
4429 Ret = Ret,
4430 Arg1 = Arg1,
4431 Arg2 = Arg2,
4432 Arg3 = Arg3,
4433 Arg4 = Arg4,
4434 Arg5 = Arg5,
4435 Arg6 = Arg6,
4436 Arg7 = Arg7,
4437 > = fn(
4438 JsValue,
4439 JsValue,
4440 JsValue,
4441 JsValue,
4442 JsValue,
4443 JsValue,
4444 JsValue,
4445 ) -> JsValue,
4446 >(
4447 this: &Function<F>,
4448 context: &JsValue,
4449 arg1: &Arg1,
4450 arg2: &Arg2,
4451 arg3: &Arg3,
4452 arg4: &Arg4,
4453 arg5: &Arg5,
4454 arg6: &Arg6,
4455 arg7: &Arg7,
4456 ) -> Function<<F as JsFunction7>::Bind7>;
4457
4458 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4459 /// with a given sequence of arguments preceding any provided when the new function is called.
4460 ///
4461 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4462 ///
4463 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4464 #[wasm_bindgen(method, js_name = bind)]
4465 pub fn bind8<
4466 Ret: JsGeneric,
4467 Arg1: JsGeneric,
4468 Arg2: JsGeneric,
4469 Arg3: JsGeneric,
4470 Arg4: JsGeneric,
4471 Arg5: JsGeneric,
4472 Arg6: JsGeneric,
4473 Arg7: JsGeneric,
4474 Arg8: JsGeneric,
4475 F: JsFunction8<
4476 Ret = Ret,
4477 Arg1 = Arg1,
4478 Arg2 = Arg2,
4479 Arg3 = Arg3,
4480 Arg4 = Arg4,
4481 Arg5 = Arg5,
4482 Arg6 = Arg6,
4483 Arg7 = Arg7,
4484 Arg8 = Arg8,
4485 > = fn(
4486 JsValue,
4487 JsValue,
4488 JsValue,
4489 JsValue,
4490 JsValue,
4491 JsValue,
4492 JsValue,
4493 JsValue,
4494 ) -> JsValue,
4495 >(
4496 this: &Function<F>,
4497 context: &JsValue,
4498 arg1: &Arg1,
4499 arg2: &Arg2,
4500 arg3: &Arg3,
4501 arg4: &Arg4,
4502 arg5: &Arg5,
4503 arg6: &Arg6,
4504 arg7: &Arg7,
4505 arg8: &Arg8,
4506 ) -> Function<<F as JsFunction8>::Bind8>;
4507
4508 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4509 /// with a given sequence of arguments preceding any provided when the new function is called.
4510 ///
4511 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4512 ///
4513 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4514 #[deprecated]
4515 #[allow(deprecated)]
4516 #[wasm_bindgen(method, js_name = bind)]
4517 pub fn bind9<
4518 Ret: JsGeneric,
4519 Arg1: JsGeneric,
4520 Arg2: JsGeneric,
4521 Arg3: JsGeneric,
4522 Arg4: JsGeneric,
4523 Arg5: JsGeneric,
4524 Arg6: JsGeneric,
4525 Arg7: JsGeneric,
4526 Arg8: JsGeneric,
4527 F: JsFunction8<
4528 Ret = Ret,
4529 Arg1 = Arg1,
4530 Arg2 = Arg2,
4531 Arg3 = Arg3,
4532 Arg4 = Arg4,
4533 Arg5 = Arg5,
4534 Arg6 = Arg6,
4535 Arg7 = Arg7,
4536 Arg8 = Arg8,
4537 > = fn(
4538 JsValue,
4539 JsValue,
4540 JsValue,
4541 JsValue,
4542 JsValue,
4543 JsValue,
4544 JsValue,
4545 JsValue,
4546 ) -> JsValue,
4547 >(
4548 this: &Function<F>,
4549 context: &JsValue,
4550 arg1: &Arg1,
4551 arg2: &Arg2,
4552 arg3: &Arg3,
4553 arg4: &Arg4,
4554 arg5: &Arg5,
4555 arg6: &Arg6,
4556 arg7: &Arg7,
4557 arg8: &Arg8,
4558 arg9: &JsValue,
4559 ) -> Function<fn() -> Ret>;
4560
4561 /// The length property indicates the number of arguments expected by the function.
4562 ///
4563 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/length)
4564 #[wasm_bindgen(method, getter)]
4565 pub fn length<T: JsFunction = fn() -> JsValue>(this: &Function<T>) -> u32;
4566
4567 /// A Function object's read-only name property indicates the function's
4568 /// name as specified when it was created or "anonymous" for functions
4569 /// created anonymously.
4570 ///
4571 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name)
4572 #[wasm_bindgen(method, getter)]
4573 pub fn name<T: JsFunction = fn() -> JsValue>(this: &Function<T>) -> JsString;
4574
4575 /// The `toString()` method returns a string representing the source code of the function.
4576 ///
4577 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/toString)
4578 #[cfg(not(js_sys_unstable_apis))]
4579 #[wasm_bindgen(method, js_name = toString)]
4580 pub fn to_string<T: JsFunction = fn() -> JsValue>(this: &Function<T>) -> JsString;
4581}
4582
4583// Basic UpcastFrom impls for Function<T>
4584impl<T: JsFunction> UpcastFrom<Function<T>> for JsValue {}
4585impl<T: JsFunction> UpcastFrom<Function<T>> for JsOption<JsValue> {}
4586impl<T: JsFunction> UpcastFrom<Function<T>> for JsNullable<JsValue> {}
4587impl<T: JsFunction> UpcastFrom<Function<T>> for Object {}
4588impl<T: JsFunction> UpcastFrom<Function<T>> for JsOption<Object> {}
4589impl<T: JsFunction> UpcastFrom<Function<T>> for JsNullable<Object> {}
4590
4591// Blanket trait for Function upcast
4592// Function<T> upcasts to Function<U> when the underlying fn type T upcasts to U.
4593// The fn signature UpcastFrom impls already encode correct variance (covariant return, contravariant args).
4594impl<T: JsFunction, U: JsFunction> UpcastFrom<Function<T>> for Function<U> where U: UpcastFrom<T> {}
4595
4596// len() method for Function<T> using JsFunction::ARITY
4597impl<T: JsFunction> Function<T> {
4598 /// Get the static arity of this function type.
4599 #[allow(clippy::len_without_is_empty)]
4600 pub fn len(&self) -> usize {
4601 T::ARITY
4602 }
4603
4604 /// Returns true if this is a zero-argument function.
4605 pub fn is_empty(&self) -> bool {
4606 T::ARITY == 0
4607 }
4608}
4609
4610// Base traits for function signature types.
4611pub trait JsFunction {
4612 type Ret: JsGeneric;
4613 const ARITY: usize;
4614}
4615
4616pub trait JsFunction1: JsFunction {
4617 type Arg1: JsGeneric;
4618 type Bind1: JsFunction;
4619}
4620pub trait JsFunction2: JsFunction1 {
4621 type Arg2: JsGeneric;
4622 type Bind2: JsFunction;
4623}
4624pub trait JsFunction3: JsFunction2 {
4625 type Arg3: JsGeneric;
4626 type Bind3: JsFunction;
4627}
4628pub trait JsFunction4: JsFunction3 {
4629 type Arg4: JsGeneric;
4630 type Bind4: JsFunction;
4631}
4632pub trait JsFunction5: JsFunction4 {
4633 type Arg5: JsGeneric;
4634 type Bind5: JsFunction;
4635}
4636pub trait JsFunction6: JsFunction5 {
4637 type Arg6: JsGeneric;
4638 type Bind6: JsFunction;
4639}
4640pub trait JsFunction7: JsFunction6 {
4641 type Arg7: JsGeneric;
4642 type Bind7: JsFunction;
4643}
4644pub trait JsFunction8: JsFunction7 {
4645 type Arg8: JsGeneric;
4646 type Bind8: JsFunction;
4647}
4648
4649// Manual impl for fn() -> R
4650impl<Ret: JsGeneric> JsFunction for fn() -> Ret {
4651 type Ret = Ret;
4652 const ARITY: usize = 0;
4653}
4654
4655macro_rules! impl_fn {
4656 () => {
4657 impl_fn!(@impl 1 [Arg1] [
4658 JsFunction1 Arg1 Bind1 {fn() -> Ret}
4659 ]);
4660 impl_fn!(@impl 2 [Arg1 Arg2] [
4661 JsFunction1 Arg1 Bind1 {fn(Arg2) -> Ret}
4662 JsFunction2 Arg2 Bind2 {fn() -> Ret}
4663 ]);
4664 impl_fn!(@impl 3 [Arg1 Arg2 Arg3] [
4665 JsFunction1 Arg1 Bind1 {fn(Arg2, Arg3) -> Ret}
4666 JsFunction2 Arg2 Bind2 {fn(Arg3) -> Ret}
4667 JsFunction3 Arg3 Bind3 {fn() -> Ret}
4668 ]);
4669 impl_fn!(@impl 4 [Arg1 Arg2 Arg3 Arg4] [
4670 JsFunction1 Arg1 Bind1 {fn(Arg2, Arg3, Arg4) -> Ret}
4671 JsFunction2 Arg2 Bind2 {fn(Arg3, Arg4) -> Ret}
4672 JsFunction3 Arg3 Bind3 {fn(Arg4) -> Ret}
4673 JsFunction4 Arg4 Bind4 {fn() -> Ret}
4674 ]);
4675 impl_fn!(@impl 5 [Arg1 Arg2 Arg3 Arg4 Arg5] [
4676 JsFunction1 Arg1 Bind1 {fn(Arg2, Arg3, Arg4, Arg5) -> Ret}
4677 JsFunction2 Arg2 Bind2 {fn(Arg3, Arg4, Arg5) -> Ret}
4678 JsFunction3 Arg3 Bind3 {fn(Arg4, Arg5) -> Ret}
4679 JsFunction4 Arg4 Bind4 {fn(Arg5) -> Ret}
4680 JsFunction5 Arg5 Bind5 {fn() -> Ret}
4681 ]);
4682 impl_fn!(@impl 6 [Arg1 Arg2 Arg3 Arg4 Arg5 Arg6] [
4683 JsFunction1 Arg1 Bind1 {fn(Arg2, Arg3, Arg4, Arg5, Arg6) -> Ret}
4684 JsFunction2 Arg2 Bind2 {fn(Arg3, Arg4, Arg5, Arg6) -> Ret}
4685 JsFunction3 Arg3 Bind3 {fn(Arg4, Arg5, Arg6) -> Ret}
4686 JsFunction4 Arg4 Bind4 {fn(Arg5, Arg6) -> Ret}
4687 JsFunction5 Arg5 Bind5 {fn(Arg6) -> Ret}
4688 JsFunction6 Arg6 Bind6 {fn() -> Ret}
4689 ]);
4690 impl_fn!(@impl 7 [Arg1 Arg2 Arg3 Arg4 Arg5 Arg6 Arg7] [
4691 JsFunction1 Arg1 Bind1 {fn(Arg2, Arg3, Arg4, Arg5, Arg6, Arg7) -> Ret}
4692 JsFunction2 Arg2 Bind2 {fn(Arg3, Arg4, Arg5, Arg6, Arg7) -> Ret}
4693 JsFunction3 Arg3 Bind3 {fn(Arg4, Arg5, Arg6, Arg7) -> Ret}
4694 JsFunction4 Arg4 Bind4 {fn(Arg5, Arg6, Arg7) -> Ret}
4695 JsFunction5 Arg5 Bind5 {fn(Arg6, Arg7) -> Ret}
4696 JsFunction6 Arg6 Bind6 {fn(Arg7) -> Ret}
4697 JsFunction7 Arg7 Bind7 {fn() -> Ret}
4698 ]);
4699 impl_fn!(@impl 8 [Arg1 Arg2 Arg3 Arg4 Arg5 Arg6 Arg7 Arg8] [
4700 JsFunction1 Arg1 Bind1 {fn(Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8) -> Ret}
4701 JsFunction2 Arg2 Bind2 {fn(Arg3, Arg4, Arg5, Arg6, Arg7, Arg8) -> Ret}
4702 JsFunction3 Arg3 Bind3 {fn(Arg4, Arg5, Arg6, Arg7, Arg8) -> Ret}
4703 JsFunction4 Arg4 Bind4 {fn(Arg5, Arg6, Arg7, Arg8) -> Ret}
4704 JsFunction5 Arg5 Bind5 {fn(Arg6, Arg7, Arg8) -> Ret}
4705 JsFunction6 Arg6 Bind6 {fn(Arg7, Arg8) -> Ret}
4706 JsFunction7 Arg7 Bind7 {fn(Arg8) -> Ret}
4707 JsFunction8 Arg8 Bind8 {fn() -> Ret}
4708 ]);
4709 };
4710
4711 (@impl $arity:literal [$($A:ident)+] [$($trait:ident $arg:ident $bind:ident {$bind_ty:ty})+]) => {
4712 impl<Ret: JsGeneric $(, $A: JsGeneric)+> JsFunction for fn($($A),+) -> Ret {
4713 type Ret = Ret;
4714 const ARITY: usize = $arity;
4715 }
4716
4717 impl_fn!(@traits [$($A)+] [$($trait $arg $bind {$bind_ty})+]);
4718 };
4719
4720 (@traits [$($A:ident)+] []) => {};
4721
4722 (@traits [$($A:ident)+] [$trait:ident $arg:ident $bind:ident {$bind_ty:ty} $($rest:tt)*]) => {
4723 impl<Ret: JsGeneric $(, $A: JsGeneric)+> $trait for fn($($A),+) -> Ret {
4724 type $arg = $arg;
4725 type $bind = $bind_ty;
4726 }
4727
4728 impl_fn!(@traits [$($A)+] [$($rest)*]);
4729 };
4730}
4731
4732impl_fn!();
4733
4734/// Trait for argument tuples that can call or bind a `Function<T>`.
4735pub trait JsArgs<T: JsFunction> {
4736 type BindOutput;
4737 fn apply_call(self, func: &Function<T>, context: &JsValue) -> Result<T::Ret, JsValue>;
4738 fn apply_bind(self, func: &Function<T>, context: &JsValue) -> Self::BindOutput;
4739}
4740
4741// Manual impl for 0-arg
4742impl<Ret: JsGeneric, F: JsFunction<Ret = Ret>> JsArgs<F> for () {
4743 type BindOutput = Function<F>;
4744
4745 #[inline]
4746 fn apply_call(self, func: &Function<F>, context: &JsValue) -> Result<Ret, JsValue> {
4747 func.call0(context)
4748 }
4749
4750 #[inline]
4751 fn apply_bind(self, func: &Function<F>, context: &JsValue) -> Self::BindOutput {
4752 func.bind0(context)
4753 }
4754}
4755
4756macro_rules! impl_js_args {
4757 ($arity:literal $trait:ident $bind_output:ident [$($A:ident)+] [$($idx:tt)+] $call:ident $bind:ident) => {
4758 impl<Ret: JsGeneric, $($A: JsGeneric,)+ F: $trait<Ret = Ret, $($A = $A,)*>> JsArgs<F> for ($(&$A,)+)
4759 {
4760 type BindOutput = Function<<F as $trait>::$bind_output>;
4761
4762 #[inline]
4763 fn apply_call(self, func: &Function<F>, context: &JsValue) -> Result<Ret, JsValue> {
4764 func.$call(context, $(self.$idx),+)
4765 }
4766
4767 #[inline]
4768 fn apply_bind(self, func: &Function<F>, context: &JsValue) -> Self::BindOutput {
4769 func.$bind(context, $(self.$idx),+)
4770 }
4771 }
4772 };
4773}
4774
4775impl_js_args!(1 JsFunction1 Bind1 [Arg1] [0] call1 bind1);
4776impl_js_args!(2 JsFunction2 Bind2 [Arg1 Arg2] [0 1] call2 bind2);
4777impl_js_args!(3 JsFunction3 Bind3 [Arg1 Arg2 Arg3] [0 1 2] call3 bind3);
4778impl_js_args!(4 JsFunction4 Bind4 [Arg1 Arg2 Arg3 Arg4] [0 1 2 3] call4 bind4);
4779impl_js_args!(5 JsFunction5 Bind5 [Arg1 Arg2 Arg3 Arg4 Arg5] [0 1 2 3 4] call5 bind5);
4780impl_js_args!(6 JsFunction6 Bind6 [Arg1 Arg2 Arg3 Arg4 Arg5 Arg6] [0 1 2 3 4 5] call6 bind6);
4781impl_js_args!(7 JsFunction7 Bind7 [Arg1 Arg2 Arg3 Arg4 Arg5 Arg6 Arg7] [0 1 2 3 4 5 6] call7 bind7);
4782impl_js_args!(8 JsFunction8 Bind8 [Arg1 Arg2 Arg3 Arg4 Arg5 Arg6 Arg7 Arg8] [0 1 2 3 4 5 6 7] call8 bind8);
4783
4784impl<T: JsFunction> Function<T> {
4785 /// The `call()` method calls a function with a given `this` value and
4786 /// arguments provided as a tuple.
4787 ///
4788 /// This method accepts a tuple of references matching the function's
4789 /// argument types.
4790 ///
4791 /// # Example
4792 ///
4793 /// ```ignore
4794 /// // 0-arg function
4795 /// let f: Function<fn() -> Number> = get_fn();
4796 /// let result = f.call(&JsValue::NULL, ())?;
4797 ///
4798 /// // 1-arg function (note trailing comma for 1-tuple)
4799 /// let f: Function<fn(JsString) -> Number> = get_fn();
4800 /// let result = f.call(&JsValue::NULL, (&name,))?;
4801 ///
4802 /// // 2-arg function
4803 /// let f: Function<fn(JsString, Boolean) -> Number> = get_fn();
4804 /// let result = f.call(&JsValue::NULL, (&name, &flag))?;
4805 /// ```
4806 ///
4807 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
4808 #[inline]
4809 pub fn call<Args: JsArgs<T>>(&self, context: &JsValue, args: Args) -> Result<T::Ret, JsValue> {
4810 args.apply_call(self, context)
4811 }
4812
4813 /// The `bind()` method creates a new function that, when called, has its
4814 /// `this` keyword set to the provided value, with a given sequence of
4815 /// arguments preceding any provided when the new function is called.
4816 ///
4817 /// This method accepts a tuple of references to bind.
4818 ///
4819 /// # Example
4820 ///
4821 /// ```ignore
4822 /// let f: Function<fn(JsString, Boolean) -> Number> = get_fn();
4823 ///
4824 /// // Bind no args - same signature
4825 /// let bound: Function<fn(JsString, Boolean) -> Number> = f.bind(&ctx, ());
4826 ///
4827 /// // Bind one arg (use 1-tuple of references)
4828 /// let bound: Function<fn(Boolean) -> Number> = f.bind(&ctx, (&my_string,));
4829 ///
4830 /// // Bind two args - becomes 0-arg function
4831 /// let bound: Function<fn() -> Number> = f.bind(&ctx, (&my_string, &my_bool));
4832 /// ```
4833 ///
4834 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4835 #[inline]
4836 pub fn bindn<Args: JsArgs<T>>(&self, context: &JsValue, args: Args) -> Args::BindOutput {
4837 args.apply_bind(self, context)
4838 }
4839
4840 /// The `bind()` method creates a new function that, when called, has its
4841 /// `this` keyword set to the provided value, with a given sequence of
4842 /// arguments preceding any provided when the new function is called.
4843 ///
4844 /// This method accepts a tuple of references to bind.
4845 ///
4846 /// # Example
4847 ///
4848 /// ```ignore
4849 /// let f: Function<fn(JsString, Boolean) -> Number> = get_fn();
4850 ///
4851 /// // Bind no args - same signature
4852 /// let bound: Function<fn(JsString, Boolean) -> Number> = f.bind(&ctx, ());
4853 ///
4854 /// // Bind one arg (use 1-tuple of references)
4855 /// let bound: Function<fn(Boolean) -> Number> = f.bind(&ctx, (&my_string,));
4856 ///
4857 /// // Bind two args - becomes 0-arg function
4858 /// let bound: Function<fn() -> Number> = f.bind(&ctx, (&my_string, &my_bool));
4859 /// ```
4860 ///
4861 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4862 #[cfg(js_sys_unstable_apis)]
4863 #[inline]
4864 pub fn bind<Args: JsArgs<T>>(&self, context: &JsValue, args: Args) -> Args::BindOutput {
4865 args.apply_bind(self, context)
4866 }
4867}
4868
4869pub trait FunctionIntoClosure: JsFunction {
4870 type ClosureTypeMut: WasmClosure + ?Sized;
4871}
4872
4873macro_rules! impl_function_into_closure {
4874 ( $(($($var:ident)*))* ) => {$(
4875 impl<$($var: FromWasmAbi + JsGeneric,)* R: IntoWasmAbi + JsGeneric> FunctionIntoClosure for fn($($var),*) -> R {
4876 type ClosureTypeMut = dyn FnMut($($var),*) -> R;
4877 }
4878 )*};
4879}
4880
4881impl_function_into_closure! {
4882 ()
4883 (A)
4884 (A B)
4885 (A B C)
4886 (A B C D)
4887 (A B C D E)
4888 (A B C D E F)
4889 (A B C D E F G)
4890 (A B C D E F G H)
4891}
4892
4893impl<F: JsFunction> Function<F> {
4894 /// Convert a borrowed `ScopedClosure` into a typed JavaScript Function reference.
4895 ///
4896 /// The conversion is a direct type-safe conversion and upcast of a
4897 /// closure into its corresponding typed JavaScript Function,
4898 /// based on covariance and contravariance [`Upcast`] trait hierarchy.
4899 ///
4900 /// For transferring ownership to JS, use [`Function::from_closure`].
4901 #[inline]
4902 pub fn closure_ref<'a, C>(closure: &'a ScopedClosure<'_, C>) -> &'a Self
4903 where
4904 F: FunctionIntoClosure,
4905 C: WasmClosure + ?Sized,
4906 <F as FunctionIntoClosure>::ClosureTypeMut: UpcastFrom<<C as WasmClosure>::AsMut>,
4907 {
4908 closure.as_js_value().unchecked_ref()
4909 }
4910
4911 /// Convert a Rust closure into a typed JavaScript Function.
4912 ///
4913 /// This function releases ownership of the closure to JS, and provides
4914 /// an owned function handle for the same closure.
4915 ///
4916 /// The conversion is a direct type-safe conversion and upcast of a
4917 /// closure into its corresponding typed JavaScript Function,
4918 /// based on covariance and contravariance [`Upcast`] trait hierarchy.
4919 ///
4920 /// This method is only supported for static closures which do not have
4921 /// borrowed lifetime data, and thus can be released into JS.
4922 ///
4923 /// For borrowed closures, which cannot cede ownership to JS,
4924 /// instead use [`Function::closure_ref`].
4925 #[inline]
4926 pub fn from_closure<C>(closure: ScopedClosure<'static, C>) -> Self
4927 where
4928 F: FunctionIntoClosure,
4929 C: WasmClosure + ?Sized,
4930 <F as FunctionIntoClosure>::ClosureTypeMut: UpcastFrom<<C as WasmClosure>::AsMut>,
4931 {
4932 closure.into_js_value().unchecked_into()
4933 }
4934}
4935
4936#[cfg(not(js_sys_unstable_apis))]
4937impl Function {
4938 /// Returns the `Function` value of this JS value if it's an instance of a
4939 /// function.
4940 ///
4941 /// If this JS value is not an instance of a function then this returns
4942 /// `None`.
4943 #[deprecated(note = "recommended to use dyn_ref instead which is now equivalent")]
4944 pub fn try_from(val: &JsValue) -> Option<&Function> {
4945 val.dyn_ref()
4946 }
4947}
4948
4949#[cfg(feature = "unsafe-eval")]
4950impl Default for Function {
4951 fn default() -> Self {
4952 Self::new_no_args("")
4953 }
4954}
4955
4956// FinalizationRegistry
4957#[wasm_bindgen]
4958extern "C" {
4959 /// The `FinalizationRegistry` object lets you request a callback when an
4960 /// object is garbage-collected.
4961 ///
4962 /// `FinalizationRegistry` provides a way to request that a cleanup
4963 /// callback get called at some point when an object registered with the
4964 /// registry has been reclaimed (garbage-collected). Cleanup callbacks
4965 /// are sometimes called *finalizers*.
4966 ///
4967 /// Avoid where possible: cleanup callbacks should not be relied upon for
4968 /// anything essential. They are best used to reduce memory usage over the
4969 /// course of a program for objects that benefit from cleanup. Whether,
4970 /// when, and in what order callbacks fire is implementation-defined.
4971 ///
4972 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/FinalizationRegistry)
4973 #[wasm_bindgen(extends = Object, typescript_type = "FinalizationRegistry<any>")]
4974 #[derive(Clone, Debug, PartialEq, Eq)]
4975 pub type FinalizationRegistry;
4976
4977 /// Creates a new `FinalizationRegistry` with the given cleanup callback.
4978 ///
4979 /// The cleanup callback is invoked, at some point after a registered
4980 /// target is garbage-collected, with the `held_value` that was passed to
4981 /// [`FinalizationRegistry::register`]. Because callbacks may be deferred
4982 /// or skipped entirely, the callback should normally outlive the
4983 /// `FinalizationRegistry` (for example by being created via
4984 /// [`Function::from_closure`]).
4985 ///
4986 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/FinalizationRegistry/FinalizationRegistry)
4987 #[wasm_bindgen(constructor)]
4988 pub fn new(cleanup_callback: &Function<fn(JsValue) -> Undefined>) -> FinalizationRegistry;
4989
4990 /// Registers `target` with this `FinalizationRegistry`. When `target` is
4991 /// reclaimed by the garbage collector the cleanup callback may be called
4992 /// with `held_value`.
4993 ///
4994 /// `target` must be an object (or a non-registered symbol).
4995 ///
4996 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/FinalizationRegistry/register)
4997 #[wasm_bindgen(method)]
4998 pub fn register(this: &FinalizationRegistry, target: &JsValue, held_value: &JsValue);
4999
5000 /// Registers `target` with this `FinalizationRegistry`, with an
5001 /// `unregister_token` that can later be passed to
5002 /// [`FinalizationRegistry::unregister`] to remove the registration.
5003 ///
5004 /// `target` and `unregister_token` must be objects (or non-registered
5005 /// symbols), and the same value may be passed for both.
5006 ///
5007 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/FinalizationRegistry/register)
5008 #[wasm_bindgen(method, js_name = register)]
5009 pub fn register_with_token(
5010 this: &FinalizationRegistry,
5011 target: &JsValue,
5012 held_value: &JsValue,
5013 unregister_token: &JsValue,
5014 );
5015
5016 /// Unregisters all entries registered with this `FinalizationRegistry`
5017 /// using `unregister_token`. Returns `true` if any cells were removed.
5018 ///
5019 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/FinalizationRegistry/unregister)
5020 #[wasm_bindgen(method)]
5021 pub fn unregister(this: &FinalizationRegistry, unregister_token: &JsValue) -> bool;
5022}
5023
5024// Generator
5025#[wasm_bindgen]
5026extern "C" {
5027 #[wasm_bindgen(extends = Object, typescript_type = "Generator<any, any, any>")]
5028 #[derive(Clone, Debug, PartialEq, Eq)]
5029 pub type Generator<T = JsValue>;
5030
5031 /// The `next()` method returns an object with two properties done and value.
5032 /// You can also provide a parameter to the next method to send a value to the generator.
5033 ///
5034 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/next)
5035 #[cfg(not(js_sys_unstable_apis))]
5036 #[wasm_bindgen(method, catch)]
5037 pub fn next<T>(this: &Generator<T>, value: &T) -> Result<JsValue, JsValue>;
5038
5039 /// The `next()` method returns an object with two properties done and value.
5040 /// You can also provide a parameter to the next method to send a value to the generator.
5041 ///
5042 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/next)
5043 #[cfg(js_sys_unstable_apis)]
5044 #[wasm_bindgen(method, catch, js_name = next)]
5045 pub fn next<T: FromWasmAbi>(this: &Generator<T>, value: &T)
5046 -> Result<IteratorNext<T>, JsValue>;
5047
5048 // Next major: deprecate
5049 /// The `next()` method returns an object with two properties done and value.
5050 /// You can also provide a parameter to the next method to send a value to the generator.
5051 ///
5052 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/next)
5053 #[wasm_bindgen(method, catch)]
5054 pub fn next_iterator<T: FromWasmAbi>(
5055 this: &Generator<T>,
5056 value: &T,
5057 ) -> Result<IteratorNext<T>, JsValue>;
5058
5059 /// The `return()` method returns the given value and finishes the generator.
5060 ///
5061 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/return)
5062 #[cfg(not(js_sys_unstable_apis))]
5063 #[wasm_bindgen(method, js_name = "return")]
5064 pub fn return_<T>(this: &Generator<T>, value: &T) -> JsValue;
5065
5066 /// The `return()` method returns the given value and finishes the generator.
5067 ///
5068 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/return)
5069 #[cfg(js_sys_unstable_apis)]
5070 #[wasm_bindgen(method, catch, js_name = "return")]
5071 pub fn return_<T: FromWasmAbi>(
5072 this: &Generator<T>,
5073 value: &T,
5074 ) -> Result<IteratorNext<T>, JsValue>;
5075
5076 // Next major: deprecate
5077 /// The `return()` method returns the given value and finishes the generator.
5078 ///
5079 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/return)
5080 #[wasm_bindgen(method, catch, js_name = "return")]
5081 pub fn try_return<T: FromWasmAbi>(
5082 this: &Generator<T>,
5083 value: &T,
5084 ) -> Result<IteratorNext<T>, JsValue>;
5085
5086 /// The `throw()` method resumes the execution of a generator by throwing an error into it
5087 /// and returns an object with two properties done and value.
5088 ///
5089 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/throw)
5090 #[cfg(not(js_sys_unstable_apis))]
5091 #[wasm_bindgen(method, catch)]
5092 pub fn throw<T>(this: &Generator<T>, error: &Error) -> Result<JsValue, JsValue>;
5093
5094 /// The `throw()` method resumes the execution of a generator by throwing an error into it
5095 /// and returns an object with two properties done and value.
5096 ///
5097 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/throw)
5098 #[cfg(js_sys_unstable_apis)]
5099 #[wasm_bindgen(method, catch, js_name = throw)]
5100 pub fn throw<T: FromWasmAbi>(
5101 this: &Generator<T>,
5102 error: &JsValue,
5103 ) -> Result<IteratorNext<T>, JsValue>;
5104
5105 // Next major: deprecate
5106 /// The `throw()` method resumes the execution of a generator by throwing an error into it
5107 /// and returns an object with two properties done and value.
5108 ///
5109 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/throw)
5110 #[wasm_bindgen(method, catch, js_name = throw)]
5111 pub fn throw_value<T: FromWasmAbi>(
5112 this: &Generator<T>,
5113 error: &JsValue,
5114 ) -> Result<IteratorNext<T>, JsValue>;
5115}
5116
5117impl<T: FromWasmAbi> Iterable for Generator<T> {
5118 type Item = T;
5119}
5120
5121// AsyncGenerator
5122#[wasm_bindgen]
5123extern "C" {
5124 #[wasm_bindgen(extends = Object, typescript_type = "AsyncGenerator<any, any, any>")]
5125 #[derive(Clone, Debug, PartialEq, Eq)]
5126 pub type AsyncGenerator<T = JsValue>;
5127
5128 /// The `next()` method returns an object with two properties done and value.
5129 /// You can also provide a parameter to the next method to send a value to the generator.
5130 ///
5131 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncGenerator/next)
5132 #[wasm_bindgen(method, catch)]
5133 pub fn next<T>(
5134 this: &AsyncGenerator<T>,
5135 value: &T,
5136 ) -> Result<Promise<IteratorNext<T>>, JsValue>;
5137
5138 /// The `return()` method returns the given value and finishes the generator.
5139 ///
5140 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncGenerator/return)
5141 #[wasm_bindgen(method, js_name = "return", catch)]
5142 pub fn return_<T>(
5143 this: &AsyncGenerator<T>,
5144 value: &T,
5145 ) -> Result<Promise<IteratorNext<T>>, JsValue>;
5146
5147 /// The `throw()` method resumes the execution of a generator by throwing an error into it
5148 /// and returns an object with two properties done and value.
5149 ///
5150 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncGenerator/throw)
5151 #[wasm_bindgen(method, catch)]
5152 pub fn throw<T>(
5153 this: &AsyncGenerator<T>,
5154 error: &JsValue,
5155 ) -> Result<Promise<IteratorNext<T>>, JsValue>;
5156}
5157
5158impl<T: FromWasmAbi> AsyncIterable for AsyncGenerator<T> {
5159 type Item = T;
5160}
5161
5162// Map
5163#[wasm_bindgen]
5164extern "C" {
5165 #[wasm_bindgen(extends = Object, typescript_type = "Map<any, any>")]
5166 #[derive(Clone, Debug, PartialEq, Eq)]
5167 pub type Map<K = JsValue, V = JsValue>;
5168
5169 /// The Map object holds key-value pairs. Any value (both objects and
5170 /// primitive values) maybe used as either a key or a value.
5171 ///
5172 /// **Note:** Consider using [`Map::new_typed`] for typing support.
5173 ///
5174 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)
5175 #[cfg(not(js_sys_unstable_apis))]
5176 #[wasm_bindgen(constructor)]
5177 pub fn new() -> Map;
5178
5179 /// The Map object holds key-value pairs. Any value (both objects and
5180 /// primitive values) maybe used as either a key or a value.
5181 ///
5182 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)
5183 #[cfg(js_sys_unstable_apis)]
5184 #[wasm_bindgen(constructor)]
5185 pub fn new<K, V>() -> Map<K, V>;
5186
5187 // Next major: deprecate
5188 /// The Map object holds key-value pairs. Any value (both objects and
5189 /// primitive values) maybe used as either a key or a value.
5190 ///
5191 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)
5192 #[wasm_bindgen(constructor)]
5193 pub fn new_typed<K, V>() -> Map<K, V>;
5194
5195 /// The Map object holds key-value pairs. Any value (both objects and
5196 /// primitive values) maybe used as either a key or a value.
5197 ///
5198 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)
5199 #[wasm_bindgen(constructor, js_name = new)]
5200 pub fn new_from_entries<K, V, I: Iterable<Item = ArrayTuple<(K, V)>>>(entries: &I)
5201 -> Map<K, V>;
5202
5203 /// The `clear()` method removes all elements from a Map object.
5204 ///
5205 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/clear)
5206 #[wasm_bindgen(method)]
5207 pub fn clear<K, V>(this: &Map<K, V>);
5208
5209 /// The `delete()` method removes the specified element from a Map object.
5210 ///
5211 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/delete)
5212 #[wasm_bindgen(method)]
5213 pub fn delete<K, V>(this: &Map<K, V>, key: &K) -> bool;
5214
5215 /// The `forEach()` method executes a provided function once per each
5216 /// key/value pair in the Map object, in insertion order.
5217 /// Note that in Javascript land the `Key` and `Value` are reversed compared to normal expectations:
5218 /// # Examples
5219 /// ```
5220 /// let js_map = Map::new();
5221 /// js_map.for_each(&mut |value, key| {
5222 /// // Do something here...
5223 /// })
5224 /// ```
5225 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/forEach)
5226 #[wasm_bindgen(method, js_name = forEach)]
5227 pub fn for_each<K, V>(this: &Map<K, V>, callback: &mut dyn FnMut(V, K));
5228
5229 /// The `forEach()` method executes a provided function once per each
5230 /// key/value pair in the Map object, in insertion order. _(Fallible variation)_
5231 /// Note that in Javascript land the `Key` and `Value` are reversed compared to normal expectations:
5232 /// # Examples
5233 /// ```
5234 /// let js_map = Map::new();
5235 /// js_map.for_each(&mut |value, key| {
5236 /// // Do something here...
5237 /// })
5238 /// ```
5239 ///
5240 /// **Note:** Consider using [`Map::try_for_each`] if the callback might throw an error.
5241 ///
5242 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/forEach)
5243 #[wasm_bindgen(method, js_name = forEach, catch)]
5244 pub fn try_for_each<K, V>(
5245 this: &Map<K, V>,
5246 callback: &mut dyn FnMut(V, K) -> Result<(), JsError>,
5247 ) -> Result<(), JsValue>;
5248
5249 /// The `get()` method returns a specified element from a Map object.
5250 /// Returns `undefined` if the key is not found.
5251 ///
5252 /// **Note:** Consider using [`Map::get_checked`] to get an `Option<V>` instead.
5253 ///
5254 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get)
5255 #[cfg(not(js_sys_unstable_apis))]
5256 #[wasm_bindgen(method)]
5257 pub fn get<K, V>(this: &Map<K, V>, key: &K) -> V;
5258
5259 /// The `get()` method returns a specified element from a Map object.
5260 /// Returns `None` if the key is not found.
5261 ///
5262 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get)
5263 #[cfg(js_sys_unstable_apis)]
5264 #[wasm_bindgen(method)]
5265 pub fn get<K, V>(this: &Map<K, V>, key: &K) -> Option<V>;
5266
5267 /// The `get()` method returns a specified element from a Map object.
5268 /// Returns `None` if the key is not found.
5269 ///
5270 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get)
5271 #[wasm_bindgen(method, js_name = get)]
5272 pub fn get_checked<K, V>(this: &Map<K, V>, key: &K) -> Option<V>;
5273
5274 /// The `has()` method returns a boolean indicating whether an element with
5275 /// the specified key exists or not.
5276 ///
5277 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/has)
5278 #[wasm_bindgen(method)]
5279 pub fn has<K, V>(this: &Map<K, V>, key: &K) -> bool;
5280
5281 /// The `set()` method adds or updates an element with a specified key
5282 /// and value to a Map object.
5283 ///
5284 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/set)
5285 #[wasm_bindgen(method)]
5286 pub fn set<K, V>(this: &Map<K, V>, key: &K, value: &V) -> Map<K, V>;
5287
5288 /// The value of size is an integer representing how many entries
5289 /// the Map object has. A set accessor function for size is undefined;
5290 /// you can not change this property.
5291 ///
5292 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/size)
5293 #[wasm_bindgen(method, getter)]
5294 pub fn size<K, V>(this: &Map<K, V>) -> u32;
5295}
5296
5297impl Default for Map<JsValue, JsValue> {
5298 fn default() -> Self {
5299 Self::new()
5300 }
5301}
5302
5303// Map Iterator
5304#[wasm_bindgen]
5305extern "C" {
5306 /// The `entries()` method returns a new Iterator object that contains
5307 /// the [key, value] pairs for each element in the Map object in
5308 /// insertion order.
5309 ///
5310 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries)
5311 #[cfg(not(js_sys_unstable_apis))]
5312 #[wasm_bindgen(method)]
5313 pub fn entries<K, V: FromWasmAbi>(this: &Map<K, V>) -> Iterator;
5314
5315 /// The `entries()` method returns a new Iterator object that contains
5316 /// the [key, value] pairs for each element in the Map object in
5317 /// insertion order.
5318 ///
5319 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries)
5320 #[cfg(js_sys_unstable_apis)]
5321 #[wasm_bindgen(method, js_name = entries)]
5322 pub fn entries<K: JsGeneric, V: FromWasmAbi + JsGeneric>(
5323 this: &Map<K, V>,
5324 ) -> Iterator<ArrayTuple<(K, V)>>;
5325
5326 // Next major: deprecate
5327 /// The `entries()` method returns a new Iterator object that contains
5328 /// the [key, value] pairs for each element in the Map object in
5329 /// insertion order.
5330 ///
5331 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries)
5332 #[wasm_bindgen(method, js_name = entries)]
5333 pub fn entries_typed<K: JsGeneric, V: FromWasmAbi + JsGeneric>(
5334 this: &Map<K, V>,
5335 ) -> Iterator<ArrayTuple<(K, V)>>;
5336
5337 /// The `keys()` method returns a new Iterator object that contains the
5338 /// keys for each element in the Map object in insertion order.
5339 ///
5340 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/keys)
5341 #[wasm_bindgen(method)]
5342 pub fn keys<K: FromWasmAbi, V: FromWasmAbi>(this: &Map<K, V>) -> Iterator<K>;
5343
5344 /// The `values()` method returns a new Iterator object that contains the
5345 /// values for each element in the Map object in insertion order.
5346 ///
5347 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/values)
5348 #[wasm_bindgen(method)]
5349 pub fn values<K, V: FromWasmAbi>(this: &Map<K, V>) -> Iterator<V>;
5350}
5351
5352impl<K, V> Iterable for Map<K, V> {
5353 type Item = ArrayTuple<(K, V)>;
5354}
5355
5356// Iterator
5357#[wasm_bindgen]
5358extern "C" {
5359 /// Any object that conforms to the JS iterator protocol. For example,
5360 /// something returned by `myArray[Symbol.iterator]()`.
5361 ///
5362 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols)
5363 #[derive(Clone, Debug)]
5364 #[wasm_bindgen(is_type_of = Iterator::looks_like_iterator, typescript_type = "Iterator<any>")]
5365 pub type Iterator<T = JsValue>;
5366
5367 /// The `next()` method always has to return an object with appropriate
5368 /// properties including done and value. If a non-object value gets returned
5369 /// (such as false or undefined), a TypeError ("iterator.next() returned a
5370 /// non-object value") will be thrown.
5371 #[wasm_bindgen(catch, method)]
5372 pub fn next<T: FromWasmAbi>(this: &Iterator<T>) -> Result<IteratorNext<T>, JsValue>;
5373}
5374
5375impl<T> UpcastFrom<Iterator<T>> for Object {}
5376
5377impl Iterator {
5378 fn looks_like_iterator(it: &JsValue) -> bool {
5379 #[wasm_bindgen]
5380 extern "C" {
5381 #[derive(Clone, Debug)]
5382 type MaybeIterator;
5383
5384 #[wasm_bindgen(method, getter)]
5385 fn next(this: &MaybeIterator) -> JsValue;
5386 }
5387
5388 if !it.is_object() {
5389 return false;
5390 }
5391
5392 let it = it.unchecked_ref::<MaybeIterator>();
5393
5394 it.next().is_function()
5395 }
5396}
5397
5398// iterators in JS are themselves iterable
5399impl<T> Iterable for Iterator<T> {
5400 type Item = T;
5401}
5402
5403// Async Iterator
5404#[wasm_bindgen]
5405extern "C" {
5406 /// Any object that conforms to the JS async iterator protocol. For example,
5407 /// something returned by `myObject[Symbol.asyncIterator]()`.
5408 ///
5409 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of)
5410 #[derive(Clone, Debug)]
5411 #[wasm_bindgen(is_type_of = Iterator::looks_like_iterator, typescript_type = "AsyncIterator<any>")]
5412 pub type AsyncIterator<T = JsValue>;
5413
5414 /// The `next()` method always has to return a Promise which resolves to an object
5415 /// with appropriate properties including done and value. If a non-object value
5416 /// gets returned (such as false or undefined), a TypeError ("iterator.next()
5417 /// returned a non-object value") will be thrown.
5418 #[cfg(not(js_sys_unstable_apis))]
5419 #[wasm_bindgen(catch, method)]
5420 pub fn next<T>(this: &AsyncIterator<T>) -> Result<Promise, JsValue>;
5421
5422 /// The `next()` method always has to return a Promise which resolves to an object
5423 /// with appropriate properties including done and value. If a non-object value
5424 /// gets returned (such as false or undefined), a TypeError ("iterator.next()
5425 /// returned a non-object value") will be thrown.
5426 #[cfg(js_sys_unstable_apis)]
5427 #[wasm_bindgen(catch, method, js_name = next)]
5428 pub fn next<T: FromWasmAbi>(
5429 this: &AsyncIterator<T>,
5430 ) -> Result<Promise<IteratorNext<T>>, JsValue>;
5431
5432 // Next major: deprecate
5433 /// The `next()` method always has to return a Promise which resolves to an object
5434 /// with appropriate properties including done and value. If a non-object value
5435 /// gets returned (such as false or undefined), a TypeError ("iterator.next()
5436 /// returned a non-object value") will be thrown.
5437 #[wasm_bindgen(catch, method, js_name = next)]
5438 pub fn next_iterator<T: FromWasmAbi>(
5439 this: &AsyncIterator<T>,
5440 ) -> Result<Promise<IteratorNext<T>>, JsValue>;
5441}
5442
5443impl<T> UpcastFrom<AsyncIterator<T>> for Object {}
5444
5445// iterators in JS are themselves iterable
5446impl<T> AsyncIterable for AsyncIterator<T> {
5447 type Item = T;
5448}
5449
5450/// An iterator over the JS `Symbol.iterator` iteration protocol.
5451///
5452/// Use the `IntoIterator for &js_sys::Iterator` implementation to create this.
5453pub struct Iter<'a, T = JsValue> {
5454 js: &'a Iterator<T>,
5455 state: IterState,
5456}
5457
5458/// An iterator over the JS `Symbol.iterator` iteration protocol.
5459///
5460/// Use the `IntoIterator for js_sys::Iterator` implementation to create this.
5461pub struct IntoIter<T = JsValue> {
5462 js: Iterator<T>,
5463 state: IterState,
5464}
5465
5466struct IterState {
5467 done: bool,
5468}
5469
5470impl<'a, T: FromWasmAbi + JsGeneric> IntoIterator for &'a Iterator<T> {
5471 type Item = Result<T, JsValue>;
5472 type IntoIter = Iter<'a, T>;
5473
5474 fn into_iter(self) -> Iter<'a, T> {
5475 Iter {
5476 js: self,
5477 state: IterState::new(),
5478 }
5479 }
5480}
5481
5482impl<T: FromWasmAbi + JsGeneric> core::iter::Iterator for Iter<'_, T> {
5483 type Item = Result<T, JsValue>;
5484
5485 fn next(&mut self) -> Option<Self::Item> {
5486 self.state.next(self.js)
5487 }
5488}
5489
5490impl<T: FromWasmAbi + JsGeneric> IntoIterator for Iterator<T> {
5491 type Item = Result<T, JsValue>;
5492 type IntoIter = IntoIter<T>;
5493
5494 fn into_iter(self) -> IntoIter<T> {
5495 IntoIter {
5496 js: self,
5497 state: IterState::new(),
5498 }
5499 }
5500}
5501
5502impl<T: FromWasmAbi + JsGeneric> core::iter::Iterator for IntoIter<T> {
5503 type Item = Result<T, JsValue>;
5504
5505 fn next(&mut self) -> Option<Self::Item> {
5506 self.state.next(&self.js)
5507 }
5508}
5509
5510impl IterState {
5511 fn new() -> IterState {
5512 IterState { done: false }
5513 }
5514
5515 fn next<T: FromWasmAbi + JsGeneric>(&mut self, js: &Iterator<T>) -> Option<Result<T, JsValue>> {
5516 if self.done {
5517 return None;
5518 }
5519 let next = match js.next() {
5520 Ok(val) => val,
5521 Err(e) => {
5522 self.done = true;
5523 return Some(Err(e));
5524 }
5525 };
5526 if next.done() {
5527 self.done = true;
5528 None
5529 } else {
5530 Some(Ok(next.value()))
5531 }
5532 }
5533}
5534
5535/// Create an iterator over `val` using the JS iteration protocol and
5536/// `Symbol.iterator`.
5537// #[cfg(not(js_sys_unstable_apis))]
5538pub fn try_iter(val: &JsValue) -> Result<Option<IntoIter<JsValue>>, JsValue> {
5539 let iter_sym = Symbol::iterator();
5540
5541 let iter_fn = Reflect::get_symbol::<Object>(val.unchecked_ref(), iter_sym.as_ref())?;
5542 let iter_fn: Function = match iter_fn.dyn_into() {
5543 Ok(iter_fn) => iter_fn,
5544 Err(_) => return Ok(None),
5545 };
5546
5547 let it: Iterator = match iter_fn.call0(val)?.dyn_into() {
5548 Ok(it) => it,
5549 Err(_) => return Ok(None),
5550 };
5551
5552 Ok(Some(it.into_iter()))
5553}
5554
5555/// Trait for JavaScript types that implement the iterable protocol via `Symbol.iterator`.
5556///
5557/// Types implementing this trait can be iterated over using JavaScript's iteration
5558/// protocol. The `Item` associated type specifies the type of values yielded.
5559///
5560/// ## Built-in Iterables
5561///
5562/// Many `js-sys` collection types implement `Iterable` out of the box:
5563///
5564/// ```ignore
5565/// use js_sys::{Array, Map, Set};
5566///
5567/// // Array<T> yields T
5568/// let arr: Array<Number> = get_numbers();
5569/// for value in arr.iter() {
5570/// let num: Number = value?;
5571/// }
5572///
5573/// // Map<K, V> yields Array (key-value pairs)
5574/// let map: Map<JsString, Number> = get_map();
5575/// for entry in map.iter() {
5576/// let pair: Array = entry?;
5577/// }
5578///
5579/// // Set<T> yields T
5580/// let set: Set<JsString> = get_set();
5581/// for value in set.iter() {
5582/// let s: JsString = value?;
5583/// }
5584/// ```
5585///
5586/// ## Typing Foreign Iterators
5587///
5588/// If you have a JavaScript value that implements the iterator protocol (has a `next()`
5589/// method) but isn't a built-in type, you can use [`JsCast`] to cast it to [`Iterator<T>`]:
5590///
5591/// ```ignore
5592/// use js_sys::Iterator;
5593/// use wasm_bindgen::JsCast;
5594///
5595/// // For a value you know implements the iterator protocol
5596/// fn process_iterator(js_iter: JsValue) {
5597/// // Checked cast - returns None if not an iterator
5598/// if let Some(iter) = js_iter.dyn_ref::<Iterator<Number>>() {
5599/// for value in iter.into_iter() {
5600/// let num: Number = value.unwrap();
5601/// // ...
5602/// }
5603/// }
5604/// }
5605///
5606/// // Or with unchecked cast when you're certain of the type
5607/// fn process_known_iterator(js_iter: JsValue) {
5608/// let iter: &Iterator<JsString> = js_iter.unchecked_ref();
5609/// for value in iter.into_iter() {
5610/// let s: JsString = value.unwrap();
5611/// // ...
5612/// }
5613/// }
5614/// ```
5615///
5616/// ## Using with `JsValue`
5617///
5618/// For dynamic or unknown iterables, use [`try_iter`] which returns an untyped iterator:
5619///
5620/// ```ignore
5621/// fn iterate_unknown(val: &JsValue) -> Result<(), JsValue> {
5622/// if let Some(iter) = js_sys::try_iter(val)? {
5623/// for item in iter {
5624/// let value: JsValue = item?;
5625/// // Handle dynamically...
5626/// }
5627/// }
5628/// Ok(())
5629/// }
5630/// ```
5631///
5632/// [`JsCast`]: wasm_bindgen::JsCast
5633/// [`Iterator<T>`]: Iterator
5634/// [`try_iter`]: crate::try_iter
5635pub trait Iterable {
5636 /// The type of values yielded by this iterable.
5637 type Item;
5638}
5639
5640impl<T: Iterable> Iterable for &T {
5641 type Item = T::Item;
5642}
5643
5644/// Trait for types known to implement the iterator protocol on Symbol.asyncIterator
5645pub trait AsyncIterable {
5646 type Item;
5647}
5648
5649impl<T: AsyncIterable> AsyncIterable for &T {
5650 type Item = T::Item;
5651}
5652
5653impl AsyncIterable for JsValue {
5654 type Item = JsValue;
5655}
5656
5657// IteratorNext
5658#[wasm_bindgen]
5659extern "C" {
5660 /// The result of calling `next()` on a JS iterator.
5661 ///
5662 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols)
5663 #[wasm_bindgen(extends = Object, typescript_type = "IteratorResult<any>")]
5664 #[derive(Clone, Debug, PartialEq, Eq)]
5665 pub type IteratorNext<T = JsValue>;
5666
5667 /// Has the value `true` if the iterator is past the end of the iterated
5668 /// sequence. In this case value optionally specifies the return value of
5669 /// the iterator.
5670 ///
5671 /// Has the value `false` if the iterator was able to produce the next value
5672 /// in the sequence. This is equivalent of not specifying the done property
5673 /// altogether.
5674 #[wasm_bindgen(method, getter)]
5675 pub fn done<T>(this: &IteratorNext<T>) -> bool;
5676
5677 /// Any JavaScript value returned by the iterator. Can be omitted when done
5678 /// is true.
5679 #[wasm_bindgen(method, getter)]
5680 pub fn value<T>(this: &IteratorNext<T>) -> T;
5681}
5682
5683#[allow(non_snake_case)]
5684pub mod Math {
5685 use super::*;
5686
5687 // Math
5688 #[wasm_bindgen]
5689 extern "C" {
5690 /// The `Math.abs()` function returns the absolute value of a number, that is
5691 /// Math.abs(x) = |x|
5692 ///
5693 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/abs)
5694 #[wasm_bindgen(js_namespace = Math)]
5695 pub fn abs(x: f64) -> f64;
5696
5697 /// The `Math.acos()` function returns the arccosine (in radians) of a
5698 /// number, that is ∀x∊[-1;1]
5699 /// Math.acos(x) = arccos(x) = the unique y∊[0;π] such that cos(y)=x
5700 ///
5701 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/acos)
5702 #[wasm_bindgen(js_namespace = Math)]
5703 pub fn acos(x: f64) -> f64;
5704
5705 /// The `Math.acosh()` function returns the hyperbolic arc-cosine of a
5706 /// number, that is ∀x ≥ 1
5707 /// Math.acosh(x) = arcosh(x) = the unique y ≥ 0 such that cosh(y) = x
5708 ///
5709 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/acosh)
5710 #[wasm_bindgen(js_namespace = Math)]
5711 pub fn acosh(x: f64) -> f64;
5712
5713 /// The `Math.asin()` function returns the arcsine (in radians) of a
5714 /// number, that is ∀x ∊ [-1;1]
5715 /// Math.asin(x) = arcsin(x) = the unique y∊[-π2;π2] such that sin(y) = x
5716 ///
5717 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/asin)
5718 #[wasm_bindgen(js_namespace = Math)]
5719 pub fn asin(x: f64) -> f64;
5720
5721 /// The `Math.asinh()` function returns the hyperbolic arcsine of a
5722 /// number, that is Math.asinh(x) = arsinh(x) = the unique y such that sinh(y) = x
5723 ///
5724 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/asinh)
5725 #[wasm_bindgen(js_namespace = Math)]
5726 pub fn asinh(x: f64) -> f64;
5727
5728 /// The `Math.atan()` function returns the arctangent (in radians) of a
5729 /// number, that is Math.atan(x) = arctan(x) = the unique y ∊ [-π2;π2]such that
5730 /// tan(y) = x
5731 #[wasm_bindgen(js_namespace = Math)]
5732 pub fn atan(x: f64) -> f64;
5733
5734 /// The `Math.atan2()` function returns the arctangent of the quotient of
5735 /// its arguments.
5736 ///
5737 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/atan2)
5738 #[wasm_bindgen(js_namespace = Math)]
5739 pub fn atan2(y: f64, x: f64) -> f64;
5740
5741 /// The `Math.atanh()` function returns the hyperbolic arctangent of a number,
5742 /// that is ∀x ∊ (-1,1), Math.atanh(x) = arctanh(x) = the unique y such that
5743 /// tanh(y) = x
5744 ///
5745 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/atanh)
5746 #[wasm_bindgen(js_namespace = Math)]
5747 pub fn atanh(x: f64) -> f64;
5748
5749 /// The `Math.cbrt() `function returns the cube root of a number, that is
5750 /// Math.cbrt(x) = ∛x = the unique y such that y^3 = x
5751 ///
5752 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/cbrt)
5753 #[wasm_bindgen(js_namespace = Math)]
5754 pub fn cbrt(x: f64) -> f64;
5755
5756 /// The `Math.ceil()` function returns the smallest integer greater than
5757 /// or equal to a given number.
5758 ///
5759 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/ceil)
5760 #[wasm_bindgen(js_namespace = Math)]
5761 pub fn ceil(x: f64) -> f64;
5762
5763 /// The `Math.clz32()` function returns the number of leading zero bits in
5764 /// the 32-bit binary representation of a number.
5765 ///
5766 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/clz32)
5767 #[wasm_bindgen(js_namespace = Math)]
5768 pub fn clz32(x: i32) -> u32;
5769
5770 /// The `Math.cos()` static function returns the cosine of the specified angle,
5771 /// which must be specified in radians. This value is length(adjacent)/length(hypotenuse).
5772 ///
5773 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/cos)
5774 #[wasm_bindgen(js_namespace = Math)]
5775 pub fn cos(x: f64) -> f64;
5776
5777 /// The `Math.cosh()` function returns the hyperbolic cosine of a number,
5778 /// that can be expressed using the constant e.
5779 ///
5780 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/cosh)
5781 #[wasm_bindgen(js_namespace = Math)]
5782 pub fn cosh(x: f64) -> f64;
5783
5784 /// The `Math.exp()` function returns e^x, where x is the argument, and e is Euler's number
5785 /// (also known as Napier's constant), the base of the natural logarithms.
5786 ///
5787 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/exp)
5788 #[wasm_bindgen(js_namespace = Math)]
5789 pub fn exp(x: f64) -> f64;
5790
5791 /// The `Math.expm1()` function returns e^x - 1, where x is the argument, and e the base of the
5792 /// natural logarithms.
5793 ///
5794 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/expm1)
5795 #[wasm_bindgen(js_namespace = Math)]
5796 pub fn expm1(x: f64) -> f64;
5797
5798 /// The `Math.floor()` function returns the largest integer less than or
5799 /// equal to a given number.
5800 ///
5801 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/floor)
5802 #[wasm_bindgen(js_namespace = Math)]
5803 pub fn floor(x: f64) -> f64;
5804
5805 /// The `Math.fround()` function returns the nearest 32-bit single precision float representation
5806 /// of a Number.
5807 ///
5808 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/fround)
5809 #[wasm_bindgen(js_namespace = Math)]
5810 pub fn fround(x: f64) -> f32;
5811
5812 /// The `Math.hypot()` function returns the square root of the sum of squares of its arguments.
5813 ///
5814 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/hypot)
5815 #[wasm_bindgen(js_namespace = Math)]
5816 pub fn hypot(x: f64, y: f64) -> f64;
5817
5818 /// The `Math.imul()` function returns the result of the C-like 32-bit multiplication of the
5819 /// two parameters.
5820 ///
5821 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/imul)
5822 #[wasm_bindgen(js_namespace = Math)]
5823 pub fn imul(x: i32, y: i32) -> i32;
5824
5825 /// The `Math.log()` function returns the natural logarithm (base e) of a number.
5826 /// The JavaScript `Math.log()` function is equivalent to ln(x) in mathematics.
5827 ///
5828 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log)
5829 #[wasm_bindgen(js_namespace = Math)]
5830 pub fn log(x: f64) -> f64;
5831
5832 /// The `Math.log10()` function returns the base 10 logarithm of a number.
5833 ///
5834 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log10)
5835 #[wasm_bindgen(js_namespace = Math)]
5836 pub fn log10(x: f64) -> f64;
5837
5838 /// The `Math.log1p()` function returns the natural logarithm (base e) of 1 + a number.
5839 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log1p)
5840 #[wasm_bindgen(js_namespace = Math)]
5841 pub fn log1p(x: f64) -> f64;
5842
5843 /// The `Math.log2()` function returns the base 2 logarithm of a number.
5844 ///
5845 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log2)
5846 #[wasm_bindgen(js_namespace = Math)]
5847 pub fn log2(x: f64) -> f64;
5848
5849 /// The `Math.max()` function returns the largest of two numbers.
5850 ///
5851 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/max)
5852 #[wasm_bindgen(js_namespace = Math)]
5853 pub fn max(x: f64, y: f64) -> f64;
5854
5855 /// The static function `Math.min()` returns the lowest-valued number passed into it.
5856 ///
5857 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/min)
5858 #[wasm_bindgen(js_namespace = Math)]
5859 pub fn min(x: f64, y: f64) -> f64;
5860
5861 /// The `Math.pow()` function returns the base to the exponent power, that is, base^exponent.
5862 ///
5863 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/pow)
5864 #[wasm_bindgen(js_namespace = Math)]
5865 pub fn pow(base: f64, exponent: f64) -> f64;
5866
5867 /// The `Math.random()` function returns a floating-point, pseudo-random number
5868 /// in the range 0–1 (inclusive of 0, but not 1) with approximately uniform distribution
5869 /// over that range — which you can then scale to your desired range.
5870 /// The implementation selects the initial seed to the random number generation algorithm;
5871 /// it cannot be chosen or reset by the user.
5872 ///
5873 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random)
5874 #[wasm_bindgen(js_namespace = Math)]
5875 pub fn random() -> f64;
5876
5877 /// The `Math.round()` function returns the value of a number rounded to the nearest integer.
5878 ///
5879 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round)
5880 #[wasm_bindgen(js_namespace = Math)]
5881 pub fn round(x: f64) -> f64;
5882
5883 /// The `Math.sign()` function returns the sign of a number, indicating whether the number is
5884 /// positive, negative or zero.
5885 ///
5886 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign)
5887 #[wasm_bindgen(js_namespace = Math)]
5888 pub fn sign(x: f64) -> f64;
5889
5890 /// The `Math.sin()` function returns the sine of a number.
5891 ///
5892 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sin)
5893 #[wasm_bindgen(js_namespace = Math)]
5894 pub fn sin(x: f64) -> f64;
5895
5896 /// The `Math.sinh()` function returns the hyperbolic sine of a number, that can be expressed
5897 /// using the constant e: Math.sinh(x) = (e^x - e^-x)/2
5898 ///
5899 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sinh)
5900 #[wasm_bindgen(js_namespace = Math)]
5901 pub fn sinh(x: f64) -> f64;
5902
5903 /// The `Math.sqrt()` function returns the square root of a number, that is
5904 /// ∀x ≥ 0, Math.sqrt(x) = √x = the unique y ≥ 0 such that y^2 = x
5905 ///
5906 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sqrt)
5907 #[wasm_bindgen(js_namespace = Math)]
5908 pub fn sqrt(x: f64) -> f64;
5909
5910 /// The `Math.tan()` function returns the tangent of a number.
5911 ///
5912 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/tan)
5913 #[wasm_bindgen(js_namespace = Math)]
5914 pub fn tan(x: f64) -> f64;
5915
5916 /// The `Math.tanh()` function returns the hyperbolic tangent of a number, that is
5917 /// tanh x = sinh x / cosh x = (e^x - e^-x)/(e^x + e^-x) = (e^2x - 1)/(e^2x + 1)
5918 ///
5919 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/tanh)
5920 #[wasm_bindgen(js_namespace = Math)]
5921 pub fn tanh(x: f64) -> f64;
5922
5923 /// The `Math.trunc()` function returns the integer part of a number by removing any fractional
5924 /// digits.
5925 ///
5926 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/trunc)
5927 #[wasm_bindgen(js_namespace = Math)]
5928 pub fn trunc(x: f64) -> f64;
5929
5930 /// The `Math.PI` property represents the ratio of the circumference of a circle to its diameter,
5931 /// approximately 3.14159.
5932 ///
5933 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/PI)
5934 #[wasm_bindgen(thread_local_v2, js_namespace = Math)]
5935 pub static PI: f64;
5936 }
5937}
5938
5939// Number.
5940#[wasm_bindgen]
5941extern "C" {
5942 #[wasm_bindgen(extends = Object, is_type_of = |v| v.as_f64().is_some(), typescript_type = "number")]
5943 #[derive(Clone, PartialEq)]
5944 pub type Number;
5945
5946 /// The `Number.isFinite()` method determines whether the passed value is a finite number.
5947 ///
5948 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isFinite)
5949 #[wasm_bindgen(static_method_of = Number, js_name = isFinite)]
5950 pub fn is_finite(value: &JsValue) -> bool;
5951
5952 /// The `Number.isInteger()` method determines whether the passed value is an integer.
5953 ///
5954 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isInteger)
5955 #[wasm_bindgen(static_method_of = Number, js_name = isInteger)]
5956 pub fn is_integer(value: &JsValue) -> bool;
5957
5958 /// The `Number.isNaN()` method determines whether the passed value is `NaN` and its type is Number.
5959 /// It is a more robust version of the original, global isNaN().
5960 ///
5961 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isNaN)
5962 #[wasm_bindgen(static_method_of = Number, js_name = isNaN)]
5963 pub fn is_nan(value: &JsValue) -> bool;
5964
5965 /// The `Number.isSafeInteger()` method determines whether the provided value is a number
5966 /// that is a safe integer.
5967 ///
5968 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isSafeInteger)
5969 #[wasm_bindgen(static_method_of = Number, js_name = isSafeInteger)]
5970 pub fn is_safe_integer(value: &JsValue) -> bool;
5971
5972 /// The `Number` JavaScript object is a wrapper object allowing
5973 /// you to work with numerical values. A `Number` object is
5974 /// created using the `Number()` constructor.
5975 ///
5976 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
5977 #[cfg(not(js_sys_unstable_apis))]
5978 #[wasm_bindgen(constructor)]
5979 #[deprecated(note = "recommended to use `Number::from` instead")]
5980 #[allow(deprecated)]
5981 pub fn new(value: &JsValue) -> Number;
5982
5983 #[wasm_bindgen(constructor)]
5984 fn new_from_str(value: &str) -> Number;
5985
5986 /// The `Number.parseInt()` method parses a string argument and returns an
5987 /// integer of the specified radix or base.
5988 ///
5989 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/parseInt)
5990 #[wasm_bindgen(static_method_of = Number, js_name = parseInt)]
5991 pub fn parse_int(text: &str, radix: u8) -> f64;
5992
5993 /// The `Number.parseFloat()` method parses a string argument and returns a
5994 /// floating point number.
5995 ///
5996 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/parseFloat)
5997 #[wasm_bindgen(static_method_of = Number, js_name = parseFloat)]
5998 pub fn parse_float(text: &str) -> f64;
5999
6000 /// The `toLocaleString()` method returns a string with a language sensitive
6001 /// representation of this number.
6002 ///
6003 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString)
6004 #[cfg(not(js_sys_unstable_apis))]
6005 #[wasm_bindgen(method, js_name = toLocaleString)]
6006 pub fn to_locale_string(this: &Number, locale: &str) -> JsString;
6007
6008 /// The `toLocaleString()` method returns a string with a language sensitive
6009 /// representation of this number.
6010 ///
6011 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString)
6012 #[cfg(js_sys_unstable_apis)]
6013 #[wasm_bindgen(method, js_name = toLocaleString)]
6014 pub fn to_locale_string(
6015 this: &Number,
6016 locales: &[JsString],
6017 options: &Intl::NumberFormatOptions,
6018 ) -> JsString;
6019
6020 /// The `toPrecision()` method returns a string representing the Number
6021 /// object to the specified precision.
6022 ///
6023 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision)
6024 #[wasm_bindgen(catch, method, js_name = toPrecision)]
6025 pub fn to_precision(this: &Number, precision: u8) -> Result<JsString, JsValue>;
6026
6027 /// The `toFixed()` method returns a string representing the Number
6028 /// object using fixed-point notation.
6029 ///
6030 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed)
6031 #[wasm_bindgen(catch, method, js_name = toFixed)]
6032 pub fn to_fixed(this: &Number, digits: u8) -> Result<JsString, JsValue>;
6033
6034 /// The `toExponential()` method returns a string representing the Number
6035 /// object in exponential notation.
6036 ///
6037 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toExponential)
6038 #[wasm_bindgen(catch, method, js_name = toExponential)]
6039 pub fn to_exponential(this: &Number, fraction_digits: u8) -> Result<JsString, JsValue>;
6040
6041 /// The `toString()` method returns a string representing the
6042 /// specified Number object.
6043 ///
6044 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString)
6045 #[cfg(not(js_sys_unstable_apis))]
6046 #[deprecated(note = "Use `Number::to_string_with_radix` instead.")]
6047 #[allow(deprecated)]
6048 #[wasm_bindgen(catch, method, js_name = toString)]
6049 pub fn to_string(this: &Number, radix: u8) -> Result<JsString, JsValue>;
6050
6051 /// The `toString()` method returns a string representing the
6052 /// specified Number object.
6053 ///
6054 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString)
6055 #[wasm_bindgen(catch, method, js_name = toString)]
6056 pub fn to_string_with_radix(this: &Number, radix: u8) -> Result<JsString, JsValue>;
6057
6058 /// The `valueOf()` method returns the wrapped primitive value of
6059 /// a Number object.
6060 ///
6061 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/valueOf)
6062 #[wasm_bindgen(method, js_name = valueOf)]
6063 pub fn value_of(this: &Number) -> f64;
6064}
6065
6066impl Number {
6067 /// The smallest interval between two representable numbers.
6068 ///
6069 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/EPSILON)
6070 pub const EPSILON: f64 = f64::EPSILON;
6071 /// The maximum safe integer in JavaScript (2^53 - 1).
6072 ///
6073 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER)
6074 pub const MAX_SAFE_INTEGER: f64 = 9007199254740991.0;
6075 /// The largest positive representable number.
6076 ///
6077 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_VALUE)
6078 pub const MAX_VALUE: f64 = f64::MAX;
6079 /// The minimum safe integer in JavaScript (-(2^53 - 1)).
6080 ///
6081 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MIN_SAFE_INTEGER)
6082 pub const MIN_SAFE_INTEGER: f64 = -9007199254740991.0;
6083 /// The smallest positive representable number—that is, the positive number closest to zero
6084 /// (without actually being zero).
6085 ///
6086 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MIN_VALUE)
6087 // Cannot use f64::MIN_POSITIVE since that is the smallest **normal** positive number.
6088 pub const MIN_VALUE: f64 = 5E-324;
6089 /// Special "Not a Number" value.
6090 ///
6091 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/NaN)
6092 pub const NAN: f64 = f64::NAN;
6093 /// Special value representing negative infinity. Returned on overflow.
6094 ///
6095 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/NEGATIVE_INFINITY)
6096 pub const NEGATIVE_INFINITY: f64 = f64::NEG_INFINITY;
6097 /// Special value representing infinity. Returned on overflow.
6098 ///
6099 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/POSITIVE_INFINITY)
6100 pub const POSITIVE_INFINITY: f64 = f64::INFINITY;
6101
6102 /// Applies the binary `**` JS operator on the two `Number`s.
6103 ///
6104 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Exponentiation)
6105 #[inline]
6106 pub fn pow(&self, rhs: &Self) -> Self {
6107 JsValue::as_ref(self)
6108 .pow(JsValue::as_ref(rhs))
6109 .unchecked_into()
6110 }
6111
6112 /// Applies the binary `>>>` JS operator on the two `Number`s.
6113 ///
6114 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Unsigned_right_shift)
6115 #[inline]
6116 pub fn unsigned_shr(&self, rhs: &Self) -> Self {
6117 Number::from(JsValue::as_ref(self).unsigned_shr(JsValue::as_ref(rhs)))
6118 }
6119}
6120
6121macro_rules! number_from {
6122 ($($x:ident)*) => ($(
6123 impl From<$x> for Number {
6124 #[inline]
6125 fn from(x: $x) -> Number {
6126 Number::unchecked_from_js(JsValue::from(x))
6127 }
6128 }
6129
6130 impl PartialEq<$x> for Number {
6131 #[inline]
6132 fn eq(&self, other: &$x) -> bool {
6133 self.value_of() == f64::from(*other)
6134 }
6135 }
6136
6137 impl UpcastFrom<$x> for Number {}
6138 )*)
6139}
6140number_from!(i8 u8 i16 u16 i32 u32 f32 f64);
6141
6142// The only guarantee for a JS number
6143impl UpcastFrom<Number> for f64 {}
6144
6145/// The error type returned when a checked integral type conversion fails.
6146#[derive(Debug, Copy, Clone, PartialEq, Eq)]
6147pub struct TryFromIntError(());
6148
6149impl fmt::Display for TryFromIntError {
6150 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
6151 fmt.write_str("out of range integral type conversion attempted")
6152 }
6153}
6154
6155#[cfg(feature = "std")]
6156impl std::error::Error for TryFromIntError {}
6157
6158macro_rules! number_try_from {
6159 ($($x:ident)*) => ($(
6160 impl TryFrom<$x> for Number {
6161 type Error = TryFromIntError;
6162
6163 #[inline]
6164 fn try_from(x: $x) -> Result<Number, Self::Error> {
6165 let x_f64 = x as f64;
6166 if (Number::MIN_SAFE_INTEGER..=Number::MAX_SAFE_INTEGER).contains(&x_f64) {
6167 Ok(Number::from(x_f64))
6168 } else {
6169 Err(TryFromIntError(()))
6170 }
6171 }
6172 }
6173 )*)
6174}
6175number_try_from!(i64 u64 i128 u128);
6176
6177impl From<&Number> for f64 {
6178 #[inline]
6179 fn from(n: &Number) -> f64 {
6180 n.value_of()
6181 }
6182}
6183
6184impl From<Number> for f64 {
6185 #[inline]
6186 fn from(n: Number) -> f64 {
6187 <f64 as From<&'_ Number>>::from(&n)
6188 }
6189}
6190
6191impl fmt::Debug for Number {
6192 #[inline]
6193 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6194 fmt::Debug::fmt(&self.value_of(), f)
6195 }
6196}
6197
6198impl fmt::Display for Number {
6199 #[inline]
6200 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6201 fmt::Display::fmt(&self.value_of(), f)
6202 }
6203}
6204
6205impl Default for Number {
6206 fn default() -> Self {
6207 Self::from(f64::default())
6208 }
6209}
6210
6211impl PartialEq<BigInt> for Number {
6212 #[inline]
6213 fn eq(&self, other: &BigInt) -> bool {
6214 JsValue::as_ref(self).loose_eq(JsValue::as_ref(other))
6215 }
6216}
6217
6218impl Not for &Number {
6219 type Output = BigInt;
6220
6221 #[inline]
6222 fn not(self) -> Self::Output {
6223 JsValue::as_ref(self).bit_not().unchecked_into()
6224 }
6225}
6226
6227forward_deref_unop!(impl Not, not for Number);
6228forward_js_unop!(impl Neg, neg for Number);
6229forward_js_binop!(impl BitAnd, bitand for Number);
6230forward_js_binop!(impl BitOr, bitor for Number);
6231forward_js_binop!(impl BitXor, bitxor for Number);
6232forward_js_binop!(impl Shl, shl for Number);
6233forward_js_binop!(impl Shr, shr for Number);
6234forward_js_binop!(impl Add, add for Number);
6235forward_js_binop!(impl Sub, sub for Number);
6236forward_js_binop!(impl Div, div for Number);
6237forward_js_binop!(impl Mul, mul for Number);
6238forward_js_binop!(impl Rem, rem for Number);
6239
6240sum_product!(Number);
6241
6242impl PartialOrd for Number {
6243 #[inline]
6244 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
6245 if Number::is_nan(self) || Number::is_nan(other) {
6246 None
6247 } else if self == other {
6248 Some(Ordering::Equal)
6249 } else if self.lt(other) {
6250 Some(Ordering::Less)
6251 } else {
6252 Some(Ordering::Greater)
6253 }
6254 }
6255
6256 #[inline]
6257 fn lt(&self, other: &Self) -> bool {
6258 JsValue::as_ref(self).lt(JsValue::as_ref(other))
6259 }
6260
6261 #[inline]
6262 fn le(&self, other: &Self) -> bool {
6263 JsValue::as_ref(self).le(JsValue::as_ref(other))
6264 }
6265
6266 #[inline]
6267 fn ge(&self, other: &Self) -> bool {
6268 JsValue::as_ref(self).ge(JsValue::as_ref(other))
6269 }
6270
6271 #[inline]
6272 fn gt(&self, other: &Self) -> bool {
6273 JsValue::as_ref(self).gt(JsValue::as_ref(other))
6274 }
6275}
6276
6277#[cfg(not(js_sys_unstable_apis))]
6278impl FromStr for Number {
6279 type Err = Infallible;
6280
6281 #[allow(deprecated)]
6282 #[inline]
6283 fn from_str(s: &str) -> Result<Self, Self::Err> {
6284 Ok(Number::new_from_str(s))
6285 }
6286}
6287
6288// Date.
6289#[wasm_bindgen]
6290extern "C" {
6291 #[wasm_bindgen(extends = Object, typescript_type = "Date")]
6292 #[derive(Clone, Debug, PartialEq, Eq)]
6293 pub type Date;
6294
6295 /// The `getDate()` method returns the day of the month for the
6296 /// specified date according to local time.
6297 ///
6298 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getDate)
6299 #[wasm_bindgen(method, js_name = getDate)]
6300 pub fn get_date(this: &Date) -> u32;
6301
6302 /// The `getDay()` method returns the day of the week for the specified date according to local time,
6303 /// where 0 represents Sunday. For the day of the month see getDate().
6304 ///
6305 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getDay)
6306 #[wasm_bindgen(method, js_name = getDay)]
6307 pub fn get_day(this: &Date) -> u32;
6308
6309 /// The `getFullYear()` method returns the year of the specified date according to local time.
6310 ///
6311 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getFullYear)
6312 #[wasm_bindgen(method, js_name = getFullYear)]
6313 pub fn get_full_year(this: &Date) -> u32;
6314
6315 /// The `getHours()` method returns the hour for the specified date, according to local time.
6316 ///
6317 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getHours)
6318 #[wasm_bindgen(method, js_name = getHours)]
6319 pub fn get_hours(this: &Date) -> u32;
6320
6321 /// The `getMilliseconds()` method returns the milliseconds in the specified date according to local time.
6322 ///
6323 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMilliseconds)
6324 #[wasm_bindgen(method, js_name = getMilliseconds)]
6325 pub fn get_milliseconds(this: &Date) -> u32;
6326
6327 /// The `getMinutes()` method returns the minutes in the specified date according to local time.
6328 ///
6329 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMinutes)
6330 #[wasm_bindgen(method, js_name = getMinutes)]
6331 pub fn get_minutes(this: &Date) -> u32;
6332
6333 /// The `getMonth()` method returns the month in the specified date according to local time,
6334 /// as a zero-based value (where zero indicates the first month of the year).
6335 ///
6336 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMonth)
6337 #[wasm_bindgen(method, js_name = getMonth)]
6338 pub fn get_month(this: &Date) -> u32;
6339
6340 /// The `getSeconds()` method returns the seconds in the specified date according to local time.
6341 ///
6342 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getSeconds)
6343 #[wasm_bindgen(method, js_name = getSeconds)]
6344 pub fn get_seconds(this: &Date) -> u32;
6345
6346 /// The `getTime()` method returns the numeric value corresponding to the time for the specified date
6347 /// according to universal time.
6348 ///
6349 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTime)
6350 #[wasm_bindgen(method, js_name = getTime)]
6351 pub fn get_time(this: &Date) -> f64;
6352
6353 /// The `getTimezoneOffset()` method returns the time zone difference, in minutes,
6354 /// from current locale (host system settings) to UTC.
6355 ///
6356 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTimezoneOffset)
6357 #[wasm_bindgen(method, js_name = getTimezoneOffset)]
6358 pub fn get_timezone_offset(this: &Date) -> f64;
6359
6360 /// The `getUTCDate()` method returns the day (date) of the month in the specified date
6361 /// according to universal time.
6362 ///
6363 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCDate)
6364 #[wasm_bindgen(method, js_name = getUTCDate)]
6365 pub fn get_utc_date(this: &Date) -> u32;
6366
6367 /// The `getUTCDay()` method returns the day of the week in the specified date according to universal time,
6368 /// where 0 represents Sunday.
6369 ///
6370 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCDay)
6371 #[wasm_bindgen(method, js_name = getUTCDay)]
6372 pub fn get_utc_day(this: &Date) -> u32;
6373
6374 /// The `getUTCFullYear()` method returns the year in the specified date according to universal time.
6375 ///
6376 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCFullYear)
6377 #[wasm_bindgen(method, js_name = getUTCFullYear)]
6378 pub fn get_utc_full_year(this: &Date) -> u32;
6379
6380 /// The `getUTCHours()` method returns the hours in the specified date according to universal time.
6381 ///
6382 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCHours)
6383 #[wasm_bindgen(method, js_name = getUTCHours)]
6384 pub fn get_utc_hours(this: &Date) -> u32;
6385
6386 /// The `getUTCMilliseconds()` method returns the milliseconds in the specified date
6387 /// according to universal time.
6388 ///
6389 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCMilliseconds)
6390 #[wasm_bindgen(method, js_name = getUTCMilliseconds)]
6391 pub fn get_utc_milliseconds(this: &Date) -> u32;
6392
6393 /// The `getUTCMinutes()` method returns the minutes in the specified date according to universal time.
6394 ///
6395 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCMinutes)
6396 #[wasm_bindgen(method, js_name = getUTCMinutes)]
6397 pub fn get_utc_minutes(this: &Date) -> u32;
6398
6399 /// The `getUTCMonth()` returns the month of the specified date according to universal time,
6400 /// as a zero-based value (where zero indicates the first month of the year).
6401 ///
6402 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCMonth)
6403 #[wasm_bindgen(method, js_name = getUTCMonth)]
6404 pub fn get_utc_month(this: &Date) -> u32;
6405
6406 /// The `getUTCSeconds()` method returns the seconds in the specified date according to universal time.
6407 ///
6408 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCSeconds)
6409 #[wasm_bindgen(method, js_name = getUTCSeconds)]
6410 pub fn get_utc_seconds(this: &Date) -> u32;
6411
6412 /// Creates a JavaScript `Date` instance that represents
6413 /// a single moment in time. `Date` objects are based on a time value that is
6414 /// the number of milliseconds since 1 January 1970 UTC.
6415 ///
6416 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6417 #[wasm_bindgen(constructor)]
6418 pub fn new(init: &JsValue) -> Date;
6419
6420 /// Creates a JavaScript `Date` instance that represents the current moment in
6421 /// time.
6422 ///
6423 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6424 #[wasm_bindgen(constructor)]
6425 pub fn new_0() -> Date;
6426
6427 /// Creates a JavaScript `Date` instance that represents
6428 /// a single moment in time. `Date` objects are based on a time value that is
6429 /// the number of milliseconds since 1 January 1970 UTC.
6430 ///
6431 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6432 #[wasm_bindgen(constructor)]
6433 pub fn new_with_year_month(year: u32, month: i32) -> Date;
6434
6435 /// Creates a JavaScript `Date` instance that represents
6436 /// a single moment in time. `Date` objects are based on a time value that is
6437 /// the number of milliseconds since 1 January 1970 UTC.
6438 ///
6439 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6440 #[wasm_bindgen(constructor)]
6441 pub fn new_with_year_month_day(year: u32, month: i32, day: i32) -> Date;
6442
6443 /// Creates a JavaScript `Date` instance that represents
6444 /// a single moment in time. `Date` objects are based on a time value that is
6445 /// the number of milliseconds since 1 January 1970 UTC.
6446 ///
6447 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6448 #[wasm_bindgen(constructor)]
6449 pub fn new_with_year_month_day_hr(year: u32, month: i32, day: i32, hr: i32) -> Date;
6450
6451 /// Creates a JavaScript `Date` instance that represents
6452 /// a single moment in time. `Date` objects are based on a time value that is
6453 /// the number of milliseconds since 1 January 1970 UTC.
6454 ///
6455 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6456 #[wasm_bindgen(constructor)]
6457 pub fn new_with_year_month_day_hr_min(
6458 year: u32,
6459 month: i32,
6460 day: i32,
6461 hr: i32,
6462 min: i32,
6463 ) -> Date;
6464
6465 /// Creates a JavaScript `Date` instance that represents
6466 /// a single moment in time. `Date` objects are based on a time value that is
6467 /// the number of milliseconds since 1 January 1970 UTC.
6468 ///
6469 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6470 #[wasm_bindgen(constructor)]
6471 pub fn new_with_year_month_day_hr_min_sec(
6472 year: u32,
6473 month: i32,
6474 day: i32,
6475 hr: i32,
6476 min: i32,
6477 sec: i32,
6478 ) -> Date;
6479
6480 /// Creates a JavaScript `Date` instance that represents
6481 /// a single moment in time. `Date` objects are based on a time value that is
6482 /// the number of milliseconds since 1 January 1970 UTC.
6483 ///
6484 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6485 #[wasm_bindgen(constructor)]
6486 pub fn new_with_year_month_day_hr_min_sec_milli(
6487 year: u32,
6488 month: i32,
6489 day: i32,
6490 hr: i32,
6491 min: i32,
6492 sec: i32,
6493 milli: i32,
6494 ) -> Date;
6495
6496 /// The `Date.now()` method returns the number of milliseconds
6497 /// elapsed since January 1, 1970 00:00:00 UTC.
6498 ///
6499 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/now)
6500 #[wasm_bindgen(static_method_of = Date)]
6501 pub fn now() -> f64;
6502
6503 /// The `Date.parse()` method parses a string representation of a date, and returns the number of milliseconds
6504 /// since January 1, 1970, 00:00:00 UTC or `NaN` if the string is unrecognized or, in some cases,
6505 /// contains illegal date values (e.g. 2015-02-31).
6506 ///
6507 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse)
6508 #[wasm_bindgen(static_method_of = Date)]
6509 pub fn parse(date: &str) -> f64;
6510
6511 /// The `setDate()` method sets the day of the Date object relative to the beginning of the currently set month.
6512 ///
6513 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setDate)
6514 #[wasm_bindgen(method, js_name = setDate)]
6515 pub fn set_date(this: &Date, day: u32) -> f64;
6516
6517 /// The `setFullYear()` method sets the full year for a specified date according to local time.
6518 /// Returns new timestamp.
6519 ///
6520 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setFullYear)
6521 #[wasm_bindgen(method, js_name = setFullYear)]
6522 pub fn set_full_year(this: &Date, year: u32) -> f64;
6523
6524 /// The `setFullYear()` method sets the full year for a specified date according to local time.
6525 /// Returns new timestamp.
6526 ///
6527 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setFullYear)
6528 #[wasm_bindgen(method, js_name = setFullYear)]
6529 pub fn set_full_year_with_month(this: &Date, year: u32, month: i32) -> f64;
6530
6531 /// The `setFullYear()` method sets the full year for a specified date according to local time.
6532 /// Returns new timestamp.
6533 ///
6534 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setFullYear)
6535 #[wasm_bindgen(method, js_name = setFullYear)]
6536 pub fn set_full_year_with_month_date(this: &Date, year: u32, month: i32, date: i32) -> f64;
6537
6538 /// The `setHours()` method sets the hours for a specified date according to local time,
6539 /// and returns the number of milliseconds since January 1, 1970 00:00:00 UTC until the time represented
6540 /// by the updated Date instance.
6541 ///
6542 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setHours)
6543 #[wasm_bindgen(method, js_name = setHours)]
6544 pub fn set_hours(this: &Date, hours: u32) -> f64;
6545
6546 /// The `setMilliseconds()` method sets the milliseconds for a specified date according to local time.
6547 ///
6548 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setMilliseconds)
6549 #[wasm_bindgen(method, js_name = setMilliseconds)]
6550 pub fn set_milliseconds(this: &Date, milliseconds: u32) -> f64;
6551
6552 /// The `setMinutes()` method sets the minutes for a specified date according to local time.
6553 ///
6554 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setMinutes)
6555 #[wasm_bindgen(method, js_name = setMinutes)]
6556 pub fn set_minutes(this: &Date, minutes: u32) -> f64;
6557
6558 /// The `setMonth()` method sets the month for a specified date according to the currently set year.
6559 ///
6560 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setMonth)
6561 #[wasm_bindgen(method, js_name = setMonth)]
6562 pub fn set_month(this: &Date, month: u32) -> f64;
6563
6564 /// The `setSeconds()` method sets the seconds for a specified date according to local time.
6565 ///
6566 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setSeconds)
6567 #[wasm_bindgen(method, js_name = setSeconds)]
6568 pub fn set_seconds(this: &Date, seconds: u32) -> f64;
6569
6570 /// The `setTime()` method sets the Date object to the time represented by a number of milliseconds
6571 /// since January 1, 1970, 00:00:00 UTC.
6572 ///
6573 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setTime)
6574 #[wasm_bindgen(method, js_name = setTime)]
6575 pub fn set_time(this: &Date, time: f64) -> f64;
6576
6577 /// The `setUTCDate()` method sets the day of the month for a specified date
6578 /// according to universal time.
6579 ///
6580 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCDate)
6581 #[wasm_bindgen(method, js_name = setUTCDate)]
6582 pub fn set_utc_date(this: &Date, day: u32) -> f64;
6583
6584 /// The `setUTCFullYear()` method sets the full year for a specified date according to universal time.
6585 ///
6586 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCFullYear)
6587 #[wasm_bindgen(method, js_name = setUTCFullYear)]
6588 pub fn set_utc_full_year(this: &Date, year: u32) -> f64;
6589
6590 /// The `setUTCFullYear()` method sets the full year for a specified date according to universal time.
6591 ///
6592 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCFullYear)
6593 #[wasm_bindgen(method, js_name = setUTCFullYear)]
6594 pub fn set_utc_full_year_with_month(this: &Date, year: u32, month: i32) -> f64;
6595
6596 /// The `setUTCFullYear()` method sets the full year for a specified date according to universal time.
6597 ///
6598 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCFullYear)
6599 #[wasm_bindgen(method, js_name = setUTCFullYear)]
6600 pub fn set_utc_full_year_with_month_date(this: &Date, year: u32, month: i32, date: i32) -> f64;
6601
6602 /// The `setUTCHours()` method sets the hour for a specified date according to universal time,
6603 /// and returns the number of milliseconds since January 1, 1970 00:00:00 UTC until the time
6604 /// represented by the updated Date instance.
6605 ///
6606 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCHours)
6607 #[wasm_bindgen(method, js_name = setUTCHours)]
6608 pub fn set_utc_hours(this: &Date, hours: u32) -> f64;
6609
6610 /// The `setUTCMilliseconds()` method sets the milliseconds for a specified date
6611 /// according to universal time.
6612 ///
6613 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCMilliseconds)
6614 #[wasm_bindgen(method, js_name = setUTCMilliseconds)]
6615 pub fn set_utc_milliseconds(this: &Date, milliseconds: u32) -> f64;
6616
6617 /// The `setUTCMinutes()` method sets the minutes for a specified date according to universal time.
6618 ///
6619 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCMinutes)
6620 #[wasm_bindgen(method, js_name = setUTCMinutes)]
6621 pub fn set_utc_minutes(this: &Date, minutes: u32) -> f64;
6622
6623 /// The `setUTCMonth()` method sets the month for a specified date according to universal time.
6624 ///
6625 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCMonth)
6626 #[wasm_bindgen(method, js_name = setUTCMonth)]
6627 pub fn set_utc_month(this: &Date, month: u32) -> f64;
6628
6629 /// The `setUTCSeconds()` method sets the seconds for a specified date according to universal time.
6630 ///
6631 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCSeconds)
6632 #[wasm_bindgen(method, js_name = setUTCSeconds)]
6633 pub fn set_utc_seconds(this: &Date, seconds: u32) -> f64;
6634
6635 /// The `toDateString()` method returns the date portion of a Date object
6636 /// in human readable form in American English.
6637 ///
6638 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toDateString)
6639 #[wasm_bindgen(method, js_name = toDateString)]
6640 pub fn to_date_string(this: &Date) -> JsString;
6641
6642 /// The `toISOString()` method returns a string in simplified extended ISO format (ISO
6643 /// 8601), which is always 24 or 27 characters long (YYYY-MM-DDTHH:mm:ss.sssZ or
6644 /// ±YYYYYY-MM-DDTHH:mm:ss.sssZ, respectively). The timezone is always zero UTC offset,
6645 /// as denoted by the suffix "Z"
6646 ///
6647 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString)
6648 #[wasm_bindgen(method, js_name = toISOString)]
6649 pub fn to_iso_string(this: &Date) -> JsString;
6650
6651 /// The `toJSON()` method returns a string representation of the Date object.
6652 ///
6653 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toJSON)
6654 #[wasm_bindgen(method, js_name = toJSON)]
6655 pub fn to_json(this: &Date) -> JsString;
6656
6657 /// The `toLocaleDateString()` method returns a string with a language sensitive
6658 /// representation of the date portion of this date. The new locales and options
6659 /// arguments let applications specify the language whose formatting conventions
6660 /// should be used and allow to customize the behavior of the function.
6661 /// In older implementations, which ignore the locales and options arguments,
6662 /// the locale used and the form of the string
6663 /// returned are entirely implementation dependent.
6664 ///
6665 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString)
6666 #[cfg(not(js_sys_unstable_apis))]
6667 #[wasm_bindgen(method, js_name = toLocaleDateString)]
6668 pub fn to_locale_date_string(this: &Date, locale: &str, options: &JsValue) -> JsString;
6669
6670 /// The `toLocaleDateString()` method returns a string with a language sensitive
6671 /// representation of the date portion of this date.
6672 ///
6673 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString)
6674 #[cfg(js_sys_unstable_apis)]
6675 #[wasm_bindgen(method, js_name = toLocaleDateString)]
6676 pub fn to_locale_date_string(
6677 this: &Date,
6678 locales: &[JsString],
6679 options: &Intl::DateTimeFormatOptions,
6680 ) -> JsString;
6681
6682 /// The `toLocaleString()` method returns a string with a language sensitive
6683 /// representation of this date. The new locales and options arguments
6684 /// let applications specify the language whose formatting conventions
6685 /// should be used and customize the behavior of the function.
6686 /// In older implementations, which ignore the locales
6687 /// and options arguments, the locale used and the form of the string
6688 /// returned are entirely implementation dependent.
6689 ///
6690 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString)
6691 #[cfg(not(js_sys_unstable_apis))]
6692 #[wasm_bindgen(method, js_name = toLocaleString)]
6693 pub fn to_locale_string(this: &Date, locale: &str, options: &JsValue) -> JsString;
6694
6695 /// The `toLocaleString()` method returns a string with a language sensitive
6696 /// representation of this date.
6697 ///
6698 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString)
6699 #[cfg(js_sys_unstable_apis)]
6700 #[wasm_bindgen(method, js_name = toLocaleString)]
6701 pub fn to_locale_string(
6702 this: &Date,
6703 locales: &[JsString],
6704 options: &Intl::DateTimeFormatOptions,
6705 ) -> JsString;
6706
6707 /// The `toLocaleTimeString()` method returns a string with a language sensitive
6708 /// representation of the time portion of this date. The new locales and options
6709 /// arguments let applications specify the language whose formatting conventions should be
6710 /// used and customize the behavior of the function. In older implementations, which ignore
6711 /// the locales and options arguments, the locale used and the form of the string
6712 /// returned are entirely implementation dependent.
6713 ///
6714 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleTimeString)
6715 #[cfg(not(js_sys_unstable_apis))]
6716 #[wasm_bindgen(method, js_name = toLocaleTimeString)]
6717 pub fn to_locale_time_string(this: &Date, locale: &str) -> JsString;
6718
6719 /// The `toLocaleTimeString()` method returns a string with a language sensitive
6720 /// representation of the time portion of this date.
6721 ///
6722 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleTimeString)
6723 #[cfg(js_sys_unstable_apis)]
6724 #[wasm_bindgen(method, js_name = toLocaleTimeString)]
6725 pub fn to_locale_time_string(
6726 this: &Date,
6727 locales: &[JsString],
6728 options: &Intl::DateTimeFormatOptions,
6729 ) -> JsString;
6730
6731 #[cfg(not(js_sys_unstable_apis))]
6732 #[wasm_bindgen(method, js_name = toLocaleTimeString)]
6733 pub fn to_locale_time_string_with_options(
6734 this: &Date,
6735 locale: &str,
6736 options: &JsValue,
6737 ) -> JsString;
6738
6739 /// The `toString()` method returns a string representing
6740 /// the specified Date object.
6741 ///
6742 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toString)
6743 #[cfg(not(js_sys_unstable_apis))]
6744 #[wasm_bindgen(method, js_name = toString)]
6745 pub fn to_string(this: &Date) -> JsString;
6746
6747 /// The `toTimeString()` method returns the time portion of a Date object in human
6748 /// readable form in American English.
6749 ///
6750 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toTimeString)
6751 #[wasm_bindgen(method, js_name = toTimeString)]
6752 pub fn to_time_string(this: &Date) -> JsString;
6753
6754 /// The `toUTCString()` method converts a date to a string,
6755 /// using the UTC time zone.
6756 ///
6757 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toUTCString)
6758 #[wasm_bindgen(method, js_name = toUTCString)]
6759 pub fn to_utc_string(this: &Date) -> JsString;
6760
6761 /// The `Date.UTC()` method accepts the same parameters as the
6762 /// longest form of the constructor, and returns the number of
6763 /// milliseconds in a `Date` object since January 1, 1970,
6764 /// 00:00:00, universal time.
6765 ///
6766 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/UTC)
6767 #[wasm_bindgen(static_method_of = Date, js_name = UTC)]
6768 pub fn utc(year: f64, month: f64) -> f64;
6769
6770 /// The `valueOf()` method returns the primitive value of
6771 /// a Date object.
6772 ///
6773 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/valueOf)
6774 #[wasm_bindgen(method, js_name = valueOf)]
6775 pub fn value_of(this: &Date) -> f64;
6776
6777 /// The `toTemporalInstant()` method converts a legacy `Date` object to a
6778 /// `Temporal.Instant` object representing the same moment in time.
6779 ///
6780 /// This method is added by the Temporal proposal to facilitate migration
6781 /// from legacy `Date` to the new Temporal API.
6782 ///
6783 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toTemporalInstant)
6784 #[cfg(js_sys_unstable_apis)]
6785 #[wasm_bindgen(method, js_name = toTemporalInstant)]
6786 pub fn to_temporal_instant(this: &Date) -> Temporal::Instant;
6787}
6788
6789// Property Descriptor.
6790#[wasm_bindgen]
6791extern "C" {
6792 #[wasm_bindgen(extends = Object)]
6793 #[derive(Clone, Debug)]
6794 pub type PropertyDescriptor<T = JsValue>;
6795
6796 #[wasm_bindgen(method, getter = writable)]
6797 pub fn get_writable<T>(this: &PropertyDescriptor<T>) -> Option<bool>;
6798
6799 #[wasm_bindgen(method, setter = writable)]
6800 pub fn set_writable<T>(this: &PropertyDescriptor<T>, writable: bool);
6801
6802 #[wasm_bindgen(method, getter = enumerable)]
6803 pub fn get_enumerable<T>(this: &PropertyDescriptor<T>) -> Option<bool>;
6804
6805 #[wasm_bindgen(method, setter = enumerable)]
6806 pub fn set_enumerable<T>(this: &PropertyDescriptor<T>, enumerable: bool);
6807
6808 #[wasm_bindgen(method, getter = configurable)]
6809 pub fn get_configurable<T>(this: &PropertyDescriptor<T>) -> Option<bool>;
6810
6811 #[wasm_bindgen(method, setter = configurable)]
6812 pub fn set_configurable<T>(this: &PropertyDescriptor<T>, configurable: bool);
6813
6814 #[wasm_bindgen(method, getter = get)]
6815 pub fn get_get<T: JsGeneric>(this: &PropertyDescriptor<T>) -> Option<Function<fn() -> T>>;
6816
6817 #[wasm_bindgen(method, setter = get)]
6818 pub fn set_get<T: JsGeneric>(this: &PropertyDescriptor<T>, get: Function<fn() -> T>);
6819
6820 #[wasm_bindgen(method, getter = set)]
6821 pub fn get_set<T: JsGeneric>(
6822 this: &PropertyDescriptor<T>,
6823 ) -> Option<Function<fn(T) -> JsValue>>;
6824
6825 #[wasm_bindgen(method, setter = set)]
6826 pub fn set_set<T: JsGeneric>(this: &PropertyDescriptor<T>, set: Function<fn(T) -> JsValue>);
6827
6828 #[wasm_bindgen(method, getter = value)]
6829 pub fn get_value<T>(this: &PropertyDescriptor<T>) -> Option<T>;
6830
6831 #[wasm_bindgen(method, setter = value)]
6832 pub fn set_value<T>(this: &PropertyDescriptor<T>, value: &T);
6833}
6834
6835impl PropertyDescriptor {
6836 #[cfg(not(js_sys_unstable_apis))]
6837 pub fn new<T>() -> PropertyDescriptor<T> {
6838 JsCast::unchecked_into(Object::new())
6839 }
6840
6841 #[cfg(js_sys_unstable_apis)]
6842 pub fn new<T>() -> PropertyDescriptor<T> {
6843 JsCast::unchecked_into(Object::<JsValue>::new())
6844 }
6845
6846 #[cfg(not(js_sys_unstable_apis))]
6847 pub fn new_value<T: JsGeneric>(value: &T) -> PropertyDescriptor<T> {
6848 let desc: PropertyDescriptor<T> = JsCast::unchecked_into(Object::new());
6849 desc.set_value(value);
6850 desc
6851 }
6852
6853 #[cfg(js_sys_unstable_apis)]
6854 pub fn new_value<T: JsGeneric>(value: &T) -> PropertyDescriptor<T> {
6855 let desc: PropertyDescriptor<T> = JsCast::unchecked_into(Object::<JsValue>::new());
6856 desc.set_value(value);
6857 desc
6858 }
6859}
6860
6861impl Default for PropertyDescriptor {
6862 fn default() -> Self {
6863 PropertyDescriptor::new()
6864 }
6865}
6866
6867// Object.
6868#[wasm_bindgen]
6869extern "C" {
6870 #[wasm_bindgen(typescript_type = "object")]
6871 #[derive(Clone, Debug)]
6872 pub type Object<T = JsValue>;
6873
6874 // Next major: deprecate
6875 /// The `Object.assign()` method is used to copy the values of all enumerable
6876 /// own properties from one or more source objects to a target object. It
6877 /// will return the target object.
6878 ///
6879 /// **Note:** Consider using [`Object::try_assign`] to support error handling.
6880 ///
6881 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
6882 #[wasm_bindgen(static_method_of = Object)]
6883 pub fn assign<T>(target: &Object<T>, source: &Object<T>) -> Object<T>;
6884
6885 // Next major: deprecate
6886 /// The `Object.assign()` method is used to copy the values of all enumerable
6887 /// own properties from one or more source objects to a target object. It
6888 /// will return the target object.
6889 ///
6890 /// **Note:** Consider using [`Object::try_assign`] to support error handling.
6891 ///
6892 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
6893 #[wasm_bindgen(static_method_of = Object, js_name = assign, catch)]
6894 pub fn try_assign<T>(target: &Object<T>, source: &Object<T>) -> Result<Object<T>, JsValue>;
6895
6896 /// The `Object.assign()` method is used to copy the values of all enumerable
6897 /// own properties from one or more source objects to a target object. It
6898 /// will return the target object.
6899 ///
6900 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
6901 #[cfg(not(js_sys_unstable_apis))]
6902 #[wasm_bindgen(static_method_of = Object, js_name = assign)]
6903 #[deprecated(note = "use `assign_many` for arbitrary assign arguments instead")]
6904 #[allow(deprecated)]
6905 pub fn assign2<T>(target: &Object<T>, source1: &Object<T>, source2: &Object<T>) -> Object<T>;
6906
6907 /// The `Object.assign()` method is used to copy the values of all enumerable
6908 /// own properties from one or more source objects to a target object. It
6909 /// will return the target object.
6910 ///
6911 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
6912 #[cfg(not(js_sys_unstable_apis))]
6913 #[wasm_bindgen(static_method_of = Object, js_name = assign)]
6914 #[deprecated(note = "use `assign_many` for arbitrary assign arguments instead")]
6915 #[allow(deprecated)]
6916 pub fn assign3<T>(
6917 target: &Object<T>,
6918 source1: &Object<T>,
6919 source2: &Object<T>,
6920 source3: &Object<T>,
6921 ) -> Object<T>;
6922
6923 /// The `Object.assign()` method is used to copy the values of all enumerable
6924 /// own properties from one or more source objects to a target object. It
6925 /// will return the target object.
6926 ///
6927 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
6928 #[wasm_bindgen(static_method_of = Object, js_name = assign, catch, variadic)]
6929 pub fn assign_many<T>(target: &Object<T>, sources: &[Object<T>]) -> Result<Object<T>, JsValue>;
6930
6931 /// The constructor property returns a reference to the `Object` constructor
6932 /// function that created the instance object.
6933 ///
6934 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/constructor)
6935 #[wasm_bindgen(method, getter)]
6936 pub fn constructor<T>(this: &Object<T>) -> Function;
6937
6938 /// The `Object.create()` method creates a new object, using an existing
6939 /// object to provide the newly created object's prototype.
6940 ///
6941 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/create)
6942 #[wasm_bindgen(static_method_of = Object)]
6943 pub fn create<T>(prototype: &Object<T>) -> Object<T>;
6944
6945 /// The static method `Object.defineProperty()` defines a new
6946 /// property directly on an object, or modifies an existing
6947 /// property on an object, and returns the object.
6948 ///
6949 /// **Note:** Consider using [`Object::define_property_str`] to support typing and error handling.
6950 ///
6951 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty)
6952 #[cfg(not(js_sys_unstable_apis))]
6953 #[wasm_bindgen(static_method_of = Object, js_name = defineProperty)]
6954 pub fn define_property<T>(obj: &Object<T>, prop: &JsValue, descriptor: &Object) -> Object<T>;
6955
6956 /// The static method `Object.defineProperty()` defines a new
6957 /// property directly on an object, or modifies an existing
6958 /// property on an object, and returns the object.
6959 ///
6960 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty)
6961 #[cfg(js_sys_unstable_apis)]
6962 #[wasm_bindgen(static_method_of = Object, js_name = defineProperty, catch)]
6963 pub fn define_property<T>(
6964 obj: &Object<T>,
6965 prop: &JsString,
6966 descriptor: &PropertyDescriptor<T>,
6967 ) -> Result<Object<T>, JsValue>;
6968
6969 // Next major: deprecate
6970 /// The static method `Object.defineProperty()` defines a new
6971 /// property directly on an object, or modifies an existing
6972 /// property on an object, and returns the object.
6973 ///
6974 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty)
6975 #[wasm_bindgen(static_method_of = Object, js_name = defineProperty, catch)]
6976 pub fn define_property_str<T>(
6977 obj: &Object<T>,
6978 prop: &JsString,
6979 descriptor: &PropertyDescriptor<T>,
6980 ) -> Result<Object<T>, JsValue>;
6981
6982 /// The static method `Object.defineProperty()` defines a new
6983 /// property directly on an object, or modifies an existing
6984 /// property on an object, and returns the object.
6985 ///
6986 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty)
6987 #[wasm_bindgen(static_method_of = Object, js_name = defineProperty, catch)]
6988 pub fn define_property_symbol<T>(
6989 obj: &Object<T>,
6990 prop: &Symbol,
6991 descriptor: &PropertyDescriptor<JsValue>,
6992 ) -> Result<Object<T>, JsValue>;
6993
6994 /// The `Object.defineProperties()` method defines new or modifies
6995 /// existing properties directly on an object, returning the
6996 /// object.
6997 ///
6998 /// **Note:** Consider using [`Object::try_define_properties`] to support typing and error handling.
6999 ///
7000 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperties)
7001 #[wasm_bindgen(static_method_of = Object, js_name = defineProperties)]
7002 pub fn define_properties<T>(obj: &Object<T>, props: &Object) -> Object<T>;
7003
7004 /// The `Object.defineProperties()` method defines new or modifies
7005 /// existing properties directly on an object, returning the
7006 /// object.
7007 ///
7008 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperties)
7009 #[cfg(js_sys_unstable_apis)]
7010 #[wasm_bindgen(static_method_of = Object, js_name = defineProperties, catch)]
7011 pub fn try_define_properties<T>(
7012 obj: &Object<T>,
7013 props: &Object<PropertyDescriptor<T>>,
7014 ) -> Result<Object<T>, JsValue>;
7015
7016 /// The `Object.entries()` method returns an array of a given
7017 /// object's own enumerable property [key, value] pairs, in the
7018 /// same order as that provided by a for...in loop (the difference
7019 /// being that a for-in loop enumerates properties in the
7020 /// prototype chain as well).
7021 ///
7022 /// **Note:** Consider using [`Object::entries_typed`] to support typing and error handling.
7023 ///
7024 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries)
7025 #[cfg(not(js_sys_unstable_apis))]
7026 #[wasm_bindgen(static_method_of = Object)]
7027 pub fn entries(object: &Object) -> Array;
7028
7029 /// The `Object.entries()` method returns an array of a given
7030 /// object's own enumerable property [key, value] pairs, in the
7031 /// same order as that provided by a for...in loop (the difference
7032 /// being that a for-in loop enumerates properties in the
7033 /// prototype chain as well).
7034 ///
7035 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries)
7036 #[cfg(js_sys_unstable_apis)]
7037 #[wasm_bindgen(static_method_of = Object, js_name = entries, catch)]
7038 pub fn entries<T: JsGeneric>(
7039 object: &Object<T>,
7040 ) -> Result<Array<ArrayTuple<(JsString, T)>>, JsValue>;
7041
7042 // Next major: deprecate
7043 /// The `Object.entries()` method returns an array of a given
7044 /// object's own enumerable property [key, value] pairs, in the
7045 /// same order as that provided by a for...in loop (the difference
7046 /// being that a for-in loop enumerates properties in the
7047 /// prototype chain as well).
7048 ///
7049 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries)
7050 #[wasm_bindgen(static_method_of = Object, js_name = entries, catch)]
7051 pub fn entries_typed<T: JsGeneric>(
7052 object: &Object<T>,
7053 ) -> Result<Array<ArrayTuple<(JsString, T)>>, JsValue>;
7054
7055 /// The `Object.freeze()` method freezes an object: that is, prevents new
7056 /// properties from being added to it; prevents existing properties from
7057 /// being removed; and prevents existing properties, or their enumerability,
7058 /// configurability, or writability, from being changed, it also prevents
7059 /// the prototype from being changed. The method returns the passed object.
7060 ///
7061 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze)
7062 #[wasm_bindgen(static_method_of = Object)]
7063 pub fn freeze<T>(value: &Object<T>) -> Object<T>;
7064
7065 /// The `Object.fromEntries()` method transforms a list of key-value pairs
7066 /// into an object.
7067 ///
7068 /// **Note:** Consider using [`Object::from_entries_typed`] to support typing and error handling.
7069 ///
7070 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/fromEntries)
7071 #[cfg(not(js_sys_unstable_apis))]
7072 #[wasm_bindgen(static_method_of = Object, catch, js_name = fromEntries)]
7073 pub fn from_entries(entries: &JsValue) -> Result<Object, JsValue>;
7074
7075 /// The `Object.fromEntries()` method transforms a list of key-value pairs
7076 /// into an object.
7077 ///
7078 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/fromEntries)
7079 #[cfg(js_sys_unstable_apis)]
7080 #[wasm_bindgen(static_method_of = Object, catch, js_name = fromEntries)]
7081 pub fn from_entries<T: JsGeneric, I: Iterable<Item = ArrayTuple<(JsString, T)>>>(
7082 entries: &I,
7083 ) -> Result<Object<T>, JsValue>;
7084
7085 // Next major: deprecate
7086 /// The `Object.fromEntries()` method transforms a list of key-value pairs
7087 /// into an object.
7088 ///
7089 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/fromEntries)
7090 #[wasm_bindgen(static_method_of = Object, catch, js_name = fromEntries)]
7091 pub fn from_entries_typed<T: JsGeneric, I: Iterable<Item = ArrayTuple<(JsString, T)>>>(
7092 entries: &I,
7093 ) -> Result<Object<T>, JsValue>;
7094
7095 /// The `Object.getOwnPropertyDescriptor()` method returns a
7096 /// property descriptor for an own property (that is, one directly
7097 /// present on an object and not in the object's prototype chain)
7098 /// of a given object.
7099 ///
7100 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor)
7101 #[cfg(not(js_sys_unstable_apis))]
7102 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptor)]
7103 pub fn get_own_property_descriptor<T>(obj: &Object<T>, prop: &JsValue) -> JsValue;
7104
7105 /// The `Object.getOwnPropertyDescriptor()` method returns a
7106 /// property descriptor for an own property (that is, one directly
7107 /// present on an object and not in the object's prototype chain)
7108 /// of a given object.
7109 ///
7110 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor)
7111 #[cfg(js_sys_unstable_apis)]
7112 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptor, catch)]
7113 pub fn get_own_property_descriptor<T>(
7114 obj: &Object<T>,
7115 prop: &JsString,
7116 ) -> Result<PropertyDescriptor<T>, JsValue>;
7117
7118 // Next major: deprecate
7119 /// The `Object.getOwnPropertyDescriptor()` method returns a
7120 /// property descriptor for an own property (that is, one directly
7121 /// present on an object and not in the object's prototype chain)
7122 /// of a given object.
7123 ///
7124 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor)
7125 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptor, catch)]
7126 pub fn get_own_property_descriptor_str<T>(
7127 obj: &Object<T>,
7128 prop: &JsString,
7129 ) -> Result<PropertyDescriptor<T>, JsValue>;
7130
7131 /// The `Object.getOwnPropertyDescriptor()` method returns a
7132 /// property descriptor for an own property (that is, one directly
7133 /// present on an object and not in the object's prototype chain)
7134 /// of a given object.
7135 ///
7136 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor)
7137 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptor, catch)]
7138 pub fn get_own_property_descriptor_symbol<T>(
7139 obj: &Object<T>,
7140 prop: &Symbol,
7141 ) -> Result<PropertyDescriptor<JsValue>, JsValue>;
7142
7143 /// The `Object.getOwnPropertyDescriptors()` method returns all own
7144 /// property descriptors of a given object.
7145 ///
7146 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptors)
7147 #[cfg(not(js_sys_unstable_apis))]
7148 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptors)]
7149 pub fn get_own_property_descriptors<T>(obj: &Object<T>) -> JsValue;
7150
7151 /// The `Object.getOwnPropertyDescriptors()` method returns all own
7152 /// property descriptors of a given object.
7153 ///
7154 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptors)
7155 #[cfg(js_sys_unstable_apis)]
7156 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptors, catch)]
7157 pub fn get_own_property_descriptors<T>(
7158 obj: &Object<T>,
7159 ) -> Result<Object<PropertyDescriptor<T>>, JsValue>;
7160
7161 /// The `Object.getOwnPropertyNames()` method returns an array of
7162 /// all properties (including non-enumerable properties except for
7163 /// those which use Symbol) found directly upon a given object.
7164 ///
7165 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyNames)
7166 #[cfg(not(js_sys_unstable_apis))]
7167 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyNames)]
7168 pub fn get_own_property_names<T>(obj: &Object<T>) -> Array;
7169
7170 /// The `Object.getOwnPropertyNames()` method returns an array of
7171 /// all properties (including non-enumerable properties except for
7172 /// those which use Symbol) found directly upon a given object.
7173 ///
7174 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyNames)
7175 #[cfg(js_sys_unstable_apis)]
7176 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyNames, catch)]
7177 pub fn get_own_property_names<T>(obj: &Object<T>) -> Result<Array<JsString>, JsValue>;
7178
7179 /// The `Object.getOwnPropertySymbols()` method returns an array of
7180 /// all symbol properties found directly upon a given object.
7181 ///
7182 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertySymbols)
7183 #[cfg(not(js_sys_unstable_apis))]
7184 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertySymbols)]
7185 pub fn get_own_property_symbols<T>(obj: &Object<T>) -> Array;
7186
7187 /// The `Object.getOwnPropertySymbols()` method returns an array of
7188 /// all symbol properties found directly upon a given object.
7189 ///
7190 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertySymbols)
7191 #[cfg(js_sys_unstable_apis)]
7192 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertySymbols, catch)]
7193 pub fn get_own_property_symbols<T>(obj: &Object<T>) -> Result<Array<Symbol>, JsValue>;
7194
7195 /// The `Object.getPrototypeOf()` method returns the prototype
7196 /// (i.e. the value of the internal [[Prototype]] property) of the
7197 /// specified object.
7198 ///
7199 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getPrototypeOf)
7200 #[wasm_bindgen(static_method_of = Object, js_name = getPrototypeOf)]
7201 pub fn get_prototype_of(obj: &JsValue) -> Object;
7202
7203 /// The `hasOwnProperty()` method returns a boolean indicating whether the
7204 /// object has the specified property as its own property (as opposed to
7205 /// inheriting it).
7206 ///
7207 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty)
7208 #[deprecated(note = "Use `Object::hasOwn` instead.")]
7209 #[allow(deprecated)]
7210 #[wasm_bindgen(method, js_name = hasOwnProperty)]
7211 pub fn has_own_property<T>(this: &Object<T>, property: &JsValue) -> bool;
7212
7213 /// The `Object.hasOwn()` method returns a boolean indicating whether the
7214 /// object passed in has the specified property as its own property (as
7215 /// opposed to inheriting it).
7216 ///
7217 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn)
7218 #[cfg(not(js_sys_unstable_apis))]
7219 #[wasm_bindgen(static_method_of = Object, js_name = hasOwn)]
7220 pub fn has_own<T>(instance: &Object<T>, property: &JsValue) -> bool;
7221
7222 /// The `Object.hasOwn()` method returns a boolean indicating whether the
7223 /// object passed in has the specified property as its own property (as
7224 /// opposed to inheriting it).
7225 ///
7226 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn)
7227 #[cfg(js_sys_unstable_apis)]
7228 #[wasm_bindgen(static_method_of = Object, js_name = hasOwn, catch)]
7229 pub fn has_own<T>(instance: &Object<T>, property: &JsString) -> Result<bool, JsValue>;
7230
7231 // Next major: deprecate
7232 /// The `Object.hasOwn()` method returns a boolean indicating whether the
7233 /// object passed in has the specified property as its own property (as
7234 /// opposed to inheriting it).
7235 ///
7236 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn)
7237 #[wasm_bindgen(static_method_of = Object, js_name = hasOwn, catch)]
7238 pub fn has_own_str<T>(instance: &Object<T>, property: &JsString) -> Result<bool, JsValue>;
7239
7240 /// The `Object.hasOwn()` method returns a boolean indicating whether the
7241 /// object passed in has the specified property as its own property (as
7242 /// opposed to inheriting it).
7243 ///
7244 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn)
7245 #[wasm_bindgen(static_method_of = Object, js_name = hasOwn, catch)]
7246 pub fn has_own_symbol<T>(instance: &Object<T>, property: &Symbol) -> Result<bool, JsValue>;
7247
7248 /// The `Object.is()` method determines whether two values are the same value.
7249 ///
7250 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is)
7251 #[wasm_bindgen(static_method_of = Object)]
7252 pub fn is(value1: &JsValue, value_2: &JsValue) -> bool;
7253
7254 /// The `Object.isExtensible()` method determines if an object is extensible
7255 /// (whether it can have new properties added to it).
7256 ///
7257 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isExtensible)
7258 #[wasm_bindgen(static_method_of = Object, js_name = isExtensible)]
7259 pub fn is_extensible<T>(object: &Object<T>) -> bool;
7260
7261 /// The `Object.isFrozen()` determines if an object is frozen.
7262 ///
7263 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isFrozen)
7264 #[wasm_bindgen(static_method_of = Object, js_name = isFrozen)]
7265 pub fn is_frozen<T>(object: &Object<T>) -> bool;
7266
7267 /// The `Object.isSealed()` method determines if an object is sealed.
7268 ///
7269 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isSealed)
7270 #[wasm_bindgen(static_method_of = Object, js_name = isSealed)]
7271 pub fn is_sealed<T>(object: &Object<T>) -> bool;
7272
7273 /// The `isPrototypeOf()` method checks if an object exists in another
7274 /// object's prototype chain.
7275 ///
7276 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isPrototypeOf)
7277 #[wasm_bindgen(method, js_name = isPrototypeOf)]
7278 pub fn is_prototype_of<T>(this: &Object<T>, value: &JsValue) -> bool;
7279
7280 /// The `Object.keys()` method returns an array of a given object's property
7281 /// names, in the same order as we get with a normal loop.
7282 ///
7283 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys)
7284 #[cfg(not(js_sys_unstable_apis))]
7285 #[wasm_bindgen(static_method_of = Object)]
7286 pub fn keys<T>(object: &Object<T>) -> Array;
7287
7288 /// The `Object.keys()` method returns an array of a given object's property
7289 /// names, in the same order as we get with a normal loop.
7290 ///
7291 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys)
7292 #[cfg(js_sys_unstable_apis)]
7293 #[wasm_bindgen(static_method_of = Object)]
7294 pub fn keys<T>(object: &Object<T>) -> Array<JsString>;
7295
7296 /// The [`Object`] constructor creates an object wrapper.
7297 ///
7298 /// **Note:** Consider using [`Object::new_typed`] for typed object records.
7299 ///
7300 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)
7301 #[wasm_bindgen(constructor)]
7302 pub fn new() -> Object;
7303
7304 // Next major: deprecate
7305 /// The [`Object`] constructor creates an object wrapper.
7306 ///
7307 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)
7308 #[wasm_bindgen(constructor)]
7309 pub fn new_typed<T>() -> Object<T>;
7310
7311 /// The `Object.preventExtensions()` method prevents new properties from
7312 /// ever being added to an object (i.e. prevents future extensions to the
7313 /// object).
7314 ///
7315 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/preventExtensions)
7316 #[wasm_bindgen(static_method_of = Object, js_name = preventExtensions)]
7317 pub fn prevent_extensions<T>(object: &Object<T>);
7318
7319 /// The `propertyIsEnumerable()` method returns a Boolean indicating
7320 /// whether the specified property is enumerable.
7321 ///
7322 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/propertyIsEnumerable)
7323 #[wasm_bindgen(method, js_name = propertyIsEnumerable)]
7324 pub fn property_is_enumerable<T>(this: &Object<T>, property: &JsValue) -> bool;
7325
7326 /// The `Object.seal()` method seals an object, preventing new properties
7327 /// from being added to it and marking all existing properties as
7328 /// non-configurable. Values of present properties can still be changed as
7329 /// long as they are writable.
7330 ///
7331 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/seal)
7332 #[wasm_bindgen(static_method_of = Object)]
7333 pub fn seal<T>(value: &Object<T>) -> Object<T>;
7334
7335 /// The `Object.setPrototypeOf()` method sets the prototype (i.e., the
7336 /// internal `[[Prototype]]` property) of a specified object to another
7337 /// object or `null`.
7338 ///
7339 /// **Note:** Consider using [`Object::try_set_prototype_of`] to support errors.
7340 ///
7341 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/setPrototypeOf)
7342 #[wasm_bindgen(static_method_of = Object, js_name = setPrototypeOf)]
7343 pub fn set_prototype_of<T>(object: &Object<T>, prototype: &Object) -> Object<T>;
7344
7345 /// The `Object.setPrototypeOf()` method sets the prototype (i.e., the
7346 /// internal `[[Prototype]]` property) of a specified object to another
7347 /// object or `null`.
7348 ///
7349 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/setPrototypeOf)
7350 #[wasm_bindgen(static_method_of = Object, js_name = setPrototypeOf, catch)]
7351 pub fn try_set_prototype_of<T>(
7352 object: &Object<T>,
7353 prototype: &Object,
7354 ) -> Result<Object<T>, JsValue>;
7355
7356 /// The `toLocaleString()` method returns a string representing the object.
7357 /// This method is meant to be overridden by derived objects for
7358 /// locale-specific purposes.
7359 ///
7360 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toLocaleString)
7361 #[wasm_bindgen(method, js_name = toLocaleString)]
7362 pub fn to_locale_string<T>(this: &Object<T>) -> JsString;
7363
7364 // Next major: deprecate
7365 /// The `toString()` method returns a string representing the object.
7366 ///
7367 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString)
7368 #[wasm_bindgen(method, js_name = toString)]
7369 pub fn to_string<T>(this: &Object<T>) -> JsString;
7370
7371 /// The `toString()` method returns a string representing the object.
7372 ///
7373 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString)
7374 #[wasm_bindgen(method, js_name = toString)]
7375 pub fn to_js_string<T>(this: &Object<T>) -> JsString;
7376
7377 /// The `valueOf()` method returns the primitive value of the
7378 /// specified object.
7379 ///
7380 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf)
7381 #[wasm_bindgen(method, js_name = valueOf)]
7382 pub fn value_of<T>(this: &Object<T>) -> Object;
7383
7384 /// The `Object.values()` method returns an array of a given object's own
7385 /// enumerable property values, in the same order as that provided by a
7386 /// `for...in` loop (the difference being that a for-in loop enumerates
7387 /// properties in the prototype chain as well).
7388 ///
7389 /// **Note:** Consider using [`Object::try_values`] to support errors.
7390 ///
7391 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values)
7392 #[cfg(not(js_sys_unstable_apis))]
7393 #[wasm_bindgen(static_method_of = Object)]
7394 pub fn values<T>(object: &Object<T>) -> Array<T>;
7395
7396 /// The `Object.values()` method returns an array of a given object's own
7397 /// enumerable property values, in the same order as that provided by a
7398 /// `for...in` loop (the difference being that a for-in loop enumerates
7399 /// properties in the prototype chain as well).
7400 ///
7401 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values)
7402 #[cfg(js_sys_unstable_apis)]
7403 #[wasm_bindgen(static_method_of = Object, catch, js_name = values)]
7404 pub fn values<T>(object: &Object<T>) -> Result<Array<T>, JsValue>;
7405
7406 // Next major: deprecate
7407 /// The `Object.values()` method returns an array of a given object's own
7408 /// enumerable property values, in the same order as that provided by a
7409 /// `for...in` loop (the difference being that a for-in loop enumerates
7410 /// properties in the prototype chain as well).
7411 ///
7412 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values)
7413 #[cfg(not(js_sys_unstable_apis))]
7414 #[wasm_bindgen(static_method_of = Object, catch, js_name = values)]
7415 pub fn try_values<T>(object: &Object<T>) -> Result<Array<T>, JsValue>;
7416}
7417
7418impl Object {
7419 /// Returns the `Object` value of this JS value if it's an instance of an
7420 /// object.
7421 ///
7422 /// If this JS value is not an instance of an object then this returns
7423 /// `None`.
7424 pub fn try_from(val: &JsValue) -> Option<&Object> {
7425 if val.is_object() {
7426 Some(val.unchecked_ref())
7427 } else {
7428 None
7429 }
7430 }
7431}
7432
7433impl PartialEq for Object {
7434 #[inline]
7435 fn eq(&self, other: &Object) -> bool {
7436 Object::is(self.as_ref(), other.as_ref())
7437 }
7438}
7439
7440impl Eq for Object {}
7441
7442impl Default for Object<JsValue> {
7443 fn default() -> Self {
7444 Self::new()
7445 }
7446}
7447
7448// Proxy
7449#[wasm_bindgen]
7450extern "C" {
7451 #[wasm_bindgen(typescript_type = "ProxyConstructor")]
7452 #[derive(Clone, Debug)]
7453 pub type Proxy;
7454
7455 /// The [`Proxy`] object is used to define custom behavior for fundamental
7456 /// operations (e.g. property lookup, assignment, enumeration, function
7457 /// invocation, etc).
7458 ///
7459 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy)
7460 #[wasm_bindgen(constructor)]
7461 pub fn new(target: &JsValue, handler: &Object) -> Proxy;
7462
7463 /// The `Proxy.revocable()` method is used to create a revocable [`Proxy`]
7464 /// object.
7465 ///
7466 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy/revocable)
7467 #[wasm_bindgen(static_method_of = Proxy)]
7468 pub fn revocable(target: &JsValue, handler: &Object) -> Object;
7469}
7470
7471// RangeError
7472#[wasm_bindgen]
7473extern "C" {
7474 /// The `RangeError` object indicates an error when a value is not in the set
7475 /// or range of allowed values.
7476 ///
7477 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError)
7478 #[wasm_bindgen(extends = Error, extends = Object, typescript_type = "RangeError")]
7479 #[derive(Clone, Debug, PartialEq, Eq)]
7480 pub type RangeError;
7481
7482 /// The `RangeError` object indicates an error when a value is not in the set
7483 /// or range of allowed values.
7484 ///
7485 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError)
7486 #[wasm_bindgen(constructor)]
7487 pub fn new(message: &str) -> RangeError;
7488
7489 /// Creates a new `RangeError` with the given message and a typed
7490 /// [`ErrorOptions`] dictionary whose `cause` property indicates the
7491 /// original cause of the error.
7492 ///
7493 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError/RangeError)
7494 #[wasm_bindgen(constructor)]
7495 pub fn new_with_options(message: &str, options: &ErrorOptions) -> RangeError;
7496}
7497
7498// ReferenceError
7499#[wasm_bindgen]
7500extern "C" {
7501 /// The `ReferenceError` object represents an error when a non-existent
7502 /// variable is referenced.
7503 ///
7504 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError)
7505 #[wasm_bindgen(extends = Error, extends = Object, typescript_type = "ReferenceError")]
7506 #[derive(Clone, Debug, PartialEq, Eq)]
7507 pub type ReferenceError;
7508
7509 /// The `ReferenceError` object represents an error when a non-existent
7510 /// variable is referenced.
7511 ///
7512 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError)
7513 #[wasm_bindgen(constructor)]
7514 pub fn new(message: &str) -> ReferenceError;
7515
7516 /// Creates a new `ReferenceError` with the given message and a typed
7517 /// [`ErrorOptions`] dictionary whose `cause` property indicates the
7518 /// original cause of the error.
7519 ///
7520 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError/ReferenceError)
7521 #[wasm_bindgen(constructor)]
7522 pub fn new_with_options(message: &str, options: &ErrorOptions) -> ReferenceError;
7523}
7524
7525#[allow(non_snake_case)]
7526pub mod Reflect {
7527 use super::*;
7528
7529 // Reflect
7530 #[wasm_bindgen]
7531 extern "C" {
7532 /// The static `Reflect.apply()` method calls a target function with
7533 /// arguments as specified.
7534 ///
7535 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/apply)
7536 #[wasm_bindgen(js_namespace = Reflect, catch)]
7537 pub fn apply<T: JsFunction = fn() -> JsValue>(
7538 target: &Function<T>,
7539 this_argument: &JsValue,
7540 arguments_list: &Array,
7541 ) -> Result<<T as JsFunction>::Ret, JsValue>;
7542
7543 /// The static `Reflect.construct()` method acts like the new operator, but
7544 /// as a function. It is equivalent to calling `new target(...args)`. It
7545 /// gives also the added option to specify a different prototype.
7546 ///
7547 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/construct)
7548 #[cfg(not(js_sys_unstable_apis))]
7549 #[wasm_bindgen(js_namespace = Reflect, catch)]
7550 pub fn construct<T: JsFunction = fn() -> JsValue>(
7551 target: &Function<T>,
7552 arguments_list: &Array,
7553 ) -> Result<JsValue, JsValue>;
7554
7555 /// The static `Reflect.construct()` method acts like the new operator, but
7556 /// as a function. It is equivalent to calling `new target(...args)`. It
7557 /// gives also the added option to specify a different prototype.
7558 ///
7559 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/construct)
7560 #[cfg(js_sys_unstable_apis)]
7561 #[wasm_bindgen(js_namespace = Reflect, catch)]
7562 pub fn construct<T: JsFunction = fn() -> JsValue>(
7563 target: &Function<T>,
7564 arguments_list: &ArrayTuple, // DOTO: <A1, A2, A3, A4, A5, A6, A7, A8>,
7565 ) -> Result<JsValue, JsValue>;
7566
7567 /// The static `Reflect.construct()` method acts like the new operator, but
7568 /// as a function. It is equivalent to calling `new target(...args)`. It
7569 /// gives also the added option to specify a different prototype.
7570 ///
7571 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/construct)
7572 #[wasm_bindgen(js_namespace = Reflect, js_name = construct, catch)]
7573 pub fn construct_with_new_target(
7574 target: &Function,
7575 arguments_list: &Array,
7576 new_target: &Function,
7577 ) -> Result<JsValue, JsValue>;
7578
7579 /// The static `Reflect.defineProperty()` method is like
7580 /// `Object.defineProperty()` but returns a `Boolean`.
7581 ///
7582 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/defineProperty)
7583 #[cfg(not(js_sys_unstable_apis))]
7584 #[wasm_bindgen(js_namespace = Reflect, js_name = defineProperty, catch)]
7585 pub fn define_property<T>(
7586 target: &Object<T>,
7587 property_key: &JsValue,
7588 attributes: &Object,
7589 ) -> Result<bool, JsValue>;
7590
7591 /// The static `Reflect.defineProperty()` method is like
7592 /// `Object.defineProperty()` but returns a `Boolean`.
7593 ///
7594 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/defineProperty)
7595 #[cfg(js_sys_unstable_apis)]
7596 #[wasm_bindgen(js_namespace = Reflect, js_name = defineProperty, catch)]
7597 pub fn define_property<T>(
7598 target: &Object<T>,
7599 property_key: &JsValue,
7600 attributes: &PropertyDescriptor<T>,
7601 ) -> Result<bool, JsValue>;
7602
7603 /// The static `Reflect.defineProperty()` method is like
7604 /// `Object.defineProperty()` but returns a `Boolean`.
7605 ///
7606 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/defineProperty)
7607 #[wasm_bindgen(js_namespace = Reflect, js_name = defineProperty, catch)]
7608 pub fn define_property_str<T>(
7609 target: &Object<T>,
7610 property_key: &JsString,
7611 attributes: &PropertyDescriptor<T>,
7612 ) -> Result<bool, JsValue>;
7613
7614 /// The static `Reflect.deleteProperty()` method allows to delete
7615 /// properties. It is like the `delete` operator as a function.
7616 ///
7617 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/deleteProperty)
7618 #[wasm_bindgen(js_namespace = Reflect, js_name = deleteProperty, catch)]
7619 pub fn delete_property<T>(target: &Object<T>, key: &JsValue) -> Result<bool, JsValue>;
7620
7621 /// The static `Reflect.deleteProperty()` method allows to delete
7622 /// properties. It is like the `delete` operator as a function.
7623 ///
7624 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/deleteProperty)
7625 #[wasm_bindgen(js_namespace = Reflect, js_name = deleteProperty, catch)]
7626 pub fn delete_property_str<T>(target: &Object<T>, key: &JsString) -> Result<bool, JsValue>;
7627
7628 /// The static `Reflect.get()` method works like getting a property from
7629 /// an object (`target[propertyKey]`) as a function.
7630 ///
7631 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/get)
7632 #[cfg(not(js_sys_unstable_apis))]
7633 #[wasm_bindgen(js_namespace = Reflect, catch)]
7634 pub fn get(target: &JsValue, key: &JsValue) -> Result<JsValue, JsValue>;
7635
7636 /// The static `Reflect.get()` method works like getting a property from
7637 /// an object (`target[propertyKey]`) as a function.
7638 ///
7639 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/get)
7640 #[cfg(js_sys_unstable_apis)]
7641 #[wasm_bindgen(js_namespace = Reflect, catch)]
7642 pub fn get<T>(target: &Object<T>, key: &JsString) -> Result<Option<T>, JsValue>;
7643
7644 /// The static `Reflect.get()` method works like getting a property from
7645 /// an object (`target[propertyKey]`) as a function.
7646 ///
7647 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/get)
7648 #[wasm_bindgen(js_namespace = Reflect, js_name = get, catch)]
7649 pub fn get_str<T>(target: &Object<T>, key: &JsString) -> Result<Option<T>, JsValue>;
7650
7651 /// The static `Reflect.get()` method works like getting a property from
7652 /// an object (`target[propertyKey]`) as a function.
7653 ///
7654 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/get)
7655 #[wasm_bindgen(js_namespace = Reflect, js_name = get, catch)]
7656 pub fn get_symbol<T>(target: &Object<T>, key: &Symbol) -> Result<JsValue, JsValue>;
7657
7658 /// The same as [`get`](fn.get.html)
7659 /// except the key is an `f64`, which is slightly faster.
7660 #[wasm_bindgen(js_namespace = Reflect, js_name = get, catch)]
7661 pub fn get_f64(target: &JsValue, key: f64) -> Result<JsValue, JsValue>;
7662
7663 /// The same as [`get`](fn.get.html)
7664 /// except the key is a `u32`, which is slightly faster.
7665 #[wasm_bindgen(js_namespace = Reflect, js_name = get, catch)]
7666 pub fn get_u32(target: &JsValue, key: u32) -> Result<JsValue, JsValue>;
7667
7668 /// The static `Reflect.getOwnPropertyDescriptor()` method is similar to
7669 /// `Object.getOwnPropertyDescriptor()`. It returns a property descriptor
7670 /// of the given property if it exists on the object, `undefined` otherwise.
7671 ///
7672 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getOwnPropertyDescriptor)
7673 #[wasm_bindgen(js_namespace = Reflect, js_name = getOwnPropertyDescriptor, catch)]
7674 pub fn get_own_property_descriptor<T>(
7675 target: &Object<T>,
7676 property_key: &JsValue,
7677 ) -> Result<JsValue, JsValue>;
7678
7679 /// The static `Reflect.getOwnPropertyDescriptor()` method is similar to
7680 /// `Object.getOwnPropertyDescriptor()`. It returns a property descriptor
7681 /// of the given property if it exists on the object, `undefined` otherwise.
7682 ///
7683 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getOwnPropertyDescriptor)
7684 #[wasm_bindgen(js_namespace = Reflect, js_name = getOwnPropertyDescriptor, catch)]
7685 pub fn get_own_property_descriptor_str<T>(
7686 target: &Object<T>,
7687 property_key: &JsString,
7688 ) -> Result<PropertyDescriptor<T>, JsValue>;
7689
7690 /// The static `Reflect.getPrototypeOf()` method is almost the same
7691 /// method as `Object.getPrototypeOf()`. It returns the prototype
7692 /// (i.e. the value of the internal `[[Prototype]]` property) of
7693 /// the specified object.
7694 ///
7695 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getPrototypeOf)
7696 #[cfg(not(js_sys_unstable_apis))]
7697 #[wasm_bindgen(js_namespace = Reflect, js_name = getPrototypeOf, catch)]
7698 pub fn get_prototype_of(target: &JsValue) -> Result<Object, JsValue>;
7699
7700 /// The static `Reflect.getPrototypeOf()` method is almost the same
7701 /// method as `Object.getPrototypeOf()`. It returns the prototype
7702 /// (i.e. the value of the internal `[[Prototype]]` property) of
7703 /// the specified object.
7704 ///
7705 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getPrototypeOf)
7706 #[cfg(js_sys_unstable_apis)]
7707 #[wasm_bindgen(js_namespace = Reflect, js_name = getPrototypeOf, catch)]
7708 pub fn get_prototype_of(target: &Object) -> Result<Object, JsValue>;
7709
7710 /// The static `Reflect.has()` method works like the in operator as a
7711 /// function.
7712 ///
7713 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/has)
7714 #[cfg(not(js_sys_unstable_apis))]
7715 #[wasm_bindgen(js_namespace = Reflect, catch)]
7716 pub fn has(target: &JsValue, property_key: &JsValue) -> Result<bool, JsValue>;
7717
7718 /// The static `Reflect.has()` method works like the in operator as a
7719 /// function.
7720 ///
7721 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/has)
7722 #[cfg(js_sys_unstable_apis)]
7723 #[wasm_bindgen(js_namespace = Reflect, catch)]
7724 pub fn has(target: &JsValue, property_key: &Symbol) -> Result<bool, JsValue>;
7725
7726 // Next major: deprecate
7727 /// The static `Reflect.has()` method works like the in operator as a
7728 /// function.
7729 ///
7730 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/has)
7731 #[wasm_bindgen(js_namespace = Reflect, js_name = has, catch)]
7732 pub fn has_str<T>(target: &Object<T>, property_key: &JsString) -> Result<bool, JsValue>;
7733
7734 /// The static `Reflect.has()` method works like the in operator as a
7735 /// function.
7736 ///
7737 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/has)
7738 #[wasm_bindgen(js_namespace = Reflect, js_name = has, catch)]
7739 pub fn has_symbol<T>(target: &Object<T>, property_key: &Symbol) -> Result<bool, JsValue>;
7740
7741 /// The static `Reflect.isExtensible()` method determines if an object is
7742 /// extensible (whether it can have new properties added to it). It is
7743 /// similar to `Object.isExtensible()`, but with some differences.
7744 ///
7745 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/isExtensible)
7746 #[wasm_bindgen(js_namespace = Reflect, js_name = isExtensible, catch)]
7747 pub fn is_extensible<T>(target: &Object<T>) -> Result<bool, JsValue>;
7748
7749 /// The static `Reflect.ownKeys()` method returns an array of the
7750 /// target object's own property keys.
7751 ///
7752 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/ownKeys)
7753 #[wasm_bindgen(js_namespace = Reflect, js_name = ownKeys, catch)]
7754 pub fn own_keys(target: &JsValue) -> Result<Array, JsValue>;
7755
7756 /// The static `Reflect.preventExtensions()` method prevents new
7757 /// properties from ever being added to an object (i.e. prevents
7758 /// future extensions to the object). It is similar to
7759 /// `Object.preventExtensions()`, but with some differences.
7760 ///
7761 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/preventExtensions)
7762 #[wasm_bindgen(js_namespace = Reflect, js_name = preventExtensions, catch)]
7763 pub fn prevent_extensions<T>(target: &Object<T>) -> Result<bool, JsValue>;
7764
7765 /// The static `Reflect.set()` method works like setting a
7766 /// property on an object.
7767 ///
7768 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
7769 #[cfg(not(js_sys_unstable_apis))]
7770 #[wasm_bindgen(js_namespace = Reflect, catch)]
7771 pub fn set(
7772 target: &JsValue,
7773 property_key: &JsValue,
7774 value: &JsValue,
7775 ) -> Result<bool, JsValue>;
7776
7777 /// The static `Reflect.set()` method works like setting a
7778 /// property on an object.
7779 ///
7780 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
7781 #[cfg(js_sys_unstable_apis)]
7782 #[wasm_bindgen(js_namespace = Reflect, catch)]
7783 pub fn set<T>(
7784 target: &Object<T>,
7785 property_key: &JsString,
7786 value: &T,
7787 ) -> Result<bool, JsValue>;
7788
7789 /// The static `Reflect.set()` method works like setting a
7790 /// property on an object.
7791 ///
7792 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
7793 #[cfg(js_sys_unstable_apis)]
7794 #[wasm_bindgen(js_namespace = Reflect, catch)]
7795 pub fn set_symbol<T>(
7796 target: &Object<T>,
7797 property_key: &Symbol,
7798 value: &JsValue,
7799 ) -> Result<bool, JsValue>;
7800
7801 // Next major: deprecate
7802 /// The static `Reflect.set()` method works like setting a
7803 /// property on an object.
7804 ///
7805 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
7806 #[wasm_bindgen(js_namespace = Reflect, js_name = set, catch)]
7807 pub fn set_str<T>(
7808 target: &Object<T>,
7809 property_key: &JsString,
7810 value: &T,
7811 ) -> Result<bool, JsValue>;
7812
7813 /// The same as [`set`](fn.set.html)
7814 /// except the key is an `f64`, which is slightly faster.
7815 #[wasm_bindgen(js_namespace = Reflect, js_name = set, catch)]
7816 pub fn set_f64(
7817 target: &JsValue,
7818 property_key: f64,
7819 value: &JsValue,
7820 ) -> Result<bool, JsValue>;
7821
7822 /// The same as [`set`](fn.set.html)
7823 /// except the key is a `u32`, which is slightly faster.
7824 #[wasm_bindgen(js_namespace = Reflect, js_name = set, catch)]
7825 pub fn set_u32(
7826 target: &JsValue,
7827 property_key: u32,
7828 value: &JsValue,
7829 ) -> Result<bool, JsValue>;
7830
7831 /// The static `Reflect.set()` method works like setting a
7832 /// property on an object.
7833 ///
7834 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
7835 #[wasm_bindgen(js_namespace = Reflect, js_name = set, catch)]
7836 pub fn set_with_receiver(
7837 target: &JsValue,
7838 property_key: &JsValue,
7839 value: &JsValue,
7840 receiver: &JsValue,
7841 ) -> Result<bool, JsValue>;
7842
7843 /// The static `Reflect.setPrototypeOf()` method is the same
7844 /// method as `Object.setPrototypeOf()`. It sets the prototype
7845 /// (i.e., the internal `[[Prototype]]` property) of a specified
7846 /// object to another object or to null.
7847 ///
7848 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/setPrototypeOf)
7849 #[wasm_bindgen(js_namespace = Reflect, js_name = setPrototypeOf, catch)]
7850 pub fn set_prototype_of<T>(
7851 target: &Object<T>,
7852 prototype: &JsValue,
7853 ) -> Result<bool, JsValue>;
7854 }
7855}
7856
7857// RegExp
7858#[wasm_bindgen]
7859extern "C" {
7860 #[wasm_bindgen(extends = Object, typescript_type = "RegExp")]
7861 #[derive(Clone, Debug, PartialEq, Eq)]
7862 pub type RegExp;
7863
7864 /// The `exec()` method executes a search for a match in a specified
7865 /// string. Returns a result array, or null.
7866 ///
7867 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec)
7868 #[cfg(not(js_sys_unstable_apis))]
7869 #[wasm_bindgen(method)]
7870 pub fn exec(this: &RegExp, text: &str) -> Option<Array<JsString>>;
7871
7872 /// The `exec()` method executes a search for a match in a specified
7873 /// string. Returns a result array, or null.
7874 ///
7875 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec)
7876 #[cfg(js_sys_unstable_apis)]
7877 #[wasm_bindgen(method)]
7878 pub fn exec(this: &RegExp, text: &str) -> Option<RegExpMatchArray>;
7879
7880 /// The flags property returns a string consisting of the flags of
7881 /// the current regular expression object.
7882 ///
7883 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/flags)
7884 #[wasm_bindgen(method, getter)]
7885 pub fn flags(this: &RegExp) -> JsString;
7886
7887 /// The global property indicates whether or not the "g" flag is
7888 /// used with the regular expression. global is a read-only
7889 /// property of an individual regular expression instance.
7890 ///
7891 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/global)
7892 #[wasm_bindgen(method, getter)]
7893 pub fn global(this: &RegExp) -> bool;
7894
7895 /// The ignoreCase property indicates whether or not the "i" flag
7896 /// is used with the regular expression. ignoreCase is a read-only
7897 /// property of an individual regular expression instance.
7898 ///
7899 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/ignoreCase)
7900 #[wasm_bindgen(method, getter, js_name = ignoreCase)]
7901 pub fn ignore_case(this: &RegExp) -> bool;
7902
7903 /// The non-standard input property is a static property of
7904 /// regular expressions that contains the string against which a
7905 /// regular expression is matched. RegExp.$_ is an alias for this
7906 /// property.
7907 ///
7908 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/input)
7909 #[wasm_bindgen(static_method_of = RegExp, getter)]
7910 pub fn input() -> JsString;
7911
7912 /// The lastIndex is a read/write integer property of regular expression
7913 /// instances that specifies the index at which to start the next match.
7914 ///
7915 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex)
7916 #[wasm_bindgen(structural, getter = lastIndex, method)]
7917 pub fn last_index(this: &RegExp) -> u32;
7918
7919 /// The lastIndex is a read/write integer property of regular expression
7920 /// instances that specifies the index at which to start the next match.
7921 ///
7922 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex)
7923 #[wasm_bindgen(structural, setter = lastIndex, method)]
7924 pub fn set_last_index(this: &RegExp, index: u32);
7925
7926 /// The non-standard lastMatch property is a static and read-only
7927 /// property of regular expressions that contains the last matched
7928 /// characters. `RegExp.$&` is an alias for this property.
7929 ///
7930 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastMatch)
7931 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = lastMatch)]
7932 pub fn last_match() -> JsString;
7933
7934 /// The non-standard lastParen property is a static and read-only
7935 /// property of regular expressions that contains the last
7936 /// parenthesized substring match, if any. `RegExp.$+` is an alias
7937 /// for this property.
7938 ///
7939 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastParen)
7940 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = lastParen)]
7941 pub fn last_paren() -> JsString;
7942
7943 /// The non-standard leftContext property is a static and
7944 /// read-only property of regular expressions that contains the
7945 /// substring preceding the most recent match. `RegExp.$`` is an
7946 /// alias for this property.
7947 ///
7948 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/leftContext)
7949 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = leftContext)]
7950 pub fn left_context() -> JsString;
7951
7952 /// The multiline property indicates whether or not the "m" flag
7953 /// is used with the regular expression. multiline is a read-only
7954 /// property of an individual regular expression instance.
7955 ///
7956 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/multiline)
7957 #[wasm_bindgen(method, getter)]
7958 pub fn multiline(this: &RegExp) -> bool;
7959
7960 /// The non-standard $1, $2, $3, $4, $5, $6, $7, $8, $9 properties
7961 /// are static and read-only properties of regular expressions
7962 /// that contain parenthesized substring matches.
7963 ///
7964 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/n)
7965 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$1")]
7966 pub fn n1() -> JsString;
7967 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$2")]
7968 pub fn n2() -> JsString;
7969 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$3")]
7970 pub fn n3() -> JsString;
7971 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$4")]
7972 pub fn n4() -> JsString;
7973 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$5")]
7974 pub fn n5() -> JsString;
7975 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$6")]
7976 pub fn n6() -> JsString;
7977 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$7")]
7978 pub fn n7() -> JsString;
7979 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$8")]
7980 pub fn n8() -> JsString;
7981 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$9")]
7982 pub fn n9() -> JsString;
7983
7984 /// The `RegExp` constructor creates a regular expression object for matching text with a pattern.
7985 ///
7986 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp)
7987 #[wasm_bindgen(constructor)]
7988 pub fn new(pattern: &str, flags: &str) -> RegExp;
7989 #[wasm_bindgen(constructor)]
7990 pub fn new_regexp(pattern: &RegExp, flags: &str) -> RegExp;
7991
7992 /// The non-standard rightContext property is a static and
7993 /// read-only property of regular expressions that contains the
7994 /// substring following the most recent match. `RegExp.$'` is an
7995 /// alias for this property.
7996 ///
7997 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/rightContext)
7998 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = rightContext)]
7999 pub fn right_context() -> JsString;
8000
8001 /// The source property returns a String containing the source
8002 /// text of the regexp object, and it doesn't contain the two
8003 /// forward slashes on both sides and any flags.
8004 ///
8005 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/source)
8006 #[wasm_bindgen(method, getter)]
8007 pub fn source(this: &RegExp) -> JsString;
8008
8009 /// The sticky property reflects whether or not the search is
8010 /// sticky (searches in strings only from the index indicated by
8011 /// the lastIndex property of this regular expression). sticky is
8012 /// a read-only property of an individual regular expression
8013 /// object.
8014 ///
8015 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/sticky)
8016 #[wasm_bindgen(method, getter)]
8017 pub fn sticky(this: &RegExp) -> bool;
8018
8019 /// The `test()` method executes a search for a match between a
8020 /// regular expression and a specified string. Returns true or
8021 /// false.
8022 ///
8023 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/test)
8024 #[wasm_bindgen(method)]
8025 pub fn test(this: &RegExp, text: &str) -> bool;
8026
8027 /// The `toString()` method returns a string representing the
8028 /// regular expression.
8029 ///
8030 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/toString)
8031 #[cfg(not(js_sys_unstable_apis))]
8032 #[wasm_bindgen(method, js_name = toString)]
8033 pub fn to_string(this: &RegExp) -> JsString;
8034
8035 /// The unicode property indicates whether or not the "u" flag is
8036 /// used with a regular expression. unicode is a read-only
8037 /// property of an individual regular expression instance.
8038 ///
8039 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/unicode)
8040 #[wasm_bindgen(method, getter)]
8041 pub fn unicode(this: &RegExp) -> bool;
8042}
8043
8044// RegExpMatchArray
8045#[wasm_bindgen]
8046extern "C" {
8047 /// The result array from `RegExp.exec()` or `String.matchAll()`.
8048 ///
8049 /// This is an array of strings with additional properties `index`, `input`, and `groups`.
8050 ///
8051 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec#return_value)
8052 #[wasm_bindgen(extends = Object, extends = Array, typescript_type = "RegExpMatchArray")]
8053 #[derive(Clone, Debug, PartialEq, Eq)]
8054 pub type RegExpMatchArray;
8055
8056 /// The 0-based index of the match in the string.
8057 #[wasm_bindgen(method, getter)]
8058 pub fn index(this: &RegExpMatchArray) -> u32;
8059
8060 /// The original string that was matched against.
8061 #[wasm_bindgen(method, getter)]
8062 pub fn input(this: &RegExpMatchArray) -> JsString;
8063
8064 /// An object of named capturing groups whose keys are the names and valuestype Array
8065 /// are the capturing groups, or `undefined` if no named capturing groups were defined.
8066 #[wasm_bindgen(method, getter)]
8067 pub fn groups(this: &RegExpMatchArray) -> Option<Object>;
8068
8069 /// The number of elements in the match array (full match + capture groups).
8070 #[wasm_bindgen(method, getter)]
8071 pub fn length(this: &RegExpMatchArray) -> u32;
8072
8073 /// Gets the matched string or capture group at the given index.
8074 /// Index 0 is the full match, indices 1+ are capture groups.
8075 #[wasm_bindgen(method, indexing_getter)]
8076 pub fn get(this: &RegExpMatchArray, index: u32) -> Option<JsString>;
8077}
8078
8079// Set
8080#[wasm_bindgen]
8081extern "C" {
8082 #[wasm_bindgen(extends = Object, typescript_type = "Set<any>")]
8083 #[derive(Clone, Debug, PartialEq, Eq)]
8084 pub type Set<T = JsValue>;
8085
8086 /// The [`Set`] object lets you store unique values of any type, whether
8087 /// primitive values or object references.
8088 ///
8089 /// **Note:** Consider using [`Set::new_typed`] to support typing.
8090 ///
8091 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
8092 #[cfg(not(js_sys_unstable_apis))]
8093 #[wasm_bindgen(constructor)]
8094 pub fn new(init: &JsValue) -> Set;
8095
8096 /// The [`Set`] object lets you store unique values of any type, whether
8097 /// primitive values or object references.
8098 ///
8099 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
8100 #[cfg(js_sys_unstable_apis)]
8101 #[wasm_bindgen(constructor)]
8102 pub fn new<T>() -> Set<T>;
8103
8104 // Next major: deprecate
8105 /// The [`Set`] object lets you store unique values of any type, whether
8106 /// primitive values or object references.
8107 ///
8108 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
8109 #[wasm_bindgen(constructor)]
8110 pub fn new_typed<T>() -> Set<T>;
8111
8112 /// The [`Set`] object lets you store unique values of any type, whether
8113 /// primitive values or object references.
8114 ///
8115 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
8116 #[wasm_bindgen(constructor, js_name = new)]
8117 pub fn new_empty<T>() -> Set<T>;
8118
8119 /// The [`Set`] object lets you store unique values of any type, whether
8120 /// primitive values or object references.
8121 ///
8122 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
8123 #[wasm_bindgen(constructor, js_name = new)]
8124 pub fn new_from_items<T>(items: &[T]) -> Set<T>;
8125
8126 /// The [`Set`] object lets you store unique values of any type, whether
8127 /// primitive values or object references.
8128 ///
8129 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
8130 #[wasm_bindgen(constructor, js_name = new, catch)]
8131 pub fn new_from_iterable<T, I: Iterable<Item = T>>(iterable: I) -> Result<Set<T>, JsValue>;
8132
8133 /// The `add()` method appends a new element with a specified value to the
8134 /// end of a [`Set`] object.
8135 ///
8136 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/add)
8137 #[wasm_bindgen(method)]
8138 pub fn add<T>(this: &Set<T>, value: &T) -> Set<T>;
8139
8140 /// The `clear()` method removes all elements from a [`Set`] object.
8141 ///
8142 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/clear)
8143 #[wasm_bindgen(method)]
8144 pub fn clear<T>(this: &Set<T>);
8145
8146 /// The `delete()` method removes the specified element from a [`Set`]
8147 /// object.
8148 ///
8149 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/delete)
8150 #[wasm_bindgen(method)]
8151 pub fn delete<T>(this: &Set<T>, value: &T) -> bool;
8152
8153 /// The `forEach()` method executes a provided function once for each value
8154 /// in the Set object, in insertion order.
8155 ///
8156 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/forEach)
8157 #[cfg(not(js_sys_unstable_apis))]
8158 #[wasm_bindgen(method, js_name = forEach)]
8159 pub fn for_each<T>(this: &Set<T>, callback: &mut dyn FnMut(T, T, Set<T>));
8160
8161 /// The `forEach()` method executes a provided function once for each value
8162 /// in the Set object, in insertion order.
8163 ///
8164 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/forEach)
8165 #[cfg(js_sys_unstable_apis)]
8166 #[wasm_bindgen(method, js_name = forEach)]
8167 pub fn for_each<T>(this: &Set<T>, callback: &mut dyn FnMut(T));
8168
8169 /// The `forEach()` method executes a provided function once for each value
8170 /// in the Set object, in insertion order.
8171 ///
8172 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/forEach)
8173 #[wasm_bindgen(method, js_name = forEach, catch)]
8174 pub fn try_for_each<T>(
8175 this: &Set<T>,
8176 callback: &mut dyn FnMut(T) -> Result<(), JsError>,
8177 ) -> Result<(), JsValue>;
8178
8179 /// The `has()` method returns a boolean indicating whether an element with
8180 /// the specified value exists in a [`Set`] object or not.
8181 ///
8182 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/has)
8183 #[wasm_bindgen(method)]
8184 pub fn has<T>(this: &Set<T>, value: &T) -> bool;
8185
8186 /// The size accessor property returns the number of elements in a [`Set`]
8187 /// object.
8188 ///
8189 /// [MDN documentation](https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Set/size)
8190 #[wasm_bindgen(method, getter)]
8191 pub fn size<T>(this: &Set<T>) -> u32;
8192
8193 /// The `union()` method returns a new set containing elements which are in
8194 /// either or both of this set and the given set.
8195 ///
8196 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/union)
8197 #[wasm_bindgen(method)]
8198 pub fn union<T>(this: &Set<T>, other: &Set<T>) -> Set<T>;
8199
8200 /// The `intersection()` method returns a new set containing elements which are
8201 /// in both this set and the given set.
8202 ///
8203 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/intersection)
8204 #[wasm_bindgen(method)]
8205 pub fn intersection<T>(this: &Set<T>, other: &Set<T>) -> Set<T>;
8206
8207 /// The `difference()` method returns a new set containing elements which are
8208 /// in this set but not in the given set.
8209 ///
8210 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/difference)
8211 #[wasm_bindgen(method)]
8212 pub fn difference<T>(this: &Set<T>, other: &Set<T>) -> Set<T>;
8213
8214 /// The `symmetricDifference()` method returns a new set containing elements
8215 /// which are in either this set or the given set, but not in both.
8216 ///
8217 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/symmetricDifference)
8218 #[wasm_bindgen(method, js_name = symmetricDifference)]
8219 pub fn symmetric_difference<T>(this: &Set<T>, other: &Set<T>) -> Set<T>;
8220
8221 /// The `isSubsetOf()` method returns a boolean indicating whether all elements
8222 /// of this set are in the given set.
8223 ///
8224 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/isSubsetOf)
8225 #[wasm_bindgen(method, js_name = isSubsetOf)]
8226 pub fn is_subset_of<T>(this: &Set<T>, other: &Set<T>) -> bool;
8227
8228 /// The `isSupersetOf()` method returns a boolean indicating whether all elements
8229 /// of the given set are in this set.
8230 ///
8231 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/isSupersetOf)
8232 #[wasm_bindgen(method, js_name = isSupersetOf)]
8233 pub fn is_superset_of<T>(this: &Set<T>, other: &Set<T>) -> bool;
8234
8235 /// The `isDisjointFrom()` method returns a boolean indicating whether this set
8236 /// has no elements in common with the given set.
8237 ///
8238 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/isDisjointFrom)
8239 #[wasm_bindgen(method, js_name = isDisjointFrom)]
8240 pub fn is_disjoint_from<T>(this: &Set<T>, other: &Set<T>) -> bool;
8241}
8242
8243impl Default for Set<JsValue> {
8244 fn default() -> Self {
8245 Self::new_typed()
8246 }
8247}
8248
8249impl<T> Iterable for Set<T> {
8250 type Item = T;
8251}
8252
8253// SetIterator
8254#[wasm_bindgen]
8255extern "C" {
8256 /// The `entries()` method returns a new Iterator object that contains an
8257 /// array of [value, value] for each element in the Set object, in insertion
8258 /// order. For Set objects there is no key like in Map objects. However, to
8259 /// keep the API similar to the Map object, each entry has the same value
8260 /// for its key and value here, so that an array [value, value] is returned.
8261 ///
8262 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/entries)
8263 #[cfg(not(js_sys_unstable_apis))]
8264 #[wasm_bindgen(method)]
8265 pub fn entries<T>(set: &Set<T>) -> Iterator;
8266
8267 /// The `entries()` method returns a new Iterator object that contains an
8268 /// array of [value, value] for each element in the Set object, in insertion
8269 /// order. For Set objects there is no key like in Map objects. However, to
8270 /// keep the API similar to the Map object, each entry has the same value
8271 /// for its key and value here, so that an array [value, value] is returned.
8272 ///
8273 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/entries)
8274 #[cfg(js_sys_unstable_apis)]
8275 #[wasm_bindgen(method, js_name = entries)]
8276 pub fn entries<T: JsGeneric>(set: &Set<T>) -> Iterator<ArrayTuple<(T, T)>>;
8277
8278 // Next major: deprecate
8279 /// The `entries()` method returns a new Iterator object that contains an
8280 /// array of [value, value] for each element in the Set object, in insertion
8281 /// order. For Set objects there is no key like in Map objects. However, to
8282 /// keep the API similar to the Map object, each entry has the same value
8283 /// for its key and value here, so that an array [value, value] is returned.
8284 ///
8285 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/entries)
8286 #[wasm_bindgen(method, js_name = entries)]
8287 pub fn entries_typed<T: JsGeneric>(set: &Set<T>) -> Iterator<ArrayTuple<(T, T)>>;
8288
8289 /// The `keys()` method is an alias for this method (for similarity with
8290 /// Map objects); it behaves exactly the same and returns values
8291 /// of Set elements.
8292 ///
8293 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/values)
8294 #[wasm_bindgen(method)]
8295 pub fn keys<T>(set: &Set<T>) -> Iterator<T>;
8296
8297 /// The `values()` method returns a new Iterator object that contains the
8298 /// values for each element in the Set object in insertion order.
8299 ///
8300 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/values)
8301 #[wasm_bindgen(method)]
8302 pub fn values<T>(set: &Set<T>) -> Iterator<T>;
8303}
8304
8305// SyntaxError
8306#[wasm_bindgen]
8307extern "C" {
8308 /// A `SyntaxError` is thrown when the JavaScript engine encounters tokens or
8309 /// token order that does not conform to the syntax of the language when
8310 /// parsing code.
8311 ///
8312 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError)
8313 #[wasm_bindgen(extends = Error, extends = Object, typescript_type = "SyntaxError")]
8314 #[derive(Clone, Debug, PartialEq, Eq)]
8315 pub type SyntaxError;
8316
8317 /// A `SyntaxError` is thrown when the JavaScript engine encounters tokens or
8318 /// token order that does not conform to the syntax of the language when
8319 /// parsing code.
8320 ///
8321 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError)
8322 #[wasm_bindgen(constructor)]
8323 pub fn new(message: &str) -> SyntaxError;
8324
8325 /// Creates a new `SyntaxError` with the given message and a typed
8326 /// [`ErrorOptions`] dictionary whose `cause` property indicates the
8327 /// original cause of the error.
8328 ///
8329 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError/SyntaxError)
8330 #[wasm_bindgen(constructor)]
8331 pub fn new_with_options(message: &str, options: &ErrorOptions) -> SyntaxError;
8332}
8333
8334// TypeError
8335#[wasm_bindgen]
8336extern "C" {
8337 /// The `TypeError` object represents an error when a value is not of the
8338 /// expected type.
8339 ///
8340 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError)
8341 #[wasm_bindgen(extends = Error, extends = Object, typescript_type = "TypeError")]
8342 #[derive(Clone, Debug, PartialEq, Eq)]
8343 pub type TypeError;
8344
8345 /// The `TypeError` object represents an error when a value is not of the
8346 /// expected type.
8347 ///
8348 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError)
8349 #[wasm_bindgen(constructor)]
8350 pub fn new(message: &str) -> TypeError;
8351
8352 /// Creates a new `TypeError` with the given message and a typed
8353 /// [`ErrorOptions`] dictionary whose `cause` property indicates the
8354 /// original cause of the error.
8355 ///
8356 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError/TypeError)
8357 #[wasm_bindgen(constructor)]
8358 pub fn new_with_options(message: &str, options: &ErrorOptions) -> TypeError;
8359}
8360
8361// URIError
8362#[wasm_bindgen]
8363extern "C" {
8364 /// The `URIError` object represents an error when a global URI handling
8365 /// function was used in a wrong way.
8366 ///
8367 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError)
8368 #[wasm_bindgen(extends = Error, extends = Object, js_name = URIError, typescript_type = "URIError")]
8369 #[derive(Clone, Debug, PartialEq, Eq)]
8370 pub type UriError;
8371
8372 /// The `URIError` object represents an error when a global URI handling
8373 /// function was used in a wrong way.
8374 ///
8375 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError)
8376 #[wasm_bindgen(constructor, js_class = "URIError")]
8377 pub fn new(message: &str) -> UriError;
8378
8379 /// Creates a new `URIError` with the given message and a typed
8380 /// [`ErrorOptions`] dictionary whose `cause` property indicates the
8381 /// original cause of the error.
8382 ///
8383 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError/URIError)
8384 #[wasm_bindgen(constructor, js_class = "URIError")]
8385 pub fn new_with_options(message: &str, options: &ErrorOptions) -> UriError;
8386}
8387
8388// WeakMap
8389#[wasm_bindgen]
8390extern "C" {
8391 #[wasm_bindgen(extends = Object, typescript_type = "WeakMap<object, any>")]
8392 #[derive(Clone, Debug, PartialEq, Eq)]
8393 pub type WeakMap<K = Object, V = JsValue>;
8394
8395 /// The [`WeakMap`] object is a collection of key/value pairs in which the
8396 /// keys are weakly referenced. The keys must be objects and the values can
8397 /// be arbitrary values.
8398 ///
8399 /// **Note:** Consider using [`WeakMap::new_typed`] to support typing.
8400 ///
8401 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap)
8402 #[cfg(not(js_sys_unstable_apis))]
8403 #[wasm_bindgen(constructor)]
8404 pub fn new() -> WeakMap;
8405
8406 /// The [`WeakMap`] object is a collection of key/value pairs in which the
8407 /// keys are weakly referenced. The keys must be objects and the values can
8408 /// be arbitrary values.
8409 ///
8410 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap)
8411 #[cfg(js_sys_unstable_apis)]
8412 #[wasm_bindgen(constructor)]
8413 pub fn new<K: JsGeneric = Object, V: JsGeneric = Object>() -> WeakMap<K, V>;
8414
8415 // Next major: deprecate
8416 /// The [`WeakMap`] object is a collection of key/value pairs in which the
8417 /// keys are weakly referenced. The keys must be objects and the values can
8418 /// be arbitrary values.
8419 ///
8420 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap)
8421 #[wasm_bindgen(constructor)]
8422 pub fn new_typed<K: JsGeneric = Object, V: JsGeneric = Object>() -> WeakMap<K, V>;
8423
8424 /// The `set()` method sets the value for the key in the [`WeakMap`] object.
8425 /// Returns the [`WeakMap`] object.
8426 ///
8427 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/set)
8428 #[wasm_bindgen(method, js_class = "WeakMap")]
8429 pub fn set<K, V>(this: &WeakMap<K, V>, key: &K, value: &V) -> WeakMap<K, V>;
8430
8431 /// The `get()` method returns a specified by key element
8432 /// from a [`WeakMap`] object. Returns `undefined` if the key is not found.
8433 ///
8434 /// **Note:** Consider using [`WeakMap::get_checked`] to get an `Option<V>` instead.
8435 ///
8436 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/get)
8437 #[cfg(not(js_sys_unstable_apis))]
8438 #[wasm_bindgen(method)]
8439 pub fn get<K, V>(this: &WeakMap<K, V>, key: &K) -> V;
8440
8441 /// The `get()` method returns a specified by key element
8442 /// from a [`WeakMap`] object. Returns `None` if the key is not found.
8443 ///
8444 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/get)
8445 #[cfg(js_sys_unstable_apis)]
8446 #[wasm_bindgen(method)]
8447 pub fn get<K, V>(this: &WeakMap<K, V>, key: &K) -> Option<V>;
8448
8449 /// The `get()` method returns a specified by key element
8450 /// from a [`WeakMap`] object. Returns `None` if the key is not found.
8451 ///
8452 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/get)
8453 #[wasm_bindgen(method, js_name = get)]
8454 pub fn get_checked<K, V>(this: &WeakMap<K, V>, key: &K) -> Option<V>;
8455
8456 /// The `has()` method returns a boolean indicating whether an element with
8457 /// the specified key exists in the [`WeakMap`] object or not.
8458 ///
8459 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/has)
8460 #[wasm_bindgen(method)]
8461 pub fn has<K, V>(this: &WeakMap<K, V>, key: &K) -> bool;
8462
8463 /// The `delete()` method removes the specified element from a [`WeakMap`]
8464 /// object.
8465 ///
8466 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/delete)
8467 #[wasm_bindgen(method)]
8468 pub fn delete<K, V>(this: &WeakMap<K, V>, key: &K) -> bool;
8469}
8470
8471impl Default for WeakMap {
8472 fn default() -> Self {
8473 Self::new()
8474 }
8475}
8476
8477// WeakSet
8478#[wasm_bindgen]
8479extern "C" {
8480 #[wasm_bindgen(extends = Object, typescript_type = "WeakSet<object>")]
8481 #[derive(Clone, Debug, PartialEq, Eq)]
8482 pub type WeakSet<T = Object>;
8483
8484 /// The `WeakSet` object lets you store weakly held objects in a collection.
8485 ///
8486 /// **Note:** Consider using [`WeakSet::new_typed`] for typed sets.
8487 ///
8488 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet)
8489 #[cfg(not(js_sys_unstable_apis))]
8490 #[wasm_bindgen(constructor)]
8491 pub fn new() -> WeakSet;
8492
8493 /// The `WeakSet` object lets you store weakly held objects in a collection.
8494 ///
8495 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet)
8496 #[cfg(js_sys_unstable_apis)]
8497 #[wasm_bindgen(constructor)]
8498 pub fn new<T = Object>() -> WeakSet<T>;
8499
8500 // Next major: deprecate
8501 /// The `WeakSet` object lets you store weakly held objects in a collection.
8502 ///
8503 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet)
8504 #[wasm_bindgen(constructor)]
8505 pub fn new_typed<T = Object>() -> WeakSet<T>;
8506
8507 /// The `has()` method returns a boolean indicating whether an object exists
8508 /// in a WeakSet or not.
8509 ///
8510 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet/has)
8511 #[wasm_bindgen(method)]
8512 pub fn has<T>(this: &WeakSet<T>, value: &T) -> bool;
8513
8514 /// The `add()` method appends a new object to the end of a WeakSet object.
8515 ///
8516 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet/add)
8517 #[wasm_bindgen(method)]
8518 pub fn add<T>(this: &WeakSet<T>, value: &T) -> WeakSet<T>;
8519
8520 /// The `delete()` method removes the specified element from a WeakSet
8521 /// object.
8522 ///
8523 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet/delete)
8524 #[wasm_bindgen(method)]
8525 pub fn delete<T>(this: &WeakSet<T>, value: &T) -> bool;
8526}
8527
8528impl Default for WeakSet {
8529 fn default() -> Self {
8530 Self::new()
8531 }
8532}
8533
8534// WeakRef
8535#[wasm_bindgen]
8536extern "C" {
8537 #[wasm_bindgen(extends = Object, typescript_type = "WeakRef<object>")]
8538 #[derive(Clone, Debug, PartialEq, Eq)]
8539 pub type WeakRef<T = Object>;
8540
8541 /// The `WeakRef` object contains a weak reference to an object. A weak
8542 /// reference to an object is a reference that does not prevent the object
8543 /// from being reclaimed by the garbage collector.
8544 ///
8545 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef)
8546 #[wasm_bindgen(constructor)]
8547 pub fn new<T = Object>(target: &T) -> WeakRef<T>;
8548
8549 /// Returns the `Object` this `WeakRef` points to, or `None` if the
8550 /// object has been garbage collected.
8551 ///
8552 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef/deref)
8553 #[wasm_bindgen(method)]
8554 pub fn deref<T>(this: &WeakRef<T>) -> Option<T>;
8555}
8556
8557#[cfg(js_sys_unstable_apis)]
8558#[allow(non_snake_case)]
8559pub mod Temporal;
8560
8561#[allow(non_snake_case)]
8562pub mod WebAssembly {
8563 use super::*;
8564
8565 // WebAssembly
8566 #[wasm_bindgen]
8567 extern "C" {
8568 /// The `WebAssembly.compile()` function compiles a `WebAssembly.Module`
8569 /// from WebAssembly binary code. This function is useful if it is
8570 /// necessary to a compile a module before it can be instantiated
8571 /// (otherwise, the `WebAssembly.instantiate()` function should be used).
8572 ///
8573 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compile)
8574 #[cfg(not(js_sys_unstable_apis))]
8575 #[wasm_bindgen(js_namespace = WebAssembly)]
8576 pub fn compile(buffer_source: &JsValue) -> Promise<JsValue>;
8577
8578 /// The `WebAssembly.compile()` function compiles a `WebAssembly.Module`
8579 /// from WebAssembly binary code. This function is useful if it is
8580 /// necessary to a compile a module before it can be instantiated
8581 /// (otherwise, the `WebAssembly.instantiate()` function should be used).
8582 ///
8583 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compile)
8584 #[cfg(js_sys_unstable_apis)]
8585 #[wasm_bindgen(js_namespace = WebAssembly)]
8586 pub fn compile(buffer_source: &JsValue) -> Promise<Module>;
8587
8588 /// The `WebAssembly.compileStreaming()` function compiles a
8589 /// `WebAssembly.Module` module directly from a streamed underlying
8590 /// source. This function is useful if it is necessary to a compile a
8591 /// module before it can be instantiated (otherwise, the
8592 /// `WebAssembly.instantiateStreaming()` function should be used).
8593 ///
8594 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compileStreaming)
8595 #[cfg(not(js_sys_unstable_apis))]
8596 #[wasm_bindgen(js_namespace = WebAssembly, js_name = compileStreaming)]
8597 pub fn compile_streaming(response: &Promise) -> Promise<JsValue>;
8598
8599 /// The `WebAssembly.compileStreaming()` function compiles a
8600 /// `WebAssembly.Module` module directly from a streamed underlying
8601 /// source. This function is useful if it is necessary to a compile a
8602 /// module before it can be instantiated (otherwise, the
8603 /// `WebAssembly.instantiateStreaming()` function should be used).
8604 ///
8605 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compileStreaming)
8606 #[cfg(js_sys_unstable_apis)]
8607 #[wasm_bindgen(js_namespace = WebAssembly, js_name = compileStreaming)]
8608 pub fn compile_streaming(response: &Promise) -> Promise<Module>;
8609
8610 /// The `WebAssembly.instantiate()` function allows you to compile and
8611 /// instantiate WebAssembly code.
8612 ///
8613 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate)
8614 #[cfg(not(js_sys_unstable_apis))]
8615 #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiate)]
8616 pub fn instantiate_buffer(buffer: &[u8], imports: &Object) -> Promise<JsValue>;
8617
8618 /// The `WebAssembly.instantiate()` function allows you to compile and
8619 /// instantiate WebAssembly code.
8620 ///
8621 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate)
8622 #[cfg(js_sys_unstable_apis)]
8623 #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiate)]
8624 pub fn instantiate_buffer(buffer: &[u8], imports: &Object) -> Promise<Instance>;
8625
8626 /// The `WebAssembly.instantiate()` function allows you to compile and
8627 /// instantiate WebAssembly code.
8628 ///
8629 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate)
8630 #[cfg(not(js_sys_unstable_apis))]
8631 #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiate)]
8632 pub fn instantiate_module(module: &Module, imports: &Object) -> Promise<JsValue>;
8633
8634 /// The `WebAssembly.instantiate()` function allows you to compile and
8635 /// instantiate WebAssembly code.
8636 ///
8637 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate)
8638 #[cfg(js_sys_unstable_apis)]
8639 #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiate)]
8640 pub fn instantiate_module(module: &Module, imports: &Object) -> Promise<Instance>;
8641
8642 /// The `WebAssembly.instantiateStreaming()` function compiles and
8643 /// instantiates a WebAssembly module directly from a streamed
8644 /// underlying source. This is the most efficient, optimized way to load
8645 /// Wasm code.
8646 ///
8647 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiateStreaming)
8648 #[cfg(not(js_sys_unstable_apis))]
8649 #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiateStreaming)]
8650 pub fn instantiate_streaming(response: &JsValue, imports: &Object) -> Promise<JsValue>;
8651
8652 /// The `WebAssembly.instantiateStreaming()` function compiles and
8653 /// instantiates a WebAssembly module directly from a streamed
8654 /// underlying source. This is the most efficient, optimized way to load
8655 /// Wasm code.
8656 ///
8657 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiateStreaming)
8658 #[cfg(js_sys_unstable_apis)]
8659 #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiateStreaming)]
8660 pub fn instantiate_streaming(response: &JsValue, imports: &Object) -> Promise<Instance>;
8661
8662 /// The `WebAssembly.validate()` function validates a given typed
8663 /// array of WebAssembly binary code, returning whether the bytes
8664 /// form a valid Wasm module (`true`) or not (`false`).
8665 ///
8666 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/validate)
8667 #[wasm_bindgen(js_namespace = WebAssembly, catch)]
8668 pub fn validate(buffer_source: &JsValue) -> Result<bool, JsValue>;
8669 }
8670
8671 // WebAssembly.CompileError
8672 #[wasm_bindgen]
8673 extern "C" {
8674 /// The `WebAssembly.CompileError()` constructor creates a new
8675 /// WebAssembly `CompileError` object, which indicates an error during
8676 /// WebAssembly decoding or validation.
8677 ///
8678 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/CompileError)
8679 #[wasm_bindgen(extends = Error, js_namespace = WebAssembly, typescript_type = "WebAssembly.CompileError")]
8680 #[derive(Clone, Debug, PartialEq, Eq)]
8681 pub type CompileError;
8682
8683 /// The `WebAssembly.CompileError()` constructor creates a new
8684 /// WebAssembly `CompileError` object, which indicates an error during
8685 /// WebAssembly decoding or validation.
8686 ///
8687 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/CompileError)
8688 #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
8689 pub fn new(message: &str) -> CompileError;
8690
8691 /// Creates a new `WebAssembly.CompileError` with the given message and
8692 /// a typed [`ErrorOptions`] dictionary whose `cause` property
8693 /// indicates the original cause of the error.
8694 ///
8695 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/CompileError/CompileError)
8696 #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
8697 pub fn new_with_options(message: &str, options: &ErrorOptions) -> CompileError;
8698 }
8699
8700 // WebAssembly.Instance
8701 #[wasm_bindgen]
8702 extern "C" {
8703 /// A `WebAssembly.Instance` object is a stateful, executable instance
8704 /// of a `WebAssembly.Module`. Instance objects contain all the exported
8705 /// WebAssembly functions that allow calling into WebAssembly code from
8706 /// JavaScript.
8707 ///
8708 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance)
8709 #[wasm_bindgen(extends = Object, js_namespace = WebAssembly, typescript_type = "WebAssembly.Instance")]
8710 #[derive(Clone, Debug, PartialEq, Eq)]
8711 pub type Instance;
8712
8713 /// The `WebAssembly.Instance()` constructor function can be called to
8714 /// synchronously instantiate a given `WebAssembly.Module`
8715 /// object. However, the primary way to get an `Instance` is through the
8716 /// asynchronous `WebAssembly.instantiateStreaming()` function.
8717 ///
8718 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance)
8719 #[wasm_bindgen(catch, constructor, js_namespace = WebAssembly)]
8720 pub fn new(module: &Module, imports: &Object) -> Result<Instance, JsValue>;
8721
8722 /// The `exports` readonly property of the `WebAssembly.Instance` object
8723 /// prototype returns an object containing as its members all the
8724 /// functions exported from the WebAssembly module instance, to allow
8725 /// them to be accessed and used by JavaScript.
8726 ///
8727 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance/exports)
8728 #[wasm_bindgen(getter, method, js_namespace = WebAssembly)]
8729 pub fn exports(this: &Instance) -> Object;
8730 }
8731
8732 // WebAssembly.LinkError
8733 #[wasm_bindgen]
8734 extern "C" {
8735 /// The `WebAssembly.LinkError()` constructor creates a new WebAssembly
8736 /// LinkError object, which indicates an error during module
8737 /// instantiation (besides traps from the start function).
8738 ///
8739 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/LinkError)
8740 #[wasm_bindgen(extends = Error, js_namespace = WebAssembly, typescript_type = "WebAssembly.LinkError")]
8741 #[derive(Clone, Debug, PartialEq, Eq)]
8742 pub type LinkError;
8743
8744 /// The `WebAssembly.LinkError()` constructor creates a new WebAssembly
8745 /// LinkError object, which indicates an error during module
8746 /// instantiation (besides traps from the start function).
8747 ///
8748 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/LinkError)
8749 #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
8750 pub fn new(message: &str) -> LinkError;
8751
8752 /// Creates a new `WebAssembly.LinkError` with the given message and a
8753 /// typed [`ErrorOptions`] dictionary whose `cause` property indicates
8754 /// the original cause of the error.
8755 ///
8756 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/LinkError/LinkError)
8757 #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
8758 pub fn new_with_options(message: &str, options: &ErrorOptions) -> LinkError;
8759 }
8760
8761 // WebAssembly.RuntimeError
8762 #[wasm_bindgen]
8763 extern "C" {
8764 /// The `WebAssembly.RuntimeError()` constructor creates a new WebAssembly
8765 /// `RuntimeError` object — the type that is thrown whenever WebAssembly
8766 /// specifies a trap.
8767 ///
8768 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/RuntimeError)
8769 #[wasm_bindgen(extends = Error, js_namespace = WebAssembly, typescript_type = "WebAssembly.RuntimeError")]
8770 #[derive(Clone, Debug, PartialEq, Eq)]
8771 pub type RuntimeError;
8772
8773 /// The `WebAssembly.RuntimeError()` constructor creates a new WebAssembly
8774 /// `RuntimeError` object — the type that is thrown whenever WebAssembly
8775 /// specifies a trap.
8776 ///
8777 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/RuntimeError)
8778 #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
8779 pub fn new(message: &str) -> RuntimeError;
8780
8781 /// Creates a new `WebAssembly.RuntimeError` with the given message
8782 /// and a typed [`ErrorOptions`] dictionary whose `cause` property
8783 /// indicates the original cause of the error.
8784 ///
8785 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/RuntimeError/RuntimeError)
8786 #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
8787 pub fn new_with_options(message: &str, options: &ErrorOptions) -> RuntimeError;
8788 }
8789
8790 // WebAssembly.Module
8791 #[wasm_bindgen]
8792 extern "C" {
8793 /// A `WebAssembly.Module` object contains stateless WebAssembly code
8794 /// that has already been compiled by the browser and can be
8795 /// efficiently shared with Workers, and instantiated multiple times.
8796 ///
8797 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module)
8798 #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Module")]
8799 #[derive(Clone, Debug, PartialEq, Eq)]
8800 pub type Module;
8801
8802 /// A `WebAssembly.Module` object contains stateless WebAssembly code
8803 /// that has already been compiled by the browser and can be
8804 /// efficiently shared with Workers, and instantiated multiple times.
8805 ///
8806 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module)
8807 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
8808 pub fn new(buffer_source: &JsValue) -> Result<Module, JsValue>;
8809
8810 /// The `WebAssembly.customSections()` function returns a copy of the
8811 /// contents of all custom sections in the given module with the given
8812 /// string name.
8813 ///
8814 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/customSections)
8815 #[wasm_bindgen(static_method_of = Module, js_namespace = WebAssembly, js_name = customSections)]
8816 pub fn custom_sections(module: &Module, sectionName: &str) -> Array;
8817
8818 /// The `WebAssembly.exports()` function returns an array containing
8819 /// descriptions of all the declared exports of the given `Module`.
8820 ///
8821 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/exports)
8822 #[wasm_bindgen(static_method_of = Module, js_namespace = WebAssembly)]
8823 pub fn exports(module: &Module) -> Array;
8824
8825 /// The `WebAssembly.imports()` function returns an array containing
8826 /// descriptions of all the declared imports of the given `Module`.
8827 ///
8828 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/imports)
8829 #[wasm_bindgen(static_method_of = Module, js_namespace = WebAssembly)]
8830 pub fn imports(module: &Module) -> Array;
8831 }
8832
8833 // WebAssembly.Table
8834 #[wasm_bindgen]
8835 extern "C" {
8836 /// The `WebAssembly.Table()` constructor creates a new `Table` object
8837 /// of the given size and element type.
8838 ///
8839 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table)
8840 #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Table")]
8841 #[derive(Clone, Debug, PartialEq, Eq)]
8842 pub type Table;
8843
8844 /// The `WebAssembly.Table()` constructor creates a new `Table` object
8845 /// of the given size and element type.
8846 ///
8847 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table)
8848 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
8849 pub fn new(table_descriptor: &Object) -> Result<Table, JsValue>;
8850
8851 /// The `WebAssembly.Table()` constructor creates a new `Table` object
8852 /// of the given size and element type.
8853 ///
8854 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table)
8855 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
8856 pub fn new_with_value(table_descriptor: &Object, value: JsValue) -> Result<Table, JsValue>;
8857
8858 /// The length prototype property of the `WebAssembly.Table` object
8859 /// returns the length of the table, i.e. the number of elements in the
8860 /// table.
8861 ///
8862 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/length)
8863 #[wasm_bindgen(method, getter, js_namespace = WebAssembly)]
8864 pub fn length(this: &Table) -> u32;
8865
8866 /// The `get()` prototype method of the `WebAssembly.Table()` object
8867 /// retrieves a function reference stored at a given index.
8868 ///
8869 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/get)
8870 #[wasm_bindgen(method, catch, js_namespace = WebAssembly)]
8871 pub fn get(this: &Table, index: u32) -> Result<Function, JsValue>;
8872
8873 /// The `get()` prototype method of the `WebAssembly.Table()` object
8874 /// retrieves a function reference stored at a given index.
8875 ///
8876 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/get)
8877 #[wasm_bindgen(method, catch, js_namespace = WebAssembly, js_name = get)]
8878 pub fn get_raw(this: &Table, index: u32) -> Result<JsValue, JsValue>;
8879
8880 /// The `grow()` prototype method of the `WebAssembly.Table` object
8881 /// increases the size of the `Table` instance by a specified number of
8882 /// elements.
8883 ///
8884 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/grow)
8885 #[wasm_bindgen(method, catch, js_namespace = WebAssembly)]
8886 pub fn grow(this: &Table, additional_capacity: u32) -> Result<u32, JsValue>;
8887
8888 /// The `grow()` prototype method of the `WebAssembly.Table` object
8889 /// increases the size of the `Table` instance by a specified number of
8890 /// elements.
8891 ///
8892 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/grow)
8893 #[wasm_bindgen(method, catch, js_namespace = WebAssembly, js_name = grow)]
8894 pub fn grow_with_value(
8895 this: &Table,
8896 additional_capacity: u32,
8897 value: JsValue,
8898 ) -> Result<u32, JsValue>;
8899
8900 /// The `set()` prototype method of the `WebAssembly.Table` object mutates a
8901 /// reference stored at a given index to a different value.
8902 ///
8903 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/set)
8904 #[wasm_bindgen(method, catch, js_namespace = WebAssembly)]
8905 pub fn set(this: &Table, index: u32, function: &Function) -> Result<(), JsValue>;
8906
8907 /// The `set()` prototype method of the `WebAssembly.Table` object mutates a
8908 /// reference stored at a given index to a different value.
8909 ///
8910 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/set)
8911 #[wasm_bindgen(method, catch, js_namespace = WebAssembly, js_name = set)]
8912 pub fn set_raw(this: &Table, index: u32, value: &JsValue) -> Result<(), JsValue>;
8913 }
8914
8915 // WebAssembly.Tag
8916 #[wasm_bindgen]
8917 extern "C" {
8918 /// The `WebAssembly.Tag()` constructor creates a new `Tag` object
8919 ///
8920 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Tag)
8921 #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Tag")]
8922 #[derive(Clone, Debug, PartialEq, Eq)]
8923 pub type Tag;
8924
8925 /// The `WebAssembly.Tag()` constructor creates a new `Tag` object
8926 ///
8927 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Tag)
8928 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
8929 pub fn new(tag_descriptor: &Object) -> Result<Tag, JsValue>;
8930 }
8931
8932 // WebAssembly.Exception
8933 #[wasm_bindgen]
8934 extern "C" {
8935 /// The `WebAssembly.Exception()` constructor creates a new `Exception` object
8936 ///
8937 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception)
8938 #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Exception")]
8939 #[derive(Clone, Debug, PartialEq, Eq)]
8940 pub type Exception;
8941
8942 /// The `WebAssembly.Exception()` constructor creates a new `Exception` object
8943 ///
8944 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception)
8945 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
8946 pub fn new(tag: &Tag, payload: &Array) -> Result<Exception, JsValue>;
8947
8948 /// The `WebAssembly.Exception()` constructor creates a new `Exception` object
8949 ///
8950 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception)
8951 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
8952 pub fn new_with_options(
8953 tag: &Tag,
8954 payload: &Array,
8955 options: &Object,
8956 ) -> Result<Exception, JsValue>;
8957
8958 /// The `is()` prototype method of the `WebAssembly.Exception` can be used to
8959 /// test if the Exception matches a given tag.
8960 ///
8961 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception/is)
8962 #[wasm_bindgen(method, js_namespace = WebAssembly)]
8963 pub fn is(this: &Exception, tag: &Tag) -> bool;
8964
8965 /// The `getArg()` prototype method of the `WebAssembly.Exception` can be used
8966 /// to get the value of a specified item in the exception's data arguments
8967 ///
8968 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception/getArg)
8969 #[wasm_bindgen(method, js_namespace = WebAssembly, js_name = getArg, catch)]
8970 pub fn get_arg(this: &Exception, tag: &Tag, index: u32) -> Result<JsValue, JsValue>;
8971 }
8972
8973 // WebAssembly.Global
8974 #[wasm_bindgen]
8975 extern "C" {
8976 /// The `WebAssembly.Global()` constructor creates a new `Global` object
8977 /// of the given type and value.
8978 ///
8979 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global)
8980 #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Global")]
8981 #[derive(Clone, Debug, PartialEq, Eq)]
8982 pub type Global;
8983
8984 /// The `WebAssembly.Global()` constructor creates a new `Global` object
8985 /// of the given type and value.
8986 ///
8987 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global)
8988 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
8989 pub fn new(global_descriptor: &Object, value: &JsValue) -> Result<Global, JsValue>;
8990
8991 /// The value prototype property of the `WebAssembly.Global` object
8992 /// returns the value of the global.
8993 ///
8994 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global)
8995 #[wasm_bindgen(method, getter, js_namespace = WebAssembly)]
8996 pub fn value(this: &Global) -> JsValue;
8997 #[wasm_bindgen(method, setter = value, js_namespace = WebAssembly)]
8998 pub fn set_value(this: &Global, value: &JsValue);
8999 }
9000
9001 // WebAssembly.Memory
9002 #[wasm_bindgen]
9003 extern "C" {
9004 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory)
9005 #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Memory")]
9006 #[derive(Clone, Debug, PartialEq, Eq)]
9007 pub type Memory;
9008
9009 /// The `WebAssembly.Memory()` constructor creates a new `Memory` object
9010 /// which is a resizable `ArrayBuffer` that holds the raw bytes of
9011 /// memory accessed by a WebAssembly `Instance`.
9012 ///
9013 /// A memory created by JavaScript or in WebAssembly code will be
9014 /// accessible and mutable from both JavaScript and WebAssembly.
9015 ///
9016 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory)
9017 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
9018 pub fn new(descriptor: &Object) -> Result<Memory, JsValue>;
9019
9020 /// An accessor property that returns the buffer contained in the
9021 /// memory.
9022 ///
9023 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory/buffer)
9024 #[wasm_bindgen(method, getter, js_namespace = WebAssembly)]
9025 pub fn buffer(this: &Memory) -> JsValue;
9026
9027 /// The `grow()` prototype method of the `Memory` object increases the
9028 /// size of the memory instance by a specified number of WebAssembly
9029 /// pages.
9030 ///
9031 /// Takes the number of pages to grow (64KiB in size) and returns the
9032 /// previous size of memory, in pages.
9033 ///
9034 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory/grow)
9035 #[wasm_bindgen(method, js_namespace = WebAssembly)]
9036 pub fn grow(this: &Memory, pages: u32) -> u32;
9037 }
9038}
9039
9040/// The `JSON` object contains methods for parsing [JavaScript Object
9041/// Notation (JSON)](https://json.org/) and converting values to JSON. It
9042/// can't be called or constructed, and aside from its two method
9043/// properties, it has no interesting functionality of its own.
9044#[allow(non_snake_case)]
9045pub mod JSON {
9046 use super::*;
9047
9048 // JSON
9049 #[wasm_bindgen]
9050 extern "C" {
9051 /// The `JSON.parse()` method parses a JSON string, constructing the
9052 /// JavaScript value or object described by the string.
9053 ///
9054 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse)
9055 #[wasm_bindgen(catch, js_namespace = JSON)]
9056 pub fn parse(text: &str) -> Result<JsValue, JsValue>;
9057
9058 /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
9059 ///
9060 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
9061 #[wasm_bindgen(catch, js_namespace = JSON)]
9062 pub fn stringify(obj: &JsValue) -> Result<JsString, JsValue>;
9063
9064 /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
9065 ///
9066 /// The `replacer` argument is a function that alters the behavior of the stringification
9067 /// process, or an array of String and Number objects that serve as a whitelist
9068 /// for selecting/filtering the properties of the value object to be included
9069 /// in the JSON string. If this value is null or not provided, all properties
9070 /// of the object are included in the resulting JSON string.
9071 ///
9072 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
9073 #[cfg(not(js_sys_unstable_apis))]
9074 #[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
9075 pub fn stringify_with_replacer(
9076 obj: &JsValue,
9077 replacer: &JsValue,
9078 ) -> Result<JsString, JsValue>;
9079
9080 /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
9081 ///
9082 /// The `replacer` argument is a function that alters the behavior of the stringification
9083 /// process, or an array of String and Number objects that serve as a whitelist
9084 /// for selecting/filtering the properties of the value object to be included
9085 /// in the JSON string. If this value is null or not provided, all properties
9086 /// of the object are included in the resulting JSON string.
9087 ///
9088 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
9089 #[cfg(js_sys_unstable_apis)]
9090 #[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
9091 pub fn stringify_with_replacer<'a>(
9092 obj: &JsValue,
9093 replacer: &mut dyn FnMut(JsString, JsValue) -> Result<Option<JsValue>, JsError>,
9094 space: Option<u32>,
9095 ) -> Result<JsString, JsValue>;
9096
9097 // Next major: deprecate
9098 /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
9099 ///
9100 /// The `replacer` argument is a function that alters the behavior of the stringification
9101 /// process, or an array of String and Number objects that serve as a whitelist
9102 /// for selecting/filtering the properties of the value object to be included
9103 /// in the JSON string. If this value is null or not provided, all properties
9104 /// of the object are included in the resulting JSON string.
9105 ///
9106 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
9107 #[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
9108 pub fn stringify_with_replacer_func<'a>(
9109 obj: &JsValue,
9110 replacer: &mut dyn FnMut(JsString, JsValue) -> Result<Option<JsValue>, JsError>,
9111 space: Option<u32>,
9112 ) -> Result<JsString, JsValue>;
9113
9114 /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
9115 ///
9116 /// The `replacer` argument is a function that alters the behavior of the stringification
9117 /// process, or an array of String and Number objects that serve as a whitelist
9118 /// for selecting/filtering the properties of the value object to be included
9119 /// in the JSON string. If this value is null or not provided, all properties
9120 /// of the object are included in the resulting JSON string.
9121 ///
9122 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
9123 #[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
9124 pub fn stringify_with_replacer_list(
9125 obj: &JsValue,
9126 replacer: Vec<String>,
9127 space: Option<u32>,
9128 ) -> Result<JsString, JsValue>;
9129
9130 // Next major: deprecate
9131 /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
9132 ///
9133 /// The `replacer` argument is a function that alters the behavior of the stringification
9134 /// process, or an array of String and Number objects that serve as a whitelist
9135 /// for selecting/filtering the properties of the value object to be included
9136 /// in the JSON string. If this value is null or not provided, all properties
9137 /// of the object are included in the resulting JSON string.
9138 ///
9139 /// The `space` argument is a String or Number object that's used to insert white space into
9140 /// the output JSON string for readability purposes. If this is a Number, it
9141 /// indicates the number of space characters to use as white space; this number
9142 /// is capped at 10 (if it is greater, the value is just 10). Values less than
9143 /// 1 indicate that no space should be used. If this is a String, the string
9144 /// (or the first 10 characters of the string, if it's longer than that) is
9145 /// used as white space. If this parameter is not provided (or is null), no
9146 /// white space is used.
9147 ///
9148 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
9149 #[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
9150 pub fn stringify_with_replacer_and_space(
9151 obj: &JsValue,
9152 replacer: &JsValue,
9153 space: &JsValue,
9154 ) -> Result<JsString, JsValue>;
9155 }
9156}
9157// JsString
9158#[wasm_bindgen]
9159extern "C" {
9160 #[wasm_bindgen(js_name = String, extends = Object, is_type_of = JsValue::is_string, typescript_type = "string")]
9161 #[derive(Clone, PartialEq, Eq)]
9162 pub type JsString;
9163
9164 /// The length property of a String object indicates the length of a string,
9165 /// in UTF-16 code units.
9166 ///
9167 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/length)
9168 #[wasm_bindgen(method, getter)]
9169 pub fn length(this: &JsString) -> u32;
9170
9171 /// The 'at()' method returns a new string consisting of the single UTF-16
9172 /// code unit located at the specified offset into the string, counting from
9173 /// the end if it's negative.
9174 ///
9175 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/at)
9176 #[wasm_bindgen(method, js_class = "String")]
9177 pub fn at(this: &JsString, index: i32) -> Option<JsString>;
9178
9179 /// The String object's `charAt()` method returns a new string consisting of
9180 /// the single UTF-16 code unit located at the specified offset into the
9181 /// string.
9182 ///
9183 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charAt)
9184 #[wasm_bindgen(method, js_class = "String", js_name = charAt)]
9185 pub fn char_at(this: &JsString, index: u32) -> JsString;
9186
9187 /// The `charCodeAt()` method returns an integer between 0 and 65535
9188 /// representing the UTF-16 code unit at the given index (the UTF-16 code
9189 /// unit matches the Unicode code point for code points representable in a
9190 /// single UTF-16 code unit, but might also be the first code unit of a
9191 /// surrogate pair for code points not representable in a single UTF-16 code
9192 /// unit, e.g. Unicode code points > 0x10000). If you want the entire code
9193 /// point value, use `codePointAt()`.
9194 ///
9195 /// Returns `NaN` if index is out of range.
9196 ///
9197 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charCodeAt)
9198 #[wasm_bindgen(method, js_class = "String", js_name = charCodeAt)]
9199 pub fn char_code_at(this: &JsString, index: u32) -> f64;
9200
9201 /// The `codePointAt()` method returns a non-negative integer that is the
9202 /// Unicode code point value.
9203 ///
9204 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/codePointAt)
9205 #[cfg(not(js_sys_unstable_apis))]
9206 #[wasm_bindgen(method, js_class = "String", js_name = codePointAt)]
9207 pub fn code_point_at(this: &JsString, pos: u32) -> JsValue;
9208
9209 /// The `codePointAt()` method returns a non-negative integer that is the
9210 /// Unicode code point value.
9211 ///
9212 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/codePointAt)
9213 #[cfg(js_sys_unstable_apis)]
9214 #[wasm_bindgen(method, js_class = "String", js_name = codePointAt)]
9215 pub fn code_point_at(this: &JsString, pos: u32) -> Option<u32>;
9216
9217 // Next major: deprecate
9218 /// The `codePointAt()` method returns a non-negative integer that is the
9219 /// Unicode code point value.
9220 ///
9221 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/codePointAt)
9222 #[wasm_bindgen(method, js_class = "String", js_name = codePointAt)]
9223 pub fn try_code_point_at(this: &JsString, pos: u32) -> Option<u16>;
9224
9225 /// The `concat()` method concatenates the string arguments to the calling
9226 /// string and returns a new string.
9227 ///
9228 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/concat)
9229 #[cfg(not(js_sys_unstable_apis))]
9230 #[wasm_bindgen(method, js_class = "String")]
9231 pub fn concat(this: &JsString, string_2: &JsValue) -> JsString;
9232
9233 /// The `concat()` method concatenates the string arguments to the calling
9234 /// string and returns a new string.
9235 ///
9236 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/concat)
9237 #[cfg(js_sys_unstable_apis)]
9238 #[wasm_bindgen(method, js_class = "String")]
9239 pub fn concat(this: &JsString, string: &JsString) -> JsString;
9240
9241 /// The `concat()` method concatenates the string arguments to the calling
9242 /// string and returns a new string.
9243 ///
9244 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/concat)
9245 #[wasm_bindgen(method, js_class = "String")]
9246 pub fn concat_many(this: &JsString, strings: &[JsString]) -> JsString;
9247
9248 /// The `endsWith()` method determines whether a string ends with the characters of a
9249 /// specified string, returning true or false as appropriate.
9250 ///
9251 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith)
9252 #[cfg(not(js_sys_unstable_apis))]
9253 #[wasm_bindgen(method, js_class = "String", js_name = endsWith)]
9254 pub fn ends_with(this: &JsString, search_string: &str, length: i32) -> bool;
9255
9256 /// The `endsWith()` method determines whether a string ends with the characters of a
9257 /// specified string, returning true or false as appropriate.
9258 ///
9259 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith)
9260 #[cfg(js_sys_unstable_apis)]
9261 #[wasm_bindgen(method, js_class = "String", js_name = endsWith)]
9262 pub fn ends_with(this: &JsString, search_string: &str) -> bool;
9263
9264 /// The static `String.fromCharCode()` method returns a string created from
9265 /// the specified sequence of UTF-16 code units.
9266 ///
9267 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
9268 ///
9269 /// # Notes
9270 ///
9271 /// There are a few bindings to `from_char_code` in `js-sys`: `from_char_code1`, `from_char_code2`, etc...
9272 /// with different arities.
9273 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode, variadic)]
9274 pub fn from_char_code(char_codes: &[u16]) -> JsString;
9275
9276 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
9277 #[cfg(not(js_sys_unstable_apis))]
9278 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
9279 pub fn from_char_code1(a: u32) -> JsString;
9280
9281 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
9282 #[cfg(js_sys_unstable_apis)]
9283 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
9284 pub fn from_char_code1(a: u16) -> JsString;
9285
9286 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
9287 #[cfg(not(js_sys_unstable_apis))]
9288 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
9289 pub fn from_char_code2(a: u32, b: u32) -> JsString;
9290
9291 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
9292 #[cfg(js_sys_unstable_apis)]
9293 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
9294 pub fn from_char_code2(a: u16, b: u16) -> JsString;
9295
9296 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
9297 #[cfg(not(js_sys_unstable_apis))]
9298 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
9299 pub fn from_char_code3(a: u32, b: u32, c: u32) -> JsString;
9300
9301 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
9302 #[cfg(js_sys_unstable_apis)]
9303 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
9304 pub fn from_char_code3(a: u16, b: u16, c: u16) -> JsString;
9305
9306 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
9307 #[cfg(not(js_sys_unstable_apis))]
9308 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
9309 pub fn from_char_code4(a: u32, b: u32, c: u32, d: u32) -> JsString;
9310
9311 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
9312 #[cfg(js_sys_unstable_apis)]
9313 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
9314 pub fn from_char_code4(a: u16, b: u16, c: u16, d: u16) -> JsString;
9315
9316 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
9317 #[cfg(not(js_sys_unstable_apis))]
9318 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
9319 pub fn from_char_code5(a: u32, b: u32, c: u32, d: u32, e: u32) -> JsString;
9320
9321 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
9322 #[cfg(js_sys_unstable_apis)]
9323 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
9324 pub fn from_char_code5(a: u16, b: u16, c: u16, d: u16, e: u16) -> JsString;
9325
9326 /// The static `String.fromCodePoint()` method returns a string created by
9327 /// using the specified sequence of code points.
9328 ///
9329 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
9330 ///
9331 /// # Exceptions
9332 ///
9333 /// A RangeError is thrown if an invalid Unicode code point is given
9334 ///
9335 /// # Notes
9336 ///
9337 /// There are a few bindings to `from_code_point` in `js-sys`: `from_code_point1`, `from_code_point2`, etc...
9338 /// with different arities.
9339 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint, variadic)]
9340 pub fn from_code_point(code_points: &[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_point1(a: 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_point2(a: u32, b: 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_point3(a: u32, b: u32, c: 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_point4(a: u32, b: u32, c: u32, d: u32) -> Result<JsString, JsValue>;
9357
9358 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
9359 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
9360 pub fn from_code_point5(a: u32, b: u32, c: u32, d: u32, e: u32) -> Result<JsString, JsValue>;
9361
9362 /// The `includes()` method determines whether one string may be found
9363 /// within another string, returning true or false as appropriate.
9364 ///
9365 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes)
9366 #[wasm_bindgen(method, js_class = "String")]
9367 pub fn includes(this: &JsString, search_string: &str, position: i32) -> bool;
9368
9369 /// The `indexOf()` method returns the index within the calling String
9370 /// object of the first occurrence of the specified value, starting the
9371 /// search at fromIndex. Returns -1 if the value is not found.
9372 ///
9373 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf)
9374 #[wasm_bindgen(method, js_class = "String", js_name = indexOf)]
9375 pub fn index_of(this: &JsString, search_value: &str, from_index: i32) -> i32;
9376
9377 /// The `lastIndexOf()` method returns the index within the calling String
9378 /// object of the last occurrence of the specified value, searching
9379 /// backwards from fromIndex. Returns -1 if the value is not found.
9380 ///
9381 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/lastIndexOf)
9382 #[wasm_bindgen(method, js_class = "String", js_name = lastIndexOf)]
9383 pub fn last_index_of(this: &JsString, search_value: &str, from_index: i32) -> i32;
9384
9385 /// The `localeCompare()` method returns a number indicating whether
9386 /// a reference string comes before or after or is the same as
9387 /// the given string in sort order.
9388 ///
9389 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare)
9390 #[cfg(not(js_sys_unstable_apis))]
9391 #[wasm_bindgen(method, js_class = "String", js_name = localeCompare)]
9392 pub fn locale_compare(
9393 this: &JsString,
9394 compare_string: &str,
9395 locales: &Array,
9396 options: &Object,
9397 ) -> i32;
9398
9399 /// The `localeCompare()` method returns a number indicating whether
9400 /// a reference string comes before or after or is the same as
9401 /// the given string in sort order.
9402 ///
9403 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare)
9404 #[cfg(js_sys_unstable_apis)]
9405 #[wasm_bindgen(method, js_class = "String", js_name = localeCompare)]
9406 pub fn locale_compare(
9407 this: &JsString,
9408 compare_string: &str,
9409 locales: &[JsString],
9410 options: &Intl::CollatorOptions,
9411 ) -> i32;
9412
9413 /// The `match()` method retrieves the matches when matching a string against a regular expression.
9414 ///
9415 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match)
9416 #[wasm_bindgen(method, js_class = "String", js_name = match)]
9417 pub fn match_(this: &JsString, pattern: &RegExp) -> Option<Object>;
9418
9419 /// The `match_all()` method is similar to `match()`, but gives an iterator of `exec()` arrays, which preserve capture groups.
9420 ///
9421 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/matchAll)
9422 #[cfg(not(js_sys_unstable_apis))]
9423 #[wasm_bindgen(method, js_class = "String", js_name = matchAll)]
9424 pub fn match_all(this: &JsString, pattern: &RegExp) -> Iterator;
9425
9426 /// The `match_all()` method is similar to `match()`, but gives an iterator of `exec()` arrays, which preserve capture groups.
9427 ///
9428 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/matchAll)
9429 #[cfg(js_sys_unstable_apis)]
9430 #[wasm_bindgen(method, js_class = "String", js_name = matchAll)]
9431 pub fn match_all(this: &JsString, pattern: &RegExp) -> Iterator<RegExpMatchArray>;
9432
9433 /// The `normalize()` method returns the Unicode Normalization Form
9434 /// of a given string (if the value isn't a string, it will be converted to one first).
9435 ///
9436 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize)
9437 #[wasm_bindgen(method, js_class = "String")]
9438 pub fn normalize(this: &JsString, form: &str) -> JsString;
9439
9440 /// The `padEnd()` method pads the current string with a given string
9441 /// (repeated, if needed) so that the resulting string reaches a given
9442 /// length. The padding is applied from the end (right) of the current
9443 /// string.
9444 ///
9445 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padEnd)
9446 #[wasm_bindgen(method, js_class = "String", js_name = padEnd)]
9447 pub fn pad_end(this: &JsString, target_length: u32, pad_string: &str) -> JsString;
9448
9449 /// The `padStart()` method pads the current string with another string
9450 /// (repeated, if needed) so that the resulting string reaches the given
9451 /// length. The padding is applied from the start (left) of the current
9452 /// string.
9453 ///
9454 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padStart)
9455 #[wasm_bindgen(method, js_class = "String", js_name = padStart)]
9456 pub fn pad_start(this: &JsString, target_length: u32, pad_string: &str) -> JsString;
9457
9458 /// The `repeat()` method constructs and returns a new string which contains the specified
9459 /// number of copies of the string on which it was called, concatenated together.
9460 ///
9461 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat)
9462 #[wasm_bindgen(method, js_class = "String")]
9463 pub fn repeat(this: &JsString, count: i32) -> JsString;
9464
9465 /// The `replace()` method returns a new string with some or all matches of a pattern
9466 /// replaced by a replacement. The pattern can be a string or a RegExp, and
9467 /// the replacement can be a string or a function to be called for each match.
9468 ///
9469 /// Note: The original string will remain unchanged.
9470 ///
9471 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
9472 #[wasm_bindgen(method, js_class = "String")]
9473 pub fn replace(this: &JsString, pattern: &str, replacement: &str) -> JsString;
9474
9475 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
9476 #[cfg(not(js_sys_unstable_apis))]
9477 #[wasm_bindgen(method, js_class = "String", js_name = replace)]
9478 pub fn replace_with_function(
9479 this: &JsString,
9480 pattern: &str,
9481 replacement: &Function,
9482 ) -> JsString;
9483
9484 /// The replacer function signature is `(match, offset, string) -> replacement`
9485 /// for patterns without capture groups, or `(match, p1, p2, ..., pN, offset, string, groups) -> replacement`
9486 /// when capture groups are present.
9487 ///
9488 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
9489 #[cfg(js_sys_unstable_apis)]
9490 #[wasm_bindgen(method, js_class = "String", js_name = replace)]
9491 pub fn replace_with_function(
9492 this: &JsString,
9493 pattern: &str,
9494 replacement: &Function<fn(JsString) -> JsString>,
9495 ) -> JsString;
9496
9497 #[wasm_bindgen(method, js_class = "String", js_name = replace)]
9498 pub fn replace_by_pattern(this: &JsString, pattern: &RegExp, replacement: &str) -> JsString;
9499
9500 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
9501 #[cfg(not(js_sys_unstable_apis))]
9502 #[wasm_bindgen(method, js_class = "String", js_name = replace)]
9503 pub fn replace_by_pattern_with_function(
9504 this: &JsString,
9505 pattern: &RegExp,
9506 replacement: &Function,
9507 ) -> JsString;
9508
9509 /// The replacer function signature is `(match, offset, string) -> replacement`
9510 /// for patterns without capture groups, or `(match, p1, p2, ..., pN, offset, string, groups) -> replacement`
9511 /// when capture groups are present.
9512 ///
9513 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
9514 #[cfg(js_sys_unstable_apis)]
9515 #[wasm_bindgen(method, js_class = "String", js_name = replace)]
9516 pub fn replace_by_pattern_with_function(
9517 this: &JsString,
9518 pattern: &RegExp,
9519 replacement: &Function<fn(JsString) -> JsString>,
9520 ) -> JsString;
9521
9522 /// The `replace_all()` method returns a new string with all matches of a pattern
9523 /// replaced by a replacement. The pattern can be a string or a global RegExp, and
9524 /// the replacement can be a string or a function to be called for each match.
9525 ///
9526 /// Note: The original string will remain unchanged.
9527 ///
9528 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)
9529 #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
9530 pub fn replace_all(this: &JsString, pattern: &str, replacement: &str) -> JsString;
9531
9532 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)
9533 #[cfg(not(js_sys_unstable_apis))]
9534 #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
9535 pub fn replace_all_with_function(
9536 this: &JsString,
9537 pattern: &str,
9538 replacement: &Function,
9539 ) -> JsString;
9540
9541 /// The replacer function signature is `(match, offset, string) -> replacement`
9542 /// for patterns without capture groups, or `(match, p1, p2, ..., pN, offset, string, groups) -> replacement`
9543 /// when capture groups are present.
9544 ///
9545 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)
9546 #[cfg(js_sys_unstable_apis)]
9547 #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
9548 pub fn replace_all_with_function(
9549 this: &JsString,
9550 pattern: &str,
9551 replacement: &Function<fn(JsString) -> JsString>,
9552 ) -> JsString;
9553
9554 #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
9555 pub fn replace_all_by_pattern(this: &JsString, pattern: &RegExp, replacement: &str)
9556 -> JsString;
9557
9558 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)
9559 #[cfg(not(js_sys_unstable_apis))]
9560 #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
9561 pub fn replace_all_by_pattern_with_function(
9562 this: &JsString,
9563 pattern: &RegExp,
9564 replacement: &Function,
9565 ) -> JsString;
9566
9567 /// The replacer function signature is `(match, offset, string) -> replacement`
9568 /// for patterns without capture groups, or `(match, p1, p2, ..., pN, offset, string, groups) -> replacement`
9569 /// when capture groups are present.
9570 ///
9571 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)
9572 #[cfg(js_sys_unstable_apis)]
9573 #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
9574 pub fn replace_all_by_pattern_with_function(
9575 this: &JsString,
9576 pattern: &RegExp,
9577 replacement: &Function<fn(JsString) -> JsString>,
9578 ) -> JsString;
9579
9580 /// The `search()` method executes a search for a match between
9581 /// a regular expression and this String object.
9582 ///
9583 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/search)
9584 #[wasm_bindgen(method, js_class = "String")]
9585 pub fn search(this: &JsString, pattern: &RegExp) -> i32;
9586
9587 /// The `slice()` method extracts a section of a string and returns it as a
9588 /// new string, without modifying the original string.
9589 ///
9590 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice)
9591 #[wasm_bindgen(method, js_class = "String")]
9592 pub fn slice(this: &JsString, start: u32, end: u32) -> JsString;
9593
9594 /// The `split()` method splits a String object into an array of strings by separating the string
9595 /// into substrings, using a specified separator string to determine where to make each split.
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")]
9599 pub fn split(this: &JsString, separator: &str) -> 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_limit(this: &JsString, separator: &str, limit: u32) -> 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(this: &JsString, pattern: &RegExp) -> Array;
9608
9609 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)
9610 #[wasm_bindgen(method, js_class = "String", js_name = split)]
9611 pub fn split_by_pattern_limit(this: &JsString, pattern: &RegExp, limit: u32) -> Array;
9612
9613 /// The `startsWith()` method determines whether a string begins with the
9614 /// characters of a specified string, returning true or false as
9615 /// appropriate.
9616 ///
9617 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith)
9618 #[wasm_bindgen(method, js_class = "String", js_name = startsWith)]
9619 pub fn starts_with(this: &JsString, search_string: &str, position: u32) -> bool;
9620
9621 /// The `substring()` method returns the part of the string between the
9622 /// start and end indexes, or to the end of the string.
9623 ///
9624 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring)
9625 #[wasm_bindgen(method, js_class = "String")]
9626 pub fn substring(this: &JsString, index_start: u32, index_end: u32) -> JsString;
9627
9628 /// The `substr()` method returns the part of a string between
9629 /// the start index and a number of characters after it.
9630 ///
9631 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr)
9632 #[wasm_bindgen(method, js_class = "String")]
9633 pub fn substr(this: &JsString, start: i32, length: i32) -> JsString;
9634
9635 /// The `toLocaleLowerCase()` method returns the calling string value converted to lower case,
9636 /// according to any locale-specific case mappings.
9637 ///
9638 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLocaleLowerCase)
9639 #[wasm_bindgen(method, js_class = "String", js_name = toLocaleLowerCase)]
9640 pub fn to_locale_lower_case(this: &JsString, locale: Option<&str>) -> JsString;
9641
9642 /// The `toLocaleUpperCase()` method returns the calling string value converted to upper case,
9643 /// according to any locale-specific case mappings.
9644 ///
9645 /// [MDN documentation](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/String/toLocaleUpperCase)
9646 #[wasm_bindgen(method, js_class = "String", js_name = toLocaleUpperCase)]
9647 pub fn to_locale_upper_case(this: &JsString, locale: Option<&str>) -> JsString;
9648
9649 /// The `toLowerCase()` method returns the calling string value
9650 /// converted to lower case.
9651 ///
9652 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLowerCase)
9653 #[wasm_bindgen(method, js_class = "String", js_name = toLowerCase)]
9654 pub fn to_lower_case(this: &JsString) -> JsString;
9655
9656 /// The `toString()` method returns a string representing the specified
9657 /// object.
9658 ///
9659 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toString)
9660 #[cfg(not(js_sys_unstable_apis))]
9661 #[wasm_bindgen(method, js_class = "String", js_name = toString)]
9662 pub fn to_string(this: &JsString) -> JsString;
9663
9664 /// The `toUpperCase()` method returns the calling string value converted to
9665 /// uppercase (the value will be converted to a string if it isn't one).
9666 ///
9667 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase)
9668 #[wasm_bindgen(method, js_class = "String", js_name = toUpperCase)]
9669 pub fn to_upper_case(this: &JsString) -> JsString;
9670
9671 /// The `trim()` method removes whitespace from both ends of a string.
9672 /// Whitespace in this context is all the whitespace characters (space, tab,
9673 /// no-break space, etc.) and all the line terminator characters (LF, CR,
9674 /// etc.).
9675 ///
9676 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trim)
9677 #[wasm_bindgen(method, js_class = "String")]
9678 pub fn trim(this: &JsString) -> JsString;
9679
9680 /// The `trimEnd()` method removes whitespace from the end of a string.
9681 /// `trimRight()` is an alias of this method.
9682 ///
9683 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimEnd)
9684 #[wasm_bindgen(method, js_class = "String", js_name = trimEnd)]
9685 pub fn trim_end(this: &JsString) -> JsString;
9686
9687 /// The `trimEnd()` method removes whitespace from the end of a string.
9688 /// `trimRight()` is an alias of this method.
9689 ///
9690 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimEnd)
9691 #[wasm_bindgen(method, js_class = "String", js_name = trimRight)]
9692 pub fn trim_right(this: &JsString) -> JsString;
9693
9694 /// The `trimStart()` method removes whitespace from the beginning of a
9695 /// string. `trimLeft()` is an alias of this method.
9696 ///
9697 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimStart)
9698 #[wasm_bindgen(method, js_class = "String", js_name = trimStart)]
9699 pub fn trim_start(this: &JsString) -> JsString;
9700
9701 /// The `trimStart()` method removes whitespace from the beginning of a
9702 /// string. `trimLeft()` is an alias of this method.
9703 ///
9704 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimStart)
9705 #[wasm_bindgen(method, js_class = "String", js_name = trimLeft)]
9706 pub fn trim_left(this: &JsString) -> JsString;
9707
9708 /// The `valueOf()` method returns the primitive value of a `String` object.
9709 ///
9710 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/valueOf)
9711 #[wasm_bindgen(method, js_class = "String", js_name = valueOf)]
9712 pub fn value_of(this: &JsString) -> JsString;
9713
9714 /// The static `raw()` method is a tag function of template literals,
9715 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9716 ///
9717 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9718 #[wasm_bindgen(catch, variadic, static_method_of = JsString, js_class = "String")]
9719 pub fn raw(call_site: &Object, substitutions: &Array) -> Result<JsString, JsValue>;
9720
9721 /// The static `raw()` method is a tag function of template literals,
9722 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9723 ///
9724 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9725 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9726 pub fn raw_0(call_site: &Object) -> Result<JsString, JsValue>;
9727
9728 /// The static `raw()` method is a tag function of template literals,
9729 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9730 ///
9731 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9732 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9733 pub fn raw_1(call_site: &Object, substitutions_1: &str) -> Result<JsString, JsValue>;
9734
9735 /// The static `raw()` method is a tag function of template literals,
9736 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9737 ///
9738 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9739 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9740 pub fn raw_2(
9741 call_site: &Object,
9742 substitutions1: &str,
9743 substitutions2: &str,
9744 ) -> Result<JsString, JsValue>;
9745
9746 /// The static `raw()` method is a tag function of template literals,
9747 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9748 ///
9749 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9750 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9751 pub fn raw_3(
9752 call_site: &Object,
9753 substitutions1: &str,
9754 substitutions2: &str,
9755 substitutions3: &str,
9756 ) -> Result<JsString, JsValue>;
9757
9758 /// The static `raw()` method is a tag function of template literals,
9759 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9760 ///
9761 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9762 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9763 pub fn raw_4(
9764 call_site: &Object,
9765 substitutions1: &str,
9766 substitutions2: &str,
9767 substitutions3: &str,
9768 substitutions4: &str,
9769 ) -> Result<JsString, JsValue>;
9770
9771 /// The static `raw()` method is a tag function of template literals,
9772 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9773 ///
9774 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9775 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9776 pub fn raw_5(
9777 call_site: &Object,
9778 substitutions1: &str,
9779 substitutions2: &str,
9780 substitutions3: &str,
9781 substitutions4: &str,
9782 substitutions5: &str,
9783 ) -> Result<JsString, JsValue>;
9784
9785 /// The static `raw()` method is a tag function of template literals,
9786 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9787 ///
9788 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9789 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9790 pub fn raw_6(
9791 call_site: &Object,
9792 substitutions1: &str,
9793 substitutions2: &str,
9794 substitutions3: &str,
9795 substitutions4: &str,
9796 substitutions5: &str,
9797 substitutions6: &str,
9798 ) -> Result<JsString, JsValue>;
9799
9800 /// The static `raw()` method is a tag function of template literals,
9801 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9802 ///
9803 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9804 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9805 pub fn raw_7(
9806 call_site: &Object,
9807 substitutions1: &str,
9808 substitutions2: &str,
9809 substitutions3: &str,
9810 substitutions4: &str,
9811 substitutions5: &str,
9812 substitutions6: &str,
9813 substitutions7: &str,
9814 ) -> Result<JsString, JsValue>;
9815}
9816
9817// These upcasts are non-castable due to the constraints on the function
9818// but the UpcastFrom covariance must still extend through closure types.
9819// (impl UpcastFrom really just means CovariantGeneric relation)
9820impl UpcastFrom<String> for JsString {}
9821impl UpcastFrom<JsString> for String {}
9822
9823impl UpcastFrom<&str> for JsString {}
9824impl UpcastFrom<JsString> for &str {}
9825
9826impl UpcastFrom<char> for JsString {}
9827impl UpcastFrom<JsString> for char {}
9828
9829impl JsString {
9830 /// Returns the `JsString` value of this JS value if it's an instance of a
9831 /// string.
9832 ///
9833 /// If this JS value is not an instance of a string then this returns
9834 /// `None`.
9835 #[cfg(not(js_sys_unstable_apis))]
9836 #[deprecated(note = "recommended to use dyn_ref instead which is now equivalent")]
9837 pub fn try_from(val: &JsValue) -> Option<&JsString> {
9838 val.dyn_ref()
9839 }
9840
9841 /// Returns whether this string is a valid UTF-16 string.
9842 ///
9843 /// This is useful for learning whether `String::from(..)` will return a
9844 /// lossless representation of the JS string. If this string contains
9845 /// unpaired surrogates then `String::from` will succeed but it will be a
9846 /// lossy representation of the JS string because unpaired surrogates will
9847 /// become replacement characters.
9848 ///
9849 /// If this function returns `false` then to get a lossless representation
9850 /// of the string you'll need to manually use the `iter` method (or the
9851 /// `char_code_at` accessor) to view the raw character codes.
9852 ///
9853 /// For more information, see the documentation on [JS strings vs Rust
9854 /// strings][docs]
9855 ///
9856 /// [docs]: https://wasm-bindgen.github.io/wasm-bindgen/reference/types/str.html
9857 pub fn is_valid_utf16(&self) -> bool {
9858 core::char::decode_utf16(self.iter()).all(|i| i.is_ok())
9859 }
9860
9861 /// Returns an iterator over the `u16` character codes that make up this JS
9862 /// string.
9863 ///
9864 /// This method will call `char_code_at` for each code in this JS string,
9865 /// returning an iterator of the codes in sequence.
9866 pub fn iter(
9867 &self,
9868 ) -> impl ExactSizeIterator<Item = u16> + DoubleEndedIterator<Item = u16> + '_ {
9869 (0..self.length()).map(move |i| self.char_code_at(i) as u16)
9870 }
9871
9872 /// If this string consists of a single Unicode code point, then this method
9873 /// converts it into a Rust `char` without doing any allocations.
9874 ///
9875 /// If this JS value is not a valid UTF-8 or consists of more than a single
9876 /// codepoint, then this returns `None`.
9877 ///
9878 /// Note that a single Unicode code point might be represented as more than
9879 /// one code unit on the JavaScript side. For example, a JavaScript string
9880 /// `"\uD801\uDC37"` is actually a single Unicode code point U+10437 which
9881 /// corresponds to a character '𐐷'.
9882 pub fn as_char(&self) -> Option<char> {
9883 let len = self.length();
9884
9885 if len == 0 || len > 2 {
9886 return None;
9887 }
9888
9889 #[cfg(not(js_sys_unstable_apis))]
9890 let cp = self.code_point_at(0).as_f64().unwrap_throw() as u32;
9891 #[cfg(js_sys_unstable_apis)]
9892 let cp = self.code_point_at(0)?;
9893
9894 let c = core::char::from_u32(cp)?;
9895
9896 if c.len_utf16() as u32 == len {
9897 Some(c)
9898 } else {
9899 None
9900 }
9901 }
9902}
9903
9904impl PartialEq<str> for JsString {
9905 #[allow(clippy::cmp_owned)] // prevent infinite recursion
9906 fn eq(&self, other: &str) -> bool {
9907 String::from(self) == other
9908 }
9909}
9910
9911impl<'a> PartialEq<&'a str> for JsString {
9912 fn eq(&self, other: &&'a str) -> bool {
9913 <JsString as PartialEq<str>>::eq(self, other)
9914 }
9915}
9916
9917impl PartialEq<String> for JsString {
9918 fn eq(&self, other: &String) -> bool {
9919 <JsString as PartialEq<str>>::eq(self, other)
9920 }
9921}
9922
9923impl<'a> PartialEq<&'a String> for JsString {
9924 fn eq(&self, other: &&'a String) -> bool {
9925 <JsString as PartialEq<str>>::eq(self, other)
9926 }
9927}
9928
9929impl Default for JsString {
9930 fn default() -> Self {
9931 Self::from("")
9932 }
9933}
9934
9935impl<'a> From<&'a str> for JsString {
9936 fn from(s: &'a str) -> Self {
9937 JsString::unchecked_from_js(JsValue::from_str(s))
9938 }
9939}
9940
9941impl From<String> for JsString {
9942 fn from(s: String) -> Self {
9943 From::from(&*s)
9944 }
9945}
9946
9947impl From<char> for JsString {
9948 #[inline]
9949 fn from(c: char) -> Self {
9950 JsString::from_code_point1(c as u32).unwrap_throw()
9951 }
9952}
9953
9954impl<'a> From<&'a JsString> for String {
9955 fn from(s: &'a JsString) -> Self {
9956 s.obj.as_string().unwrap_throw()
9957 }
9958}
9959
9960impl From<JsString> for String {
9961 fn from(s: JsString) -> Self {
9962 From::from(&s)
9963 }
9964}
9965
9966impl fmt::Debug for JsString {
9967 #[inline]
9968 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9969 fmt::Debug::fmt(&String::from(self), f)
9970 }
9971}
9972
9973impl fmt::Display for JsString {
9974 #[inline]
9975 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9976 fmt::Display::fmt(&String::from(self), f)
9977 }
9978}
9979
9980impl str::FromStr for JsString {
9981 type Err = convert::Infallible;
9982 fn from_str(s: &str) -> Result<Self, Self::Err> {
9983 Ok(JsString::from(s))
9984 }
9985}
9986
9987// Symbol
9988#[wasm_bindgen]
9989extern "C" {
9990 #[wasm_bindgen(is_type_of = JsValue::is_symbol, typescript_type = "Symbol")]
9991 #[derive(Clone, Debug)]
9992 pub type Symbol;
9993
9994 /// The `Symbol.hasInstance` well-known symbol is used to determine
9995 /// if a constructor object recognizes an object as its instance.
9996 /// The `instanceof` operator's behavior can be customized by this symbol.
9997 ///
9998 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/hasInstance)
9999 #[wasm_bindgen(static_method_of = Symbol, getter, js_name = hasInstance)]
10000 pub fn has_instance() -> Symbol;
10001
10002 /// The `Symbol.isConcatSpreadable` well-known symbol is used to configure
10003 /// if an object should be flattened to its array elements when using the
10004 /// `Array.prototype.concat()` method.
10005 ///
10006 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/isConcatSpreadable)
10007 #[wasm_bindgen(static_method_of = Symbol, getter, js_name = isConcatSpreadable)]
10008 pub fn is_concat_spreadable() -> Symbol;
10009
10010 /// The `Symbol.asyncIterator` well-known symbol specifies the default AsyncIterator for an object.
10011 /// If this property is set on an object, it is an async iterable and can be used in a `for await...of` loop.
10012 ///
10013 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/asyncIterator)
10014 #[wasm_bindgen(static_method_of = Symbol, getter, js_name = asyncIterator)]
10015 pub fn async_iterator() -> Symbol;
10016
10017 /// The `Symbol.iterator` well-known symbol specifies the default iterator
10018 /// for an object. Used by `for...of`.
10019 ///
10020 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/iterator)
10021 #[wasm_bindgen(static_method_of = Symbol, getter)]
10022 pub fn iterator() -> Symbol;
10023
10024 /// The `Symbol.match` well-known symbol specifies the matching of a regular
10025 /// expression against a string. This function is called by the
10026 /// `String.prototype.match()` method.
10027 ///
10028 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/match)
10029 #[wasm_bindgen(static_method_of = Symbol, getter, js_name = match)]
10030 pub fn match_() -> Symbol;
10031
10032 /// The `Symbol.replace` well-known symbol specifies the method that
10033 /// replaces matched substrings of a string. This function is called by the
10034 /// `String.prototype.replace()` method.
10035 ///
10036 /// For more information, see `RegExp.prototype[@@replace]()` and
10037 /// `String.prototype.replace()`.
10038 ///
10039 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/replace)
10040 #[wasm_bindgen(static_method_of = Symbol, getter)]
10041 pub fn replace() -> Symbol;
10042
10043 /// The `Symbol.search` well-known symbol specifies the method that returns
10044 /// the index within a string that matches the regular expression. This
10045 /// function is called by the `String.prototype.search()` method.
10046 ///
10047 /// For more information, see `RegExp.prototype[@@search]()` and
10048 /// `String.prototype.search()`.
10049 ///
10050 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/search)
10051 #[wasm_bindgen(static_method_of = Symbol, getter)]
10052 pub fn search() -> Symbol;
10053
10054 /// The well-known symbol `Symbol.species` specifies a function-valued
10055 /// property that the constructor function uses to create derived objects.
10056 ///
10057 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/species)
10058 #[wasm_bindgen(static_method_of = Symbol, getter)]
10059 pub fn species() -> Symbol;
10060
10061 /// The `Symbol.split` well-known symbol specifies the method that splits a
10062 /// string at the indices that match a regular expression. This function is
10063 /// called by the `String.prototype.split()` method.
10064 ///
10065 /// For more information, see `RegExp.prototype[@@split]()` and
10066 /// `String.prototype.split()`.
10067 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/split)
10068 #[wasm_bindgen(static_method_of = Symbol, getter)]
10069 pub fn split() -> Symbol;
10070
10071 /// The `Symbol.toPrimitive` is a symbol that specifies a function valued
10072 /// property that is called to convert an object to a corresponding
10073 /// primitive value.
10074 ///
10075 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toPrimitive)
10076 #[wasm_bindgen(static_method_of = Symbol, getter, js_name = toPrimitive)]
10077 pub fn to_primitive() -> Symbol;
10078
10079 /// The `Symbol.toStringTag` well-known symbol is a string valued property
10080 /// that is used in the creation of the default string description of an
10081 /// object. It is accessed internally by the `Object.prototype.toString()`
10082 /// method.
10083 ///
10084 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toString)
10085 #[wasm_bindgen(static_method_of = Symbol, getter, js_name = toStringTag)]
10086 pub fn to_string_tag() -> Symbol;
10087
10088 /// The `Symbol.for(key)` method searches for existing symbols in a runtime-wide symbol registry with
10089 /// the given key and returns it if found.
10090 /// Otherwise a new symbol gets created in the global symbol registry with this key.
10091 ///
10092 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/for)
10093 #[wasm_bindgen(static_method_of = Symbol, js_name = for)]
10094 pub fn for_(key: &str) -> Symbol;
10095
10096 /// The `Symbol.keyFor(sym)` method retrieves a shared symbol key from the global symbol registry for the given symbol.
10097 ///
10098 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/keyFor)
10099 #[wasm_bindgen(static_method_of = Symbol, js_name = keyFor)]
10100 pub fn key_for(sym: &Symbol) -> JsValue;
10101
10102 // Next major: deprecate
10103 /// The `toString()` method returns a string representing the specified Symbol object.
10104 ///
10105 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toString)
10106 #[wasm_bindgen(method, js_name = toString)]
10107 pub fn to_string(this: &Symbol) -> JsString;
10108
10109 /// The `toString()` method returns a string representing the specified Symbol object.
10110 ///
10111 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toString)
10112 #[wasm_bindgen(method, js_name = toString)]
10113 pub fn to_js_string(this: &Symbol) -> JsString;
10114
10115 /// The `Symbol.unscopables` well-known symbol is used to specify an object
10116 /// value of whose own and inherited property names are excluded from the
10117 /// with environment bindings of the associated object.
10118 ///
10119 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/unscopables)
10120 #[wasm_bindgen(static_method_of = Symbol, getter)]
10121 pub fn unscopables() -> Symbol;
10122
10123 /// The `valueOf()` method returns the primitive value of a Symbol object.
10124 ///
10125 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/valueOf)
10126 #[wasm_bindgen(method, js_name = valueOf)]
10127 pub fn value_of(this: &Symbol) -> Symbol;
10128}
10129
10130#[allow(non_snake_case)]
10131pub mod Intl {
10132 use super::*;
10133
10134 // Intl
10135 #[wasm_bindgen]
10136 extern "C" {
10137 /// The `Intl.getCanonicalLocales()` method returns an array containing
10138 /// the canonical locale names. Duplicates will be omitted and elements
10139 /// will be validated as structurally valid language tags.
10140 ///
10141 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/getCanonicalLocales)
10142 #[cfg(not(js_sys_unstable_apis))]
10143 #[wasm_bindgen(js_name = getCanonicalLocales, js_namespace = Intl)]
10144 pub fn get_canonical_locales(s: &JsValue) -> Array;
10145
10146 /// The `Intl.getCanonicalLocales()` method returns an array containing
10147 /// the canonical locale names. Duplicates will be omitted and elements
10148 /// will be validated as structurally valid language tags.
10149 ///
10150 /// Throws a `RangeError` if any of the strings are not valid locale identifiers.
10151 ///
10152 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/getCanonicalLocales)
10153 #[cfg(js_sys_unstable_apis)]
10154 #[wasm_bindgen(js_name = getCanonicalLocales, js_namespace = Intl, catch)]
10155 pub fn get_canonical_locales(s: &[JsString]) -> Result<Array<JsString>, JsValue>;
10156
10157 /// The `Intl.supportedValuesOf()` method returns an array containing the
10158 /// supported calendar, collation, currency, numbering system, or unit values
10159 /// supported by the implementation.
10160 ///
10161 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/supportedValuesOf)
10162 #[wasm_bindgen(js_name = supportedValuesOf, js_namespace = Intl)]
10163 pub fn supported_values_of(key: SupportedValuesKey) -> Array<JsString>;
10164 }
10165
10166 // Intl string enums
10167
10168 /// Key for `Intl.supportedValuesOf()`.
10169 #[wasm_bindgen]
10170 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10171 pub enum SupportedValuesKey {
10172 Calendar = "calendar",
10173 Collation = "collation",
10174 Currency = "currency",
10175 NumberingSystem = "numberingSystem",
10176 TimeZone = "timeZone",
10177 Unit = "unit",
10178 }
10179
10180 /// Locale matching algorithm for Intl constructors.
10181 #[wasm_bindgen]
10182 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10183 pub enum LocaleMatcher {
10184 Lookup = "lookup",
10185 BestFit = "best fit",
10186 }
10187
10188 /// Usage for `Intl.Collator`.
10189 #[wasm_bindgen]
10190 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10191 pub enum CollatorUsage {
10192 Sort = "sort",
10193 Search = "search",
10194 }
10195
10196 /// Sensitivity for `Intl.Collator`.
10197 #[wasm_bindgen]
10198 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10199 pub enum CollatorSensitivity {
10200 Base = "base",
10201 Accent = "accent",
10202 Case = "case",
10203 Variant = "variant",
10204 }
10205
10206 /// Case first option for `Intl.Collator`.
10207 #[wasm_bindgen]
10208 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10209 pub enum CollatorCaseFirst {
10210 Upper = "upper",
10211 Lower = "lower",
10212 False = "false",
10213 }
10214
10215 /// Style for `Intl.NumberFormat`.
10216 #[wasm_bindgen]
10217 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10218 pub enum NumberFormatStyle {
10219 Decimal = "decimal",
10220 Currency = "currency",
10221 Percent = "percent",
10222 Unit = "unit",
10223 }
10224
10225 /// Currency display for `Intl.NumberFormat`.
10226 #[wasm_bindgen]
10227 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10228 pub enum CurrencyDisplay {
10229 Code = "code",
10230 Symbol = "symbol",
10231 NarrowSymbol = "narrowSymbol",
10232 Name = "name",
10233 }
10234
10235 /// Currency sign for `Intl.NumberFormat`.
10236 #[wasm_bindgen]
10237 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10238 pub enum CurrencySign {
10239 Standard = "standard",
10240 Accounting = "accounting",
10241 }
10242
10243 /// Unit display for `Intl.NumberFormat`.
10244 #[wasm_bindgen]
10245 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10246 pub enum UnitDisplay {
10247 Short = "short",
10248 Narrow = "narrow",
10249 Long = "long",
10250 }
10251
10252 /// Notation for `Intl.NumberFormat`.
10253 #[wasm_bindgen]
10254 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10255 pub enum NumberFormatNotation {
10256 Standard = "standard",
10257 Scientific = "scientific",
10258 Engineering = "engineering",
10259 Compact = "compact",
10260 }
10261
10262 /// Compact display for `Intl.NumberFormat`.
10263 #[wasm_bindgen]
10264 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10265 pub enum CompactDisplay {
10266 Short = "short",
10267 Long = "long",
10268 }
10269
10270 /// Sign display for `Intl.NumberFormat`.
10271 #[wasm_bindgen]
10272 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10273 pub enum SignDisplay {
10274 Auto = "auto",
10275 Never = "never",
10276 Always = "always",
10277 ExceptZero = "exceptZero",
10278 }
10279
10280 /// Rounding mode for `Intl.NumberFormat`.
10281 #[wasm_bindgen]
10282 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10283 pub enum RoundingMode {
10284 Ceil = "ceil",
10285 Floor = "floor",
10286 Expand = "expand",
10287 Trunc = "trunc",
10288 HalfCeil = "halfCeil",
10289 HalfFloor = "halfFloor",
10290 HalfExpand = "halfExpand",
10291 HalfTrunc = "halfTrunc",
10292 HalfEven = "halfEven",
10293 }
10294
10295 /// Rounding priority for `Intl.NumberFormat`.
10296 #[wasm_bindgen]
10297 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10298 pub enum RoundingPriority {
10299 Auto = "auto",
10300 MorePrecision = "morePrecision",
10301 LessPrecision = "lessPrecision",
10302 }
10303
10304 /// Trailing zero display for `Intl.NumberFormat`.
10305 #[wasm_bindgen]
10306 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10307 pub enum TrailingZeroDisplay {
10308 Auto = "auto",
10309 StripIfInteger = "stripIfInteger",
10310 }
10311
10312 /// Use grouping option for `Intl.NumberFormat`.
10313 ///
10314 /// Determines whether to use grouping separators, such as thousands
10315 /// separators or thousand/lakh/crore separators.
10316 ///
10317 /// The default is `Min2` if notation is "compact", and `Auto` otherwise.
10318 ///
10319 /// Note: The string values `"true"` and `"false"` are accepted by JavaScript
10320 /// but are always converted to the default value. Use `True` and `False`
10321 /// variants for the boolean behavior.
10322 ///
10323 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#usegrouping)
10324 #[wasm_bindgen]
10325 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10326 pub enum UseGrouping {
10327 /// Display grouping separators even if the locale prefers otherwise.
10328 Always = "always",
10329 /// Display grouping separators based on the locale preference,
10330 /// which may also be dependent on the currency.
10331 Auto = "auto",
10332 /// Display grouping separators when there are at least 2 digits in a group.
10333 Min2 = "min2",
10334 /// Same as `Always`. Display grouping separators even if the locale prefers otherwise.
10335 True = "true",
10336 /// Display no grouping separators.
10337 False = "false",
10338 }
10339
10340 /// Date/time style for `Intl.DateTimeFormat`.
10341 #[wasm_bindgen]
10342 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10343 pub enum DateTimeStyle {
10344 Full = "full",
10345 Long = "long",
10346 Medium = "medium",
10347 Short = "short",
10348 }
10349
10350 /// Hour cycle for `Intl.DateTimeFormat`.
10351 #[wasm_bindgen]
10352 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10353 pub enum HourCycle {
10354 H11 = "h11",
10355 H12 = "h12",
10356 H23 = "h23",
10357 H24 = "h24",
10358 }
10359
10360 /// Weekday format for `Intl.DateTimeFormat`.
10361 #[wasm_bindgen]
10362 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10363 pub enum WeekdayFormat {
10364 Narrow = "narrow",
10365 Short = "short",
10366 Long = "long",
10367 }
10368
10369 /// Era format for `Intl.DateTimeFormat`.
10370 #[wasm_bindgen]
10371 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10372 pub enum EraFormat {
10373 Narrow = "narrow",
10374 Short = "short",
10375 Long = "long",
10376 }
10377
10378 /// Year format for `Intl.DateTimeFormat`.
10379 #[wasm_bindgen]
10380 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10381 pub enum YearFormat {
10382 Numeric = "numeric",
10383 TwoDigit = "2-digit",
10384 }
10385
10386 /// Month format for `Intl.DateTimeFormat`.
10387 #[wasm_bindgen]
10388 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10389 pub enum MonthFormat {
10390 #[wasm_bindgen]
10391 Numeric = "numeric",
10392 #[wasm_bindgen]
10393 TwoDigit = "2-digit",
10394 #[wasm_bindgen]
10395 Narrow = "narrow",
10396 #[wasm_bindgen]
10397 Short = "short",
10398 #[wasm_bindgen]
10399 Long = "long",
10400 }
10401
10402 /// Day format for `Intl.DateTimeFormat`.
10403 #[wasm_bindgen]
10404 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10405 pub enum DayFormat {
10406 #[wasm_bindgen]
10407 Numeric = "numeric",
10408 #[wasm_bindgen]
10409 TwoDigit = "2-digit",
10410 }
10411
10412 /// Hour/minute/second format for `Intl.DateTimeFormat`.
10413 #[wasm_bindgen]
10414 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10415 pub enum NumericFormat {
10416 #[wasm_bindgen]
10417 Numeric = "numeric",
10418 #[wasm_bindgen]
10419 TwoDigit = "2-digit",
10420 }
10421
10422 /// Time zone name format for `Intl.DateTimeFormat`.
10423 #[wasm_bindgen]
10424 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10425 pub enum TimeZoneNameFormat {
10426 Short = "short",
10427 Long = "long",
10428 ShortOffset = "shortOffset",
10429 LongOffset = "longOffset",
10430 ShortGeneric = "shortGeneric",
10431 LongGeneric = "longGeneric",
10432 }
10433
10434 /// Day period format for `Intl.DateTimeFormat`.
10435 #[wasm_bindgen]
10436 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10437 pub enum DayPeriodFormat {
10438 Narrow = "narrow",
10439 Short = "short",
10440 Long = "long",
10441 }
10442
10443 /// Part type for `DateTimeFormat.formatToParts()`.
10444 #[wasm_bindgen]
10445 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10446 pub enum DateTimeFormatPartType {
10447 Day = "day",
10448 DayPeriod = "dayPeriod",
10449 Era = "era",
10450 FractionalSecond = "fractionalSecond",
10451 Hour = "hour",
10452 Literal = "literal",
10453 Minute = "minute",
10454 Month = "month",
10455 RelatedYear = "relatedYear",
10456 Second = "second",
10457 TimeZoneName = "timeZoneName",
10458 Weekday = "weekday",
10459 Year = "year",
10460 YearName = "yearName",
10461 }
10462
10463 /// Part type for `NumberFormat.formatToParts()`.
10464 #[wasm_bindgen]
10465 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10466 pub enum NumberFormatPartType {
10467 Compact = "compact",
10468 Currency = "currency",
10469 Decimal = "decimal",
10470 ExponentInteger = "exponentInteger",
10471 ExponentMinusSign = "exponentMinusSign",
10472 ExponentSeparator = "exponentSeparator",
10473 Fraction = "fraction",
10474 Group = "group",
10475 Infinity = "infinity",
10476 Integer = "integer",
10477 Literal = "literal",
10478 MinusSign = "minusSign",
10479 Nan = "nan",
10480 PercentSign = "percentSign",
10481 PlusSign = "plusSign",
10482 Unit = "unit",
10483 Unknown = "unknown",
10484 }
10485
10486 /// Type for `Intl.PluralRules` (cardinal or ordinal).
10487 #[wasm_bindgen]
10488 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10489 pub enum PluralRulesType {
10490 Cardinal = "cardinal",
10491 Ordinal = "ordinal",
10492 }
10493
10494 /// Plural category returned by `PluralRules.select()`.
10495 #[wasm_bindgen]
10496 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10497 pub enum PluralCategory {
10498 Zero = "zero",
10499 One = "one",
10500 Two = "two",
10501 Few = "few",
10502 Many = "many",
10503 Other = "other",
10504 }
10505
10506 /// Numeric option for `Intl.RelativeTimeFormat`.
10507 #[wasm_bindgen]
10508 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10509 pub enum RelativeTimeFormatNumeric {
10510 Always = "always",
10511 Auto = "auto",
10512 }
10513
10514 /// Style for `Intl.RelativeTimeFormat`.
10515 #[wasm_bindgen]
10516 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10517 pub enum RelativeTimeFormatStyle {
10518 Long = "long",
10519 Short = "short",
10520 Narrow = "narrow",
10521 }
10522
10523 /// Unit for `RelativeTimeFormat.format()`.
10524 #[wasm_bindgen]
10525 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10526 pub enum RelativeTimeFormatUnit {
10527 Year = "year",
10528 Years = "years",
10529 Quarter = "quarter",
10530 Quarters = "quarters",
10531 Month = "month",
10532 Months = "months",
10533 Week = "week",
10534 Weeks = "weeks",
10535 Day = "day",
10536 Days = "days",
10537 Hour = "hour",
10538 Hours = "hours",
10539 Minute = "minute",
10540 Minutes = "minutes",
10541 Second = "second",
10542 Seconds = "seconds",
10543 }
10544
10545 /// Part type for `RelativeTimeFormat.formatToParts()`.
10546 #[wasm_bindgen]
10547 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10548 pub enum RelativeTimeFormatPartType {
10549 Literal = "literal",
10550 Integer = "integer",
10551 Decimal = "decimal",
10552 Fraction = "fraction",
10553 }
10554
10555 /// Source indicator for range format parts.
10556 ///
10557 /// Indicates which part of the range (start, end, or shared) a formatted
10558 /// part belongs to when using `formatRangeToParts()`.
10559 ///
10560 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatRangeToParts#description)
10561 #[wasm_bindgen]
10562 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10563 pub enum RangeSource {
10564 /// The part is from the start of the range.
10565 StartRange = "startRange",
10566 /// The part is from the end of the range.
10567 EndRange = "endRange",
10568 /// The part is shared between start and end (e.g., a separator or common element).
10569 Shared = "shared",
10570 }
10571
10572 /// Type for `Intl.ListFormat`.
10573 #[wasm_bindgen]
10574 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10575 pub enum ListFormatType {
10576 /// For lists of standalone items (default).
10577 Conjunction = "conjunction",
10578 /// For lists representing alternatives.
10579 Disjunction = "disjunction",
10580 /// For lists of values with units.
10581 Unit = "unit",
10582 }
10583
10584 /// Style for `Intl.ListFormat`.
10585 #[wasm_bindgen]
10586 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10587 pub enum ListFormatStyle {
10588 /// "A, B, and C" (default).
10589 Long = "long",
10590 /// "A, B, C".
10591 Short = "short",
10592 /// "A B C".
10593 Narrow = "narrow",
10594 }
10595
10596 /// Part type for `Intl.ListFormat.formatToParts()`.
10597 #[wasm_bindgen]
10598 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10599 pub enum ListFormatPartType {
10600 /// A value from the list.
10601 Element = "element",
10602 /// A linguistic construct (e.g., ", ", " and ").
10603 Literal = "literal",
10604 }
10605
10606 /// Type for `Intl.Segmenter`.
10607 #[wasm_bindgen]
10608 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10609 pub enum SegmenterGranularity {
10610 /// Segment by grapheme clusters (user-perceived characters).
10611 Grapheme = "grapheme",
10612 /// Segment by words.
10613 Word = "word",
10614 /// Segment by sentences.
10615 Sentence = "sentence",
10616 }
10617
10618 /// Type for `Intl.DisplayNames`.
10619 #[wasm_bindgen]
10620 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10621 pub enum DisplayNamesType {
10622 /// Language display names.
10623 Language = "language",
10624 /// Region display names.
10625 Region = "region",
10626 /// Script display names.
10627 Script = "script",
10628 /// Currency display names.
10629 Currency = "currency",
10630 /// Calendar display names.
10631 Calendar = "calendar",
10632 /// Date/time field display names.
10633 DateTimeField = "dateTimeField",
10634 }
10635
10636 /// Style for `Intl.DisplayNames`.
10637 #[wasm_bindgen]
10638 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10639 pub enum DisplayNamesStyle {
10640 /// Full display name (default).
10641 Long = "long",
10642 /// Abbreviated display name.
10643 Short = "short",
10644 /// Minimal display name.
10645 Narrow = "narrow",
10646 }
10647
10648 /// Fallback for `Intl.DisplayNames`.
10649 #[wasm_bindgen]
10650 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10651 pub enum DisplayNamesFallback {
10652 /// Return the input code if no display name is available (default).
10653 Code = "code",
10654 /// Return undefined if no display name is available.
10655 None = "none",
10656 }
10657
10658 /// Language display for `Intl.DisplayNames`.
10659 #[wasm_bindgen]
10660 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10661 pub enum DisplayNamesLanguageDisplay {
10662 /// Use dialect names (e.g., "British English").
10663 Dialect = "dialect",
10664 /// Use standard names (e.g., "English (United Kingdom)").
10665 Standard = "standard",
10666 }
10667
10668 // Intl.RelativeTimeFormatOptions
10669 #[wasm_bindgen]
10670 extern "C" {
10671 /// Options for `Intl.RelativeTimeFormat` constructor.
10672 ///
10673 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/RelativeTimeFormat#options)
10674 #[wasm_bindgen(extends = Object)]
10675 #[derive(Clone, Debug)]
10676 pub type RelativeTimeFormatOptions;
10677
10678 #[wasm_bindgen(method, getter = localeMatcher)]
10679 pub fn get_locale_matcher(this: &RelativeTimeFormatOptions) -> Option<LocaleMatcher>;
10680 #[wasm_bindgen(method, setter = localeMatcher)]
10681 pub fn set_locale_matcher(this: &RelativeTimeFormatOptions, value: LocaleMatcher);
10682
10683 #[wasm_bindgen(method, getter = numeric)]
10684 pub fn get_numeric(this: &RelativeTimeFormatOptions) -> Option<RelativeTimeFormatNumeric>;
10685 #[wasm_bindgen(method, setter = numeric)]
10686 pub fn set_numeric(this: &RelativeTimeFormatOptions, value: RelativeTimeFormatNumeric);
10687
10688 #[wasm_bindgen(method, getter = style)]
10689 pub fn get_style(this: &RelativeTimeFormatOptions) -> Option<RelativeTimeFormatStyle>;
10690 #[wasm_bindgen(method, setter = style)]
10691 pub fn set_style(this: &RelativeTimeFormatOptions, value: RelativeTimeFormatStyle);
10692 }
10693
10694 impl RelativeTimeFormatOptions {
10695 pub fn new() -> RelativeTimeFormatOptions {
10696 JsCast::unchecked_into(Object::new())
10697 }
10698 }
10699
10700 impl Default for RelativeTimeFormatOptions {
10701 fn default() -> Self {
10702 RelativeTimeFormatOptions::new()
10703 }
10704 }
10705
10706 // Intl.ResolvedRelativeTimeFormatOptions
10707 #[wasm_bindgen]
10708 extern "C" {
10709 /// Resolved options returned by `Intl.RelativeTimeFormat.prototype.resolvedOptions()`.
10710 ///
10711 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/resolvedOptions)
10712 #[wasm_bindgen(extends = RelativeTimeFormatOptions)]
10713 #[derive(Clone, Debug)]
10714 pub type ResolvedRelativeTimeFormatOptions;
10715
10716 /// The resolved locale string.
10717 #[wasm_bindgen(method, getter = locale)]
10718 pub fn get_locale(this: &ResolvedRelativeTimeFormatOptions) -> JsString;
10719
10720 /// The numbering system used.
10721 #[wasm_bindgen(method, getter = numberingSystem)]
10722 pub fn get_numbering_system(this: &ResolvedRelativeTimeFormatOptions) -> JsString;
10723 }
10724
10725 // Intl.RelativeTimeFormatPart
10726 #[wasm_bindgen]
10727 extern "C" {
10728 /// A part of the formatted relative time returned by `formatToParts()`.
10729 ///
10730 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/formatToParts)
10731 #[wasm_bindgen(extends = Object)]
10732 #[derive(Clone, Debug)]
10733 pub type RelativeTimeFormatPart;
10734
10735 /// The type of this part.
10736 #[wasm_bindgen(method, getter = type)]
10737 pub fn type_(this: &RelativeTimeFormatPart) -> RelativeTimeFormatPartType;
10738
10739 /// The string value of this part.
10740 #[wasm_bindgen(method, getter = value)]
10741 pub fn value(this: &RelativeTimeFormatPart) -> JsString;
10742
10743 /// The unit used in this part (only for integer parts).
10744 #[wasm_bindgen(method, getter = unit)]
10745 pub fn unit(this: &RelativeTimeFormatPart) -> Option<JsString>;
10746 }
10747
10748 // Intl.LocaleMatcherOptions
10749 #[wasm_bindgen]
10750 extern "C" {
10751 /// Options for `supportedLocalesOf` methods.
10752 #[wasm_bindgen(extends = Object)]
10753 #[derive(Clone, Debug)]
10754 pub type LocaleMatcherOptions;
10755
10756 #[wasm_bindgen(method, getter = localeMatcher)]
10757 pub fn get_locale_matcher(this: &LocaleMatcherOptions) -> Option<LocaleMatcher>;
10758
10759 #[wasm_bindgen(method, setter = localeMatcher)]
10760 pub fn set_locale_matcher(this: &LocaleMatcherOptions, value: LocaleMatcher);
10761 }
10762
10763 impl LocaleMatcherOptions {
10764 pub fn new() -> LocaleMatcherOptions {
10765 JsCast::unchecked_into(Object::new())
10766 }
10767 }
10768
10769 impl Default for LocaleMatcherOptions {
10770 fn default() -> Self {
10771 LocaleMatcherOptions::new()
10772 }
10773 }
10774
10775 // Intl.Collator Options
10776 #[wasm_bindgen]
10777 extern "C" {
10778 /// Options for `Intl.Collator` and `String.prototype.localeCompare`.
10779 ///
10780 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Collator/Collator#options)
10781 #[wasm_bindgen(extends = Object)]
10782 #[derive(Clone, Debug)]
10783 pub type CollatorOptions;
10784
10785 #[wasm_bindgen(method, getter = localeMatcher)]
10786 pub fn get_locale_matcher(this: &CollatorOptions) -> Option<LocaleMatcher>;
10787 #[wasm_bindgen(method, setter = localeMatcher)]
10788 pub fn set_locale_matcher(this: &CollatorOptions, value: LocaleMatcher);
10789
10790 #[wasm_bindgen(method, getter = usage)]
10791 pub fn get_usage(this: &CollatorOptions) -> Option<CollatorUsage>;
10792 #[wasm_bindgen(method, setter = usage)]
10793 pub fn set_usage(this: &CollatorOptions, value: CollatorUsage);
10794
10795 #[wasm_bindgen(method, getter = sensitivity)]
10796 pub fn get_sensitivity(this: &CollatorOptions) -> Option<CollatorSensitivity>;
10797 #[wasm_bindgen(method, setter = sensitivity)]
10798 pub fn set_sensitivity(this: &CollatorOptions, value: CollatorSensitivity);
10799
10800 #[wasm_bindgen(method, getter = ignorePunctuation)]
10801 pub fn get_ignore_punctuation(this: &CollatorOptions) -> Option<bool>;
10802 #[wasm_bindgen(method, setter = ignorePunctuation)]
10803 pub fn set_ignore_punctuation(this: &CollatorOptions, value: bool);
10804
10805 #[wasm_bindgen(method, getter = numeric)]
10806 pub fn get_numeric(this: &CollatorOptions) -> Option<bool>;
10807 #[wasm_bindgen(method, setter = numeric)]
10808 pub fn set_numeric(this: &CollatorOptions, value: bool);
10809
10810 #[wasm_bindgen(method, getter = caseFirst)]
10811 pub fn get_case_first(this: &CollatorOptions) -> Option<CollatorCaseFirst>;
10812 #[wasm_bindgen(method, setter = caseFirst)]
10813 pub fn set_case_first(this: &CollatorOptions, value: CollatorCaseFirst);
10814 }
10815 impl CollatorOptions {
10816 pub fn new() -> CollatorOptions {
10817 JsCast::unchecked_into(Object::new())
10818 }
10819 }
10820 impl Default for CollatorOptions {
10821 fn default() -> Self {
10822 CollatorOptions::new()
10823 }
10824 }
10825
10826 // Intl.Collator ResolvedCollatorOptions
10827 #[wasm_bindgen]
10828 extern "C" {
10829 #[wasm_bindgen(extends = CollatorOptions)]
10830 #[derive(Clone, Debug)]
10831 pub type ResolvedCollatorOptions;
10832
10833 #[wasm_bindgen(method, getter = locale)]
10834 pub fn get_locale(this: &ResolvedCollatorOptions) -> JsString; // not Option, always present
10835 #[wasm_bindgen(method, getter = collation)]
10836 pub fn get_collation(this: &ResolvedCollatorOptions) -> JsString;
10837 }
10838
10839 // Intl.Collator
10840 #[wasm_bindgen]
10841 extern "C" {
10842 /// The `Intl.Collator` object is a constructor for collators, objects
10843 /// that enable language sensitive string comparison.
10844 ///
10845 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator)
10846 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.Collator")]
10847 #[derive(Clone, Debug)]
10848 pub type Collator;
10849
10850 /// The `Intl.Collator` object is a constructor for collators, objects
10851 /// that enable language sensitive string comparison.
10852 ///
10853 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator)
10854 #[cfg(not(js_sys_unstable_apis))]
10855 #[wasm_bindgen(constructor, js_namespace = Intl)]
10856 pub fn new(locales: &Array, options: &Object) -> Collator;
10857
10858 /// The `Intl.Collator` object is a constructor for collators, objects
10859 /// that enable language sensitive string comparison.
10860 ///
10861 /// Throws a `RangeError` if locales contain invalid values.
10862 ///
10863 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator)
10864 #[cfg(js_sys_unstable_apis)]
10865 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
10866 pub fn new(locales: &[JsString], options: &CollatorOptions) -> Result<Collator, JsValue>;
10867
10868 /// The Intl.Collator.prototype.compare property returns a function that
10869 /// compares two strings according to the sort order of this Collator
10870 /// object.
10871 ///
10872 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/compare)
10873 #[cfg(not(js_sys_unstable_apis))]
10874 #[wasm_bindgen(method, getter, js_class = "Intl.Collator")]
10875 pub fn compare(this: &Collator) -> Function;
10876
10877 /// Compares two strings according to the sort order of this Collator.
10878 ///
10879 /// Returns a negative value if `a` comes before `b`, positive if `a` comes
10880 /// after `b`, and zero if they are equal.
10881 ///
10882 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Collator/compare)
10883 #[cfg(js_sys_unstable_apis)]
10884 #[wasm_bindgen(method, js_class = "Intl.Collator")]
10885 pub fn compare(this: &Collator, a: &str, b: &str) -> i32;
10886
10887 /// The `Intl.Collator.prototype.resolvedOptions()` method returns a new
10888 /// object with properties reflecting the locale and collation options
10889 /// computed during initialization of this Collator object.
10890 ///
10891 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/resolvedOptions)
10892 #[cfg(not(js_sys_unstable_apis))]
10893 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
10894 pub fn resolved_options(this: &Collator) -> Object;
10895
10896 /// The `Intl.Collator.prototype.resolvedOptions()` method returns a new
10897 /// object with properties reflecting the locale and collation options
10898 /// computed during initialization of this Collator object.
10899 ///
10900 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/resolvedOptions)
10901 #[cfg(js_sys_unstable_apis)]
10902 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
10903 pub fn resolved_options(this: &Collator) -> ResolvedCollatorOptions;
10904
10905 /// The `Intl.Collator.supportedLocalesOf()` method returns an array
10906 /// containing those of the provided locales that are supported in
10907 /// collation without having to fall back to the runtime's default
10908 /// locale.
10909 ///
10910 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/supportedLocalesOf)
10911 #[cfg(not(js_sys_unstable_apis))]
10912 #[wasm_bindgen(static_method_of = Collator, js_namespace = Intl, js_name = supportedLocalesOf)]
10913 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
10914
10915 /// The `Intl.Collator.supportedLocalesOf()` method returns an array
10916 /// containing those of the provided locales that are supported in
10917 /// collation without having to fall back to the runtime's default
10918 /// locale.
10919 ///
10920 /// Throws a `RangeError` if locales contain invalid values.
10921 ///
10922 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/supportedLocalesOf)
10923 #[cfg(js_sys_unstable_apis)]
10924 #[wasm_bindgen(static_method_of = Collator, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
10925 pub fn supported_locales_of(
10926 locales: &[JsString],
10927 options: &LocaleMatcherOptions,
10928 ) -> Result<Array<JsString>, JsValue>;
10929 }
10930
10931 #[cfg(not(js_sys_unstable_apis))]
10932 impl Default for Collator {
10933 fn default() -> Self {
10934 Self::new(
10935 &JsValue::UNDEFINED.unchecked_into(),
10936 &JsValue::UNDEFINED.unchecked_into(),
10937 )
10938 }
10939 }
10940
10941 #[cfg(js_sys_unstable_apis)]
10942 impl Default for Collator {
10943 fn default() -> Self {
10944 Self::new(&[], &Default::default()).unwrap()
10945 }
10946 }
10947
10948 // Intl.DateTimeFormatOptions
10949 #[wasm_bindgen]
10950 extern "C" {
10951 /// Options for `Intl.DateTimeFormat` constructor.
10952 ///
10953 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat#options)
10954 #[wasm_bindgen(extends = Object)]
10955 #[derive(Clone, Debug)]
10956 pub type DateTimeFormatOptions;
10957
10958 // Locale matching
10959 #[wasm_bindgen(method, getter = localeMatcher)]
10960 pub fn get_locale_matcher(this: &DateTimeFormatOptions) -> Option<LocaleMatcher>;
10961 #[wasm_bindgen(method, setter = localeMatcher)]
10962 pub fn set_locale_matcher(this: &DateTimeFormatOptions, value: LocaleMatcher);
10963
10964 // Calendar/numbering (free-form strings, no enum)
10965 #[wasm_bindgen(method, getter = calendar)]
10966 pub fn get_calendar(this: &DateTimeFormatOptions) -> Option<JsString>;
10967 #[wasm_bindgen(method, setter = calendar)]
10968 pub fn set_calendar(this: &DateTimeFormatOptions, value: &str);
10969
10970 #[wasm_bindgen(method, getter = numberingSystem)]
10971 pub fn get_numbering_system(this: &DateTimeFormatOptions) -> Option<JsString>;
10972 #[wasm_bindgen(method, setter = numberingSystem)]
10973 pub fn set_numbering_system(this: &DateTimeFormatOptions, value: &str);
10974
10975 // Timezone (free-form string)
10976 #[wasm_bindgen(method, getter = timeZone)]
10977 pub fn get_time_zone(this: &DateTimeFormatOptions) -> Option<JsString>;
10978 #[wasm_bindgen(method, setter = timeZone)]
10979 pub fn set_time_zone(this: &DateTimeFormatOptions, value: &str);
10980
10981 // Hour cycle
10982 #[wasm_bindgen(method, getter = hour12)]
10983 pub fn get_hour12(this: &DateTimeFormatOptions) -> Option<bool>;
10984 #[wasm_bindgen(method, setter = hour12)]
10985 pub fn set_hour12(this: &DateTimeFormatOptions, value: bool);
10986
10987 #[wasm_bindgen(method, getter = hourCycle)]
10988 pub fn get_hour_cycle(this: &DateTimeFormatOptions) -> Option<HourCycle>;
10989 #[wasm_bindgen(method, setter = hourCycle)]
10990 pub fn set_hour_cycle(this: &DateTimeFormatOptions, value: HourCycle);
10991
10992 // Style shortcuts
10993 #[wasm_bindgen(method, getter = dateStyle)]
10994 pub fn get_date_style(this: &DateTimeFormatOptions) -> Option<DateTimeStyle>;
10995 #[wasm_bindgen(method, setter = dateStyle)]
10996 pub fn set_date_style(this: &DateTimeFormatOptions, value: DateTimeStyle);
10997
10998 #[wasm_bindgen(method, getter = timeStyle)]
10999 pub fn get_time_style(this: &DateTimeFormatOptions) -> Option<DateTimeStyle>;
11000 #[wasm_bindgen(method, setter = timeStyle)]
11001 pub fn set_time_style(this: &DateTimeFormatOptions, value: DateTimeStyle);
11002
11003 // Component options
11004 #[wasm_bindgen(method, getter = weekday)]
11005 pub fn get_weekday(this: &DateTimeFormatOptions) -> Option<WeekdayFormat>;
11006 #[wasm_bindgen(method, setter = weekday)]
11007 pub fn set_weekday(this: &DateTimeFormatOptions, value: WeekdayFormat);
11008
11009 #[wasm_bindgen(method, getter = era)]
11010 pub fn get_era(this: &DateTimeFormatOptions) -> Option<EraFormat>;
11011 #[wasm_bindgen(method, setter = era)]
11012 pub fn set_era(this: &DateTimeFormatOptions, value: EraFormat);
11013
11014 #[wasm_bindgen(method, getter = year)]
11015 pub fn get_year(this: &DateTimeFormatOptions) -> Option<YearFormat>;
11016 #[wasm_bindgen(method, setter = year)]
11017 pub fn set_year(this: &DateTimeFormatOptions, value: YearFormat);
11018
11019 #[wasm_bindgen(method, getter = month)]
11020 pub fn get_month(this: &DateTimeFormatOptions) -> Option<MonthFormat>;
11021 #[wasm_bindgen(method, setter = month)]
11022 pub fn set_month(this: &DateTimeFormatOptions, value: MonthFormat);
11023
11024 #[wasm_bindgen(method, getter = day)]
11025 pub fn get_day(this: &DateTimeFormatOptions) -> Option<DayFormat>;
11026 #[wasm_bindgen(method, setter = day)]
11027 pub fn set_day(this: &DateTimeFormatOptions, value: DayFormat);
11028
11029 #[wasm_bindgen(method, getter = hour)]
11030 pub fn get_hour(this: &DateTimeFormatOptions) -> Option<NumericFormat>;
11031 #[wasm_bindgen(method, setter = hour)]
11032 pub fn set_hour(this: &DateTimeFormatOptions, value: NumericFormat);
11033
11034 #[wasm_bindgen(method, getter = minute)]
11035 pub fn get_minute(this: &DateTimeFormatOptions) -> Option<NumericFormat>;
11036 #[wasm_bindgen(method, setter = minute)]
11037 pub fn set_minute(this: &DateTimeFormatOptions, value: NumericFormat);
11038
11039 #[wasm_bindgen(method, getter = second)]
11040 pub fn get_second(this: &DateTimeFormatOptions) -> Option<NumericFormat>;
11041 #[wasm_bindgen(method, setter = second)]
11042 pub fn set_second(this: &DateTimeFormatOptions, value: NumericFormat);
11043
11044 #[wasm_bindgen(method, getter = fractionalSecondDigits)]
11045 pub fn get_fractional_second_digits(this: &DateTimeFormatOptions) -> Option<u8>;
11046 #[wasm_bindgen(method, setter = fractionalSecondDigits)]
11047 pub fn set_fractional_second_digits(this: &DateTimeFormatOptions, value: u8);
11048
11049 #[wasm_bindgen(method, getter = timeZoneName)]
11050 pub fn get_time_zone_name(this: &DateTimeFormatOptions) -> Option<TimeZoneNameFormat>;
11051 #[wasm_bindgen(method, setter = timeZoneName)]
11052 pub fn set_time_zone_name(this: &DateTimeFormatOptions, value: TimeZoneNameFormat);
11053
11054 #[wasm_bindgen(method, getter = dayPeriod)]
11055 pub fn get_day_period(this: &DateTimeFormatOptions) -> Option<DayPeriodFormat>;
11056 #[wasm_bindgen(method, setter = dayPeriod)]
11057 pub fn set_day_period(this: &DateTimeFormatOptions, value: DayPeriodFormat);
11058 }
11059
11060 impl DateTimeFormatOptions {
11061 pub fn new() -> DateTimeFormatOptions {
11062 JsCast::unchecked_into(Object::new())
11063 }
11064 }
11065
11066 impl Default for DateTimeFormatOptions {
11067 fn default() -> Self {
11068 DateTimeFormatOptions::new()
11069 }
11070 }
11071
11072 // Intl.ResolvedDateTimeFormatOptions
11073 #[wasm_bindgen]
11074 extern "C" {
11075 /// Resolved options returned by `Intl.DateTimeFormat.prototype.resolvedOptions()`.
11076 ///
11077 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/resolvedOptions)
11078 #[wasm_bindgen(extends = DateTimeFormatOptions)]
11079 #[derive(Clone, Debug)]
11080 pub type ResolvedDateTimeFormatOptions;
11081
11082 /// The resolved locale string.
11083 #[wasm_bindgen(method, getter = locale)]
11084 pub fn get_locale(this: &ResolvedDateTimeFormatOptions) -> JsString;
11085 }
11086
11087 // Intl.DateTimeFormatPart
11088 #[wasm_bindgen]
11089 extern "C" {
11090 /// A part of the formatted date returned by `formatToParts()`.
11091 ///
11092 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatToParts)
11093 #[wasm_bindgen(extends = Object)]
11094 #[derive(Clone, Debug)]
11095 pub type DateTimeFormatPart;
11096
11097 /// The type of the part (e.g., "day", "month", "year", "literal", etc.)
11098 #[wasm_bindgen(method, getter = type)]
11099 pub fn type_(this: &DateTimeFormatPart) -> DateTimeFormatPartType;
11100
11101 /// The value of the part.
11102 #[wasm_bindgen(method, getter)]
11103 pub fn value(this: &DateTimeFormatPart) -> JsString;
11104 }
11105
11106 // Intl.DateTimeRangeFormatPart
11107 #[wasm_bindgen]
11108 extern "C" {
11109 /// A part of the formatted date range returned by `formatRangeToParts()`.
11110 ///
11111 /// Extends `DateTimeFormatPart` with a `source` property indicating whether
11112 /// the part is from the start date, end date, or shared between them.
11113 ///
11114 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatRangeToParts)
11115 #[wasm_bindgen(extends = DateTimeFormatPart)]
11116 #[derive(Clone, Debug)]
11117 pub type DateTimeRangeFormatPart;
11118
11119 /// The source of the part: "startRange", "endRange", or "shared".
11120 #[wasm_bindgen(method, getter)]
11121 pub fn source(this: &DateTimeRangeFormatPart) -> RangeSource;
11122 }
11123
11124 // Intl.DateTimeFormat
11125 #[wasm_bindgen]
11126 extern "C" {
11127 /// The `Intl.DateTimeFormat` object is a constructor for objects
11128 /// that enable language-sensitive date and time formatting.
11129 ///
11130 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat)
11131 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.DateTimeFormat")]
11132 #[derive(Clone, Debug)]
11133 pub type DateTimeFormat;
11134
11135 /// The `Intl.DateTimeFormat` object is a constructor for objects
11136 /// that enable language-sensitive date and time formatting.
11137 ///
11138 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat)
11139 #[cfg(not(js_sys_unstable_apis))]
11140 #[wasm_bindgen(constructor, js_namespace = Intl)]
11141 pub fn new(locales: &Array, options: &Object) -> DateTimeFormat;
11142
11143 /// The `Intl.DateTimeFormat` object is a constructor for objects
11144 /// that enable language-sensitive date and time formatting.
11145 ///
11146 /// Throws a `RangeError` if locales contain invalid values.
11147 ///
11148 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat)
11149 #[cfg(js_sys_unstable_apis)]
11150 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
11151 pub fn new(
11152 locales: &[JsString],
11153 options: &DateTimeFormatOptions,
11154 ) -> Result<DateTimeFormat, JsValue>;
11155
11156 /// The Intl.DateTimeFormat.prototype.format property returns a getter function that
11157 /// formats a date according to the locale and formatting options of this
11158 /// Intl.DateTimeFormat object.
11159 ///
11160 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/format)
11161 #[cfg(not(js_sys_unstable_apis))]
11162 #[wasm_bindgen(method, getter, js_class = "Intl.DateTimeFormat")]
11163 pub fn format(this: &DateTimeFormat) -> Function;
11164
11165 /// Formats a date according to the locale and formatting options of this
11166 /// `Intl.DateTimeFormat` object.
11167 ///
11168 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/format)
11169 #[cfg(js_sys_unstable_apis)]
11170 #[wasm_bindgen(method, js_class = "Intl.DateTimeFormat")]
11171 pub fn format(this: &DateTimeFormat, date: &Date) -> JsString;
11172
11173 /// The `Intl.DateTimeFormat.prototype.formatToParts()` method allows locale-aware
11174 /// formatting of strings produced by DateTimeFormat formatters.
11175 ///
11176 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/formatToParts)
11177 #[cfg(not(js_sys_unstable_apis))]
11178 #[wasm_bindgen(method, js_class = "Intl.DateTimeFormat", js_name = formatToParts)]
11179 pub fn format_to_parts(this: &DateTimeFormat, date: &Date) -> Array;
11180
11181 /// The `Intl.DateTimeFormat.prototype.formatToParts()` method allows locale-aware
11182 /// formatting of strings produced by DateTimeFormat formatters.
11183 ///
11184 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/formatToParts)
11185 #[cfg(js_sys_unstable_apis)]
11186 #[wasm_bindgen(method, js_class = "Intl.DateTimeFormat", js_name = formatToParts)]
11187 pub fn format_to_parts(this: &DateTimeFormat, date: &Date) -> Array<DateTimeFormatPart>;
11188
11189 /// The `Intl.DateTimeFormat.prototype.formatRange()` method formats a date range
11190 /// in the most concise way based on the locales and options provided when
11191 /// instantiating this `Intl.DateTimeFormat` object.
11192 ///
11193 /// Throws a `TypeError` if the dates are invalid.
11194 ///
11195 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatRange)
11196 #[wasm_bindgen(method, js_class = "Intl.DateTimeFormat", js_name = formatRange, catch)]
11197 pub fn format_range(
11198 this: &DateTimeFormat,
11199 start_date: &Date,
11200 end_date: &Date,
11201 ) -> Result<JsString, JsValue>;
11202
11203 /// The `Intl.DateTimeFormat.prototype.formatRangeToParts()` method returns an array
11204 /// of locale-specific tokens representing each part of the formatted date range
11205 /// produced by `Intl.DateTimeFormat` formatters.
11206 ///
11207 /// Throws a `TypeError` if the dates are invalid.
11208 ///
11209 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatRangeToParts)
11210 #[wasm_bindgen(method, js_class = "Intl.DateTimeFormat", js_name = formatRangeToParts, catch)]
11211 pub fn format_range_to_parts(
11212 this: &DateTimeFormat,
11213 start_date: &Date,
11214 end_date: &Date,
11215 ) -> Result<Array<DateTimeRangeFormatPart>, JsValue>;
11216
11217 /// The `Intl.DateTimeFormat.prototype.resolvedOptions()` method returns a new
11218 /// object with properties reflecting the locale and date and time formatting
11219 /// options computed during initialization of this DateTimeFormat object.
11220 ///
11221 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/resolvedOptions)
11222 #[cfg(not(js_sys_unstable_apis))]
11223 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11224 pub fn resolved_options(this: &DateTimeFormat) -> Object;
11225
11226 /// The `Intl.DateTimeFormat.prototype.resolvedOptions()` method returns a new
11227 /// object with properties reflecting the locale and date and time formatting
11228 /// options computed during initialization of this DateTimeFormat object.
11229 ///
11230 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/resolvedOptions)
11231 #[cfg(js_sys_unstable_apis)]
11232 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11233 pub fn resolved_options(this: &DateTimeFormat) -> ResolvedDateTimeFormatOptions;
11234
11235 /// The `Intl.DateTimeFormat.supportedLocalesOf()` method returns an array
11236 /// containing those of the provided locales that are supported in date
11237 /// and time formatting without having to fall back to the runtime's default
11238 /// locale.
11239 ///
11240 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/supportedLocalesOf)
11241 #[cfg(not(js_sys_unstable_apis))]
11242 #[wasm_bindgen(static_method_of = DateTimeFormat, js_namespace = Intl, js_name = supportedLocalesOf)]
11243 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
11244
11245 /// The `Intl.DateTimeFormat.supportedLocalesOf()` method returns an array
11246 /// containing those of the provided locales that are supported in date
11247 /// and time formatting without having to fall back to the runtime's default
11248 /// locale.
11249 ///
11250 /// Throws a `RangeError` if locales contain invalid values.
11251 ///
11252 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/supportedLocalesOf)
11253 #[cfg(js_sys_unstable_apis)]
11254 #[wasm_bindgen(static_method_of = DateTimeFormat, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
11255 pub fn supported_locales_of(
11256 locales: &[JsString],
11257 options: &LocaleMatcherOptions,
11258 ) -> Result<Array<JsString>, JsValue>;
11259 }
11260
11261 #[cfg(not(js_sys_unstable_apis))]
11262 impl Default for DateTimeFormat {
11263 fn default() -> Self {
11264 Self::new(
11265 &JsValue::UNDEFINED.unchecked_into(),
11266 &JsValue::UNDEFINED.unchecked_into(),
11267 )
11268 }
11269 }
11270
11271 #[cfg(js_sys_unstable_apis)]
11272 impl Default for DateTimeFormat {
11273 fn default() -> Self {
11274 Self::new(&[], &Default::default()).unwrap()
11275 }
11276 }
11277
11278 // Intl.NumberFormatOptions
11279 #[wasm_bindgen]
11280 extern "C" {
11281 /// Options for `Intl.NumberFormat` constructor.
11282 ///
11283 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#options)
11284 #[wasm_bindgen(extends = Object)]
11285 #[derive(Clone, Debug)]
11286 pub type NumberFormatOptions;
11287
11288 // Locale matching
11289 #[wasm_bindgen(method, getter = localeMatcher)]
11290 pub fn get_locale_matcher(this: &NumberFormatOptions) -> Option<LocaleMatcher>;
11291 #[wasm_bindgen(method, setter = localeMatcher)]
11292 pub fn set_locale_matcher(this: &NumberFormatOptions, value: LocaleMatcher);
11293
11294 // Numbering system (free-form string)
11295 #[wasm_bindgen(method, getter = numberingSystem)]
11296 pub fn get_numbering_system(this: &NumberFormatOptions) -> Option<JsString>;
11297 #[wasm_bindgen(method, setter = numberingSystem)]
11298 pub fn set_numbering_system(this: &NumberFormatOptions, value: &str);
11299
11300 // Style
11301 #[wasm_bindgen(method, getter = style)]
11302 pub fn get_style(this: &NumberFormatOptions) -> Option<NumberFormatStyle>;
11303 #[wasm_bindgen(method, setter = style)]
11304 pub fn set_style(this: &NumberFormatOptions, value: NumberFormatStyle);
11305
11306 // Currency options (currency code is free-form ISO 4217 string)
11307 #[wasm_bindgen(method, getter = currency)]
11308 pub fn get_currency(this: &NumberFormatOptions) -> Option<JsString>;
11309 #[wasm_bindgen(method, setter = currency)]
11310 pub fn set_currency(this: &NumberFormatOptions, value: &str);
11311
11312 #[wasm_bindgen(method, getter = currencyDisplay)]
11313 pub fn get_currency_display(this: &NumberFormatOptions) -> Option<CurrencyDisplay>;
11314 #[wasm_bindgen(method, setter = currencyDisplay)]
11315 pub fn set_currency_display(this: &NumberFormatOptions, value: CurrencyDisplay);
11316
11317 #[wasm_bindgen(method, getter = currencySign)]
11318 pub fn get_currency_sign(this: &NumberFormatOptions) -> Option<CurrencySign>;
11319 #[wasm_bindgen(method, setter = currencySign)]
11320 pub fn set_currency_sign(this: &NumberFormatOptions, value: CurrencySign);
11321
11322 // Unit options (unit name is free-form string)
11323 #[wasm_bindgen(method, getter = unit)]
11324 pub fn get_unit(this: &NumberFormatOptions) -> Option<JsString>;
11325 #[wasm_bindgen(method, setter = unit)]
11326 pub fn set_unit(this: &NumberFormatOptions, value: &str);
11327
11328 #[wasm_bindgen(method, getter = unitDisplay)]
11329 pub fn get_unit_display(this: &NumberFormatOptions) -> Option<UnitDisplay>;
11330 #[wasm_bindgen(method, setter = unitDisplay)]
11331 pub fn set_unit_display(this: &NumberFormatOptions, value: UnitDisplay);
11332
11333 // Notation
11334 #[wasm_bindgen(method, getter = notation)]
11335 pub fn get_notation(this: &NumberFormatOptions) -> Option<NumberFormatNotation>;
11336 #[wasm_bindgen(method, setter = notation)]
11337 pub fn set_notation(this: &NumberFormatOptions, value: NumberFormatNotation);
11338
11339 #[wasm_bindgen(method, getter = compactDisplay)]
11340 pub fn get_compact_display(this: &NumberFormatOptions) -> Option<CompactDisplay>;
11341 #[wasm_bindgen(method, setter = compactDisplay)]
11342 pub fn set_compact_display(this: &NumberFormatOptions, value: CompactDisplay);
11343
11344 // Sign display
11345 #[wasm_bindgen(method, getter = signDisplay)]
11346 pub fn get_sign_display(this: &NumberFormatOptions) -> Option<SignDisplay>;
11347 #[wasm_bindgen(method, setter = signDisplay)]
11348 pub fn set_sign_display(this: &NumberFormatOptions, value: SignDisplay);
11349
11350 // Digit options
11351 #[wasm_bindgen(method, getter = minimumIntegerDigits)]
11352 pub fn get_minimum_integer_digits(this: &NumberFormatOptions) -> Option<u8>;
11353 #[wasm_bindgen(method, setter = minimumIntegerDigits)]
11354 pub fn set_minimum_integer_digits(this: &NumberFormatOptions, value: u8);
11355
11356 #[wasm_bindgen(method, getter = minimumFractionDigits)]
11357 pub fn get_minimum_fraction_digits(this: &NumberFormatOptions) -> Option<u8>;
11358 #[wasm_bindgen(method, setter = minimumFractionDigits)]
11359 pub fn set_minimum_fraction_digits(this: &NumberFormatOptions, value: u8);
11360
11361 #[wasm_bindgen(method, getter = maximumFractionDigits)]
11362 pub fn get_maximum_fraction_digits(this: &NumberFormatOptions) -> Option<u8>;
11363 #[wasm_bindgen(method, setter = maximumFractionDigits)]
11364 pub fn set_maximum_fraction_digits(this: &NumberFormatOptions, value: u8);
11365
11366 #[wasm_bindgen(method, getter = minimumSignificantDigits)]
11367 pub fn get_minimum_significant_digits(this: &NumberFormatOptions) -> Option<u8>;
11368 #[wasm_bindgen(method, setter = minimumSignificantDigits)]
11369 pub fn set_minimum_significant_digits(this: &NumberFormatOptions, value: u8);
11370
11371 #[wasm_bindgen(method, getter = maximumSignificantDigits)]
11372 pub fn get_maximum_significant_digits(this: &NumberFormatOptions) -> Option<u8>;
11373 #[wasm_bindgen(method, setter = maximumSignificantDigits)]
11374 pub fn set_maximum_significant_digits(this: &NumberFormatOptions, value: u8);
11375
11376 // Grouping
11377 #[wasm_bindgen(method, getter = useGrouping)]
11378 pub fn get_use_grouping(this: &NumberFormatOptions) -> Option<UseGrouping>;
11379 #[wasm_bindgen(method, setter = useGrouping)]
11380 pub fn set_use_grouping(this: &NumberFormatOptions, value: UseGrouping);
11381
11382 // Rounding
11383 #[wasm_bindgen(method, getter = roundingMode)]
11384 pub fn get_rounding_mode(this: &NumberFormatOptions) -> Option<RoundingMode>;
11385 #[wasm_bindgen(method, setter = roundingMode)]
11386 pub fn set_rounding_mode(this: &NumberFormatOptions, value: RoundingMode);
11387
11388 #[wasm_bindgen(method, getter = roundingPriority)]
11389 pub fn get_rounding_priority(this: &NumberFormatOptions) -> Option<RoundingPriority>;
11390 #[wasm_bindgen(method, setter = roundingPriority)]
11391 pub fn set_rounding_priority(this: &NumberFormatOptions, value: RoundingPriority);
11392
11393 #[wasm_bindgen(method, getter = roundingIncrement)]
11394 pub fn get_rounding_increment(this: &NumberFormatOptions) -> Option<u32>;
11395 #[wasm_bindgen(method, setter = roundingIncrement)]
11396 pub fn set_rounding_increment(this: &NumberFormatOptions, value: u32);
11397
11398 #[wasm_bindgen(method, getter = trailingZeroDisplay)]
11399 pub fn get_trailing_zero_display(this: &NumberFormatOptions)
11400 -> Option<TrailingZeroDisplay>;
11401 #[wasm_bindgen(method, setter = trailingZeroDisplay)]
11402 pub fn set_trailing_zero_display(this: &NumberFormatOptions, value: TrailingZeroDisplay);
11403 }
11404
11405 impl NumberFormatOptions {
11406 pub fn new() -> NumberFormatOptions {
11407 JsCast::unchecked_into(Object::new())
11408 }
11409 }
11410
11411 impl Default for NumberFormatOptions {
11412 fn default() -> Self {
11413 NumberFormatOptions::new()
11414 }
11415 }
11416
11417 // Intl.ResolvedNumberFormatOptions
11418 #[wasm_bindgen]
11419 extern "C" {
11420 /// Resolved options returned by `Intl.NumberFormat.prototype.resolvedOptions()`.
11421 ///
11422 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/resolvedOptions)
11423 #[wasm_bindgen(extends = NumberFormatOptions)]
11424 #[derive(Clone, Debug)]
11425 pub type ResolvedNumberFormatOptions;
11426
11427 /// The resolved locale string.
11428 #[wasm_bindgen(method, getter = locale)]
11429 pub fn get_locale(this: &ResolvedNumberFormatOptions) -> JsString;
11430 }
11431
11432 // Intl.NumberFormatPart
11433 #[wasm_bindgen]
11434 extern "C" {
11435 /// A part of the formatted number returned by `formatToParts()`.
11436 ///
11437 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatToParts)
11438 #[wasm_bindgen(extends = Object)]
11439 #[derive(Clone, Debug)]
11440 pub type NumberFormatPart;
11441
11442 /// The type of the part (e.g., "integer", "decimal", "fraction", "currency", etc.)
11443 #[wasm_bindgen(method, getter = type)]
11444 pub fn type_(this: &NumberFormatPart) -> NumberFormatPartType;
11445
11446 /// The value of the part.
11447 #[wasm_bindgen(method, getter)]
11448 pub fn value(this: &NumberFormatPart) -> JsString;
11449 }
11450
11451 // Intl.NumberRangeFormatPart
11452 #[wasm_bindgen]
11453 extern "C" {
11454 /// A part of the formatted number range returned by `formatRangeToParts()`.
11455 ///
11456 /// Extends `NumberFormatPart` with a `source` property indicating whether
11457 /// the part is from the start number, end number, or shared between them.
11458 ///
11459 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatRangeToParts)
11460 #[wasm_bindgen(extends = NumberFormatPart)]
11461 #[derive(Clone, Debug)]
11462 pub type NumberRangeFormatPart;
11463
11464 /// The source of the part: "startRange", "endRange", or "shared".
11465 #[wasm_bindgen(method, getter)]
11466 pub fn source(this: &NumberRangeFormatPart) -> RangeSource;
11467 }
11468
11469 // Intl.NumberFormat
11470 #[wasm_bindgen]
11471 extern "C" {
11472 /// The `Intl.NumberFormat` object is a constructor for objects
11473 /// that enable language sensitive number formatting.
11474 ///
11475 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat)
11476 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.NumberFormat")]
11477 #[derive(Clone, Debug)]
11478 pub type NumberFormat;
11479
11480 /// The `Intl.NumberFormat` object is a constructor for objects
11481 /// that enable language sensitive number formatting.
11482 ///
11483 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat)
11484 #[cfg(not(js_sys_unstable_apis))]
11485 #[wasm_bindgen(constructor, js_namespace = Intl)]
11486 pub fn new(locales: &Array, options: &Object) -> NumberFormat;
11487
11488 /// The `Intl.NumberFormat` object is a constructor for objects
11489 /// that enable language sensitive number formatting.
11490 ///
11491 /// Throws a `RangeError` if locales contain invalid values.
11492 ///
11493 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat)
11494 #[cfg(js_sys_unstable_apis)]
11495 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
11496 pub fn new(
11497 locales: &[JsString],
11498 options: &NumberFormatOptions,
11499 ) -> Result<NumberFormat, JsValue>;
11500
11501 /// The Intl.NumberFormat.prototype.format property returns a getter function that
11502 /// formats a number according to the locale and formatting options of this
11503 /// NumberFormat object.
11504 ///
11505 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/format)
11506 #[cfg(not(js_sys_unstable_apis))]
11507 #[wasm_bindgen(method, getter, js_class = "Intl.NumberFormat")]
11508 pub fn format(this: &NumberFormat) -> Function;
11509
11510 /// Formats a number according to the locale and formatting options of this
11511 /// `Intl.NumberFormat` object.
11512 ///
11513 /// Accepts numeric strings for BigInt/arbitrary precision (e.g., `"123n"` → `"123"`,
11514 /// or use E notation: `"1000000E-6"` → `"1"`).
11515 ///
11516 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/format)
11517 #[cfg(js_sys_unstable_apis)]
11518 #[wasm_bindgen(method, js_class = "Intl.NumberFormat")]
11519 pub fn format(this: &NumberFormat, value: &JsString) -> JsString;
11520
11521 /// The `Intl.Numberformat.prototype.formatToParts()` method allows locale-aware
11522 /// formatting of strings produced by NumberTimeFormat formatters.
11523 ///
11524 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/formatToParts)
11525 #[cfg(not(js_sys_unstable_apis))]
11526 #[wasm_bindgen(method, js_class = "Intl.NumberFormat", js_name = formatToParts)]
11527 pub fn format_to_parts(this: &NumberFormat, number: f64) -> Array;
11528
11529 /// The `Intl.NumberFormat.prototype.formatToParts()` method allows locale-aware
11530 /// formatting of strings produced by `Intl.NumberFormat` formatters.
11531 ///
11532 /// Accepts numeric strings for BigInt/arbitrary precision (e.g., `"123n"` → `"123"`,
11533 /// or use E notation: `"1000000E-6"` → `"1"`).
11534 ///
11535 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatToParts)
11536 #[cfg(js_sys_unstable_apis)]
11537 #[wasm_bindgen(method, js_class = "Intl.NumberFormat", js_name = formatToParts)]
11538 pub fn format_to_parts(this: &NumberFormat, value: &JsString) -> Array<NumberFormatPart>;
11539
11540 /// Formats a range of numbers according to the locale and formatting options
11541 /// of this `Intl.NumberFormat` object.
11542 ///
11543 /// Accepts numeric strings for BigInt/arbitrary precision (e.g., `"123n"` → `"123"`,
11544 /// or use E notation: `"1000000E-6"` → `"1"`).
11545 ///
11546 /// Throws a `TypeError` if the values are invalid.
11547 ///
11548 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatRange)
11549 #[wasm_bindgen(method, js_class = "Intl.NumberFormat", js_name = formatRange, catch)]
11550 pub fn format_range(
11551 this: &NumberFormat,
11552 start: &JsString,
11553 end: &JsString,
11554 ) -> Result<JsString, JsValue>;
11555
11556 /// Returns an array of locale-specific tokens representing each part of
11557 /// the formatted number range.
11558 ///
11559 /// Accepts numeric strings for BigInt/arbitrary precision (e.g., `"123n"` → `"123"`,
11560 /// or use E notation: `"1000000E-6"` → `"1"`).
11561 ///
11562 /// Throws a `TypeError` if the values are invalid.
11563 ///
11564 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatRangeToParts)
11565 #[wasm_bindgen(method, js_class = "Intl.NumberFormat", js_name = formatRangeToParts, catch)]
11566 pub fn format_range_to_parts(
11567 this: &NumberFormat,
11568 start: &JsString,
11569 end: &JsString,
11570 ) -> Result<Array<NumberRangeFormatPart>, JsValue>;
11571
11572 /// The `Intl.NumberFormat.prototype.resolvedOptions()` method returns a new
11573 /// object with properties reflecting the locale and number formatting
11574 /// options computed during initialization of this NumberFormat object.
11575 ///
11576 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/resolvedOptions)
11577 #[cfg(not(js_sys_unstable_apis))]
11578 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11579 pub fn resolved_options(this: &NumberFormat) -> Object;
11580
11581 /// The `Intl.NumberFormat.prototype.resolvedOptions()` method returns a new
11582 /// object with properties reflecting the locale and number formatting
11583 /// options computed during initialization of this NumberFormat object.
11584 ///
11585 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/resolvedOptions)
11586 #[cfg(js_sys_unstable_apis)]
11587 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11588 pub fn resolved_options(this: &NumberFormat) -> ResolvedNumberFormatOptions;
11589
11590 /// The `Intl.NumberFormat.supportedLocalesOf()` method returns an array
11591 /// containing those of the provided locales that are supported in number
11592 /// formatting without having to fall back to the runtime's default locale.
11593 ///
11594 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/supportedLocalesOf)
11595 #[cfg(not(js_sys_unstable_apis))]
11596 #[wasm_bindgen(static_method_of = NumberFormat, js_namespace = Intl, js_name = supportedLocalesOf)]
11597 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
11598
11599 /// The `Intl.NumberFormat.supportedLocalesOf()` method returns an array
11600 /// containing those of the provided locales that are supported in number
11601 /// formatting without having to fall back to the runtime's default locale.
11602 ///
11603 /// Throws a `RangeError` if locales contain invalid values.
11604 ///
11605 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/supportedLocalesOf)
11606 #[cfg(js_sys_unstable_apis)]
11607 #[wasm_bindgen(static_method_of = NumberFormat, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
11608 pub fn supported_locales_of(
11609 locales: &[JsString],
11610 options: &LocaleMatcherOptions,
11611 ) -> Result<Array<JsString>, JsValue>;
11612 }
11613
11614 #[cfg(not(js_sys_unstable_apis))]
11615 impl Default for NumberFormat {
11616 fn default() -> Self {
11617 Self::new(
11618 &JsValue::UNDEFINED.unchecked_into(),
11619 &JsValue::UNDEFINED.unchecked_into(),
11620 )
11621 }
11622 }
11623
11624 #[cfg(js_sys_unstable_apis)]
11625 impl Default for NumberFormat {
11626 fn default() -> Self {
11627 Self::new(&[], &Default::default()).unwrap()
11628 }
11629 }
11630
11631 // Intl.PluralRulesOptions
11632 #[wasm_bindgen]
11633 extern "C" {
11634 /// Options for `Intl.PluralRules` constructor.
11635 ///
11636 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules/PluralRules#options)
11637 #[wasm_bindgen(extends = Object)]
11638 #[derive(Clone, Debug)]
11639 pub type PluralRulesOptions;
11640
11641 #[wasm_bindgen(method, getter = localeMatcher)]
11642 pub fn get_locale_matcher(this: &PluralRulesOptions) -> Option<LocaleMatcher>;
11643 #[wasm_bindgen(method, setter = localeMatcher)]
11644 pub fn set_locale_matcher(this: &PluralRulesOptions, value: LocaleMatcher);
11645
11646 #[wasm_bindgen(method, getter = type)]
11647 pub fn get_type(this: &PluralRulesOptions) -> Option<PluralRulesType>;
11648 #[wasm_bindgen(method, setter = type)]
11649 pub fn set_type(this: &PluralRulesOptions, value: PluralRulesType);
11650
11651 #[wasm_bindgen(method, getter = minimumIntegerDigits)]
11652 pub fn get_minimum_integer_digits(this: &PluralRulesOptions) -> Option<u8>;
11653 #[wasm_bindgen(method, setter = minimumIntegerDigits)]
11654 pub fn set_minimum_integer_digits(this: &PluralRulesOptions, value: u8);
11655
11656 #[wasm_bindgen(method, getter = minimumFractionDigits)]
11657 pub fn get_minimum_fraction_digits(this: &PluralRulesOptions) -> Option<u8>;
11658 #[wasm_bindgen(method, setter = minimumFractionDigits)]
11659 pub fn set_minimum_fraction_digits(this: &PluralRulesOptions, value: u8);
11660
11661 #[wasm_bindgen(method, getter = maximumFractionDigits)]
11662 pub fn get_maximum_fraction_digits(this: &PluralRulesOptions) -> Option<u8>;
11663 #[wasm_bindgen(method, setter = maximumFractionDigits)]
11664 pub fn set_maximum_fraction_digits(this: &PluralRulesOptions, value: u8);
11665
11666 #[wasm_bindgen(method, getter = minimumSignificantDigits)]
11667 pub fn get_minimum_significant_digits(this: &PluralRulesOptions) -> Option<u8>;
11668 #[wasm_bindgen(method, setter = minimumSignificantDigits)]
11669 pub fn set_minimum_significant_digits(this: &PluralRulesOptions, value: u8);
11670
11671 #[wasm_bindgen(method, getter = maximumSignificantDigits)]
11672 pub fn get_maximum_significant_digits(this: &PluralRulesOptions) -> Option<u8>;
11673 #[wasm_bindgen(method, setter = maximumSignificantDigits)]
11674 pub fn set_maximum_significant_digits(this: &PluralRulesOptions, value: u8);
11675
11676 #[wasm_bindgen(method, getter = roundingPriority)]
11677 pub fn get_rounding_priority(this: &PluralRulesOptions) -> Option<RoundingPriority>;
11678 #[wasm_bindgen(method, setter = roundingPriority)]
11679 pub fn set_rounding_priority(this: &PluralRulesOptions, value: RoundingPriority);
11680
11681 #[wasm_bindgen(method, getter = roundingIncrement)]
11682 pub fn get_rounding_increment(this: &PluralRulesOptions) -> Option<u32>;
11683 #[wasm_bindgen(method, setter = roundingIncrement)]
11684 pub fn set_rounding_increment(this: &PluralRulesOptions, value: u32);
11685
11686 #[wasm_bindgen(method, getter = roundingMode)]
11687 pub fn get_rounding_mode(this: &PluralRulesOptions) -> Option<RoundingMode>;
11688 #[wasm_bindgen(method, setter = roundingMode)]
11689 pub fn set_rounding_mode(this: &PluralRulesOptions, value: RoundingMode);
11690
11691 #[wasm_bindgen(method, getter = trailingZeroDisplay)]
11692 pub fn get_trailing_zero_display(this: &PluralRulesOptions) -> Option<TrailingZeroDisplay>;
11693 #[wasm_bindgen(method, setter = trailingZeroDisplay)]
11694 pub fn set_trailing_zero_display(this: &PluralRulesOptions, value: TrailingZeroDisplay);
11695 }
11696
11697 impl PluralRulesOptions {
11698 pub fn new() -> PluralRulesOptions {
11699 JsCast::unchecked_into(Object::new())
11700 }
11701 }
11702
11703 impl Default for PluralRulesOptions {
11704 fn default() -> Self {
11705 PluralRulesOptions::new()
11706 }
11707 }
11708
11709 // Intl.ResolvedPluralRulesOptions
11710 #[wasm_bindgen]
11711 extern "C" {
11712 /// Resolved options returned by `Intl.PluralRules.prototype.resolvedOptions()`.
11713 ///
11714 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules/resolvedOptions)
11715 #[wasm_bindgen(extends = PluralRulesOptions)]
11716 #[derive(Clone, Debug)]
11717 pub type ResolvedPluralRulesOptions;
11718
11719 /// The resolved locale string.
11720 #[wasm_bindgen(method, getter = locale)]
11721 pub fn get_locale(this: &ResolvedPluralRulesOptions) -> JsString;
11722
11723 /// The plural categories used by the locale.
11724 #[wasm_bindgen(method, getter = pluralCategories)]
11725 pub fn get_plural_categories(this: &ResolvedPluralRulesOptions) -> Array<JsString>;
11726 }
11727
11728 // Intl.PluralRules
11729 #[wasm_bindgen]
11730 extern "C" {
11731 /// The `Intl.PluralRules` object is a constructor for objects
11732 /// that enable plural sensitive formatting and plural language rules.
11733 ///
11734 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules)
11735 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.PluralRules")]
11736 #[derive(Clone, Debug)]
11737 pub type PluralRules;
11738
11739 /// The `Intl.PluralRules` object is a constructor for objects
11740 /// that enable plural sensitive formatting and plural language rules.
11741 ///
11742 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules)
11743 #[cfg(not(js_sys_unstable_apis))]
11744 #[wasm_bindgen(constructor, js_namespace = Intl)]
11745 pub fn new(locales: &Array, options: &Object) -> PluralRules;
11746
11747 /// The `Intl.PluralRules` object is a constructor for objects
11748 /// that enable plural sensitive formatting and plural language rules.
11749 ///
11750 /// Throws a `RangeError` if locales contain invalid values.
11751 ///
11752 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules)
11753 #[cfg(js_sys_unstable_apis)]
11754 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
11755 pub fn new(
11756 locales: &[JsString],
11757 options: &PluralRulesOptions,
11758 ) -> Result<PluralRules, JsValue>;
11759
11760 /// The `Intl.PluralRules.prototype.resolvedOptions()` method returns a new
11761 /// object with properties reflecting the locale and plural formatting
11762 /// options computed during initialization of this PluralRules object.
11763 ///
11764 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/resolvedOptions)
11765 #[cfg(not(js_sys_unstable_apis))]
11766 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11767 pub fn resolved_options(this: &PluralRules) -> Object;
11768
11769 /// The `Intl.PluralRules.prototype.resolvedOptions()` method returns a new
11770 /// object with properties reflecting the locale and plural formatting
11771 /// options computed during initialization of this PluralRules object.
11772 ///
11773 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/resolvedOptions)
11774 #[cfg(js_sys_unstable_apis)]
11775 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11776 pub fn resolved_options(this: &PluralRules) -> ResolvedPluralRulesOptions;
11777
11778 /// The `Intl.PluralRules.prototype.select()` method returns a String indicating
11779 /// which plural rule to use for locale-aware formatting.
11780 ///
11781 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/select)
11782 #[cfg(not(js_sys_unstable_apis))]
11783 #[wasm_bindgen(method, js_namespace = Intl)]
11784 pub fn select(this: &PluralRules, number: f64) -> JsString;
11785
11786 /// The `Intl.PluralRules.prototype.select()` method returns a String indicating
11787 /// which plural rule to use for locale-aware formatting.
11788 ///
11789 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/select)
11790 #[cfg(js_sys_unstable_apis)]
11791 #[wasm_bindgen(method, js_namespace = Intl)]
11792 pub fn select(this: &PluralRules, number: f64) -> PluralCategory;
11793
11794 /// The `Intl.PluralRules.prototype.selectRange()` method returns a string indicating
11795 /// which plural rule to use for locale-aware formatting of a range of numbers.
11796 ///
11797 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules/selectRange)
11798 #[cfg(not(js_sys_unstable_apis))]
11799 #[wasm_bindgen(method, js_namespace = Intl, js_name = selectRange)]
11800 pub fn select_range(this: &PluralRules, start: f64, end: f64) -> JsString;
11801
11802 /// The `Intl.PluralRules.prototype.selectRange()` method returns a string indicating
11803 /// which plural rule to use for locale-aware formatting of a range of numbers.
11804 ///
11805 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules/selectRange)
11806 #[cfg(js_sys_unstable_apis)]
11807 #[wasm_bindgen(method, js_namespace = Intl, js_name = selectRange)]
11808 pub fn select_range(this: &PluralRules, start: f64, end: f64) -> PluralCategory;
11809
11810 /// The `Intl.PluralRules.supportedLocalesOf()` method returns an array
11811 /// containing those of the provided locales that are supported in plural
11812 /// formatting without having to fall back to the runtime's default locale.
11813 ///
11814 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/supportedLocalesOf)
11815 #[cfg(not(js_sys_unstable_apis))]
11816 #[wasm_bindgen(static_method_of = PluralRules, js_namespace = Intl, js_name = supportedLocalesOf)]
11817 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
11818
11819 /// The `Intl.PluralRules.supportedLocalesOf()` method returns an array
11820 /// containing those of the provided locales that are supported in plural
11821 /// formatting without having to fall back to the runtime's default locale.
11822 ///
11823 /// Throws a `RangeError` if locales contain invalid values.
11824 ///
11825 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/supportedLocalesOf)
11826 #[cfg(js_sys_unstable_apis)]
11827 #[wasm_bindgen(static_method_of = PluralRules, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
11828 pub fn supported_locales_of(
11829 locales: &[JsString],
11830 options: &LocaleMatcherOptions,
11831 ) -> Result<Array<JsString>, JsValue>;
11832 }
11833
11834 #[cfg(not(js_sys_unstable_apis))]
11835 impl Default for PluralRules {
11836 fn default() -> Self {
11837 Self::new(
11838 &JsValue::UNDEFINED.unchecked_into(),
11839 &JsValue::UNDEFINED.unchecked_into(),
11840 )
11841 }
11842 }
11843
11844 #[cfg(js_sys_unstable_apis)]
11845 impl Default for PluralRules {
11846 fn default() -> Self {
11847 Self::new(&[], &Default::default()).unwrap()
11848 }
11849 }
11850
11851 // Intl.RelativeTimeFormat
11852 #[wasm_bindgen]
11853 extern "C" {
11854 /// The `Intl.RelativeTimeFormat` object is a constructor for objects
11855 /// that enable language-sensitive relative time formatting.
11856 ///
11857 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat)
11858 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.RelativeTimeFormat")]
11859 #[derive(Clone, Debug)]
11860 pub type RelativeTimeFormat;
11861
11862 /// The `Intl.RelativeTimeFormat` object is a constructor for objects
11863 /// that enable language-sensitive relative time formatting.
11864 ///
11865 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat)
11866 #[cfg(not(js_sys_unstable_apis))]
11867 #[wasm_bindgen(constructor, js_namespace = Intl)]
11868 pub fn new(locales: &Array, options: &Object) -> RelativeTimeFormat;
11869
11870 /// The `Intl.RelativeTimeFormat` object is a constructor for objects
11871 /// that enable language-sensitive relative time formatting.
11872 ///
11873 /// Throws a `RangeError` if locales contain invalid values.
11874 ///
11875 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat)
11876 #[cfg(js_sys_unstable_apis)]
11877 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
11878 pub fn new(locales: &[JsString]) -> Result<RelativeTimeFormat, JsValue>;
11879
11880 /// The `Intl.RelativeTimeFormat` object is a constructor for objects
11881 /// that enable language-sensitive relative time formatting.
11882 ///
11883 /// Throws a `RangeError` if locales or options contain invalid values.
11884 ///
11885 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat)
11886 #[cfg(js_sys_unstable_apis)]
11887 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
11888 pub fn new_with_options(
11889 locales: &[JsString],
11890 options: &RelativeTimeFormatOptions,
11891 ) -> Result<RelativeTimeFormat, JsValue>;
11892
11893 /// The `Intl.RelativeTimeFormat.prototype.format` method formats a `value` and `unit`
11894 /// according to the locale and formatting options of this Intl.RelativeTimeFormat object.
11895 ///
11896 /// Throws a `RangeError` if unit is invalid.
11897 ///
11898 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/format)
11899 #[cfg(not(js_sys_unstable_apis))]
11900 #[wasm_bindgen(method, js_class = "Intl.RelativeTimeFormat")]
11901 pub fn format(this: &RelativeTimeFormat, value: f64, unit: &str) -> JsString;
11902
11903 /// The `Intl.RelativeTimeFormat.prototype.format` method formats a `value` and `unit`
11904 /// according to the locale and formatting options of this Intl.RelativeTimeFormat object.
11905 ///
11906 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/format)
11907 #[cfg(js_sys_unstable_apis)]
11908 #[wasm_bindgen(method, js_class = "Intl.RelativeTimeFormat")]
11909 pub fn format(
11910 this: &RelativeTimeFormat,
11911 value: f64,
11912 unit: RelativeTimeFormatUnit,
11913 ) -> JsString;
11914
11915 /// The `Intl.RelativeTimeFormat.prototype.formatToParts()` method returns an array of
11916 /// objects representing the relative time format in parts that can be used for custom locale-aware formatting.
11917 ///
11918 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/formatToParts)
11919 #[cfg(not(js_sys_unstable_apis))]
11920 #[wasm_bindgen(method, js_class = "Intl.RelativeTimeFormat", js_name = formatToParts)]
11921 pub fn format_to_parts(this: &RelativeTimeFormat, value: f64, unit: &str) -> Array;
11922
11923 /// The `Intl.RelativeTimeFormat.prototype.formatToParts()` method returns an array of
11924 /// objects representing the relative time format in parts that can be used for custom locale-aware formatting.
11925 ///
11926 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/formatToParts)
11927 #[cfg(js_sys_unstable_apis)]
11928 #[wasm_bindgen(method, js_class = "Intl.RelativeTimeFormat", js_name = formatToParts)]
11929 pub fn format_to_parts(
11930 this: &RelativeTimeFormat,
11931 value: f64,
11932 unit: RelativeTimeFormatUnit,
11933 ) -> Array<RelativeTimeFormatPart>;
11934
11935 /// The `Intl.RelativeTimeFormat.prototype.resolvedOptions()` method returns a new
11936 /// object with properties reflecting the locale and relative time formatting
11937 /// options computed during initialization of this RelativeTimeFormat object.
11938 ///
11939 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/resolvedOptions)
11940 #[cfg(not(js_sys_unstable_apis))]
11941 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11942 pub fn resolved_options(this: &RelativeTimeFormat) -> Object;
11943
11944 /// The `Intl.RelativeTimeFormat.prototype.resolvedOptions()` method returns a new
11945 /// object with properties reflecting the locale and relative time formatting
11946 /// options computed during initialization of this RelativeTimeFormat object.
11947 ///
11948 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/resolvedOptions)
11949 #[cfg(js_sys_unstable_apis)]
11950 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11951 pub fn resolved_options(this: &RelativeTimeFormat) -> ResolvedRelativeTimeFormatOptions;
11952
11953 /// The `Intl.RelativeTimeFormat.supportedLocalesOf()` method returns an array
11954 /// containing those of the provided locales that are supported in date and time
11955 /// formatting without having to fall back to the runtime's default locale.
11956 ///
11957 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RelativeTimeFormat/supportedLocalesOf)
11958 #[cfg(not(js_sys_unstable_apis))]
11959 #[wasm_bindgen(static_method_of = RelativeTimeFormat, js_namespace = Intl, js_name = supportedLocalesOf)]
11960 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
11961
11962 /// The `Intl.RelativeTimeFormat.supportedLocalesOf()` method returns an array
11963 /// containing those of the provided locales that are supported in date and time
11964 /// formatting without having to fall back to the runtime's default locale.
11965 ///
11966 /// Throws a `RangeError` if locales contain invalid values.
11967 ///
11968 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RelativeTimeFormat/supportedLocalesOf)
11969 #[cfg(js_sys_unstable_apis)]
11970 #[wasm_bindgen(static_method_of = RelativeTimeFormat, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
11971 pub fn supported_locales_of(
11972 locales: &[JsString],
11973 options: &LocaleMatcherOptions,
11974 ) -> Result<Array<JsString>, JsValue>;
11975 }
11976
11977 #[cfg(not(js_sys_unstable_apis))]
11978 impl Default for RelativeTimeFormat {
11979 fn default() -> Self {
11980 Self::new(
11981 &JsValue::UNDEFINED.unchecked_into(),
11982 &JsValue::UNDEFINED.unchecked_into(),
11983 )
11984 }
11985 }
11986
11987 #[cfg(js_sys_unstable_apis)]
11988 impl Default for RelativeTimeFormat {
11989 fn default() -> Self {
11990 Self::new(&[]).unwrap()
11991 }
11992 }
11993
11994 // Intl.ListFormatOptions
11995 #[wasm_bindgen]
11996 extern "C" {
11997 /// Options for `Intl.ListFormat` constructor.
11998 ///
11999 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/ListFormat#options)
12000 #[wasm_bindgen(extends = Object)]
12001 #[derive(Clone, Debug)]
12002 pub type ListFormatOptions;
12003
12004 #[wasm_bindgen(method, getter = localeMatcher)]
12005 pub fn get_locale_matcher(this: &ListFormatOptions) -> Option<LocaleMatcher>;
12006 #[wasm_bindgen(method, setter = localeMatcher)]
12007 pub fn set_locale_matcher(this: &ListFormatOptions, value: LocaleMatcher);
12008
12009 #[wasm_bindgen(method, getter = type)]
12010 pub fn get_type(this: &ListFormatOptions) -> Option<ListFormatType>;
12011 #[wasm_bindgen(method, setter = type)]
12012 pub fn set_type(this: &ListFormatOptions, value: ListFormatType);
12013
12014 #[wasm_bindgen(method, getter = style)]
12015 pub fn get_style(this: &ListFormatOptions) -> Option<ListFormatStyle>;
12016 #[wasm_bindgen(method, setter = style)]
12017 pub fn set_style(this: &ListFormatOptions, value: ListFormatStyle);
12018 }
12019
12020 impl ListFormatOptions {
12021 pub fn new() -> ListFormatOptions {
12022 JsCast::unchecked_into(Object::new())
12023 }
12024 }
12025
12026 impl Default for ListFormatOptions {
12027 fn default() -> Self {
12028 ListFormatOptions::new()
12029 }
12030 }
12031
12032 // Intl.ResolvedListFormatOptions
12033 #[wasm_bindgen]
12034 extern "C" {
12035 /// Resolved options returned by `Intl.ListFormat.prototype.resolvedOptions()`.
12036 ///
12037 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/resolvedOptions)
12038 #[wasm_bindgen(extends = ListFormatOptions)]
12039 #[derive(Clone, Debug)]
12040 pub type ResolvedListFormatOptions;
12041
12042 /// The resolved locale string.
12043 #[wasm_bindgen(method, getter = locale)]
12044 pub fn get_locale(this: &ResolvedListFormatOptions) -> JsString;
12045 }
12046
12047 // Intl.ListFormatPart
12048 #[wasm_bindgen]
12049 extern "C" {
12050 /// A part of the formatted list returned by `formatToParts()`.
12051 ///
12052 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/formatToParts)
12053 #[wasm_bindgen(extends = Object)]
12054 #[derive(Clone, Debug)]
12055 pub type ListFormatPart;
12056
12057 /// The type of the part ("element" or "literal").
12058 #[wasm_bindgen(method, getter = type)]
12059 pub fn type_(this: &ListFormatPart) -> ListFormatPartType;
12060
12061 /// The value of the part.
12062 #[wasm_bindgen(method, getter)]
12063 pub fn value(this: &ListFormatPart) -> JsString;
12064 }
12065
12066 // Intl.ListFormat
12067 #[wasm_bindgen]
12068 extern "C" {
12069 /// The `Intl.ListFormat` object enables language-sensitive list formatting.
12070 ///
12071 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat)
12072 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.ListFormat")]
12073 #[derive(Clone, Debug)]
12074 pub type ListFormat;
12075
12076 /// Creates a new `Intl.ListFormat` object.
12077 ///
12078 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/ListFormat)
12079 #[cfg(not(js_sys_unstable_apis))]
12080 #[wasm_bindgen(constructor, js_namespace = Intl)]
12081 pub fn new(locales: &Array, options: &Object) -> ListFormat;
12082
12083 /// Creates a new `Intl.ListFormat` object.
12084 ///
12085 /// Throws a `RangeError` if locales or options contain invalid values.
12086 ///
12087 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/ListFormat)
12088 #[cfg(js_sys_unstable_apis)]
12089 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
12090 pub fn new(
12091 locales: &[JsString],
12092 options: &ListFormatOptions,
12093 ) -> Result<ListFormat, JsValue>;
12094
12095 /// Formats a list of strings according to the locale and options.
12096 ///
12097 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/format)
12098 #[cfg(not(js_sys_unstable_apis))]
12099 #[wasm_bindgen(method, js_class = "Intl.ListFormat")]
12100 pub fn format(this: &ListFormat, list: &Array) -> JsString;
12101
12102 /// Formats a list of strings according to the locale and options.
12103 ///
12104 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/format)
12105 #[cfg(js_sys_unstable_apis)]
12106 #[wasm_bindgen(method, js_class = "Intl.ListFormat")]
12107 pub fn format(this: &ListFormat, list: &[JsString]) -> JsString;
12108
12109 /// Returns an array of objects representing the list in parts.
12110 ///
12111 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/formatToParts)
12112 #[cfg(not(js_sys_unstable_apis))]
12113 #[wasm_bindgen(method, js_class = "Intl.ListFormat", js_name = formatToParts)]
12114 pub fn format_to_parts(this: &ListFormat, list: &Array) -> Array;
12115
12116 /// Returns an array of objects representing the list in parts.
12117 ///
12118 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/formatToParts)
12119 #[cfg(js_sys_unstable_apis)]
12120 #[wasm_bindgen(method, js_class = "Intl.ListFormat", js_name = formatToParts)]
12121 pub fn format_to_parts(this: &ListFormat, list: &[JsString]) -> Array<ListFormatPart>;
12122
12123 /// Returns an object with properties reflecting the options used.
12124 ///
12125 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/resolvedOptions)
12126 #[cfg(not(js_sys_unstable_apis))]
12127 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
12128 pub fn resolved_options(this: &ListFormat) -> Object;
12129
12130 /// Returns an object with properties reflecting the options used.
12131 ///
12132 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/resolvedOptions)
12133 #[cfg(js_sys_unstable_apis)]
12134 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
12135 pub fn resolved_options(this: &ListFormat) -> ResolvedListFormatOptions;
12136
12137 /// Returns an array of supported locales.
12138 ///
12139 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/supportedLocalesOf)
12140 #[cfg(not(js_sys_unstable_apis))]
12141 #[wasm_bindgen(static_method_of = ListFormat, js_namespace = Intl, js_name = supportedLocalesOf)]
12142 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
12143
12144 /// Returns an array of supported locales.
12145 ///
12146 /// Throws a `RangeError` if locales contain invalid values.
12147 ///
12148 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/supportedLocalesOf)
12149 #[cfg(js_sys_unstable_apis)]
12150 #[wasm_bindgen(static_method_of = ListFormat, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
12151 pub fn supported_locales_of(
12152 locales: &[JsString],
12153 options: &LocaleMatcherOptions,
12154 ) -> Result<Array<JsString>, JsValue>;
12155 }
12156
12157 #[cfg(not(js_sys_unstable_apis))]
12158 impl Default for ListFormat {
12159 fn default() -> Self {
12160 Self::new(
12161 &JsValue::UNDEFINED.unchecked_into(),
12162 &JsValue::UNDEFINED.unchecked_into(),
12163 )
12164 }
12165 }
12166
12167 #[cfg(js_sys_unstable_apis)]
12168 impl Default for ListFormat {
12169 fn default() -> Self {
12170 Self::new(&[], &Default::default()).unwrap()
12171 }
12172 }
12173
12174 // Intl.SegmenterOptions
12175 #[wasm_bindgen]
12176 extern "C" {
12177 /// Options for `Intl.Segmenter` constructor.
12178 ///
12179 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/Segmenter#options)
12180 #[wasm_bindgen(extends = Object)]
12181 #[derive(Clone, Debug)]
12182 pub type SegmenterOptions;
12183
12184 #[wasm_bindgen(method, getter = localeMatcher)]
12185 pub fn get_locale_matcher(this: &SegmenterOptions) -> Option<LocaleMatcher>;
12186 #[wasm_bindgen(method, setter = localeMatcher)]
12187 pub fn set_locale_matcher(this: &SegmenterOptions, value: LocaleMatcher);
12188
12189 #[wasm_bindgen(method, getter = granularity)]
12190 pub fn get_granularity(this: &SegmenterOptions) -> Option<SegmenterGranularity>;
12191 #[wasm_bindgen(method, setter = granularity)]
12192 pub fn set_granularity(this: &SegmenterOptions, value: SegmenterGranularity);
12193 }
12194
12195 impl SegmenterOptions {
12196 pub fn new() -> SegmenterOptions {
12197 JsCast::unchecked_into(Object::new())
12198 }
12199 }
12200
12201 impl Default for SegmenterOptions {
12202 fn default() -> Self {
12203 SegmenterOptions::new()
12204 }
12205 }
12206
12207 // Intl.ResolvedSegmenterOptions
12208 #[wasm_bindgen]
12209 extern "C" {
12210 /// Resolved options returned by `Intl.Segmenter.prototype.resolvedOptions()`.
12211 ///
12212 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/resolvedOptions)
12213 #[wasm_bindgen(extends = SegmenterOptions)]
12214 #[derive(Clone, Debug)]
12215 pub type ResolvedSegmenterOptions;
12216
12217 /// The resolved locale string.
12218 #[wasm_bindgen(method, getter = locale)]
12219 pub fn get_locale(this: &ResolvedSegmenterOptions) -> JsString;
12220 }
12221
12222 // Intl.SegmentData
12223 #[wasm_bindgen]
12224 extern "C" {
12225 /// Data about a segment returned by the Segments iterator.
12226 ///
12227 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/segment/Segments#segment_data)
12228 #[wasm_bindgen(extends = Object)]
12229 #[derive(Clone, Debug)]
12230 pub type SegmentData;
12231
12232 /// The segment string.
12233 #[wasm_bindgen(method, getter)]
12234 pub fn segment(this: &SegmentData) -> JsString;
12235
12236 /// The index of the segment in the original string.
12237 #[wasm_bindgen(method, getter)]
12238 pub fn index(this: &SegmentData) -> u32;
12239
12240 /// The original input string.
12241 #[wasm_bindgen(method, getter)]
12242 pub fn input(this: &SegmentData) -> JsString;
12243
12244 /// Whether the segment is word-like (only for word granularity).
12245 #[wasm_bindgen(method, getter = isWordLike)]
12246 pub fn is_word_like(this: &SegmentData) -> Option<bool>;
12247 }
12248
12249 // Intl.Segments
12250 #[wasm_bindgen]
12251 extern "C" {
12252 /// The Segments object is an iterable collection of segments of a string.
12253 ///
12254 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/segment/Segments)
12255 #[wasm_bindgen(extends = Object)]
12256 #[derive(Clone, Debug)]
12257 pub type Segments;
12258
12259 /// Returns segment data for the segment containing the character at the given index.
12260 ///
12261 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/segment/Segments/containing)
12262 #[wasm_bindgen(method)]
12263 pub fn containing(this: &Segments, index: u32) -> Option<SegmentData>;
12264 }
12265
12266 // Intl.Segmenter
12267 #[wasm_bindgen]
12268 extern "C" {
12269 /// The `Intl.Segmenter` object enables locale-sensitive text segmentation.
12270 ///
12271 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter)
12272 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.Segmenter")]
12273 #[derive(Clone, Debug)]
12274 pub type Segmenter;
12275
12276 /// Creates a new `Intl.Segmenter` object.
12277 ///
12278 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/Segmenter)
12279 #[cfg(not(js_sys_unstable_apis))]
12280 #[wasm_bindgen(constructor, js_namespace = Intl)]
12281 pub fn new(locales: &Array, options: &Object) -> Segmenter;
12282
12283 /// Creates a new `Intl.Segmenter` object.
12284 ///
12285 /// Throws a `RangeError` if locales or options contain invalid values.
12286 ///
12287 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/Segmenter)
12288 #[cfg(js_sys_unstable_apis)]
12289 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
12290 pub fn new(locales: &[JsString], options: &SegmenterOptions) -> Result<Segmenter, JsValue>;
12291
12292 /// Returns a Segments object containing the segments of the input string.
12293 ///
12294 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/segment)
12295 #[wasm_bindgen(method, js_class = "Intl.Segmenter")]
12296 pub fn segment(this: &Segmenter, input: &str) -> Segments;
12297
12298 /// Returns an object with properties reflecting the options used.
12299 ///
12300 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/resolvedOptions)
12301 #[cfg(not(js_sys_unstable_apis))]
12302 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
12303 pub fn resolved_options(this: &Segmenter) -> Object;
12304
12305 /// Returns an object with properties reflecting the options used.
12306 ///
12307 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/resolvedOptions)
12308 #[cfg(js_sys_unstable_apis)]
12309 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
12310 pub fn resolved_options(this: &Segmenter) -> ResolvedSegmenterOptions;
12311
12312 /// Returns an array of supported locales.
12313 ///
12314 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/supportedLocalesOf)
12315 #[cfg(not(js_sys_unstable_apis))]
12316 #[wasm_bindgen(static_method_of = Segmenter, js_namespace = Intl, js_name = supportedLocalesOf)]
12317 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
12318
12319 /// Returns an array of supported locales.
12320 ///
12321 /// Throws a `RangeError` if locales contain invalid values.
12322 ///
12323 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/supportedLocalesOf)
12324 #[cfg(js_sys_unstable_apis)]
12325 #[wasm_bindgen(static_method_of = Segmenter, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
12326 pub fn supported_locales_of(
12327 locales: &[JsString],
12328 options: &LocaleMatcherOptions,
12329 ) -> Result<Array<JsString>, JsValue>;
12330 }
12331
12332 #[cfg(not(js_sys_unstable_apis))]
12333 impl Default for Segmenter {
12334 fn default() -> Self {
12335 Self::new(
12336 &JsValue::UNDEFINED.unchecked_into(),
12337 &JsValue::UNDEFINED.unchecked_into(),
12338 )
12339 }
12340 }
12341
12342 #[cfg(js_sys_unstable_apis)]
12343 impl Default for Segmenter {
12344 fn default() -> Self {
12345 Self::new(&[], &Default::default()).unwrap()
12346 }
12347 }
12348
12349 // Intl.DisplayNamesOptions
12350 #[wasm_bindgen]
12351 extern "C" {
12352 /// Options for `Intl.DisplayNames` constructor.
12353 ///
12354 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/DisplayNames#options)
12355 #[wasm_bindgen(extends = Object)]
12356 #[derive(Clone, Debug)]
12357 pub type DisplayNamesOptions;
12358
12359 #[wasm_bindgen(method, getter = localeMatcher)]
12360 pub fn get_locale_matcher(this: &DisplayNamesOptions) -> Option<LocaleMatcher>;
12361 #[wasm_bindgen(method, setter = localeMatcher)]
12362 pub fn set_locale_matcher(this: &DisplayNamesOptions, value: LocaleMatcher);
12363
12364 #[wasm_bindgen(method, getter = type)]
12365 pub fn get_type(this: &DisplayNamesOptions) -> Option<DisplayNamesType>;
12366 #[wasm_bindgen(method, setter = type)]
12367 pub fn set_type(this: &DisplayNamesOptions, value: DisplayNamesType);
12368
12369 #[wasm_bindgen(method, getter = style)]
12370 pub fn get_style(this: &DisplayNamesOptions) -> Option<DisplayNamesStyle>;
12371 #[wasm_bindgen(method, setter = style)]
12372 pub fn set_style(this: &DisplayNamesOptions, value: DisplayNamesStyle);
12373
12374 #[wasm_bindgen(method, getter = fallback)]
12375 pub fn get_fallback(this: &DisplayNamesOptions) -> Option<DisplayNamesFallback>;
12376 #[wasm_bindgen(method, setter = fallback)]
12377 pub fn set_fallback(this: &DisplayNamesOptions, value: DisplayNamesFallback);
12378
12379 #[wasm_bindgen(method, getter = languageDisplay)]
12380 pub fn get_language_display(
12381 this: &DisplayNamesOptions,
12382 ) -> Option<DisplayNamesLanguageDisplay>;
12383 #[wasm_bindgen(method, setter = languageDisplay)]
12384 pub fn set_language_display(this: &DisplayNamesOptions, value: DisplayNamesLanguageDisplay);
12385 }
12386
12387 impl DisplayNamesOptions {
12388 pub fn new() -> DisplayNamesOptions {
12389 JsCast::unchecked_into(Object::new())
12390 }
12391 }
12392
12393 impl Default for DisplayNamesOptions {
12394 fn default() -> Self {
12395 DisplayNamesOptions::new()
12396 }
12397 }
12398
12399 // Intl.ResolvedDisplayNamesOptions
12400 #[wasm_bindgen]
12401 extern "C" {
12402 /// Resolved options returned by `Intl.DisplayNames.prototype.resolvedOptions()`.
12403 ///
12404 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/resolvedOptions)
12405 #[wasm_bindgen(extends = DisplayNamesOptions)]
12406 #[derive(Clone, Debug)]
12407 pub type ResolvedDisplayNamesOptions;
12408
12409 /// The resolved locale string.
12410 #[wasm_bindgen(method, getter = locale)]
12411 pub fn get_locale(this: &ResolvedDisplayNamesOptions) -> JsString;
12412 }
12413
12414 // Intl.DisplayNames
12415 #[wasm_bindgen]
12416 extern "C" {
12417 /// The `Intl.DisplayNames` object enables the consistent translation of
12418 /// language, region, and script display names.
12419 ///
12420 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames)
12421 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.DisplayNames")]
12422 #[derive(Clone, Debug)]
12423 pub type DisplayNames;
12424
12425 /// Creates a new `Intl.DisplayNames` object.
12426 ///
12427 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/DisplayNames)
12428 #[cfg(not(js_sys_unstable_apis))]
12429 #[wasm_bindgen(constructor, js_namespace = Intl)]
12430 pub fn new(locales: &Array, options: &Object) -> DisplayNames;
12431
12432 /// Creates a new `Intl.DisplayNames` object.
12433 ///
12434 /// Throws a `RangeError` if locales or options contain invalid values.
12435 ///
12436 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/DisplayNames)
12437 #[cfg(js_sys_unstable_apis)]
12438 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
12439 pub fn new(
12440 locales: &[JsString],
12441 options: &DisplayNamesOptions,
12442 ) -> Result<DisplayNames, JsValue>;
12443
12444 /// Returns the display name for the given code.
12445 ///
12446 /// Returns `undefined` if fallback is "none" and no name is available.
12447 ///
12448 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/of)
12449 #[wasm_bindgen(method, js_class = "Intl.DisplayNames")]
12450 pub fn of(this: &DisplayNames, code: &str) -> Option<JsString>;
12451
12452 /// Returns an object with properties reflecting the options used.
12453 ///
12454 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/resolvedOptions)
12455 #[cfg(not(js_sys_unstable_apis))]
12456 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
12457 pub fn resolved_options(this: &DisplayNames) -> Object;
12458
12459 /// Returns an object with properties reflecting the options used.
12460 ///
12461 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/resolvedOptions)
12462 #[cfg(js_sys_unstable_apis)]
12463 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
12464 pub fn resolved_options(this: &DisplayNames) -> ResolvedDisplayNamesOptions;
12465
12466 /// Returns an array of supported locales.
12467 ///
12468 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/supportedLocalesOf)
12469 #[cfg(not(js_sys_unstable_apis))]
12470 #[wasm_bindgen(static_method_of = DisplayNames, js_namespace = Intl, js_name = supportedLocalesOf)]
12471 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
12472
12473 /// Returns an array of supported locales.
12474 ///
12475 /// Throws a `RangeError` if locales contain invalid values.
12476 ///
12477 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/supportedLocalesOf)
12478 #[cfg(js_sys_unstable_apis)]
12479 #[wasm_bindgen(static_method_of = DisplayNames, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
12480 pub fn supported_locales_of(
12481 locales: &[JsString],
12482 options: &LocaleMatcherOptions,
12483 ) -> Result<Array<JsString>, JsValue>;
12484 }
12485
12486 // Intl.Locale
12487 #[wasm_bindgen]
12488 extern "C" {
12489 /// The `Intl.Locale` object is a standard built-in property of the Intl object
12490 /// that represents a Unicode locale identifier.
12491 ///
12492 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale)
12493 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.Locale")]
12494 #[derive(Clone, Debug)]
12495 pub type Locale;
12496
12497 /// Creates a new `Intl.Locale` object.
12498 ///
12499 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/Locale)
12500 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
12501 pub fn new(tag: &str) -> Result<Locale, JsValue>;
12502
12503 /// Creates a new `Intl.Locale` object with options.
12504 ///
12505 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/Locale)
12506 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
12507 pub fn new_with_options(tag: &str, options: &Object) -> Result<Locale, JsValue>;
12508
12509 /// The base name of the locale (language + region + script).
12510 ///
12511 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/baseName)
12512 #[wasm_bindgen(method, getter = baseName)]
12513 pub fn base_name(this: &Locale) -> JsString;
12514
12515 /// The calendar type for the locale.
12516 ///
12517 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/calendar)
12518 #[wasm_bindgen(method, getter)]
12519 pub fn calendar(this: &Locale) -> Option<JsString>;
12520
12521 /// The case first sorting option.
12522 ///
12523 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/caseFirst)
12524 #[wasm_bindgen(method, getter = caseFirst)]
12525 pub fn case_first(this: &Locale) -> Option<JsString>;
12526
12527 /// The collation type for the locale.
12528 ///
12529 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/collation)
12530 #[wasm_bindgen(method, getter)]
12531 pub fn collation(this: &Locale) -> Option<JsString>;
12532
12533 /// The hour cycle for the locale.
12534 ///
12535 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/hourCycle)
12536 #[wasm_bindgen(method, getter = hourCycle)]
12537 pub fn hour_cycle(this: &Locale) -> Option<JsString>;
12538
12539 /// The language code for the locale.
12540 ///
12541 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/language)
12542 #[wasm_bindgen(method, getter)]
12543 pub fn language(this: &Locale) -> JsString;
12544
12545 /// The numbering system for the locale.
12546 ///
12547 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/numberingSystem)
12548 #[wasm_bindgen(method, getter = numberingSystem)]
12549 pub fn numbering_system(this: &Locale) -> Option<JsString>;
12550
12551 /// Whether the locale uses numeric collation.
12552 ///
12553 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/numeric)
12554 #[wasm_bindgen(method, getter)]
12555 pub fn numeric(this: &Locale) -> bool;
12556
12557 /// The region code for the locale.
12558 ///
12559 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/region)
12560 #[wasm_bindgen(method, getter)]
12561 pub fn region(this: &Locale) -> Option<JsString>;
12562
12563 /// The script code for the locale.
12564 ///
12565 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/script)
12566 #[wasm_bindgen(method, getter)]
12567 pub fn script(this: &Locale) -> Option<JsString>;
12568
12569 /// Returns an array of available calendars for the locale.
12570 ///
12571 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getCalendars)
12572 #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getCalendars)]
12573 pub fn get_calendars(this: &Locale) -> Array<JsString>;
12574
12575 /// Returns an array of available collations for the locale.
12576 ///
12577 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getCollations)
12578 #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getCollations)]
12579 pub fn get_collations(this: &Locale) -> Array<JsString>;
12580
12581 /// Returns an array of available hour cycles for the locale.
12582 ///
12583 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getHourCycles)
12584 #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getHourCycles)]
12585 pub fn get_hour_cycles(this: &Locale) -> Array<JsString>;
12586
12587 /// Returns an array of available numbering systems for the locale.
12588 ///
12589 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getNumberingSystems)
12590 #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getNumberingSystems)]
12591 pub fn get_numbering_systems(this: &Locale) -> Array<JsString>;
12592
12593 /// Returns an array of available time zones for the locale's region.
12594 ///
12595 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getTimeZones)
12596 #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getTimeZones)]
12597 pub fn get_time_zones(this: &Locale) -> Option<Array<JsString>>;
12598
12599 /// Returns week information for the locale.
12600 ///
12601 /// May not be available in all environments.
12602 ///
12603 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getWeekInfo)
12604 #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getWeekInfo, catch)]
12605 pub fn get_week_info(this: &Locale) -> Result<WeekInfo, JsValue>;
12606
12607 /// Returns text layout information for the locale.
12608 ///
12609 /// May not be available in all environments.
12610 ///
12611 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getTextInfo)
12612 #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getTextInfo, catch)]
12613 pub fn get_text_info(this: &Locale) -> Result<TextInfo, JsValue>;
12614
12615 /// Returns a new Locale with the specified calendar.
12616 ///
12617 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/maximize)
12618 #[wasm_bindgen(method, js_class = "Intl.Locale")]
12619 pub fn maximize(this: &Locale) -> Locale;
12620
12621 /// Returns a new Locale with the minimal subtags.
12622 ///
12623 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/minimize)
12624 #[wasm_bindgen(method, js_class = "Intl.Locale")]
12625 pub fn minimize(this: &Locale) -> Locale;
12626 }
12627
12628 // Intl.Locale WeekInfo
12629 #[wasm_bindgen]
12630 extern "C" {
12631 /// Week information for a locale.
12632 ///
12633 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getWeekInfo)
12634 #[wasm_bindgen(extends = Object)]
12635 #[derive(Clone, Debug)]
12636 pub type WeekInfo;
12637
12638 /// The first day of the week (1 = Monday, 7 = Sunday).
12639 #[wasm_bindgen(method, getter = firstDay)]
12640 pub fn first_day(this: &WeekInfo) -> u8;
12641
12642 /// Array of weekend days.
12643 #[wasm_bindgen(method, getter)]
12644 pub fn weekend(this: &WeekInfo) -> Array<Number>;
12645
12646 /// Minimal days in the first week of the year.
12647 #[wasm_bindgen(method, getter = minimalDays)]
12648 pub fn minimal_days(this: &WeekInfo) -> u8;
12649 }
12650
12651 // Intl.Locale TextInfo
12652 #[wasm_bindgen]
12653 extern "C" {
12654 /// Text layout information for a locale.
12655 ///
12656 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getTextInfo)
12657 #[wasm_bindgen(extends = Object)]
12658 #[derive(Clone, Debug)]
12659 pub type TextInfo;
12660
12661 /// The text direction ("ltr" or "rtl").
12662 #[wasm_bindgen(method, getter)]
12663 pub fn direction(this: &TextInfo) -> JsString;
12664 }
12665
12666 // Intl.DurationFormat enums
12667
12668 /// The style for duration formatting.
12669 ///
12670 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat#style)
12671 #[wasm_bindgen]
12672 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
12673 pub enum DurationFormatStyle {
12674 Long = "long",
12675 Short = "short",
12676 Narrow = "narrow",
12677 Digital = "digital",
12678 }
12679
12680 /// The display style for individual duration units.
12681 ///
12682 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat#years)
12683 #[wasm_bindgen]
12684 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
12685 pub enum DurationUnitStyle {
12686 Long = "long",
12687 Short = "short",
12688 Narrow = "narrow",
12689 }
12690
12691 /// The display style for time duration units (hours, minutes, seconds).
12692 ///
12693 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat#hours)
12694 #[wasm_bindgen]
12695 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
12696 pub enum DurationTimeUnitStyle {
12697 Long = "long",
12698 Short = "short",
12699 Narrow = "narrow",
12700 Numeric = "numeric",
12701 #[wasm_bindgen(js_name = "2-digit")]
12702 TwoDigit = "2-digit",
12703 }
12704
12705 /// The display option for duration units.
12706 ///
12707 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat#yearsdisplay)
12708 #[wasm_bindgen]
12709 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
12710 pub enum DurationUnitDisplay {
12711 Auto = "auto",
12712 Always = "always",
12713 }
12714
12715 /// The type of a duration format part.
12716 ///
12717 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/formatToParts#type)
12718 #[wasm_bindgen]
12719 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
12720 pub enum DurationFormatPartType {
12721 Years = "years",
12722 Months = "months",
12723 Weeks = "weeks",
12724 Days = "days",
12725 Hours = "hours",
12726 Minutes = "minutes",
12727 Seconds = "seconds",
12728 Milliseconds = "milliseconds",
12729 Microseconds = "microseconds",
12730 Nanoseconds = "nanoseconds",
12731 Literal = "literal",
12732 Integer = "integer",
12733 Decimal = "decimal",
12734 Fraction = "fraction",
12735 }
12736
12737 // Intl.DurationFormatOptions
12738 #[wasm_bindgen]
12739 extern "C" {
12740 /// Options for `Intl.DurationFormat` constructor.
12741 ///
12742 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat#options)
12743 #[wasm_bindgen(extends = Object)]
12744 #[derive(Clone, Debug)]
12745 pub type DurationFormatOptions;
12746
12747 #[wasm_bindgen(method, getter = localeMatcher)]
12748 pub fn get_locale_matcher(this: &DurationFormatOptions) -> Option<LocaleMatcher>;
12749 #[wasm_bindgen(method, setter = localeMatcher)]
12750 pub fn set_locale_matcher(this: &DurationFormatOptions, value: LocaleMatcher);
12751
12752 #[wasm_bindgen(method, getter = style)]
12753 pub fn get_style(this: &DurationFormatOptions) -> Option<DurationFormatStyle>;
12754 #[wasm_bindgen(method, setter = style)]
12755 pub fn set_style(this: &DurationFormatOptions, value: DurationFormatStyle);
12756
12757 #[wasm_bindgen(method, getter = years)]
12758 pub fn get_years(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
12759 #[wasm_bindgen(method, setter = years)]
12760 pub fn set_years(this: &DurationFormatOptions, value: DurationUnitStyle);
12761
12762 #[wasm_bindgen(method, getter = yearsDisplay)]
12763 pub fn get_years_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
12764 #[wasm_bindgen(method, setter = yearsDisplay)]
12765 pub fn set_years_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12766
12767 #[wasm_bindgen(method, getter = months)]
12768 pub fn get_months(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
12769 #[wasm_bindgen(method, setter = months)]
12770 pub fn set_months(this: &DurationFormatOptions, value: DurationUnitStyle);
12771
12772 #[wasm_bindgen(method, getter = monthsDisplay)]
12773 pub fn get_months_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
12774 #[wasm_bindgen(method, setter = monthsDisplay)]
12775 pub fn set_months_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12776
12777 #[wasm_bindgen(method, getter = weeks)]
12778 pub fn get_weeks(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
12779 #[wasm_bindgen(method, setter = weeks)]
12780 pub fn set_weeks(this: &DurationFormatOptions, value: DurationUnitStyle);
12781
12782 #[wasm_bindgen(method, getter = weeksDisplay)]
12783 pub fn get_weeks_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
12784 #[wasm_bindgen(method, setter = weeksDisplay)]
12785 pub fn set_weeks_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12786
12787 #[wasm_bindgen(method, getter = days)]
12788 pub fn get_days(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
12789 #[wasm_bindgen(method, setter = days)]
12790 pub fn set_days(this: &DurationFormatOptions, value: DurationUnitStyle);
12791
12792 #[wasm_bindgen(method, getter = daysDisplay)]
12793 pub fn get_days_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
12794 #[wasm_bindgen(method, setter = daysDisplay)]
12795 pub fn set_days_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12796
12797 #[wasm_bindgen(method, getter = hours)]
12798 pub fn get_hours(this: &DurationFormatOptions) -> Option<DurationTimeUnitStyle>;
12799 #[wasm_bindgen(method, setter = hours)]
12800 pub fn set_hours(this: &DurationFormatOptions, value: DurationTimeUnitStyle);
12801
12802 #[wasm_bindgen(method, getter = hoursDisplay)]
12803 pub fn get_hours_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
12804 #[wasm_bindgen(method, setter = hoursDisplay)]
12805 pub fn set_hours_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12806
12807 #[wasm_bindgen(method, getter = minutes)]
12808 pub fn get_minutes(this: &DurationFormatOptions) -> Option<DurationTimeUnitStyle>;
12809 #[wasm_bindgen(method, setter = minutes)]
12810 pub fn set_minutes(this: &DurationFormatOptions, value: DurationTimeUnitStyle);
12811
12812 #[wasm_bindgen(method, getter = minutesDisplay)]
12813 pub fn get_minutes_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
12814 #[wasm_bindgen(method, setter = minutesDisplay)]
12815 pub fn set_minutes_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12816
12817 #[wasm_bindgen(method, getter = seconds)]
12818 pub fn get_seconds(this: &DurationFormatOptions) -> Option<DurationTimeUnitStyle>;
12819 #[wasm_bindgen(method, setter = seconds)]
12820 pub fn set_seconds(this: &DurationFormatOptions, value: DurationTimeUnitStyle);
12821
12822 #[wasm_bindgen(method, getter = secondsDisplay)]
12823 pub fn get_seconds_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
12824 #[wasm_bindgen(method, setter = secondsDisplay)]
12825 pub fn set_seconds_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12826
12827 #[wasm_bindgen(method, getter = milliseconds)]
12828 pub fn get_milliseconds(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
12829 #[wasm_bindgen(method, setter = milliseconds)]
12830 pub fn set_milliseconds(this: &DurationFormatOptions, value: DurationUnitStyle);
12831
12832 #[wasm_bindgen(method, getter = millisecondsDisplay)]
12833 pub fn get_milliseconds_display(
12834 this: &DurationFormatOptions,
12835 ) -> Option<DurationUnitDisplay>;
12836 #[wasm_bindgen(method, setter = millisecondsDisplay)]
12837 pub fn set_milliseconds_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12838
12839 #[wasm_bindgen(method, getter = microseconds)]
12840 pub fn get_microseconds(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
12841 #[wasm_bindgen(method, setter = microseconds)]
12842 pub fn set_microseconds(this: &DurationFormatOptions, value: DurationUnitStyle);
12843
12844 #[wasm_bindgen(method, getter = microsecondsDisplay)]
12845 pub fn get_microseconds_display(
12846 this: &DurationFormatOptions,
12847 ) -> Option<DurationUnitDisplay>;
12848 #[wasm_bindgen(method, setter = microsecondsDisplay)]
12849 pub fn set_microseconds_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12850
12851 #[wasm_bindgen(method, getter = nanoseconds)]
12852 pub fn get_nanoseconds(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
12853 #[wasm_bindgen(method, setter = nanoseconds)]
12854 pub fn set_nanoseconds(this: &DurationFormatOptions, value: DurationUnitStyle);
12855
12856 #[wasm_bindgen(method, getter = nanosecondsDisplay)]
12857 pub fn get_nanoseconds_display(this: &DurationFormatOptions)
12858 -> Option<DurationUnitDisplay>;
12859 #[wasm_bindgen(method, setter = nanosecondsDisplay)]
12860 pub fn set_nanoseconds_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12861
12862 #[wasm_bindgen(method, getter = fractionalDigits)]
12863 pub fn get_fractional_digits(this: &DurationFormatOptions) -> Option<u8>;
12864 #[wasm_bindgen(method, setter = fractionalDigits)]
12865 pub fn set_fractional_digits(this: &DurationFormatOptions, value: u8);
12866 }
12867
12868 impl DurationFormatOptions {
12869 pub fn new() -> DurationFormatOptions {
12870 JsCast::unchecked_into(Object::new())
12871 }
12872 }
12873
12874 impl Default for DurationFormatOptions {
12875 fn default() -> Self {
12876 DurationFormatOptions::new()
12877 }
12878 }
12879
12880 // Intl.ResolvedDurationFormatOptions
12881 #[wasm_bindgen]
12882 extern "C" {
12883 /// Resolved options returned by `Intl.DurationFormat.prototype.resolvedOptions()`.
12884 ///
12885 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/resolvedOptions)
12886 #[wasm_bindgen(extends = DurationFormatOptions)]
12887 #[derive(Clone, Debug)]
12888 pub type ResolvedDurationFormatOptions;
12889
12890 /// The resolved locale string.
12891 #[wasm_bindgen(method, getter = locale)]
12892 pub fn get_locale(this: &ResolvedDurationFormatOptions) -> JsString;
12893
12894 /// The resolved numbering system.
12895 #[wasm_bindgen(method, getter = numberingSystem)]
12896 pub fn get_numbering_system(this: &ResolvedDurationFormatOptions) -> JsString;
12897 }
12898
12899 // Intl.Duration (input object for DurationFormat)
12900 #[wasm_bindgen]
12901 extern "C" {
12902 /// A duration object used as input to `Intl.DurationFormat.format()`.
12903 ///
12904 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/format#duration)
12905 #[wasm_bindgen(extends = Object)]
12906 #[derive(Clone, Debug)]
12907 pub type Duration;
12908
12909 #[wasm_bindgen(method, getter)]
12910 pub fn years(this: &Duration) -> Option<f64>;
12911 #[wasm_bindgen(method, setter)]
12912 pub fn set_years(this: &Duration, value: f64);
12913
12914 #[wasm_bindgen(method, getter)]
12915 pub fn months(this: &Duration) -> Option<f64>;
12916 #[wasm_bindgen(method, setter)]
12917 pub fn set_months(this: &Duration, value: f64);
12918
12919 #[wasm_bindgen(method, getter)]
12920 pub fn weeks(this: &Duration) -> Option<f64>;
12921 #[wasm_bindgen(method, setter)]
12922 pub fn set_weeks(this: &Duration, value: f64);
12923
12924 #[wasm_bindgen(method, getter)]
12925 pub fn days(this: &Duration) -> Option<f64>;
12926 #[wasm_bindgen(method, setter)]
12927 pub fn set_days(this: &Duration, value: f64);
12928
12929 #[wasm_bindgen(method, getter)]
12930 pub fn hours(this: &Duration) -> Option<f64>;
12931 #[wasm_bindgen(method, setter)]
12932 pub fn set_hours(this: &Duration, value: f64);
12933
12934 #[wasm_bindgen(method, getter)]
12935 pub fn minutes(this: &Duration) -> Option<f64>;
12936 #[wasm_bindgen(method, setter)]
12937 pub fn set_minutes(this: &Duration, value: f64);
12938
12939 #[wasm_bindgen(method, getter)]
12940 pub fn seconds(this: &Duration) -> Option<f64>;
12941 #[wasm_bindgen(method, setter)]
12942 pub fn set_seconds(this: &Duration, value: f64);
12943
12944 #[wasm_bindgen(method, getter)]
12945 pub fn milliseconds(this: &Duration) -> Option<f64>;
12946 #[wasm_bindgen(method, setter)]
12947 pub fn set_milliseconds(this: &Duration, value: f64);
12948
12949 #[wasm_bindgen(method, getter)]
12950 pub fn microseconds(this: &Duration) -> Option<f64>;
12951 #[wasm_bindgen(method, setter)]
12952 pub fn set_microseconds(this: &Duration, value: f64);
12953
12954 #[wasm_bindgen(method, getter)]
12955 pub fn nanoseconds(this: &Duration) -> Option<f64>;
12956 #[wasm_bindgen(method, setter)]
12957 pub fn set_nanoseconds(this: &Duration, value: f64);
12958 }
12959
12960 impl Duration {
12961 pub fn new() -> Duration {
12962 JsCast::unchecked_into(Object::new())
12963 }
12964 }
12965
12966 impl Default for Duration {
12967 fn default() -> Self {
12968 Duration::new()
12969 }
12970 }
12971
12972 // Intl.DurationFormatPart
12973 #[wasm_bindgen]
12974 extern "C" {
12975 /// A part of the formatted duration returned by `formatToParts()`.
12976 ///
12977 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/formatToParts)
12978 #[wasm_bindgen(extends = Object)]
12979 #[derive(Clone, Debug)]
12980 pub type DurationFormatPart;
12981
12982 /// The type of the part.
12983 #[wasm_bindgen(method, getter = type)]
12984 pub fn type_(this: &DurationFormatPart) -> DurationFormatPartType;
12985
12986 /// The value of the part.
12987 #[wasm_bindgen(method, getter)]
12988 pub fn value(this: &DurationFormatPart) -> JsString;
12989
12990 /// The unit this part represents (if applicable).
12991 #[wasm_bindgen(method, getter)]
12992 pub fn unit(this: &DurationFormatPart) -> Option<JsString>;
12993 }
12994
12995 // Intl.DurationFormat
12996 #[wasm_bindgen]
12997 extern "C" {
12998 /// The `Intl.DurationFormat` object enables language-sensitive duration formatting.
12999 ///
13000 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat)
13001 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.DurationFormat")]
13002 #[derive(Clone, Debug)]
13003 pub type DurationFormat;
13004
13005 /// Creates a new `Intl.DurationFormat` object.
13006 ///
13007 /// Throws a `RangeError` if locales or options contain invalid values.
13008 ///
13009 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat)
13010 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
13011 pub fn new(
13012 locales: &[JsString],
13013 options: &DurationFormatOptions,
13014 ) -> Result<DurationFormat, JsValue>;
13015
13016 /// Formats a duration according to the locale and formatting options.
13017 ///
13018 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/format)
13019 #[wasm_bindgen(method, js_class = "Intl.DurationFormat")]
13020 pub fn format(this: &DurationFormat, duration: &Duration) -> JsString;
13021
13022 /// Returns an array of objects representing the formatted duration in parts.
13023 ///
13024 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/formatToParts)
13025 #[wasm_bindgen(method, js_class = "Intl.DurationFormat", js_name = formatToParts)]
13026 pub fn format_to_parts(
13027 this: &DurationFormat,
13028 duration: &Duration,
13029 ) -> Array<DurationFormatPart>;
13030
13031 /// Returns an object with properties reflecting the options used.
13032 ///
13033 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/resolvedOptions)
13034 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
13035 pub fn resolved_options(this: &DurationFormat) -> ResolvedDurationFormatOptions;
13036
13037 /// Returns an array of supported locales.
13038 ///
13039 /// Throws a `RangeError` if locales contain invalid values.
13040 ///
13041 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/supportedLocalesOf)
13042 #[wasm_bindgen(static_method_of = DurationFormat, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
13043 pub fn supported_locales_of(
13044 locales: &[JsString],
13045 options: &LocaleMatcherOptions,
13046 ) -> Result<Array<JsString>, JsValue>;
13047 }
13048
13049 impl Default for DurationFormat {
13050 fn default() -> Self {
13051 Self::new(&[], &Default::default()).unwrap()
13052 }
13053 }
13054}
13055
13056#[wasm_bindgen]
13057extern "C" {
13058 /// The `PromiseState` object represents the the status of the promise,
13059 /// as used in `allSettled`.
13060 ///
13061 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled)
13062 #[must_use]
13063 #[wasm_bindgen(extends = Object, typescript_type = "any")]
13064 #[derive(Clone, Debug)]
13065 pub type PromiseState<T = JsValue>;
13066
13067 /// A string, either "fulfilled" or "rejected", indicating the eventual state of the promise.
13068 #[wasm_bindgen(method, getter = status)]
13069 pub fn get_status<T>(this: &PromiseState<T>) -> String;
13070
13071 /// Only present if status is "fulfilled". The value that the promise was fulfilled with.
13072 #[wasm_bindgen(method, getter = value)]
13073 pub fn get_value<T>(this: &PromiseState<T>) -> Option<T>;
13074
13075 /// Only present if status is "rejected". The reason that the promise was rejected with.
13076 #[wasm_bindgen(method, getter = reason)]
13077 pub fn get_reason<T>(this: &PromiseState<T>) -> Option<JsValue>;
13078}
13079
13080impl<T> PromiseState<T> {
13081 pub fn is_fulfilled(&self) -> bool {
13082 self.get_status() == "fulfilled"
13083 }
13084
13085 pub fn is_rejected(&self) -> bool {
13086 self.get_status() == "rejected"
13087 }
13088}
13089
13090/// Converts a `PromiseState<T>` into a `Result<T, JsValue>`, matching the
13091/// spec invariant that exactly one of the fulfilled value or the rejection
13092/// reason is populated per slot.
13093impl<T: JsGeneric + FromWasmAbi> From<PromiseState<T>> for Result<T, JsValue> {
13094 fn from(state: PromiseState<T>) -> Result<T, JsValue> {
13095 if state.is_fulfilled() {
13096 Ok(state.get_value().unwrap())
13097 } else {
13098 Err(state.get_reason().unwrap())
13099 }
13100 }
13101}
13102
13103// Promise
13104#[wasm_bindgen]
13105extern "C" {
13106 /// The `Promise` object represents the eventual completion (or failure) of
13107 /// an asynchronous operation, and its resulting value.
13108 ///
13109 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
13110 #[must_use]
13111 #[wasm_bindgen(extends = Object, typescript_type = "Promise<any>", no_promising)]
13112 #[derive(Clone, Debug)]
13113 pub type Promise<T = JsValue>;
13114
13115 /// Creates a new `Promise` with the provided executor `cb`
13116 ///
13117 /// The `cb` is a function that is passed with the arguments `resolve` and
13118 /// `reject`. The `cb` function is executed immediately by the `Promise`
13119 /// implementation, passing `resolve` and `reject` functions (the executor
13120 /// is called before the `Promise` constructor even returns the created
13121 /// object). The `resolve` and `reject` functions, when called, resolve or
13122 /// reject the promise, respectively. The executor normally initiates
13123 /// some asynchronous work, and then, once that completes, either calls
13124 /// the `resolve` function to resolve the promise or else rejects it if an
13125 /// error occurred.
13126 ///
13127 /// If an error is thrown in the executor function, the promise is rejected.
13128 /// The return value of the executor is ignored.
13129 ///
13130 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
13131 #[cfg(not(js_sys_unstable_apis))]
13132 #[wasm_bindgen(constructor)]
13133 pub fn new(cb: &mut dyn FnMut(Function, Function)) -> Promise;
13134
13135 /// Creates a new `Promise` with the provided executor `cb`
13136 ///
13137 /// The `cb` is a function that is passed with the arguments `resolve` and
13138 /// `reject`. The `cb` function is executed immediately by the `Promise`
13139 /// implementation, passing `resolve` and `reject` functions (the executor
13140 /// is called before the `Promise` constructor even returns the created
13141 /// object). The `resolve` and `reject` functions, when called, resolve or
13142 /// reject the promise, respectively. The executor normally initiates
13143 /// some asynchronous work, and then, once that completes, either calls
13144 /// the `resolve` function to resolve the promise or else rejects it if an
13145 /// error occurred.
13146 ///
13147 /// If an error is thrown in the executor function, the promise is rejected.
13148 /// The return value of the executor is ignored.
13149 ///
13150 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
13151 #[cfg(js_sys_unstable_apis)]
13152 #[wasm_bindgen(constructor)]
13153 pub fn new<T: JsGeneric>(
13154 cb: &mut dyn FnMut(Function<fn(T) -> Undefined>, Function<fn(JsValue) -> Undefined>),
13155 ) -> Promise<T>;
13156
13157 // Next major: deprecate
13158 /// Creates a new `Promise` with the provided executor `cb`
13159 ///
13160 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
13161 #[wasm_bindgen(constructor)]
13162 pub fn new_typed<T: Promising + JsGeneric>(
13163 cb: &mut dyn FnMut(Function<fn(T) -> Undefined>, Function<fn(JsValue) -> Undefined>),
13164 ) -> Promise<<T as Promising>::Resolution>;
13165
13166 /// The `Promise.all(iterable)` method returns a single `Promise` that
13167 /// resolves when all of the promises in the iterable argument have resolved
13168 /// or when the iterable argument contains no promises. It rejects with the
13169 /// reason of the first promise that rejects.
13170 ///
13171 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all)
13172 #[cfg(not(js_sys_unstable_apis))]
13173 #[wasm_bindgen(static_method_of = Promise)]
13174 pub fn all(obj: &JsValue) -> Promise;
13175
13176 /// The `Promise.all(iterable)` method returns a single `Promise` that
13177 /// resolves when all of the promises in the iterable argument have resolved
13178 /// or when the iterable argument contains no promises. It rejects with the
13179 /// reason of the first promise that rejects.
13180 ///
13181 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all)
13182 #[cfg(js_sys_unstable_apis)]
13183 #[wasm_bindgen(static_method_of = Promise, js_name = all)]
13184 pub fn all<I: Iterable>(obj: &I) -> Promise<Array<<I::Item as Promising>::Resolution>>
13185 where
13186 I::Item: Promising;
13187
13188 // Next major: deprecate
13189 /// The `Promise.all(iterable)` method returns a single `Promise` that
13190 /// resolves when all of the promises in the iterable argument have resolved
13191 /// or when the iterable argument contains no promises. It rejects with the
13192 /// reason of the first promise that rejects.
13193 ///
13194 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all)
13195 #[wasm_bindgen(static_method_of = Promise, js_name = all)]
13196 pub fn all_iterable<I: Iterable>(obj: &I) -> Promise<Array<<I::Item as Promising>::Resolution>>
13197 where
13198 I::Item: Promising;
13199
13200 /// The `Promise.allSettled(iterable)` method returns a single `Promise` that
13201 /// resolves when all of the promises in the iterable argument have either
13202 /// fulfilled or rejected or when the iterable argument contains no promises.
13203 ///
13204 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled)
13205 #[cfg(not(js_sys_unstable_apis))]
13206 #[wasm_bindgen(static_method_of = Promise, js_name = allSettled)]
13207 pub fn all_settled(obj: &JsValue) -> Promise;
13208
13209 /// The `Promise.allSettled(iterable)` method returns a single `Promise` that
13210 /// resolves when all of the promises in the iterable argument have either
13211 /// fulfilled or rejected or when the iterable argument contains no promises.
13212 ///
13213 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled)
13214 #[cfg(js_sys_unstable_apis)]
13215 #[wasm_bindgen(static_method_of = Promise, js_name = allSettled)]
13216 pub fn all_settled<I: Iterable>(
13217 obj: &I,
13218 ) -> Promise<Array<PromiseState<<I::Item as Promising>::Resolution>>>
13219 where
13220 I::Item: Promising;
13221
13222 // Next major: deprecate
13223 /// The `Promise.allSettled(iterable)` method returns a single `Promise` that
13224 /// resolves when all of the promises in the iterable argument have either
13225 /// fulfilled or rejected or when the iterable argument contains no promises.
13226 ///
13227 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled)
13228 #[wasm_bindgen(static_method_of = Promise, js_name = allSettled)]
13229 pub fn all_settled_iterable<I: Iterable>(
13230 obj: &I,
13231 ) -> Promise<Array<PromiseState<<I::Item as Promising>::Resolution>>>
13232 where
13233 I::Item: Promising;
13234
13235 /// The `Promise.any(iterable)` method returns a single `Promise` that
13236 /// resolves when any of the promises in the iterable argument have resolved
13237 /// or when the iterable argument contains no promises. It rejects with an
13238 /// `AggregateError` if all promises in the iterable rejected.
13239 ///
13240 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/any)
13241 #[cfg(not(js_sys_unstable_apis))]
13242 #[wasm_bindgen(static_method_of = Promise)]
13243 pub fn any(obj: &JsValue) -> Promise;
13244
13245 /// The `Promise.any(iterable)` method returns a single `Promise` that
13246 /// resolves when any of the promises in the iterable argument have resolved
13247 /// or when the iterable argument contains no promises. It rejects with an
13248 /// `AggregateError` if all promises in the iterable rejected.
13249 ///
13250 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/any)
13251 #[cfg(js_sys_unstable_apis)]
13252 #[wasm_bindgen(static_method_of = Promise, js_name = any)]
13253 pub fn any<I: Iterable>(obj: &I) -> Promise<<I::Item as Promising>::Resolution>
13254 where
13255 I::Item: Promising;
13256
13257 // Next major: deprecate
13258 /// The `Promise.any(iterable)` method returns a single `Promise` that
13259 /// resolves when any of the promises in the iterable argument have resolved
13260 /// or when the iterable argument contains no promises. It rejects with an
13261 /// `AggregateError` if all promises in the iterable rejected.
13262 ///
13263 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/any)
13264 #[wasm_bindgen(static_method_of = Promise, js_name = any)]
13265 pub fn any_iterable<I: Iterable>(obj: &I) -> Promise<<I::Item as Promising>::Resolution>
13266 where
13267 I::Item: Promising;
13268
13269 /// The `Promise.race(iterable)` method returns a promise that resolves or
13270 /// rejects as soon as one of the promises in the iterable resolves or
13271 /// rejects, with the value or reason from that promise.
13272 ///
13273 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/race)
13274 #[cfg(not(js_sys_unstable_apis))]
13275 #[wasm_bindgen(static_method_of = Promise)]
13276 pub fn race(obj: &JsValue) -> Promise;
13277
13278 /// The `Promise.race(iterable)` method returns a promise that resolves or
13279 /// rejects as soon as one of the promises in the iterable resolves or
13280 /// rejects, with the value or reason from that promise.
13281 ///
13282 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/race)
13283 #[cfg(js_sys_unstable_apis)]
13284 #[wasm_bindgen(static_method_of = Promise, js_name = race)]
13285 pub fn race<I: Iterable>(obj: &I) -> Promise<<I::Item as Promising>::Resolution>
13286 where
13287 I::Item: Promising;
13288
13289 // Next major: deprecate
13290 /// The `Promise.race(iterable)` method returns a promise that resolves or
13291 /// rejects as soon as one of the promises in the iterable resolves or
13292 /// rejects, with the value or reason from that promise.
13293 ///
13294 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/race)
13295 #[wasm_bindgen(static_method_of = Promise, js_name = race)]
13296 pub fn race_iterable<I: Iterable>(obj: &I) -> Promise<<I::Item as Promising>::Resolution>
13297 where
13298 I::Item: Promising;
13299
13300 /// The `Promise.reject(reason)` method returns a `Promise` object that is
13301 /// rejected with the given reason.
13302 ///
13303 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/reject)
13304 #[cfg(not(js_sys_unstable_apis))]
13305 #[wasm_bindgen(static_method_of = Promise)]
13306 pub fn reject(obj: &JsValue) -> Promise;
13307
13308 /// The `Promise.reject(reason)` method returns a `Promise` object that is
13309 /// rejected with the given reason.
13310 ///
13311 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/reject)
13312 #[cfg(js_sys_unstable_apis)]
13313 #[wasm_bindgen(static_method_of = Promise, js_name = reject)]
13314 pub fn reject<T>(obj: &JsValue) -> Promise<T>;
13315
13316 // Next major: deprecate
13317 /// The `Promise.reject(reason)` method returns a `Promise` object that is
13318 /// rejected with the given reason.
13319 ///
13320 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/reject)
13321 #[wasm_bindgen(static_method_of = Promise, js_name = reject)]
13322 pub fn reject_typed<T>(obj: &JsValue) -> Promise<T>;
13323
13324 /// The `Promise.resolve(value)` method returns a `Promise` object that is
13325 /// resolved with the given value. If the value is a promise, that promise
13326 /// is returned; if the value is a thenable (i.e. has a "then" method), the
13327 /// returned promise will "follow" that thenable, adopting its eventual
13328 /// state; otherwise the returned promise will be fulfilled with the value.
13329 ///
13330 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/resolve)
13331 #[wasm_bindgen(static_method_of = Promise, js_name = resolve)]
13332 pub fn resolve<U: Promising>(obj: &U) -> Promise<U::Resolution>;
13333
13334 /// The `catch()` method returns a `Promise` and deals with rejected cases
13335 /// only. It behaves the same as calling `Promise.prototype.then(undefined,
13336 /// onRejected)` (in fact, calling `obj.catch(onRejected)` internally calls
13337 /// `obj.then(undefined, onRejected)`).
13338 ///
13339 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch)
13340 #[cfg(not(js_sys_unstable_apis))]
13341 #[wasm_bindgen(method)]
13342 pub fn catch<T>(this: &Promise<T>, cb: &ScopedClosure<dyn FnMut(JsValue)>) -> Promise<JsValue>;
13343
13344 /// The `catch()` method returns a `Promise` and deals with rejected cases
13345 /// only. It behaves the same as calling `Promise.prototype.then(undefined,
13346 /// onRejected)` (in fact, calling `obj.catch(onRejected)` internally calls
13347 /// `obj.then(undefined, onRejected)`).
13348 ///
13349 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch)
13350 #[cfg(js_sys_unstable_apis)]
13351 #[wasm_bindgen(method, js_name = catch)]
13352 pub fn catch<'a, T, R: Promising>(
13353 this: &Promise<T>,
13354 cb: &ScopedClosure<'a, dyn FnMut(T) -> Result<R, JsError>>,
13355 ) -> Promise<R::Resolution>;
13356
13357 // Next major: deprecate
13358 /// Same as `catch`, but returning a result to become the new Promise value.
13359 #[wasm_bindgen(method, js_name = catch)]
13360 pub fn catch_map<'a, T, R: Promising>(
13361 this: &Promise<T>,
13362 cb: &ScopedClosure<'a, dyn FnMut(T) -> Result<R, JsError>>,
13363 ) -> Promise<R::Resolution>;
13364
13365 /// The `then()` method returns a `Promise`. It takes up to two arguments:
13366 /// callback functions for the success and failure cases of the `Promise`.
13367 ///
13368 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then)
13369 #[cfg(not(js_sys_unstable_apis))]
13370 #[wasm_bindgen(method)]
13371 pub fn then<'a, T>(this: &Promise<T>, cb: &ScopedClosure<'a, dyn FnMut(T)>)
13372 -> Promise<JsValue>;
13373
13374 /// The `then()` method returns a `Promise`. It takes up to two arguments:
13375 /// callback functions for the success and failure cases of the `Promise`.
13376 ///
13377 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then)
13378 #[cfg(js_sys_unstable_apis)]
13379 #[wasm_bindgen(method, js_name = then)]
13380 pub fn then<'a, T, R: Promising>(
13381 this: &Promise<T>,
13382 cb: &ScopedClosure<'a, dyn FnMut(T) -> Result<R, JsError>>,
13383 ) -> Promise<R::Resolution>;
13384
13385 /// The `then()` method returns a `Promise`. It takes up to two arguments:
13386 /// callback functions for the success and failure cases of the `Promise`.
13387 ///
13388 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then)
13389 #[wasm_bindgen(method, js_name = then)]
13390 pub fn then_with_reject<'a, T, R: Promising>(
13391 this: &Promise<T>,
13392 resolve: &ScopedClosure<'a, dyn FnMut(T) -> Result<R, JsError>>,
13393 reject: &ScopedClosure<'a, dyn FnMut(JsValue) -> Result<R, JsError>>,
13394 ) -> Promise<R::Resolution>;
13395
13396 // Next major: deprecate
13397 /// Alias for `then()` with a return value.
13398 /// The `then()` method returns a `Promise`. It takes up to two arguments:
13399 /// callback functions for the success and failure cases of the `Promise`.
13400 ///
13401 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then)
13402 #[wasm_bindgen(method, js_name = then)]
13403 pub fn then_map<'a, T, R: Promising>(
13404 this: &Promise<T>,
13405 cb: &ScopedClosure<'a, dyn FnMut(T) -> Result<R, JsError>>,
13406 ) -> Promise<R::Resolution>;
13407
13408 /// Same as `then`, only with both arguments provided.
13409 ///
13410 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then)
13411 #[wasm_bindgen(method, js_name = then)]
13412 pub fn then2(
13413 this: &Promise,
13414 resolve: &ScopedClosure<dyn FnMut(JsValue)>,
13415 reject: &ScopedClosure<dyn FnMut(JsValue)>,
13416 ) -> Promise;
13417
13418 /// The `finally()` method returns a `Promise`. When the promise is settled,
13419 /// whether fulfilled or rejected, the specified callback function is
13420 /// executed. This provides a way for code that must be executed once the
13421 /// `Promise` has been dealt with to be run whether the promise was
13422 /// fulfilled successfully or rejected.
13423 ///
13424 /// This lets you avoid duplicating code in both the promise's `then()` and
13425 /// `catch()` handlers.
13426 ///
13427 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/finally)
13428 #[wasm_bindgen(method)]
13429 pub fn finally<T>(this: &Promise<T>, cb: &ScopedClosure<dyn FnMut()>) -> Promise<JsValue>;
13430}
13431
13432impl<T: JsGeneric> Promising for Promise<T> {
13433 type Resolution = T;
13434}
13435
13436/// Internal: maps a tuple of `Promise<T_i>` to the result shapes of
13437/// [`Promise::all_tuple`] and [`Promise::all_settled_tuple`].
13438///
13439/// Implemented for every tuple arity 1..=8 of `Promise<T: JsGeneric>`. The
13440/// associated `Joined` / `Settled` types pin down the [`ArrayTuple`] shape
13441/// of the result so the one [`JsCast::unchecked_into`] needed to reinterpret
13442/// the [`Array<JsValue>`] returned by `Promise.all` / `Promise.allSettled`
13443/// is encapsulated inside each impl — the caller sees a fully-typed
13444/// `Promise<ArrayTuple<...>>`.
13445///
13446/// The soundness of the `unchecked_into`s here rests on `Promise.all` and
13447/// `Promise.allSettled` preserving input order and arity, which they do by
13448/// spec.
13449///
13450/// You normally call [`Promise::all_tuple`] / [`Promise::all_settled_tuple`]
13451/// rather than using this trait directly.
13452#[doc(hidden)]
13453pub trait PromiseTuple {
13454 /// The typed `ArrayTuple` shape the joined promise resolves to.
13455 ///
13456 /// For a tuple `(Promise<T1>, Promise<T2>, ...)` this is
13457 /// `ArrayTuple<(T1, T2, ...)>`.
13458 type Joined: JsGeneric;
13459
13460 /// The typed `ArrayTuple` shape the all-settled promise resolves to.
13461 ///
13462 /// For a tuple `(Promise<T1>, Promise<T2>, ...)` this is
13463 /// `ArrayTuple<(PromiseState<T1>, PromiseState<T2>, ...)>`.
13464 type Settled: JsGeneric;
13465
13466 /// Join via `Promise.all`, returning a typed `Promise`.
13467 fn all(self) -> Promise<Self::Joined>;
13468
13469 /// Settle via `Promise.allSettled`, returning a typed `Promise`.
13470 fn all_settled(self) -> Promise<Self::Settled>;
13471}
13472
13473macro_rules! impl_promise_tuple {
13474 ([$($T:ident)+] [$($idx:tt)+]) => {
13475 // Rust tuple of `Promise<T_i>`. Builds the heterogeneous
13476 // `ArrayTuple` of promises via the existing `From<(...)>` impl
13477 // (each element upcasts through `JsGeneric`), then delegates to
13478 // the `ArrayTuple` impl below.
13479 impl<$($T: JsGeneric),+> PromiseTuple for ($(Promise<$T>,)+) {
13480 type Joined = ArrayTuple<($($T,)+)>;
13481 type Settled = ArrayTuple<($(PromiseState<$T>,)+)>;
13482
13483 fn all(self) -> Promise<Self::Joined> {
13484 let tuple: ArrayTuple<($(Promise<$T>,)+)> = ($(self.$idx,)+).into();
13485 tuple.all()
13486 }
13487
13488 fn all_settled(self) -> Promise<Self::Settled> {
13489 let tuple: ArrayTuple<($(Promise<$T>,)+)> = ($(self.$idx,)+).into();
13490 tuple.all_settled()
13491 }
13492 }
13493
13494 // `ArrayTuple<(Promise<T_1>, ..., Promise<T_n>)>` — callers who
13495 // already have an `ArrayTuple` (e.g. from a binding that returns
13496 // one, or built via `.into()` earlier in a pipeline) can pass it
13497 // directly without unpacking into a Rust tuple.
13498 //
13499 // Hands the `ArrayTuple` straight to `Promise.all_iterable` /
13500 // `Promise.allSettled_iterable` and reinterprets the result
13501 // `Array<JsValue>` as the intended typed `ArrayTuple`. Safe because
13502 // `Promise.all` / `Promise.allSettled` preserve input order and
13503 // arity by spec.
13504 impl<$($T: JsGeneric),+> PromiseTuple for ArrayTuple<($(Promise<$T>,)+)> {
13505 type Joined = ArrayTuple<($($T,)+)>;
13506 type Settled = ArrayTuple<($(PromiseState<$T>,)+)>;
13507
13508 fn all(self) -> Promise<Self::Joined> {
13509 use wasm_bindgen::JsCast;
13510 Promise::all_iterable(&self).unchecked_into()
13511 }
13512
13513 fn all_settled(self) -> Promise<Self::Settled> {
13514 use wasm_bindgen::JsCast;
13515 Promise::all_settled_iterable(&self).unchecked_into()
13516 }
13517 }
13518 };
13519}
13520
13521impl_promise_tuple!([T1][0]);
13522impl_promise_tuple!([T1 T2] [0 1]);
13523impl_promise_tuple!([T1 T2 T3] [0 1 2]);
13524impl_promise_tuple!([T1 T2 T3 T4] [0 1 2 3]);
13525impl_promise_tuple!([T1 T2 T3 T4 T5] [0 1 2 3 4]);
13526impl_promise_tuple!([T1 T2 T3 T4 T5 T6] [0 1 2 3 4 5]);
13527impl_promise_tuple!([T1 T2 T3 T4 T5 T6 T7] [0 1 2 3 4 5 6]);
13528impl_promise_tuple!([T1 T2 T3 T4 T5 T6 T7 T8] [0 1 2 3 4 5 6 7]);
13529
13530impl Promise {
13531 /// Heterogeneous counterpart to [`Promise::all_iterable`]: accepts a Rust
13532 /// tuple of `Promise<T_i>` and returns a single [`Promise`] resolving to a
13533 /// typed [`ArrayTuple<(T_1, T_2, ..., T_n)>`].
13534 ///
13535 /// Destructure the awaited result via [`ArrayTuple::into_tuple`] to get
13536 /// the individual values back as a native Rust tuple. Implemented for
13537 /// arity 1..=8.
13538 ///
13539 /// Rejects with the first rejection, matching `Promise.all` semantics.
13540 ///
13541 /// # Example
13542 ///
13543 /// ```ignore
13544 /// use js_sys::Promise;
13545 ///
13546 /// let (response, buffer) = Promise::all_tuple((fetch_promise, buffer_promise))
13547 /// .await?
13548 /// .into_tuple();
13549 /// ```
13550 #[inline]
13551 pub fn all_tuple<T: PromiseTuple>(promises: T) -> Promise<T::Joined> {
13552 promises.all()
13553 }
13554
13555 /// Heterogeneous counterpart to [`Promise::all_settled_iterable`]: accepts
13556 /// a Rust tuple of `Promise<T_i>` and returns a single [`Promise`]
13557 /// resolving to a typed
13558 /// `ArrayTuple<(PromiseState<T_1>, ..., PromiseState<T_n>)>`.
13559 ///
13560 /// Unlike [`Promise::all_tuple`], this never rejects early: every input
13561 /// settles (fulfills or rejects) and is reflected by its [`PromiseState`]
13562 /// slot in the result tuple. Implemented for arity 1..=8.
13563 ///
13564 /// # Example
13565 ///
13566 /// ```ignore
13567 /// use js_sys::Promise;
13568 ///
13569 /// let results = Promise::all_settled_tuple((fetch_promise, buffer_promise)).await?;
13570 /// let (response_state, buffer_state) = results.into_tuple();
13571 /// ```
13572 #[inline]
13573 pub fn all_settled_tuple<T: PromiseTuple>(promises: T) -> Promise<T::Settled> {
13574 promises.all_settled()
13575 }
13576}
13577
13578/// Returns a handle to the global scope object.
13579///
13580/// This allows access to the global properties and global names by accessing
13581/// the `Object` returned.
13582pub fn global() -> Object {
13583 use wasm_bindgen::__rt::LazyCell;
13584
13585 #[cfg_attr(target_feature = "atomics", thread_local)]
13586 static GLOBAL: LazyCell<Object> = LazyCell::new(get_global_object);
13587
13588 return GLOBAL.clone();
13589
13590 fn get_global_object() -> Object {
13591 // Accessing the global object is not an easy thing to do, and what we
13592 // basically want is `globalThis` but we can't rely on that existing
13593 // everywhere. In the meantime we've got the fallbacks mentioned in:
13594 //
13595 // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis
13596 //
13597 // Note that this is pretty heavy code-size wise but it at least gets
13598 // the job largely done for now and avoids the `Function` constructor at
13599 // the end which triggers CSP errors.
13600 #[wasm_bindgen]
13601 extern "C" {
13602 #[derive(Clone, Debug)]
13603 type Global;
13604
13605 #[wasm_bindgen(thread_local_v2, js_name = globalThis)]
13606 static GLOBAL_THIS: Option<Object>;
13607
13608 #[wasm_bindgen(thread_local_v2, js_name = self)]
13609 static SELF: Option<Object>;
13610
13611 #[wasm_bindgen(thread_local_v2, js_name = window)]
13612 static WINDOW: Option<Object>;
13613
13614 #[wasm_bindgen(thread_local_v2, js_name = global)]
13615 static GLOBAL: Option<Object>;
13616 }
13617
13618 // The order is important: in Firefox Extension Content Scripts `globalThis`
13619 // is a Sandbox (not Window), so `globalThis` must be checked after `window`.
13620 let static_object = SELF
13621 .with(Option::clone)
13622 .or_else(|| WINDOW.with(Option::clone))
13623 .or_else(|| GLOBAL_THIS.with(Option::clone))
13624 .or_else(|| GLOBAL.with(Option::clone));
13625 if let Some(obj) = static_object {
13626 if !obj.is_undefined() {
13627 return obj;
13628 }
13629 }
13630
13631 // Global object not found
13632 JsValue::undefined().unchecked_into()
13633 }
13634}
13635
13636// Float16Array
13637//
13638// Rust does not yet have a stable builtin `f16`, so the raw JS bindings live
13639// here and any Rust-side helper APIs use explicit `u16` / `f32` naming. The
13640// unsuffixed float APIs are reserved for a future native `f16` binding.
13641#[wasm_bindgen]
13642extern "C" {
13643 #[wasm_bindgen(extends = Object, typescript_type = "Float16Array")]
13644 #[derive(Clone, Debug)]
13645 pub type Float16Array;
13646
13647 /// The `Float16Array()` constructor creates a new array.
13648 ///
13649 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float16Array)
13650 #[wasm_bindgen(constructor)]
13651 pub fn new(constructor_arg: &JsValue) -> Float16Array;
13652
13653 /// The `Float16Array()` constructor creates an array with an internal
13654 /// buffer large enough for `length` elements.
13655 ///
13656 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float16Array)
13657 #[wasm_bindgen(constructor)]
13658 pub fn new_with_length(length: u32) -> Float16Array;
13659
13660 /// The `Float16Array()` constructor creates an array with the given
13661 /// buffer but is a view starting at `byte_offset`.
13662 ///
13663 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float16Array)
13664 #[wasm_bindgen(constructor)]
13665 pub fn new_with_byte_offset(buffer: &JsValue, byte_offset: u32) -> Float16Array;
13666
13667 /// The `Float16Array()` constructor creates an array with the given
13668 /// buffer but is a view starting at `byte_offset` for `length` elements.
13669 ///
13670 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float16Array)
13671 #[wasm_bindgen(constructor)]
13672 pub fn new_with_byte_offset_and_length(
13673 buffer: &JsValue,
13674 byte_offset: u32,
13675 length: u32,
13676 ) -> Float16Array;
13677
13678 /// The `fill()` method fills all elements from a start index to an end
13679 /// index with a static `f32` value.
13680 ///
13681 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/fill)
13682 #[wasm_bindgen(method, js_name = fill)]
13683 pub fn fill_with_f32(this: &Float16Array, value: f32, start: u32, end: u32) -> Float16Array;
13684
13685 /// The buffer accessor property represents the `ArrayBuffer` referenced
13686 /// by a `TypedArray` at construction time.
13687 #[wasm_bindgen(getter, method)]
13688 pub fn buffer(this: &Float16Array) -> ArrayBuffer;
13689
13690 /// The `subarray()` method returns a new `TypedArray` on the same
13691 /// `ArrayBuffer` store and with the same element types as this array.
13692 #[wasm_bindgen(method)]
13693 pub fn subarray(this: &Float16Array, begin: u32, end: u32) -> Float16Array;
13694
13695 /// The `slice()` method returns a shallow copy of a portion of a typed
13696 /// array into a new typed array object.
13697 #[wasm_bindgen(method)]
13698 pub fn slice(this: &Float16Array, begin: u32, end: u32) -> Float16Array;
13699
13700 /// The `forEach()` method executes a provided function once per array
13701 /// element, passing values as `f32`.
13702 #[wasm_bindgen(method, js_name = forEach)]
13703 pub fn for_each_as_f32(this: &Float16Array, callback: &mut dyn FnMut(f32, u32, Float16Array));
13704
13705 /// The `forEach()` method executes a provided function once per array
13706 /// element, passing values as `f32`.
13707 #[wasm_bindgen(method, js_name = forEach, catch)]
13708 pub fn try_for_each_as_f32(
13709 this: &Float16Array,
13710 callback: &mut dyn FnMut(f32, u32, Float16Array) -> Result<(), JsError>,
13711 ) -> Result<(), JsValue>;
13712
13713 /// The length accessor property represents the length (in elements) of a
13714 /// typed array.
13715 #[wasm_bindgen(method, getter)]
13716 pub fn length(this: &Float16Array) -> u32;
13717
13718 /// The byteLength accessor property represents the length (in bytes) of a
13719 /// typed array.
13720 #[wasm_bindgen(method, getter, js_name = byteLength)]
13721 pub fn byte_length(this: &Float16Array) -> u32;
13722
13723 /// The byteOffset accessor property represents the offset (in bytes) of a
13724 /// typed array from the start of its `ArrayBuffer`.
13725 #[wasm_bindgen(method, getter, js_name = byteOffset)]
13726 pub fn byte_offset(this: &Float16Array) -> u32;
13727
13728 /// The `set()` method stores multiple values in the typed array, reading
13729 /// input values from a specified array.
13730 #[wasm_bindgen(method)]
13731 pub fn set(this: &Float16Array, src: &JsValue, offset: u32);
13732
13733 /// Gets the value at `idx` as an `f32`, counting from the end if negative.
13734 #[wasm_bindgen(method, js_name = at)]
13735 pub fn at_as_f32(this: &Float16Array, idx: i32) -> Option<f32>;
13736
13737 /// The `copyWithin()` method shallow copies part of a typed array to another
13738 /// location in the same typed array and returns it, without modifying its size.
13739 ///
13740 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin)
13741 #[wasm_bindgen(method, js_name = copyWithin)]
13742 pub fn copy_within(this: &Float16Array, target: i32, start: i32, end: i32) -> Float16Array;
13743
13744 /// Gets the value at `idx` as an `f32`, equivalent to JavaScript
13745 /// `arr[idx]`.
13746 #[wasm_bindgen(method, indexing_getter)]
13747 pub fn get_index_as_f32(this: &Float16Array, idx: u32) -> f32;
13748
13749 /// Sets the value at `idx` from an `f32`, equivalent to JavaScript
13750 /// `arr[idx] = value`.
13751 #[wasm_bindgen(method, indexing_setter)]
13752 pub fn set_index_from_f32(this: &Float16Array, idx: u32, value: f32);
13753}
13754
13755impl Default for Float16Array {
13756 fn default() -> Self {
13757 Self::new(&JsValue::UNDEFINED.unchecked_into())
13758 }
13759}
13760
13761impl TypedArray for Float16Array {}
13762
13763impl Float16Array {
13764 fn as_uint16_view(&self) -> Uint16Array {
13765 let buffer = self.buffer();
13766 Uint16Array::new_with_byte_offset_and_length(
13767 buffer.as_ref(),
13768 self.byte_offset(),
13769 self.length(),
13770 )
13771 }
13772
13773 /// Creates an array from raw IEEE 754 binary16 bit patterns.
13774 ///
13775 /// This pairs naturally with the optional `half` crate:
13776 ///
13777 /// ```rust
13778 /// use half::f16;
13779 /// use js_sys::Float16Array;
13780 ///
13781 /// let values = [f16::from_f32(1.0), f16::from_f32(-2.0)];
13782 /// let bits = values.map(f16::to_bits);
13783 /// let array = Float16Array::new_from_u16_slice(&bits);
13784 /// ```
13785 pub fn new_from_u16_slice(slice: &[u16]) -> Float16Array {
13786 let array = Float16Array::new_with_length(slice.len() as u32);
13787 array.copy_from_u16_slice(slice);
13788 array
13789 }
13790
13791 /// Copy the raw IEEE 754 binary16 bit patterns from this JS typed array
13792 /// into the destination Rust slice.
13793 ///
13794 /// # Panics
13795 ///
13796 /// This function will panic if this typed array's length is different than
13797 /// the length of the provided `dst` array.
13798 ///
13799 /// Values copied into `dst` can be converted back into `half::f16` with
13800 /// `half::f16::from_bits`.
13801 pub fn copy_to_u16_slice(&self, dst: &mut [u16]) {
13802 self.as_uint16_view().copy_to(dst);
13803 }
13804
13805 /// Copy raw IEEE 754 binary16 bit patterns from the source Rust slice into
13806 /// this JS typed array.
13807 ///
13808 /// # Panics
13809 ///
13810 /// This function will panic if this typed array's length is different than
13811 /// the length of the provided `src` array.
13812 ///
13813 /// When using the optional `half` crate, populate `src` with
13814 /// `half::f16::to_bits()`.
13815 pub fn copy_from_u16_slice(&self, src: &[u16]) {
13816 self.as_uint16_view().copy_from(src);
13817 }
13818
13819 /// Efficiently copies the contents of this JS typed array into a new Vec of
13820 /// raw IEEE 754 binary16 bit patterns.
13821 ///
13822 /// This makes it easy to round-trip through the optional `half` crate:
13823 ///
13824 /// ```rust
13825 /// use half::f16;
13826 ///
13827 /// let bits = array.to_u16_vec();
13828 /// let values: Vec<f16> = bits.into_iter().map(f16::from_bits).collect();
13829 /// ```
13830 pub fn to_u16_vec(&self) -> Vec<u16> {
13831 self.as_uint16_view().to_vec()
13832 }
13833}
13834
13835macro_rules! arrays {
13836 ($(#[doc = $ctor:literal] #[doc = $mdn:literal] $name:ident: $ty:ident,)*) => ($(
13837 #[wasm_bindgen]
13838 extern "C" {
13839 #[wasm_bindgen(extends = Object, typescript_type = $name)]
13840 #[derive(Clone, Debug)]
13841 pub type $name;
13842
13843 /// The
13844 #[doc = $ctor]
13845 /// constructor creates a new array.
13846 ///
13847 /// [MDN documentation](
13848 #[doc = $mdn]
13849 /// )
13850 #[wasm_bindgen(constructor)]
13851 pub fn new(constructor_arg: &JsValue) -> $name;
13852
13853 /// An
13854 #[doc = $ctor]
13855 /// which creates an array with an internal buffer large
13856 /// enough for `length` elements.
13857 ///
13858 /// [MDN documentation](
13859 #[doc = $mdn]
13860 /// )
13861 #[wasm_bindgen(constructor)]
13862 pub fn new_with_length(length: u32) -> $name;
13863
13864 /// An
13865 #[doc = $ctor]
13866 /// which creates an array from a Rust slice.
13867 ///
13868 /// [MDN documentation](
13869 #[doc = $mdn]
13870 /// )
13871 #[wasm_bindgen(constructor)]
13872 pub fn new_from_slice(slice: &[$ty]) -> $name;
13873
13874 /// An
13875 #[doc = $ctor]
13876 /// which creates an array with the given buffer but is a
13877 /// view starting at `byte_offset`.
13878 ///
13879 /// [MDN documentation](
13880 #[doc = $mdn]
13881 /// )
13882 #[wasm_bindgen(constructor)]
13883 pub fn new_with_byte_offset(buffer: &JsValue, byte_offset: u32) -> $name;
13884
13885 /// An
13886 #[doc = $ctor]
13887 /// which creates an array with the given buffer but is a
13888 /// view starting at `byte_offset` for `length` elements.
13889 ///
13890 /// [MDN documentation](
13891 #[doc = $mdn]
13892 /// )
13893 #[wasm_bindgen(constructor)]
13894 pub fn new_with_byte_offset_and_length(
13895 buffer: &JsValue,
13896 byte_offset: u32,
13897 length: u32,
13898 ) -> $name;
13899
13900 /// The `fill()` method fills all the elements of an array from a start index
13901 /// to an end index with a static value. The end index is not included.
13902 ///
13903 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/fill)
13904 #[wasm_bindgen(method)]
13905 pub fn fill(this: &$name, value: $ty, start: u32, end: u32) -> $name;
13906
13907 /// The buffer accessor property represents the `ArrayBuffer` referenced
13908 /// by a `TypedArray` at construction time.
13909 #[wasm_bindgen(getter, method)]
13910 pub fn buffer(this: &$name) -> ArrayBuffer;
13911
13912 /// The `subarray()` method returns a new `TypedArray` on the same
13913 /// `ArrayBuffer` store and with the same element types as for this
13914 /// `TypedArray` object.
13915 #[wasm_bindgen(method)]
13916 pub fn subarray(this: &$name, begin: u32, end: u32) -> $name;
13917
13918 /// The `slice()` method returns a shallow copy of a portion of a typed
13919 /// array into a new typed array object. This method has the same algorithm
13920 /// as `Array.prototype.slice()`.
13921 #[wasm_bindgen(method)]
13922 pub fn slice(this: &$name, begin: u32, end: u32) -> $name;
13923
13924 /// The `forEach()` method executes a provided function once per array
13925 /// element. This method has the same algorithm as
13926 /// `Array.prototype.forEach()`. `TypedArray` is one of the typed array
13927 /// types here.
13928 #[wasm_bindgen(method, js_name = forEach)]
13929 pub fn for_each(this: &$name, callback: &mut dyn FnMut($ty, u32, $name));
13930
13931 /// The `forEach()` method executes a provided function once per array
13932 /// element. This method has the same algorithm as
13933 /// `Array.prototype.forEach()`. `TypedArray` is one of the typed array
13934 /// types here.
13935 #[wasm_bindgen(method, js_name = forEach, catch)]
13936 pub fn try_for_each(this: &$name, callback: &mut dyn FnMut($ty, u32, $name) -> Result<(), JsError>) -> Result<(), JsValue>;
13937
13938 /// The length accessor property represents the length (in elements) of a
13939 /// typed array.
13940 #[wasm_bindgen(method, getter)]
13941 pub fn length(this: &$name) -> u32;
13942
13943 /// The byteLength accessor property represents the length (in bytes) of a
13944 /// typed array.
13945 #[wasm_bindgen(method, getter, js_name = byteLength)]
13946 pub fn byte_length(this: &$name) -> u32;
13947
13948 /// The byteOffset accessor property represents the offset (in bytes) of a
13949 /// typed array from the start of its `ArrayBuffer`.
13950 #[wasm_bindgen(method, getter, js_name = byteOffset)]
13951 pub fn byte_offset(this: &$name) -> u32;
13952
13953 /// The `set()` method stores multiple values in the typed array, reading
13954 /// input values from a specified array.
13955 #[wasm_bindgen(method)]
13956 pub fn set(this: &$name, src: &JsValue, offset: u32);
13957
13958 /// Gets the value at `idx`, counting from the end if negative.
13959 #[wasm_bindgen(method)]
13960 pub fn at(this: &$name, idx: i32) -> Option<$ty>;
13961
13962 /// The `copyWithin()` method shallow copies part of a typed array to another
13963 /// location in the same typed array and returns it, without modifying its size.
13964 ///
13965 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin)
13966 #[wasm_bindgen(method, js_name = copyWithin)]
13967 pub fn copy_within(this: &$name, target: i32, start: i32, end: i32) -> $name;
13968
13969 /// Gets the value at `idx`, equivalent to the javascript `my_var = arr[idx]`.
13970 #[wasm_bindgen(method, indexing_getter)]
13971 pub fn get_index(this: &$name, idx: u32) -> $ty;
13972
13973 /// Sets the value at `idx`, equivalent to the javascript `arr[idx] = value`.
13974 #[wasm_bindgen(method, indexing_setter)]
13975 pub fn set_index(this: &$name, idx: u32, value: $ty);
13976
13977 /// Copies the Rust slice's data to self.
13978 ///
13979 /// This method is not expected to be public. It requires the length of the
13980 /// TypedArray to be the same as the slice, use `self.copy_from(slice)` instead.
13981 #[wasm_bindgen(method, js_name = set)]
13982 fn copy_from_slice(this: &$name, slice: &[$ty]);
13983
13984 /// Copies this TypedArray's data to Rust slice;
13985 ///
13986 /// This method is not expected to be public. It requires the length of the
13987 /// TypedArray to be the same as the slice, use `self.copy_to(slice)` instead.
13988 ///
13989 /// # Workaround
13990 ///
13991 /// We actually need `slice.set(typed_array)` here, but since slice cannot be treated as
13992 /// `Uint8Array` on the Rust side, we use `Uint8Array.prototype.set.call`, which allows
13993 /// us to specify the `this` value inside the function.
13994 ///
13995 /// Therefore, `Uint8Array.prototype.set.call(slice, typed_array)` is equivalent to
13996 /// `slice.set(typed_array)`.
13997 #[wasm_bindgen(js_namespace = $name, js_name = "prototype.set.call")]
13998 fn copy_to_slice(slice: &mut [$ty], this: &$name);
13999 }
14000
14001 impl $name {
14002 /// Creates a JS typed array which is a view into wasm's linear
14003 /// memory at the slice specified.
14004 ///
14005 /// This function returns a new typed array which is a view into
14006 /// wasm's memory. This view does not copy the underlying data.
14007 ///
14008 /// # Safety
14009 ///
14010 /// Views into WebAssembly memory are only valid so long as the
14011 /// backing buffer isn't resized in JS. Once this function is called
14012 /// any future calls to `Box::new` (or malloc of any form) may cause
14013 /// the returned value here to be invalidated. Use with caution!
14014 ///
14015 /// Additionally the returned object can be safely mutated but the
14016 /// input slice isn't guaranteed to be mutable.
14017 ///
14018 /// Finally, the returned object is disconnected from the input
14019 /// slice's lifetime, so there's no guarantee that the data is read
14020 /// at the right time.
14021 pub unsafe fn view(rust: &[$ty]) -> $name {
14022 wasm_bindgen::__rt::wbg_cast(rust)
14023 }
14024
14025 /// Creates a JS typed array which is a view into wasm's linear
14026 /// memory at the specified pointer with specified length.
14027 ///
14028 /// This function returns a new typed array which is a view into
14029 /// wasm's memory. This view does not copy the underlying data.
14030 ///
14031 /// # Safety
14032 ///
14033 /// Views into WebAssembly memory are only valid so long as the
14034 /// backing buffer isn't resized in JS. Once this function is called
14035 /// any future calls to `Box::new` (or malloc of any form) may cause
14036 /// the returned value here to be invalidated. Use with caution!
14037 ///
14038 /// Additionally the returned object can be safely mutated,
14039 /// the changes are guaranteed to be reflected in the input array.
14040 pub unsafe fn view_mut_raw(ptr: *mut $ty, length: usize) -> $name {
14041 let slice = core::slice::from_raw_parts_mut(ptr, length);
14042 Self::view(slice)
14043 }
14044
14045 /// Copy the contents of this JS typed array into the destination
14046 /// Rust pointer.
14047 ///
14048 /// This function will efficiently copy the memory from a typed
14049 /// array into this Wasm module's own linear memory, initializing
14050 /// the memory destination provided.
14051 ///
14052 /// # Safety
14053 ///
14054 /// This function requires `dst` to point to a buffer
14055 /// large enough to fit this array's contents.
14056 pub unsafe fn raw_copy_to_ptr(&self, dst: *mut $ty) {
14057 let slice = core::slice::from_raw_parts_mut(dst, self.length() as usize);
14058 self.copy_to(slice);
14059 }
14060
14061 /// Copy the contents of this JS typed array into the destination
14062 /// Rust slice.
14063 ///
14064 /// This function will efficiently copy the memory from a typed
14065 /// array into this Wasm module's own linear memory, initializing
14066 /// the memory destination provided.
14067 ///
14068 /// # Panics
14069 ///
14070 /// This function will panic if this typed array's length is
14071 /// different than the length of the provided `dst` array.
14072 pub fn copy_to(&self, dst: &mut [$ty]) {
14073 core::assert_eq!(self.length() as usize, dst.len());
14074 $name::copy_to_slice(dst, self);
14075 }
14076
14077 /// Copy the contents of this JS typed array into the destination
14078 /// Rust slice.
14079 ///
14080 /// This function will efficiently copy the memory from a typed
14081 /// array into this Wasm module's own linear memory, initializing
14082 /// the memory destination provided.
14083 ///
14084 /// # Panics
14085 ///
14086 /// This function will panic if this typed array's length is
14087 /// different than the length of the provided `dst` array.
14088 pub fn copy_to_uninit<'dst>(&self, dst: &'dst mut [MaybeUninit<$ty>]) -> &'dst mut [$ty] {
14089 core::assert_eq!(self.length() as usize, dst.len());
14090 let dst = unsafe { &mut *(dst as *mut [MaybeUninit<$ty>] as *mut [$ty]) };
14091 self.copy_to(dst);
14092 dst
14093 }
14094
14095 /// Copy the contents of the source Rust slice into this
14096 /// JS typed array.
14097 ///
14098 /// This function will efficiently copy the memory from within
14099 /// the Wasm module's own linear memory to this typed array.
14100 ///
14101 /// # Panics
14102 ///
14103 /// This function will panic if this typed array's length is
14104 /// different than the length of the provided `src` array.
14105 pub fn copy_from(&self, src: &[$ty]) {
14106 core::assert_eq!(self.length() as usize, src.len());
14107 self.copy_from_slice(src);
14108 }
14109
14110 /// Efficiently copies the contents of this JS typed array into a new Vec.
14111 pub fn to_vec(&self) -> Vec<$ty> {
14112 let len = self.length() as usize;
14113 let mut output = Vec::with_capacity(len);
14114 // Safety: the capacity has been set
14115 unsafe {
14116 self.raw_copy_to_ptr(output.as_mut_ptr());
14117 output.set_len(len);
14118 }
14119 output
14120 }
14121 }
14122
14123 impl<'a> From<&'a [$ty]> for $name {
14124 #[inline]
14125 fn from(slice: &'a [$ty]) -> $name {
14126 // This is safe because the `new` function makes a copy if its argument is a TypedArray
14127 $name::new_from_slice(slice)
14128 }
14129 }
14130
14131 impl Default for $name {
14132 fn default() -> Self {
14133 Self::new(&JsValue::UNDEFINED.unchecked_into())
14134 }
14135 }
14136
14137 impl TypedArray for $name {}
14138
14139
14140 )*);
14141}
14142
14143arrays! {
14144 /// `Int8Array()`
14145 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int8Array
14146 Int8Array: i8,
14147
14148 /// `Int16Array()`
14149 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int16Array
14150 Int16Array: i16,
14151
14152 /// `Int32Array()`
14153 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int32Array
14154 Int32Array: i32,
14155
14156 /// `Uint8Array()`
14157 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array
14158 Uint8Array: u8,
14159
14160 /// `Uint8ClampedArray()`
14161 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8ClampedArray
14162 Uint8ClampedArray: u8,
14163
14164 /// `Uint16Array()`
14165 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint16Array
14166 Uint16Array: u16,
14167
14168 /// `Uint32Array()`
14169 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint32Array
14170 Uint32Array: u32,
14171
14172 /// `Float32Array()`
14173 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array
14174 Float32Array: f32,
14175
14176 /// `Float64Array()`
14177 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float64Array
14178 Float64Array: f64,
14179
14180 /// `BigInt64Array()`
14181 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt64Array
14182 BigInt64Array: i64,
14183
14184 /// `BigUint64Array()`
14185 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigUint64Array
14186 BigUint64Array: u64,
14187}
14188
14189/// Bridging between JavaScript `Promise`s and Rust `Future`s.
14190///
14191/// Enables `promise.await` directly on any [`Promise`].
14192/// This module is also re-exported by `wasm-bindgen-futures` for backwards compatibility.
14193pub mod futures;