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(
31 all(feature = "futures", target_feature = "atomics"),
32 feature(stdarch_wasm_atomic_wait)
33)]
34
35extern crate alloc;
36
37use alloc::string::String;
38use alloc::vec::Vec;
39use core::cmp::Ordering;
40#[cfg(not(js_sys_unstable_apis))]
41use core::convert::Infallible;
42use core::convert::{self, TryFrom};
43use core::f64;
44use core::fmt;
45use core::iter::{self, Product, Sum};
46use core::marker::PhantomData;
47use core::mem::MaybeUninit;
48use core::ops::{Add, BitAnd, BitOr, BitXor, Div, Mul, Neg, Not, Rem, Shl, Shr, Sub};
49use core::str;
50use core::str::FromStr;
51pub use wasm_bindgen;
52use wasm_bindgen::closure::{ScopedClosure, WasmClosure};
53use wasm_bindgen::convert::{FromWasmAbi, IntoWasmAbi, Upcast, UpcastFrom};
54use wasm_bindgen::prelude::*;
55use wasm_bindgen::JsError;
56
57// Re-export sys types as js-sys types
58pub use wasm_bindgen::sys::{JsOption, Null, Promising, Undefined};
59pub use wasm_bindgen::JsGeneric;
60
61// When adding new imports:
62//
63// * Keep imports in alphabetical order.
64//
65// * Rename imports with `js_name = ...` according to the note about `camelCase`
66// and `snake_case` in the module's documentation above.
67//
68// * Include the one sentence summary of the import from the MDN link in the
69// module's documentation above, and the MDN link itself.
70//
71// * If a function or method can throw an exception, make it catchable by adding
72// `#[wasm_bindgen(catch)]`.
73//
74// * Add a new `#[test]` into the appropriate file in the
75// `crates/js-sys/tests/wasm/` directory. If the imported function or method
76// can throw an exception, make sure to also add test coverage for that case.
77//
78// * Arguments that are `JsValue`s or imported JavaScript types should be taken
79// by reference.
80//
81// * Name JavaScript's `toString()` method as `to_js_string()` to avoid conflict
82// with Rust's `ToString` trait.
83
84macro_rules! forward_deref_unop {
85 (impl $imp:ident, $method:ident for $t:ty) => {
86 impl $imp for $t {
87 type Output = <&'static $t as $imp>::Output;
88
89 #[inline]
90 fn $method(self) -> Self::Output {
91 $imp::$method(&self)
92 }
93 }
94 };
95 (impl<$($gen:ident),+> $imp:ident, $method:ident for $t:ty) => {
96 impl<$($gen),+> $imp for $t {
97 type Output = <&'static $t as $imp>::Output;
98
99 #[inline]
100 fn $method(self) -> Self::Output {
101 $imp::$method(&self)
102 }
103 }
104 };
105}
106
107macro_rules! forward_deref_binop {
108 (impl $imp:ident, $method:ident for $t:ty) => {
109 impl<'a> $imp<$t> for &'a $t {
110 type Output = <&'static $t as $imp<&'static $t>>::Output;
111
112 #[inline]
113 fn $method(self, other: $t) -> Self::Output {
114 $imp::$method(self, &other)
115 }
116 }
117
118 impl $imp<&$t> for $t {
119 type Output = <&'static $t as $imp<&'static $t>>::Output;
120
121 #[inline]
122 fn $method(self, other: &$t) -> Self::Output {
123 $imp::$method(&self, other)
124 }
125 }
126
127 impl $imp<$t> for $t {
128 type Output = <&'static $t as $imp<&'static $t>>::Output;
129
130 #[inline]
131 fn $method(self, other: $t) -> Self::Output {
132 $imp::$method(&self, &other)
133 }
134 }
135 };
136 (impl<$($gen:ident),+> $imp:ident, $method:ident for $t:ty) => {
137 impl<'a, $($gen),+> $imp<$t> for &'a $t {
138 type Output = <&'static $t as $imp<&'static $t>>::Output;
139
140 #[inline]
141 fn $method(self, other: $t) -> Self::Output {
142 $imp::$method(self, &other)
143 }
144 }
145
146 impl<$($gen),+> $imp<&$t> for $t {
147 type Output = <&'static $t as $imp<&'static $t>>::Output;
148
149 #[inline]
150 fn $method(self, other: &$t) -> Self::Output {
151 $imp::$method(&self, other)
152 }
153 }
154
155 impl<$($gen),+> $imp<$t> for $t {
156 type Output = <&'static $t as $imp<&'static $t>>::Output;
157
158 #[inline]
159 fn $method(self, other: $t) -> Self::Output {
160 $imp::$method(&self, &other)
161 }
162 }
163 };
164}
165
166macro_rules! forward_js_unop {
167 (impl $imp:ident, $method:ident for $t:ty) => {
168 impl $imp for &$t {
169 type Output = $t;
170
171 #[inline]
172 fn $method(self) -> Self::Output {
173 $imp::$method(JsValue::as_ref(self)).unchecked_into()
174 }
175 }
176
177 forward_deref_unop!(impl $imp, $method for $t);
178 };
179 (impl<$($gen:ident),+> $imp:ident, $method:ident for $t:ty) => {
180 impl<$($gen),+> $imp for &$t {
181 type Output = $t;
182
183 #[inline]
184 fn $method(self) -> Self::Output {
185 $imp::$method(JsValue::as_ref(self)).unchecked_into()
186 }
187 }
188
189 forward_deref_unop!(impl<$($gen),+> $imp, $method for $t);
190 };
191}
192
193macro_rules! forward_js_binop {
194 (impl $imp:ident, $method:ident for $t:ty) => {
195 impl $imp<&$t> for &$t {
196 type Output = $t;
197
198 #[inline]
199 fn $method(self, other: &$t) -> Self::Output {
200 $imp::$method(JsValue::as_ref(self), JsValue::as_ref(other)).unchecked_into()
201 }
202 }
203
204 forward_deref_binop!(impl $imp, $method for $t);
205 };
206 (impl<$($gen:ident),+> $imp:ident, $method:ident for $t:ty) => {
207 impl<$($gen),+> $imp<&$t> for &$t {
208 type Output = $t;
209
210 #[inline]
211 fn $method(self, other: &$t) -> Self::Output {
212 $imp::$method(JsValue::as_ref(self), JsValue::as_ref(other)).unchecked_into()
213 }
214 }
215
216 forward_deref_binop!(impl<$($gen),+> $imp, $method for $t);
217 };
218}
219
220macro_rules! sum_product {
221 ($($a:ident)*) => ($(
222 impl Sum for $a {
223 #[inline]
224 fn sum<I: iter::Iterator<Item=Self>>(iter: I) -> Self {
225 iter.fold(
226 $a::from(0),
227 |a, b| a + b,
228 )
229 }
230 }
231
232 impl Product for $a {
233 #[inline]
234 fn product<I: iter::Iterator<Item=Self>>(iter: I) -> Self {
235 iter.fold(
236 $a::from(1),
237 |a, b| a * b,
238 )
239 }
240 }
241
242 impl<'a> Sum<&'a $a> for $a {
243 fn sum<I: iter::Iterator<Item=&'a Self>>(iter: I) -> Self {
244 iter.fold(
245 $a::from(0),
246 |a, b| a + b,
247 )
248 }
249 }
250
251 impl<'a> Product<&'a $a> for $a {
252 #[inline]
253 fn product<I: iter::Iterator<Item=&'a Self>>(iter: I) -> Self {
254 iter.fold(
255 $a::from(1),
256 |a, b| a * b,
257 )
258 }
259 }
260 )*);
261 // Generic variant: impl<T> for Type<T>
262 (impl<$gen:ident> $a:ident<$g2:ident>) => {
263 impl<$gen> Sum for $a<$g2>
264 where
265 $a<$g2>: From<$gen>,
266 $g2: From<u32>
267 {
268 #[inline]
269 fn sum<I: iter::Iterator<Item=Self>>(iter: I) -> Self {
270 iter.fold(
271 $a::from($g2::from(0)),
272 |a, b| a + b,
273 )
274 }
275 }
276
277 impl<$gen> Product for $a<$g2>
278 where
279 $a<$g2>: From<$gen>,
280 $g2: From<u32>
281 {
282 #[inline]
283 fn product<I: iter::Iterator<Item=Self>>(iter: I) -> Self {
284 iter.fold(
285 $a::from($g2::from(1)),
286 |a, b| a * b,
287 )
288 }
289 }
290
291 impl<'a, $gen> Sum<&'a $a<$g2>> for $a<$g2>
292 where
293 $a<$g2>: From<$gen>,
294 $g2: From<u32>
295 {
296 fn sum<I: iter::Iterator<Item=&'a Self>>(iter: I) -> Self {
297 iter.fold(
298 $a::from($g2::from(0)),
299 |a, b| a + b,
300 )
301 }
302 }
303
304 impl<'a, $gen> Product<&'a $a<$g2>> for $a<$g2>
305 where
306 $a<$g2>: From<$gen>,
307 $g2: From<u32>
308 {
309 #[inline]
310 fn product<I: iter::Iterator<Item=&'a Self>>(iter: I) -> Self {
311 iter.fold(
312 $a::from($g2::from(1)),
313 |a, b| a * b,
314 )
315 }
316 }
317 };
318}
319
320macro_rules! partialord_ord {
321 ($t:ident) => {
322 impl PartialOrd for $t {
323 #[inline]
324 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
325 Some(self.cmp(other))
326 }
327
328 #[inline]
329 fn lt(&self, other: &Self) -> bool {
330 JsValue::as_ref(self).lt(JsValue::as_ref(other))
331 }
332
333 #[inline]
334 fn le(&self, other: &Self) -> bool {
335 JsValue::as_ref(self).le(JsValue::as_ref(other))
336 }
337
338 #[inline]
339 fn ge(&self, other: &Self) -> bool {
340 JsValue::as_ref(self).ge(JsValue::as_ref(other))
341 }
342
343 #[inline]
344 fn gt(&self, other: &Self) -> bool {
345 JsValue::as_ref(self).gt(JsValue::as_ref(other))
346 }
347 }
348
349 impl Ord for $t {
350 #[inline]
351 fn cmp(&self, other: &Self) -> Ordering {
352 if self == other {
353 Ordering::Equal
354 } else if self.lt(other) {
355 Ordering::Less
356 } else {
357 Ordering::Greater
358 }
359 }
360 }
361 };
362}
363
364#[wasm_bindgen]
365extern "C" {
366 /// The `decodeURI()` function decodes a Uniform Resource Identifier (URI)
367 /// previously created by `encodeURI` or by a similar routine.
368 ///
369 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURI)
370 #[wasm_bindgen(catch, js_name = decodeURI)]
371 pub fn decode_uri(encoded: &str) -> Result<JsString, JsValue>;
372
373 /// The `decodeURIComponent()` function decodes a Uniform Resource Identifier (URI) component
374 /// previously created by `encodeURIComponent` or by a similar routine.
375 ///
376 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURIComponent)
377 #[wasm_bindgen(catch, js_name = decodeURIComponent)]
378 pub fn decode_uri_component(encoded: &str) -> Result<JsString, JsValue>;
379
380 /// The `encodeURI()` function encodes a Uniform Resource Identifier (URI)
381 /// by replacing each instance of certain characters by one, two, three, or
382 /// four escape sequences representing the UTF-8 encoding of the character
383 /// (will only be four escape sequences for characters composed of two
384 /// "surrogate" characters).
385 ///
386 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURI)
387 #[wasm_bindgen(js_name = encodeURI)]
388 pub fn encode_uri(decoded: &str) -> JsString;
389
390 /// The `encodeURIComponent()` function encodes a Uniform Resource Identifier (URI) component
391 /// by replacing each instance of certain characters by one, two, three, or four escape sequences
392 /// representing the UTF-8 encoding of the character
393 /// (will only be four escape sequences for characters composed of two "surrogate" characters).
394 ///
395 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent)
396 #[wasm_bindgen(js_name = encodeURIComponent)]
397 pub fn encode_uri_component(decoded: &str) -> JsString;
398
399 /// The `eval()` function evaluates JavaScript code represented as a string.
400 ///
401 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval)
402 #[cfg(feature = "unsafe-eval")]
403 #[wasm_bindgen(catch)]
404 pub fn eval(js_source_text: &str) -> Result<JsValue, JsValue>;
405
406 /// The global `isFinite()` function determines whether the passed value is a finite number.
407 /// If needed, the parameter is first converted to a number.
408 ///
409 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isFinite)
410 #[wasm_bindgen(js_name = isFinite)]
411 pub fn is_finite(value: &JsValue) -> bool;
412
413 /// The `parseInt()` function parses a string argument and returns an integer
414 /// of the specified radix (the base in mathematical numeral systems), or NaN on error.
415 ///
416 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt)
417 #[wasm_bindgen(js_name = parseInt)]
418 pub fn parse_int(text: &str, radix: u8) -> f64;
419
420 /// The `parseFloat()` function parses an argument and returns a floating point number,
421 /// or NaN on error.
422 ///
423 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseFloat)
424 #[wasm_bindgen(js_name = parseFloat)]
425 pub fn parse_float(text: &str) -> f64;
426
427 /// The `escape()` function computes a new string in which certain characters have been
428 /// replaced by a hexadecimal escape sequence.
429 ///
430 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/escape)
431 #[wasm_bindgen]
432 pub fn escape(string: &str) -> JsString;
433
434 /// The `unescape()` function computes a new string in which hexadecimal escape
435 /// sequences are replaced with the character that it represents. The escape sequences might
436 /// be introduced by a function like `escape`. Usually, `decodeURI` or `decodeURIComponent`
437 /// are preferred over `unescape`.
438 ///
439 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/unescape)
440 #[wasm_bindgen]
441 pub fn unescape(string: &str) -> JsString;
442}
443
444// Array
445#[wasm_bindgen]
446extern "C" {
447 #[wasm_bindgen(extends = Object, is_type_of = Array::is_array, typescript_type = "Array<any>")]
448 #[derive(Clone, Debug, PartialEq, Eq)]
449 pub type Array<T = JsValue>;
450
451 /// Creates a new empty array.
452 ///
453 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Array)
454 #[cfg(not(js_sys_unstable_apis))]
455 #[wasm_bindgen(constructor)]
456 pub fn new() -> Array;
457
458 /// Creates a new empty array.
459 ///
460 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Array)
461 #[cfg(js_sys_unstable_apis)]
462 #[wasm_bindgen(constructor)]
463 pub fn new<T>() -> Array<T>;
464
465 // Next major: deprecate
466 /// Creates a new empty array.
467 ///
468 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Array)
469 #[wasm_bindgen(constructor)]
470 pub fn new_typed<T>() -> Array<T>;
471
472 /// Creates a new array with the specified length (elements are initialized to `undefined`).
473 ///
474 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Array)
475 #[cfg(not(js_sys_unstable_apis))]
476 #[wasm_bindgen(constructor)]
477 pub fn new_with_length(len: u32) -> Array;
478
479 /// Creates a new array with the specified length (elements are initialized to `undefined`).
480 ///
481 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Array)
482 #[cfg(js_sys_unstable_apis)]
483 #[wasm_bindgen(constructor)]
484 pub fn new_with_length<T>(len: u32) -> Array<T>;
485
486 // Next major: deprecate
487 /// Creates a new array with the specified length (elements are initialized to `undefined`).
488 ///
489 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Array)
490 #[wasm_bindgen(constructor)]
491 pub fn new_with_length_typed<T>(len: u32) -> Array<T>;
492
493 /// Retrieves the element at the index, counting from the end if negative
494 /// (returns `undefined` if the index is out of range).
495 ///
496 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at)
497 #[cfg(not(js_sys_unstable_apis))]
498 #[wasm_bindgen(method)]
499 pub fn at<T>(this: &Array<T>, index: i32) -> T;
500
501 /// Retrieves the element at the index, counting from the end if negative
502 /// (returns `None` if the index is out of range).
503 ///
504 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at)
505 #[cfg(js_sys_unstable_apis)]
506 #[wasm_bindgen(method)]
507 pub fn at<T>(this: &Array<T>, index: i32) -> Option<T>;
508
509 /// Retrieves the element at the index (returns `undefined` if the index is out of range).
510 ///
511 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at)
512 #[cfg(not(js_sys_unstable_apis))]
513 #[wasm_bindgen(method, indexing_getter)]
514 pub fn get<T>(this: &Array<T>, index: u32) -> T;
515
516 /// Retrieves the element at the index (returns `None` if the index is out of range).
517 ///
518 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at)
519 #[cfg(js_sys_unstable_apis)]
520 #[wasm_bindgen(method, indexing_getter)]
521 pub fn get<T>(this: &Array<T>, index: u32) -> Option<T>;
522
523 /// Retrieves the element at the index (returns `undefined` if the index is out of range).
524 ///
525 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at)
526 #[wasm_bindgen(method, indexing_getter)]
527 pub fn get_unchecked<T>(this: &Array<T>, index: u32) -> T;
528
529 // Next major: deprecate
530 /// Retrieves the element at the index (returns `None` if the index is out of range,
531 /// or if the element is explicitly `undefined`).
532 #[wasm_bindgen(method, indexing_getter)]
533 pub fn get_checked<T>(this: &Array<T>, index: u32) -> Option<T>;
534
535 /// Sets the element at the index (auto-enlarges the array if the index is out of range).
536 #[cfg(not(js_sys_unstable_apis))]
537 #[wasm_bindgen(method, indexing_setter)]
538 pub fn set<T>(this: &Array<T>, index: u32, value: T);
539
540 /// Sets the element at the index (auto-enlarges the array if the index is out of range).
541 #[cfg(js_sys_unstable_apis)]
542 #[wasm_bindgen(method, indexing_setter)]
543 pub fn set<T>(this: &Array<T>, index: u32, value: &T);
544
545 // Next major: deprecate
546 /// Sets the element at the index (auto-enlarges the array if the index is out of range).
547 #[wasm_bindgen(method, indexing_setter)]
548 pub fn set_ref<T>(this: &Array<T>, index: u32, value: &T);
549
550 /// Deletes the element at the index (does nothing if the index is out of range).
551 ///
552 /// The element at the index is set to `undefined`.
553 ///
554 /// This does not resize the array, the array will still be the same length.
555 #[wasm_bindgen(method, indexing_deleter)]
556 pub fn delete<T>(this: &Array<T>, index: u32);
557
558 /// The `Array.from()` static method creates a new, shallow-copied `Array` instance
559 /// from an array-like or iterable object.
560 ///
561 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from)
562 #[cfg(not(js_sys_unstable_apis))]
563 #[wasm_bindgen(static_method_of = Array)]
564 pub fn from(val: &JsValue) -> Array;
565
566 /// The `Array.from()` static method creates a new, shallow-copied `Array` instance
567 /// from an array-like or iterable object.
568 ///
569 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from)
570 #[cfg(js_sys_unstable_apis)]
571 #[wasm_bindgen(static_method_of = Array, catch, js_name = from)]
572 pub fn from<I: Iterable>(val: &I) -> Result<Array<I::Item>, JsValue>;
573
574 // Next major: deprecate
575 /// The `Array.from()` static method creates a new, shallow-copied `Array` instance
576 /// from an array-like or iterable object.
577 ///
578 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from)
579 #[wasm_bindgen(static_method_of = Array, catch, js_name = from)]
580 pub fn from_iterable<I: Iterable>(val: &I) -> Result<Array<I::Item>, JsValue>;
581
582 /// The `Array.from()` static method with a map function creates a new, shallow-copied
583 /// `Array` instance from an array-like or iterable object, applying the map function
584 /// to each value.
585 ///
586 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from)
587 #[wasm_bindgen(static_method_of = Array, catch, js_name = from)]
588 pub fn from_iterable_map<I: Iterable, U>(
589 val: &I,
590 map: &mut dyn FnMut(I::Item, u32) -> Result<U, JsError>,
591 ) -> Result<Array<U>, JsValue>;
592
593 /// The `Array.fromAsync()` static method creates a new, shallow-copied `Array` instance
594 /// from an async iterable, iterable or array-like object.
595 ///
596 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fromAsync)
597 #[wasm_bindgen(static_method_of = Array, catch, js_name = fromAsync)]
598 pub fn from_async<I: AsyncIterable>(val: &I) -> Result<Promise<Array<I::Item>>, JsValue>;
599
600 /// The `Array.fromAsync()` static method with a map function creates a new, shallow-copied
601 /// `Array` instance from an async iterable, iterable or array-like object, applying the map
602 /// function to each value.
603 ///
604 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fromAsync)
605 #[wasm_bindgen(static_method_of = Array, catch, js_name = fromAsync)]
606 pub fn from_async_map<'a, I: AsyncIterable, R: Promising>(
607 val: &I,
608 map: &ScopedClosure<'a, dyn FnMut(I::Item, u32) -> Result<R, JsError>>,
609 ) -> Result<Promise<Array<R::Resolution>>, JsValue>;
610
611 /// The `copyWithin()` method shallow copies part of an array to another
612 /// location in the same array and returns it, without modifying its size.
613 ///
614 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin)
615 #[wasm_bindgen(method, js_name = copyWithin)]
616 pub fn copy_within<T>(this: &Array<T>, target: i32, start: i32, end: i32) -> Array<T>;
617
618 /// The `concat()` method is used to merge two or more arrays. This method
619 /// does not change the existing arrays, but instead returns a new array.
620 ///
621 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat)
622 #[wasm_bindgen(method)]
623 pub fn concat<T, U: Upcast<T>>(this: &Array<T>, array: &Array<U>) -> Array<T>;
624
625 /// The `concat()` method is used to merge two or more arrays. This method
626 /// does not change the existing arrays, but instead returns a new array.
627 ///
628 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat)
629 #[wasm_bindgen(method)]
630 pub fn concat_many<T, U: Upcast<T>>(this: &Array<T>, array: &[Array<U>]) -> Array<T>;
631
632 /// The `every()` method tests whether all elements in the array pass the test
633 /// implemented by the provided function.
634 ///
635 /// **Note:** Consider using [`Array::try_every`] if the predicate might throw an error.
636 ///
637 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every)
638 #[wasm_bindgen(method)]
639 pub fn every<T>(this: &Array<T>, predicate: &mut dyn FnMut(T, u32, Array<T>) -> bool) -> bool;
640
641 /// The `every()` method tests whether all elements in the array pass the test
642 /// implemented by the provided function. _(Fallible variation)_
643 ///
644 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every)
645 #[wasm_bindgen(method, js_name = every, catch)]
646 pub fn try_every<T>(
647 this: &Array<T>,
648 predicate: &mut dyn FnMut(T, u32) -> Result<bool, JsError>,
649 ) -> Result<bool, JsValue>;
650
651 /// The `fill()` method fills all the elements of an array from a start index
652 /// to an end index with a static value. The end index is not included.
653 ///
654 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill)
655 #[wasm_bindgen(method)]
656 pub fn fill<T>(this: &Array<T>, value: &T, start: u32, end: u32) -> Array<T>;
657
658 /// The `filter()` method creates a new array with all elements that pass the
659 /// test implemented by the provided function.
660 ///
661 /// **Note:** Consider using [`Array::try_filter`] if the predicate might throw an error.
662 ///
663 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter)
664 #[wasm_bindgen(method)]
665 pub fn filter<T>(
666 this: &Array<T>,
667 predicate: &mut dyn FnMut(T, u32, Array<T>) -> bool,
668 ) -> Array<T>;
669
670 /// The `filter()` method creates a new array with all elements that pass the
671 /// test implemented by the provided function. _(Fallible variation)_
672 ///
673 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter)
674 #[wasm_bindgen(method, js_name = filter, catch)]
675 pub fn try_filter<T>(
676 this: &Array<T>,
677 predicate: &mut dyn FnMut(T, u32) -> Result<bool, JsError>,
678 ) -> Result<Array<T>, JsValue>;
679
680 /// The `find()` method returns the value of the first element in the array that satisfies
681 /// the provided testing function. Otherwise `undefined` is returned.
682 ///
683 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)
684 #[cfg(not(js_sys_unstable_apis))]
685 #[wasm_bindgen(method)]
686 pub fn find<T>(this: &Array<T>, predicate: &mut dyn FnMut(T, u32, Array<T>) -> bool) -> T;
687
688 /// The `find()` method returns the value of the first element in the array that satisfies
689 /// the provided testing function. Returns `None` if no element matches.
690 ///
691 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)
692 #[cfg(js_sys_unstable_apis)]
693 #[wasm_bindgen(method)]
694 pub fn find<T>(
695 this: &Array<T>,
696 predicate: &mut dyn FnMut(T, u32, Array<T>) -> bool,
697 ) -> Option<T>;
698
699 /// The `find()` method returns the value of the first element in the array that satisfies
700 /// the provided testing function. Otherwise `undefined` is returned. _(Fallible variation)_
701 ///
702 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)
703 #[wasm_bindgen(method, js_name = find, catch)]
704 pub fn try_find<T>(
705 this: &Array<T>,
706 predicate: &mut dyn FnMut(T, u32) -> Result<bool, JsError>,
707 ) -> Result<Option<T>, JsValue>;
708
709 /// The `findIndex()` method returns the index of the first element in the array that
710 /// satisfies the provided testing function. Otherwise -1 is returned.
711 ///
712 /// **Note:** Consider using [`Array::try_find_index`] if the predicate might throw an error.
713 ///
714 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex)
715 #[wasm_bindgen(method, js_name = findIndex)]
716 pub fn find_index<T>(
717 this: &Array<T>,
718 predicate: &mut dyn FnMut(T, u32, Array<T>) -> bool,
719 ) -> i32;
720
721 /// The `findIndex()` method returns the index of the first element in the array that
722 /// satisfies the provided testing function. Otherwise -1 is returned. _(Fallible variation)_
723 ///
724 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex)
725 #[wasm_bindgen(method, js_name = findIndex, catch)]
726 pub fn try_find_index<T>(
727 this: &Array<T>,
728 predicate: &mut dyn FnMut(T, u32) -> Result<bool, JsError>,
729 ) -> Result<i32, JsValue>;
730
731 /// The `findLast()` method of Array instances iterates the array in reverse order
732 /// and returns the value of the first element that satisfies the provided testing function.
733 /// If no elements satisfy the testing function, undefined is returned.
734 ///
735 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLast)
736 #[cfg(not(js_sys_unstable_apis))]
737 #[wasm_bindgen(method, js_name = findLast)]
738 pub fn find_last<T>(this: &Array<T>, predicate: &mut dyn FnMut(T, u32, Array<T>) -> bool) -> T;
739
740 /// The `findLast()` method of Array instances iterates the array in reverse order
741 /// and returns the value of the first element that satisfies the provided testing function.
742 /// Returns `None` if no element matches.
743 ///
744 /// **Note:** Consider using [`Array::try_find_last`] if the predicate might throw an error.
745 ///
746 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLast)
747 #[cfg(js_sys_unstable_apis)]
748 #[wasm_bindgen(method, js_name = findLast)]
749 pub fn find_last<T>(this: &Array<T>, predicate: &mut dyn FnMut(T, u32) -> bool) -> Option<T>;
750
751 /// The `findLast()` method of Array instances iterates the array in reverse order
752 /// and returns the value of the first element that satisfies the provided testing function.
753 /// If no elements satisfy the testing function, undefined is returned. _(Fallible variation)_
754 ///
755 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLast)
756 #[wasm_bindgen(method, js_name = findLast, catch)]
757 pub fn try_find_last<T>(
758 this: &Array<T>,
759 predicate: &mut dyn FnMut(T, u32) -> Result<bool, JsError>,
760 ) -> Result<Option<T>, JsValue>;
761
762 /// The `findLastIndex()` method of Array instances iterates the array in reverse order
763 /// and returns the index of the first element that satisfies the provided testing function.
764 /// If no elements satisfy the testing function, -1 is returned.
765 ///
766 /// **Note:** Consider using [`Array::try_find_last_index`] if the predicate might throw an error.
767 ///
768 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLastIndex)
769 #[wasm_bindgen(method, js_name = findLastIndex)]
770 pub fn find_last_index<T>(
771 this: &Array<T>,
772 predicate: &mut dyn FnMut(T, u32, Array<T>) -> bool,
773 ) -> i32;
774
775 /// The `findLastIndex()` method of Array instances iterates the array in reverse order
776 /// and returns the index of the first element that satisfies the provided testing function.
777 /// If no elements satisfy the testing function, -1 is returned. _(Fallible variation)_
778 ///
779 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLastIndex)
780 #[wasm_bindgen(method, js_name = findLastIndex, catch)]
781 pub fn try_find_last_index<T>(
782 this: &Array<T>,
783 predicate: &mut dyn FnMut(T, u32) -> Result<bool, JsError>,
784 ) -> Result<i32, JsValue>;
785
786 /// The `flat()` method creates a new array with all sub-array elements concatenated into it
787 /// recursively up to the specified depth.
788 ///
789 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat)
790 #[wasm_bindgen(method)]
791 pub fn flat<T>(this: &Array<T>, depth: i32) -> Array<JsValue>;
792
793 /// The `flatMap()` method first maps each element using a mapping function, then flattens
794 /// the result into a new array.
795 ///
796 /// **Note:** Consider using [`Array::try_flat_map`] for safer fallible handling.
797 ///
798 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap)
799 #[wasm_bindgen(method, js_name = flatMap)]
800 pub fn flat_map<T, U>(
801 this: &Array<T>,
802 callback: &mut dyn FnMut(T, u32, Array<T>) -> Vec<U>,
803 ) -> Array<U>;
804
805 /// The `flatMap()` method first maps each element using a mapping function, then flattens
806 /// the result into a new array.
807 ///
808 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap)
809 #[wasm_bindgen(method, js_name = flatMap, catch)]
810 pub fn try_flat_map<T, U>(
811 this: &Array<T>,
812 callback: &mut dyn FnMut(T, u32) -> Vec<U>,
813 ) -> Result<Array<U>, JsValue>;
814
815 /// The `forEach()` method executes a provided function once for each array element.
816 ///
817 /// **Note:** Consider using [`Array::try_for_each`] if the callback might throw an error.
818 ///
819 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach)
820 #[wasm_bindgen(method, js_name = forEach)]
821 pub fn for_each<T: JsGeneric>(this: &Array<T>, callback: &mut dyn FnMut(T, u32, Array<T>));
822
823 /// The `forEach()` method executes a provided function once for each array element. _(Fallible variation)_
824 ///
825 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach)
826 #[wasm_bindgen(method, js_name = forEach, catch)]
827 pub fn try_for_each<T>(
828 this: &Array<T>,
829 callback: &mut dyn FnMut(T, u32) -> Result<(), JsError>,
830 ) -> Result<(), JsValue>;
831
832 /// The `includes()` method determines whether an array includes a certain
833 /// element, returning true or false as appropriate.
834 ///
835 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes)
836 #[wasm_bindgen(method)]
837 pub fn includes<T>(this: &Array<T>, value: &T, from_index: i32) -> bool;
838
839 /// The `indexOf()` method returns the first index at which a given element
840 /// can be found in the array, or -1 if it is not present.
841 ///
842 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf)
843 #[wasm_bindgen(method, js_name = indexOf)]
844 pub fn index_of<T>(this: &Array<T>, value: &T, from_index: i32) -> i32;
845
846 /// The `Array.isArray()` method determines whether the passed value is an Array.
847 ///
848 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray)
849 #[wasm_bindgen(static_method_of = Array, js_name = isArray)]
850 pub fn is_array(value: &JsValue) -> bool;
851
852 /// The `join()` method joins all elements of an array (or an array-like object)
853 /// into a string and returns this string.
854 ///
855 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join)
856 #[wasm_bindgen(method)]
857 pub fn join<T>(this: &Array<T>, delimiter: &str) -> JsString;
858
859 /// The `lastIndexOf()` method returns the last index at which a given element
860 /// can be found in the array, or -1 if it is not present. The array is
861 /// searched backwards, starting at fromIndex.
862 ///
863 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/lastIndexOf)
864 #[wasm_bindgen(method, js_name = lastIndexOf)]
865 pub fn last_index_of<T>(this: &Array<T>, value: &T, from_index: i32) -> i32;
866
867 /// The length property of an object which is an instance of type Array
868 /// sets or returns the number of elements in that array. The value is an
869 /// unsigned, 32-bit integer that is always numerically greater than the
870 /// highest index in the array.
871 ///
872 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/length)
873 #[wasm_bindgen(method, getter)]
874 pub fn length<T>(this: &Array<T>) -> u32;
875
876 /// Sets the length of the array.
877 ///
878 /// If it is set to less than the current length of the array, it will
879 /// shrink the array.
880 ///
881 /// If it is set to more than the current length of the array, it will
882 /// increase the length of the array, filling the new space with empty
883 /// slots.
884 ///
885 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/length)
886 #[wasm_bindgen(method, setter)]
887 pub fn set_length<T>(this: &Array<T>, value: u32);
888
889 /// `map()` calls a provided callback function once for each element in an array,
890 /// in order, and constructs a new array from the results. callback is invoked
891 /// only for indexes of the array which have assigned values, including undefined.
892 /// It is not called for missing elements of the array (that is, indexes that have
893 /// never been set, which have been deleted or which have never been assigned a value).
894 ///
895 /// **Note:** Consider using [`Array::try_map`] for safer fallible handling.
896 ///
897 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map)
898 #[wasm_bindgen(method)]
899 pub fn map<T, U>(this: &Array<T>, predicate: &mut dyn FnMut(T, u32, Array<T>) -> U)
900 -> Array<U>;
901
902 /// `map()` calls a provided callback function once for each element in an array,
903 /// in order, and constructs a new array from the results. callback is invoked
904 /// only for indexes of the array which have assigned values, including undefined.
905 /// It is not called for missing elements of the array (that is, indexes that have
906 /// never been set, which have been deleted or which have never been assigned a value).
907 /// _(Fallible variation)_
908 ///
909 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map)
910 #[wasm_bindgen(method, js_name = map, catch)]
911 pub fn try_map<T, U>(
912 this: &Array<T>,
913 predicate: &mut dyn FnMut(T, u32) -> Result<U, JsError>,
914 ) -> Result<Array<U>, JsValue>;
915
916 /// The `Array.of()` method creates a new Array instance with a variable
917 /// number of arguments, regardless of number or type of the arguments.
918 ///
919 /// Note: For type inference use `Array::<T>::of(&[T])`.
920 ///
921 /// The difference between `Array.of()` and the `Array` constructor is in the
922 /// handling of integer arguments: `Array.of(7)` creates an array with a single
923 /// element, `7`, whereas `Array(7)` creates an empty array with a `length`
924 /// property of `7` (Note: this implies an array of 7 empty slots, not slots
925 /// with actual undefined values).
926 ///
927 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of)
928 #[wasm_bindgen(static_method_of = Array, js_name = of, variadic)]
929 pub fn of<T>(values: &[T]) -> Array<T>;
930
931 // Next major: deprecate these
932 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of)
933 #[wasm_bindgen(static_method_of = Array, js_name = of)]
934 pub fn of1(a: &JsValue) -> Array;
935
936 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of)
937 #[wasm_bindgen(static_method_of = Array, js_name = of)]
938 pub fn of2(a: &JsValue, b: &JsValue) -> Array;
939
940 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of)
941 #[wasm_bindgen(static_method_of = Array, js_name = of)]
942 pub fn of3(a: &JsValue, b: &JsValue, c: &JsValue) -> Array;
943
944 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of)
945 #[wasm_bindgen(static_method_of = Array, js_name = of)]
946 pub fn of4(a: &JsValue, b: &JsValue, c: &JsValue, d: &JsValue) -> Array;
947
948 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of)
949 #[wasm_bindgen(static_method_of = Array, js_name = of)]
950 pub fn of5(a: &JsValue, b: &JsValue, c: &JsValue, d: &JsValue, e: &JsValue) -> Array;
951
952 /// The `pop()` method removes the last element from an array and returns that
953 /// element. This method changes the length of the array.
954 ///
955 /// **Note:** Consider using [`Array::pop_checked`] for handling empty arrays.
956 ///
957 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pop)
958 #[cfg(not(js_sys_unstable_apis))]
959 #[wasm_bindgen(method)]
960 pub fn pop<T>(this: &Array<T>) -> T;
961
962 /// The `pop()` method removes the last element from an array and returns that
963 /// element. This method changes the length of the array.
964 /// Returns `None` if the array is empty.
965 ///
966 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pop)
967 #[cfg(js_sys_unstable_apis)]
968 #[wasm_bindgen(method)]
969 pub fn pop<T>(this: &Array<T>) -> Option<T>;
970
971 // Next major: deprecate
972 /// The `pop()` method removes the last element from an array and returns that
973 /// element. This method changes the length of the array.
974 ///
975 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pop)
976 #[wasm_bindgen(method, js_name = pop)]
977 pub fn pop_checked<T>(this: &Array<T>) -> Option<T>;
978
979 /// The `push()` method adds one element to the end of an array and
980 /// returns the new length of the array.
981 ///
982 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push)
983 #[wasm_bindgen(method)]
984 pub fn push<T>(this: &Array<T>, value: &T) -> u32;
985
986 /// The `push()` method adds one or more elements to the end of an array and
987 /// returns the new length of the array.
988 ///
989 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push)
990 #[wasm_bindgen(method, js_name = push, variadic)]
991 pub fn push_many<T>(this: &Array<T>, values: &[T]) -> u32;
992
993 /// The `reduce()` method applies a function against an accumulator and each element in
994 /// the array (from left to right) to reduce it to a single value.
995 ///
996 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce)
997 #[cfg(not(js_sys_unstable_apis))]
998 #[wasm_bindgen(method)]
999 pub fn reduce<T>(
1000 this: &Array<T>,
1001 predicate: &mut dyn FnMut(JsValue, T, u32, Array<T>) -> JsValue,
1002 initial_value: &JsValue,
1003 ) -> JsValue;
1004
1005 /// The `reduce()` method applies a function against an accumulator and each element in
1006 /// the array (from left to right) to reduce it to a single value.
1007 ///
1008 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce)
1009 #[cfg(js_sys_unstable_apis)]
1010 #[wasm_bindgen(method)]
1011 pub fn reduce<T, A>(
1012 this: &Array<T>,
1013 predicate: &mut dyn FnMut(A, T, u32, Array<T>) -> A,
1014 initial_value: &A,
1015 ) -> A;
1016
1017 /// The `reduce()` method applies a function against an accumulator and each element in
1018 /// the array (from left to right) to reduce it to a single value. _(Fallible variation)_
1019 ///
1020 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce)
1021 #[wasm_bindgen(method, js_name = reduce, catch)]
1022 pub fn try_reduce<T, A>(
1023 this: &Array<T>,
1024 predicate: &mut dyn FnMut(A, T, u32) -> Result<A, JsError>,
1025 initial_value: &A,
1026 ) -> Result<A, JsValue>;
1027
1028 /// The `reduceRight()` method applies a function against an accumulator and each value
1029 /// of the array (from right-to-left) to reduce it to a single value.
1030 ///
1031 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/ReduceRight)
1032 #[cfg(not(js_sys_unstable_apis))]
1033 #[wasm_bindgen(method, js_name = reduceRight)]
1034 pub fn reduce_right<T>(
1035 this: &Array<T>,
1036 predicate: &mut dyn FnMut(JsValue, T, u32, Array<T>) -> JsValue,
1037 initial_value: &JsValue,
1038 ) -> JsValue;
1039
1040 /// The `reduceRight()` method applies a function against an accumulator and each value
1041 /// of the array (from right-to-left) to reduce it to a single value.
1042 ///
1043 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/ReduceRight)
1044 #[cfg(js_sys_unstable_apis)]
1045 #[wasm_bindgen(method, js_name = reduceRight)]
1046 pub fn reduce_right<T, A>(
1047 this: &Array<T>,
1048 predicate: &mut dyn FnMut(A, T, u32, Array<T>) -> A,
1049 initial_value: &A,
1050 ) -> A;
1051
1052 /// The `reduceRight()` method applies a function against an accumulator and each value
1053 /// of the array (from right-to-left) to reduce it to a single value. _(Fallible variation)_
1054 ///
1055 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/ReduceRight)
1056 #[wasm_bindgen(method, js_name = reduceRight, catch)]
1057 pub fn try_reduce_right<T, A>(
1058 this: &Array<T>,
1059 predicate: &mut dyn FnMut(JsValue, T, u32) -> Result<A, JsError>,
1060 initial_value: &A,
1061 ) -> Result<A, JsValue>;
1062
1063 /// The `reverse()` method reverses an array in place. The first array
1064 /// element becomes the last, and the last array element becomes the first.
1065 ///
1066 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse)
1067 #[wasm_bindgen(method)]
1068 pub fn reverse<T>(this: &Array<T>) -> Array<T>;
1069
1070 /// The `shift()` method removes the first element from an array and returns
1071 /// that removed element. This method changes the length of the array.
1072 ///
1073 /// **Note:** Consider using [`Array::shift_checked`] for handling empty arrays.
1074 ///
1075 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift)
1076 #[cfg(not(js_sys_unstable_apis))]
1077 #[wasm_bindgen(method)]
1078 pub fn shift<T>(this: &Array<T>) -> T;
1079
1080 /// The `shift()` method removes the first element from an array and returns
1081 /// that removed element. This method changes the length of the array.
1082 /// Returns `None` if the array is empty.
1083 ///
1084 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift)
1085 #[cfg(js_sys_unstable_apis)]
1086 #[wasm_bindgen(method)]
1087 pub fn shift<T>(this: &Array<T>) -> Option<T>;
1088
1089 // Next major: deprecate
1090 /// The `shift()` method removes the first element from an array and returns
1091 /// that removed element. This method changes the length of the array.
1092 ///
1093 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift)
1094 #[wasm_bindgen(method, js_name = shift)]
1095 pub fn shift_checked<T>(this: &Array<T>) -> Option<T>;
1096
1097 /// The `slice()` method returns a shallow copy of a portion of an array into
1098 /// a new array object selected from begin to end (end not included).
1099 /// The original array will not be modified.
1100 ///
1101 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)
1102 #[cfg(not(js_sys_unstable_apis))]
1103 #[wasm_bindgen(method)]
1104 pub fn slice<T>(this: &Array<T>, start: u32, end: u32) -> Array<T>;
1105
1106 /// The `slice()` method returns a shallow copy of a portion of an array into
1107 /// a new array object selected from begin to end (end not included).
1108 /// The original array will not be modified. Negative indices count from the end.
1109 ///
1110 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)
1111 #[cfg(js_sys_unstable_apis)]
1112 #[wasm_bindgen(method)]
1113 pub fn slice<T>(this: &Array<T>, start: i32, end: i32) -> Array<T>;
1114
1115 /// The `slice()` method returns a shallow copy of a portion of an array into
1116 /// a new array object selected from the given index to the end.
1117 /// The original array will not be modified.
1118 ///
1119 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)
1120 #[cfg(not(js_sys_unstable_apis))]
1121 #[wasm_bindgen(method, js_name = slice)]
1122 pub fn slice_from<T>(this: &Array<T>, start: u32) -> Array<T>;
1123
1124 /// The `slice()` method returns a shallow copy of a portion of an array into
1125 /// a new array object selected from the given index to the end.
1126 /// The original array will not be modified. Negative indices count from the end.
1127 ///
1128 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)
1129 #[cfg(js_sys_unstable_apis)]
1130 #[wasm_bindgen(method, js_name = slice)]
1131 pub fn slice_from<T>(this: &Array<T>, start: i32) -> Array<T>;
1132
1133 /// The `some()` method tests whether at least one element in the array passes the test implemented
1134 /// by the provided function.
1135 /// Note: This method returns false for any condition put on an empty array.
1136 ///
1137 /// **Note:** Consider using [`Array::try_some`] if the predicate might throw an error.
1138 ///
1139 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some)
1140 #[wasm_bindgen(method)]
1141 pub fn some<T>(this: &Array<T>, predicate: &mut dyn FnMut(T) -> bool) -> bool;
1142
1143 /// The `some()` method tests whether at least one element in the array passes the test implemented
1144 /// by the provided function. _(Fallible variation)_
1145 /// Note: This method returns false for any condition put on an empty array.
1146 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some)
1147 #[wasm_bindgen(method, js_name = some, catch)]
1148 pub fn try_some<T>(
1149 this: &Array<T>,
1150 predicate: &mut dyn FnMut(T) -> Result<bool, JsError>,
1151 ) -> Result<bool, JsValue>;
1152
1153 /// The `sort()` method sorts the elements of an array in place and returns
1154 /// the array. The sort is not necessarily stable. The default sort
1155 /// order is according to string Unicode code points.
1156 ///
1157 /// The time and space complexity of the sort cannot be guaranteed as it
1158 /// is implementation dependent.
1159 ///
1160 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)
1161 #[wasm_bindgen(method)]
1162 pub fn sort<T>(this: &Array<T>) -> Array<T>;
1163
1164 /// The `sort()` method with a custom compare function.
1165 ///
1166 /// **Note:** Consider using [`Array::try_sort_by`] if the predicate might throw an error.
1167 ///
1168 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)
1169 #[wasm_bindgen(method, js_name = sort)]
1170 pub fn sort_by<T>(this: &Array<T>, compare_fn: &mut dyn FnMut(T, T) -> i32) -> Array<T>;
1171
1172 /// The `sort()` method with a custom compare function. _(Fallible variation)_
1173 ///
1174 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)
1175 #[wasm_bindgen(method, js_name = sort, catch)]
1176 pub fn try_sort_by<T>(
1177 this: &Array<T>,
1178 compare_fn: &mut dyn FnMut(T, T) -> Result<i32, JsError>,
1179 ) -> Result<Array<T>, JsValue>;
1180
1181 /// The `splice()` method changes the contents of an array by removing existing elements and/or
1182 /// adding new elements.
1183 ///
1184 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice)
1185 #[wasm_bindgen(method)]
1186 pub fn splice<T>(this: &Array<T>, start: u32, delete_count: u32, item: &T) -> Array<T>;
1187
1188 /// The `splice()` method changes the contents of an array by removing existing elements and/or
1189 /// adding new elements.
1190 ///
1191 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice)
1192 #[wasm_bindgen(method, js_name = splice, variadic)]
1193 pub fn splice_many<T>(this: &Array<T>, start: u32, delete_count: u32, items: &[T]) -> Array<T>;
1194
1195 /// The `toLocaleString()` method returns a string representing the elements of the array.
1196 /// The elements are converted to Strings using their toLocaleString methods and these
1197 /// Strings are separated by a locale-specific String (such as a comma ",").
1198 ///
1199 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toLocaleString)
1200 #[cfg(not(js_sys_unstable_apis))]
1201 #[wasm_bindgen(method, js_name = toLocaleString)]
1202 pub fn to_locale_string<T>(this: &Array<T>, locales: &JsValue, options: &JsValue) -> JsString;
1203
1204 /// The `toLocaleString()` method returns a string representing the elements of the array.
1205 /// The elements are converted to Strings using their toLocaleString methods and these
1206 /// Strings are separated by a locale-specific String (such as a comma ",").
1207 ///
1208 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toLocaleString)
1209 #[cfg(js_sys_unstable_apis)]
1210 #[wasm_bindgen(method, js_name = toLocaleString)]
1211 pub fn to_locale_string<T>(
1212 this: &Array<T>,
1213 locales: &[JsString],
1214 options: &Intl::NumberFormatOptions,
1215 ) -> JsString;
1216
1217 /// The `toReversed()` method returns a new array with the elements in reversed order,
1218 /// without modifying the original array.
1219 ///
1220 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toReversed)
1221 #[wasm_bindgen(method, js_name = toReversed)]
1222 pub fn to_reversed<T>(this: &Array<T>) -> Array<T>;
1223
1224 /// The `toSorted()` method returns a new array with the elements sorted in ascending order,
1225 /// without modifying the original array.
1226 ///
1227 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toSorted)
1228 #[wasm_bindgen(method, js_name = toSorted)]
1229 pub fn to_sorted<T>(this: &Array<T>) -> Array<T>;
1230
1231 /// The `toSorted()` method with a custom compare function.
1232 ///
1233 /// **Note:** Consider using [`Array::try_to_sorted_by`] if the predicate might throw an error.
1234 ///
1235 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toSorted)
1236 #[wasm_bindgen(method, js_name = toSorted)]
1237 pub fn to_sorted_by<T>(this: &Array<T>, compare_fn: &mut dyn FnMut(T, T) -> i32) -> Array<T>;
1238
1239 /// The `toSorted()` method with a custom compare function. _(Fallible variation)_
1240 ///
1241 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toSorted)
1242 #[wasm_bindgen(method, js_name = toSorted, catch)]
1243 pub fn try_to_sorted_by<T>(
1244 this: &Array<T>,
1245 compare_fn: &mut dyn FnMut(T, T) -> Result<i32, JsError>,
1246 ) -> Result<Array<T>, JsValue>;
1247
1248 /// The `toSpliced()` method returns a new array with some elements removed and/or
1249 /// replaced at a given index, without modifying the original array.
1250 ///
1251 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toSpliced)
1252 #[wasm_bindgen(method, js_name = toSpliced, variadic)]
1253 pub fn to_spliced<T>(this: &Array<T>, start: u32, delete_count: u32, items: &[T]) -> Array<T>;
1254
1255 /// The `toString()` method returns a string representing the specified array
1256 /// and its elements.
1257 ///
1258 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toString)
1259 #[cfg(not(js_sys_unstable_apis))]
1260 #[wasm_bindgen(method, js_name = toString)]
1261 pub fn to_string<T>(this: &Array<T>) -> JsString;
1262
1263 /// Converts the Array into a Vector.
1264 #[wasm_bindgen(method, js_name = slice)]
1265 pub fn to_vec<T>(this: &Array<T>) -> Vec<T>;
1266
1267 /// The `unshift()` method adds one element to the beginning of an
1268 /// array and returns the new length of the array.
1269 ///
1270 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift)
1271 #[wasm_bindgen(method)]
1272 pub fn unshift<T>(this: &Array<T>, value: &T) -> u32;
1273
1274 /// The `unshift()` method adds one or more elements to the beginning of an
1275 /// array and returns the new length of the array.
1276 ///
1277 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift)
1278 #[wasm_bindgen(method, js_name = unshift, variadic)]
1279 pub fn unshift_many<T>(this: &Array<T>, values: &[T]) -> u32;
1280
1281 /// The `with()` method returns a new array with the element at the given index
1282 /// replaced with the given value, without modifying the original array.
1283 ///
1284 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/with)
1285 #[wasm_bindgen(method, js_name = with)]
1286 pub fn with<T>(this: &Array<T>, index: u32, value: &T) -> Array<T>;
1287}
1288
1289// Tuples as a typed array variant
1290#[wasm_bindgen]
1291extern "C" {
1292 #[wasm_bindgen(extends = Object, js_name = Array, is_type_of = Array::is_array, no_upcast, typescript_type = "Array<any>")]
1293 #[derive(Clone, Debug)]
1294 pub type ArrayTuple<T: JsTuple = (JsValue,)>;
1295
1296 /// Creates a new JS array typed as a 1-tuple.
1297 #[wasm_bindgen(js_class = Array, static_method_of = ArrayTuple, js_name = of)]
1298 pub fn new1<T1>(t1: &T1) -> ArrayTuple<(T1,)>;
1299
1300 /// Creates a new JS array typed as a 2-tuple.
1301 #[wasm_bindgen(js_class = Array, static_method_of = ArrayTuple, js_name = of)]
1302 pub fn new2<T1, T2>(t1: &T1, t2: &T2) -> ArrayTuple<(T1, T2)>;
1303
1304 /// Creates a new JS array typed as a 3-tuple.
1305 #[wasm_bindgen(js_class = Array, static_method_of = ArrayTuple, js_name = of)]
1306 pub fn new3<T1, T2, T3>(t1: &T1, t2: &T2, t3: &T3) -> ArrayTuple<(T1, T2, T3)>;
1307
1308 /// Creates a new JS array typed as a 4-tuple.
1309 #[wasm_bindgen(js_class = Array, static_method_of = ArrayTuple, js_name = of)]
1310 pub fn new4<T1, T2, T3, T4>(t1: &T1, t2: &T2, t3: &T3, t4: &T4)
1311 -> ArrayTuple<(T1, T2, T3, T4)>;
1312
1313 /// Creates a new JS array typed as a 5-tuple.
1314 #[wasm_bindgen(js_class = Array, static_method_of = ArrayTuple, js_name = of)]
1315 pub fn new5<T1, T2, T3, T4, T5>(
1316 t1: &T1,
1317 t2: &T2,
1318 t3: &T3,
1319 t4: &T4,
1320 t5: &T5,
1321 ) -> ArrayTuple<(T1, T2, T3, T4, T5)>;
1322
1323 /// Creates a new JS array typed as a 6-tuple.
1324 #[wasm_bindgen(js_class = Array, static_method_of = ArrayTuple, js_name = of)]
1325 pub fn new6<T1, T2, T3, T4, T5, T6>(
1326 t1: &T1,
1327 t2: &T2,
1328 t3: &T3,
1329 t4: &T4,
1330 t5: &T5,
1331 t6: &T6,
1332 ) -> ArrayTuple<(T1, T2, T3, T4, T5, T6)>;
1333
1334 /// Creates a new JS array typed as a 7-tuple.
1335 #[wasm_bindgen(js_class = Array, static_method_of = ArrayTuple, js_name = of)]
1336 pub fn new7<T1, T2, T3, T4, T5, T6, T7>(
1337 t1: &T1,
1338 t2: &T2,
1339 t3: &T3,
1340 t4: &T4,
1341 t5: &T5,
1342 t6: &T6,
1343 t7: &T7,
1344 ) -> ArrayTuple<(T1, T2, T3, T4, T5, T6, T7)>;
1345
1346 /// Creates a new JS array typed as a 8-tuple.
1347 #[wasm_bindgen(js_class = Array, static_method_of = ArrayTuple, js_name = of)]
1348 pub fn new8<T1, T2, T3, T4, T5, T6, T7, T8>(
1349 t1: &T1,
1350 t2: &T2,
1351 t3: &T3,
1352 t4: &T4,
1353 t5: &T5,
1354 t6: &T6,
1355 t7: &T7,
1356 t8: &T8,
1357 ) -> ArrayTuple<(T1, T2, T3, T4, T5, T6, T7, T8)>;
1358
1359 /// Gets the 1st item
1360 #[wasm_bindgen(
1361 method,
1362 js_class = Array,
1363 getter,
1364 js_name = "0"
1365 )]
1366 pub fn get0<T: JsTuple1 = (JsValue,)>(this: &ArrayTuple<T>) -> <T as JsTuple1>::T1;
1367
1368 /// Gets the 2nd item
1369 #[wasm_bindgen(
1370 method,
1371 js_class = Array,
1372 getter,
1373 js_name = "1"
1374 )]
1375 pub fn get1<T: JsTuple2 = (JsValue, JsValue)>(this: &ArrayTuple<T>) -> <T as JsTuple2>::T2;
1376
1377 /// Gets the 3rd item
1378 #[wasm_bindgen(
1379 method,
1380 js_class = Array,
1381 getter,
1382 js_name = "2"
1383 )]
1384 pub fn get2<T: JsTuple3 = (JsValue, JsValue, JsValue)>(
1385 this: &ArrayTuple<T>,
1386 ) -> <T as JsTuple3>::T3;
1387
1388 /// Gets the 4th item
1389 #[wasm_bindgen(
1390 method,
1391 js_class = Array,
1392 getter,
1393 js_name = "3"
1394 )]
1395 pub fn get3<T: JsTuple4 = (JsValue, JsValue, JsValue, JsValue)>(
1396 this: &ArrayTuple<T>,
1397 ) -> <T as JsTuple4>::T4;
1398
1399 /// Gets the 5th item
1400 #[wasm_bindgen(
1401 method,
1402 js_class = Array,
1403 getter,
1404 js_name = "4"
1405 )]
1406 pub fn get4<T: JsTuple5 = (JsValue, JsValue, JsValue, JsValue, JsValue)>(
1407 this: &ArrayTuple<T>,
1408 ) -> <T as JsTuple5>::T5;
1409
1410 /// Gets the 6th item
1411 #[wasm_bindgen(
1412 method,
1413 js_class = Array,
1414 getter,
1415 js_name = "5"
1416 )]
1417 pub fn get5<T: JsTuple6 = (JsValue, JsValue, JsValue, JsValue, JsValue, JsValue)>(
1418 this: &ArrayTuple<T>,
1419 ) -> <T as JsTuple6>::T6;
1420
1421 /// Gets the 7th item
1422 #[wasm_bindgen(
1423 method,
1424 js_class = Array,
1425 getter,
1426 js_name = "6"
1427 )]
1428 pub fn get6<
1429 T: JsTuple7 = (
1430 JsValue,
1431 JsValue,
1432 JsValue,
1433 JsValue,
1434 JsValue,
1435 JsValue,
1436 JsValue,
1437 ),
1438 >(
1439 this: &ArrayTuple<T>,
1440 ) -> <T as JsTuple7>::T7;
1441
1442 /// Gets the 8th item
1443 #[wasm_bindgen(
1444 method,
1445 js_class = Array,
1446 getter,
1447 js_name = "7"
1448 )]
1449 pub fn get7<
1450 T: JsTuple8 = (
1451 JsValue,
1452 JsValue,
1453 JsValue,
1454 JsValue,
1455 JsValue,
1456 JsValue,
1457 JsValue,
1458 JsValue,
1459 ),
1460 >(
1461 this: &ArrayTuple<T>,
1462 ) -> <T as JsTuple8>::T8;
1463
1464 /// Sets the 1st item
1465 #[wasm_bindgen(
1466 method,
1467 js_class = Array,
1468 setter,
1469 js_name = "0"
1470 )]
1471 pub fn set0<T: JsTuple1 = (JsValue,)>(this: &ArrayTuple<T>, value: &<T as JsTuple1>::T1);
1472
1473 /// Sets the 2nd item
1474 #[wasm_bindgen(
1475 method,
1476 js_class = Array,
1477 setter,
1478 js_name = "1"
1479 )]
1480 pub fn set1<T: JsTuple2 = (JsValue, JsValue)>(
1481 this: &ArrayTuple<T>,
1482 value: &<T as JsTuple2>::T2,
1483 );
1484
1485 /// Sets the 3rd item
1486 #[wasm_bindgen(
1487 method,
1488 js_class = Array,
1489 setter,
1490 js_name = "2"
1491 )]
1492 pub fn set2<T: JsTuple3 = (JsValue, JsValue, JsValue)>(
1493 this: &ArrayTuple<T>,
1494 value: &<T as JsTuple3>::T3,
1495 );
1496
1497 /// Sets the 4th item
1498 #[wasm_bindgen(
1499 method,
1500 js_class = Array,
1501 setter,
1502 js_name = "3"
1503 )]
1504 pub fn set3<T: JsTuple4 = (JsValue, JsValue, JsValue, JsValue)>(
1505 this: &ArrayTuple<T>,
1506 value: &<T as JsTuple4>::T4,
1507 );
1508
1509 /// Sets the 5th item
1510 #[wasm_bindgen(
1511 method,
1512 js_class = Array,
1513 setter,
1514 js_name = "4"
1515 )]
1516 pub fn set4<T: JsTuple5 = (JsValue, JsValue, JsValue, JsValue, JsValue)>(
1517 this: &ArrayTuple<T>,
1518 value: &<T as JsTuple5>::T5,
1519 );
1520
1521 /// Sets the 6th item
1522 #[wasm_bindgen(
1523 method,
1524 js_class = Array,
1525 setter,
1526 js_name = "5"
1527 )]
1528 pub fn set5<T: JsTuple6 = (JsValue, JsValue, JsValue, JsValue, JsValue, JsValue)>(
1529 this: &ArrayTuple<T>,
1530 value: &<T as JsTuple6>::T6,
1531 );
1532
1533 /// Sets the 7th item
1534 #[wasm_bindgen(
1535 method,
1536 js_class = Array,
1537 setter,
1538 js_name = "6"
1539 )]
1540 pub fn set6<
1541 T: JsTuple7 = (
1542 JsValue,
1543 JsValue,
1544 JsValue,
1545 JsValue,
1546 JsValue,
1547 JsValue,
1548 JsValue,
1549 ),
1550 >(
1551 this: &ArrayTuple<T>,
1552 value: &<T as JsTuple7>::T7,
1553 );
1554
1555 /// Sets the 8th item
1556 #[wasm_bindgen(
1557 method,
1558 js_class = Array,
1559 setter,
1560 js_name = "7"
1561 )]
1562 pub fn set7<
1563 T: JsTuple8 = (
1564 JsValue,
1565 JsValue,
1566 JsValue,
1567 JsValue,
1568 JsValue,
1569 JsValue,
1570 JsValue,
1571 JsValue,
1572 ),
1573 >(
1574 this: &ArrayTuple<T>,
1575 value: &<T as JsTuple8>::T8,
1576 );
1577}
1578
1579/// Base trait for tuple types.
1580pub trait JsTuple {
1581 const ARITY: usize;
1582}
1583
1584macro_rules! impl_tuple_traits {
1585 // Base case: first trait has no parent (besides JsTuple)
1586 ($name:ident $ty:tt) => {
1587 pub trait $name: JsTuple {
1588 type $ty;
1589 }
1590 };
1591
1592 // Recursive case: define trait with parent, then recurse
1593 ($name:ident $ty:tt $($rest_name:ident $rest_ty:tt)+) => {
1594 pub trait $name: JsTuple {
1595 type $ty;
1596 }
1597
1598 impl_tuple_traits!(@with_parent $name $($rest_name $rest_ty)+);
1599 };
1600
1601 // Internal: traits that have a parent
1602 (@with_parent $trait:ident $name:ident $ty:tt) => {
1603 pub trait $name: $trait {
1604 type $ty;
1605 }
1606 };
1607
1608 (@with_parent $trait:ident $name:ident $ty:tt $($rest_name:ident $rest_ty:tt)+) => {
1609 pub trait $name: $trait {
1610 type $ty;
1611 }
1612
1613 impl_tuple_traits!(@with_parent $name $($rest_name $rest_ty)+);
1614 };
1615}
1616
1617macro_rules! impl_parent_traits {
1618 ([$($types:tt),+] [] []) => {};
1619
1620 ([$($types:tt),+] [$trait:ident $($rest_traits:ident)*] [$ty:tt $($rest_tys:tt)*]) => {
1621 impl<$($types),+> $trait for ($($types),+,) {
1622 type $ty = $ty;
1623 }
1624
1625 impl_parent_traits!([$($types),+] [$($rest_traits)*] [$($rest_tys)*]);
1626 };
1627}
1628
1629// Define the trait hierarchy once
1630impl_tuple_traits!(
1631 JsTuple1 T1
1632 JsTuple2 T2
1633 JsTuple3 T3
1634 JsTuple4 T4
1635 JsTuple5 T5
1636 JsTuple6 T6
1637 JsTuple7 T7
1638 JsTuple8 T8
1639);
1640
1641impl<T: JsTuple> ArrayTuple<T> {
1642 /// Get the static arity of the ArrayTuple type.
1643 #[allow(clippy::len_without_is_empty)]
1644 pub fn len(&self) -> usize {
1645 <T as JsTuple>::ARITY
1646 }
1647}
1648
1649macro_rules! impl_tuple {
1650 ($arity:literal [$($traits:ident)*] [$($T:tt)+] [$($vars:tt)+] $new:ident $last:ident $last_ty:tt) => {
1651 impl<$($T),+> JsTuple for ($($T),+,) {
1652 const ARITY: usize = $arity;
1653 }
1654
1655 impl_parent_traits!([$($T),+] [$($traits)*] [$($T)*]);
1656
1657 impl<$($T: JsGeneric),+> From<($($T,)+)> for ArrayTuple<($($T),+,)> {
1658 fn from(($($vars,)+): ($($T,)+)) -> Self {
1659 $(let $vars: JsValue = $vars.upcast_into();)+
1660 Array::of(&[$($vars),+]).unchecked_into()
1661 }
1662 }
1663
1664 impl<$($T: JsGeneric + Default),+> Default for ArrayTuple<($($T),+,)> {
1665 fn default() -> Self {
1666 (
1667 $($T::default(),)+
1668 ).into()
1669 }
1670 }
1671
1672 impl<$($T: JsGeneric),+> ArrayTuple<($($T),+,)> {
1673 /// Get the first element of the ArrayTuple
1674 pub fn first(&self) -> T1 {
1675 self.get0()
1676 }
1677
1678 /// Get the last element of the ArrayTuple
1679 pub fn last(&self) -> $last_ty {
1680 self.$last()
1681 }
1682
1683 /// Convert the ArrayTuple into its corresponding Rust tuple
1684 pub fn into_parts(self) -> ($($T,)+) {
1685 ($(self.$vars(),)+)
1686 }
1687
1688 /// Create a new ArrayTuple from the corresponding parts.
1689 ///
1690 /// # Example
1691 ///
1692 /// ```
1693 /// use js_sys::{ArrayTuple, JsString};
1694 ///
1695 /// let tuple = ArrayTuple::<JsString, JsString>::new(&"a".into(), &"b".into());
1696 /// ```
1697 ///
1698 /// Note: You must specify the T using `::<...>` syntax on `ArrayTuple`.
1699 /// Alternatively, use `new1`, `new2`, etc. for type inference from the left-hand side.
1700 pub fn new($($vars: &$T),+) -> ArrayTuple<($($T),+,)> {
1701 ArrayTuple::$new($($vars),+)
1702 }
1703 }
1704 };
1705}
1706
1707// Implement for each tuple size
1708impl_tuple!(1 [JsTuple1] [T1] [get0] new1 get0 T1);
1709impl_tuple!(2 [JsTuple1 JsTuple2] [T1 T2] [get0 get1] new2 get1 T2);
1710impl_tuple!(3 [JsTuple1 JsTuple2 JsTuple3] [T1 T2 T3] [get0 get1 get2] new3 get2 T3);
1711impl_tuple!(4 [JsTuple1 JsTuple2 JsTuple3 JsTuple4] [T1 T2 T3 T4] [get0 get1 get2 get3] new4 get3 T4);
1712impl_tuple!(5 [JsTuple1 JsTuple2 JsTuple3 JsTuple4 JsTuple5] [T1 T2 T3 T4 T5] [get0 get1 get2 get3 get4] new5 get4 T5);
1713impl_tuple!(6 [JsTuple1 JsTuple2 JsTuple3 JsTuple4 JsTuple5 JsTuple6] [T1 T2 T3 T4 T5 T6] [get0 get1 get2 get3 get4 get5] new6 get5 T6);
1714impl_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);
1715impl_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);
1716
1717// Macro to generate structural covariance impls for each arity
1718macro_rules! impl_tuple_covariance {
1719 ([$($T:ident)+] [$($Target:ident)+] [$($Ts:ident)+]) => {
1720 // ArrayTuple -> Array
1721 // Allows (T1, T2, ...) to be used where (Target) is expected
1722 // when all T1, T2, ... are covariant to Target
1723 impl<$($T,)+ Target> UpcastFrom<ArrayTuple<($($T,)+)>> for Array<Target>
1724 where
1725 $(Target: UpcastFrom<$T>,)+
1726 {
1727 }
1728 impl<$($T,)+ Target> UpcastFrom<ArrayTuple<($($T,)+)>> for JsOption<Array<Target>>
1729 where
1730 $(Target: UpcastFrom<$T>,)+
1731 {}
1732 // Array<T> -> ArrayTuple<T, ...>
1733 impl<T> UpcastFrom<Array<T>> for ArrayTuple<($($Ts,)+)> {}
1734 impl<T: JsGeneric> UpcastFrom<Array<T>> for ArrayTuple<($(JsOption<$Ts>,)+)> {}
1735 };
1736}
1737
1738impl_tuple_covariance!([T1][Target1][T]);
1739impl_tuple_covariance!([T1 T2] [Target1 Target2] [T T]);
1740impl_tuple_covariance!([T1 T2 T3] [Target1 Target2 Target3] [T T T]);
1741impl_tuple_covariance!([T1 T2 T3 T4] [Target1 Target2 Target3 Target4] [T T T T]);
1742impl_tuple_covariance!([T1 T2 T3 T4 T5] [Target1 Target2 Target3 Target4 Target5] [T T T T T]);
1743impl_tuple_covariance!([T1 T2 T3 T4 T5 T6] [Target1 Target2 Target3 Target4 Target5 Target6] [T T T T T T]);
1744impl_tuple_covariance!([T1 T2 T3 T4 T5 T6 T7] [Target1 Target2 Target3 Target4 Target5 Target6 Target7] [T T T T T T T]);
1745impl_tuple_covariance!([T1 T2 T3 T4 T5 T6 T7 T8] [Target1 Target2 Target3 Target4 Target5 Target6 Target7 Target8] [T T T T T T T T]);
1746
1747// Tuple casting is implemented in core
1748impl<T: JsTuple, U: JsTuple> UpcastFrom<ArrayTuple<T>> for ArrayTuple<U> where U: UpcastFrom<T> {}
1749impl<T: JsTuple> UpcastFrom<ArrayTuple<T>> for JsValue {}
1750impl<T: JsTuple> UpcastFrom<ArrayTuple<T>> for JsOption<JsValue> {}
1751
1752/// Iterator returned by `Array::into_iter`
1753#[derive(Debug, Clone)]
1754pub struct ArrayIntoIter<T: JsGeneric = JsValue> {
1755 range: core::ops::Range<u32>,
1756 array: Array<T>,
1757}
1758
1759#[cfg(not(js_sys_unstable_apis))]
1760impl<T: JsGeneric> core::iter::Iterator for ArrayIntoIter<T> {
1761 type Item = T;
1762
1763 fn next(&mut self) -> Option<Self::Item> {
1764 let index = self.range.next()?;
1765 Some(self.array.get(index))
1766 }
1767
1768 #[inline]
1769 fn size_hint(&self) -> (usize, Option<usize>) {
1770 self.range.size_hint()
1771 }
1772
1773 #[inline]
1774 fn count(self) -> usize
1775 where
1776 Self: Sized,
1777 {
1778 self.range.count()
1779 }
1780
1781 #[inline]
1782 fn last(self) -> Option<Self::Item>
1783 where
1784 Self: Sized,
1785 {
1786 let Self { range, array } = self;
1787 range.last().map(|index| array.get(index))
1788 }
1789
1790 #[inline]
1791 fn nth(&mut self, n: usize) -> Option<Self::Item> {
1792 self.range.nth(n).map(|index| self.array.get(index))
1793 }
1794}
1795
1796#[cfg(js_sys_unstable_apis)]
1797impl<T: JsGeneric> core::iter::Iterator for ArrayIntoIter<T> {
1798 type Item = T;
1799
1800 fn next(&mut self) -> Option<Self::Item> {
1801 let index = self.range.next()?;
1802 self.array.get(index)
1803 }
1804
1805 #[inline]
1806 fn size_hint(&self) -> (usize, Option<usize>) {
1807 self.range.size_hint()
1808 }
1809
1810 #[inline]
1811 fn count(self) -> usize
1812 where
1813 Self: Sized,
1814 {
1815 self.range.count()
1816 }
1817
1818 #[inline]
1819 fn last(self) -> Option<Self::Item>
1820 where
1821 Self: Sized,
1822 {
1823 let Self { range, array } = self;
1824 range.last().and_then(|index| array.get(index))
1825 }
1826
1827 #[inline]
1828 fn nth(&mut self, n: usize) -> Option<Self::Item> {
1829 self.range.nth(n).and_then(|index| self.array.get(index))
1830 }
1831}
1832
1833#[cfg(not(js_sys_unstable_apis))]
1834impl<T: JsGeneric> core::iter::DoubleEndedIterator for ArrayIntoIter<T> {
1835 fn next_back(&mut self) -> Option<Self::Item> {
1836 let index = self.range.next_back()?;
1837 Some(self.array.get(index))
1838 }
1839
1840 fn nth_back(&mut self, n: usize) -> Option<Self::Item> {
1841 self.range.nth_back(n).map(|index| self.array.get(index))
1842 }
1843}
1844
1845#[cfg(js_sys_unstable_apis)]
1846impl<T: JsGeneric> core::iter::DoubleEndedIterator for ArrayIntoIter<T> {
1847 fn next_back(&mut self) -> Option<Self::Item> {
1848 let index = self.range.next_back()?;
1849 self.array.get(index)
1850 }
1851
1852 fn nth_back(&mut self, n: usize) -> Option<Self::Item> {
1853 self.range
1854 .nth_back(n)
1855 .and_then(|index| self.array.get(index))
1856 }
1857}
1858
1859impl<T: JsGeneric> core::iter::FusedIterator for ArrayIntoIter<T> {}
1860
1861impl<T: JsGeneric> core::iter::ExactSizeIterator for ArrayIntoIter<T> {}
1862
1863/// Iterator returned by `Array::iter`
1864#[derive(Debug, Clone)]
1865pub struct ArrayIter<'a, T: JsGeneric = JsValue> {
1866 range: core::ops::Range<u32>,
1867 array: &'a Array<T>,
1868}
1869
1870impl<T: JsGeneric> core::iter::Iterator for ArrayIter<'_, T> {
1871 type Item = T;
1872
1873 fn next(&mut self) -> Option<Self::Item> {
1874 let index = self.range.next()?;
1875 Some(self.array.get_unchecked(index))
1876 }
1877
1878 #[inline]
1879 fn size_hint(&self) -> (usize, Option<usize>) {
1880 self.range.size_hint()
1881 }
1882
1883 #[inline]
1884 fn count(self) -> usize
1885 where
1886 Self: Sized,
1887 {
1888 self.range.count()
1889 }
1890
1891 #[inline]
1892 fn last(self) -> Option<Self::Item>
1893 where
1894 Self: Sized,
1895 {
1896 let Self { range, array } = self;
1897 range.last().map(|index| array.get_unchecked(index))
1898 }
1899
1900 #[inline]
1901 fn nth(&mut self, n: usize) -> Option<Self::Item> {
1902 self.range
1903 .nth(n)
1904 .map(|index| self.array.get_unchecked(index))
1905 }
1906}
1907
1908impl<T: JsGeneric> core::iter::DoubleEndedIterator for ArrayIter<'_, T> {
1909 fn next_back(&mut self) -> Option<Self::Item> {
1910 let index = self.range.next_back()?;
1911 Some(self.array.get_unchecked(index))
1912 }
1913
1914 fn nth_back(&mut self, n: usize) -> Option<Self::Item> {
1915 self.range
1916 .nth_back(n)
1917 .map(|index| self.array.get_unchecked(index))
1918 }
1919}
1920
1921impl<T: JsGeneric> core::iter::FusedIterator for ArrayIter<'_, T> {}
1922
1923impl<T: JsGeneric> core::iter::ExactSizeIterator for ArrayIter<'_, T> {}
1924
1925impl<T: JsGeneric> Array<T> {
1926 /// Returns an iterator over the values of the JS array.
1927 pub fn iter(&self) -> ArrayIter<'_, T> {
1928 ArrayIter {
1929 range: 0..self.length(),
1930 array: self,
1931 }
1932 }
1933}
1934
1935impl<T: JsGeneric> core::iter::IntoIterator for Array<T> {
1936 type Item = T;
1937 type IntoIter = ArrayIntoIter<T>;
1938
1939 fn into_iter(self) -> Self::IntoIter {
1940 ArrayIntoIter {
1941 range: 0..self.length(),
1942 array: self,
1943 }
1944 }
1945}
1946
1947#[cfg(not(js_sys_unstable_apis))]
1948impl<A> core::iter::FromIterator<A> for Array
1949where
1950 A: AsRef<JsValue>,
1951{
1952 fn from_iter<I>(iter: I) -> Array
1953 where
1954 I: IntoIterator<Item = A>,
1955 {
1956 let mut out = Array::new();
1957 out.extend(iter);
1958 out
1959 }
1960}
1961
1962#[cfg(js_sys_unstable_apis)]
1963impl<A, T: JsGeneric> core::iter::FromIterator<A> for Array<T>
1964where
1965 A: AsRef<T>,
1966{
1967 fn from_iter<I>(iter: I) -> Array<T>
1968 where
1969 I: IntoIterator<Item = A>,
1970 {
1971 let iter = iter.into_iter();
1972 let (lower, upper) = iter.size_hint();
1973 let capacity = upper.unwrap_or(lower);
1974 let out = Array::new_with_length_typed(capacity as u32);
1975 let mut i = 0;
1976 for value in iter {
1977 out.set(i, value.as_ref());
1978 i += 1;
1979 }
1980 // Trim to the actual number of items written, in case size_hint over-estimated.
1981 if i < capacity as u32 {
1982 out.set_length(i);
1983 }
1984 out
1985 }
1986}
1987
1988#[cfg(not(js_sys_unstable_apis))]
1989impl<A> core::iter::Extend<A> for Array
1990where
1991 A: AsRef<JsValue>,
1992{
1993 fn extend<I>(&mut self, iter: I)
1994 where
1995 I: IntoIterator<Item = A>,
1996 {
1997 for value in iter {
1998 self.push(value.as_ref());
1999 }
2000 }
2001}
2002
2003#[cfg(js_sys_unstable_apis)]
2004impl<A, T: JsGeneric> core::iter::Extend<A> for Array<T>
2005where
2006 A: AsRef<T>,
2007{
2008 fn extend<I>(&mut self, iter: I)
2009 where
2010 I: IntoIterator<Item = A>,
2011 {
2012 for value in iter {
2013 self.push(value.as_ref());
2014 }
2015 }
2016}
2017
2018impl Default for Array<JsValue> {
2019 fn default() -> Self {
2020 Self::new()
2021 }
2022}
2023
2024impl<T> Iterable for Array<T> {
2025 type Item = T;
2026}
2027
2028impl<T: JsTuple> Iterable for ArrayTuple<T> {
2029 type Item = JsValue;
2030}
2031
2032// ArrayBufferOptions
2033#[wasm_bindgen]
2034extern "C" {
2035 #[wasm_bindgen(extends = Object, typescript_type = "ArrayBufferOptions")]
2036 #[derive(Clone, Debug, PartialEq, Eq)]
2037 pub type ArrayBufferOptions;
2038
2039 /// The maximum size, in bytes, that the array buffer can be resized to.
2040 #[wasm_bindgen(method, setter, js_name = maxByteLength)]
2041 pub fn set_max_byte_length(this: &ArrayBufferOptions, max_byte_length: usize);
2042
2043 /// The maximum size, in bytes, that the array buffer can be resized to.
2044 #[wasm_bindgen(method, getter, js_name = maxByteLength)]
2045 pub fn get_max_byte_length(this: &ArrayBufferOptions) -> usize;
2046}
2047
2048impl ArrayBufferOptions {
2049 #[cfg(not(js_sys_unstable_apis))]
2050 pub fn new(max_byte_length: usize) -> ArrayBufferOptions {
2051 let options = JsCast::unchecked_into::<ArrayBufferOptions>(Object::new());
2052 options.set_max_byte_length(max_byte_length);
2053 options
2054 }
2055
2056 #[cfg(js_sys_unstable_apis)]
2057 pub fn new(max_byte_length: usize) -> ArrayBufferOptions {
2058 let options = JsCast::unchecked_into::<ArrayBufferOptions>(Object::<JsValue>::new());
2059 options.set_max_byte_length(max_byte_length);
2060 options
2061 }
2062}
2063
2064// ArrayBuffer
2065#[wasm_bindgen]
2066extern "C" {
2067 #[wasm_bindgen(extends = Object, typescript_type = "ArrayBuffer")]
2068 #[derive(Clone, Debug, PartialEq, Eq)]
2069 pub type ArrayBuffer;
2070
2071 /// The `ArrayBuffer` object is used to represent a generic,
2072 /// fixed-length raw binary data buffer. You cannot directly
2073 /// manipulate the contents of an `ArrayBuffer`; instead, you
2074 /// create one of the typed array objects or a `DataView` object
2075 /// which represents the buffer in a specific format, and use that
2076 /// to read and write the contents of the buffer.
2077 ///
2078 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer)
2079 #[cfg(not(js_sys_unstable_apis))]
2080 #[wasm_bindgen(constructor)]
2081 pub fn new(length: u32) -> ArrayBuffer;
2082
2083 /// The `ArrayBuffer` object is used to represent a generic,
2084 /// fixed-length raw binary data buffer. You cannot directly
2085 /// manipulate the contents of an `ArrayBuffer`; instead, you
2086 /// create one of the typed array objects or a `DataView` object
2087 /// which represents the buffer in a specific format, and use that
2088 /// to read and write the contents of the buffer.
2089 ///
2090 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer)
2091 #[cfg(js_sys_unstable_apis)]
2092 #[wasm_bindgen(constructor)]
2093 pub fn new(length: usize) -> ArrayBuffer;
2094
2095 /// The `ArrayBuffer` object is used to represent a generic,
2096 /// fixed-length raw binary data buffer. You cannot directly
2097 /// manipulate the contents of an `ArrayBuffer`; instead, you
2098 /// create one of the typed array objects or a `DataView` object
2099 /// which represents the buffer in a specific format, and use that
2100 /// to read and write the contents of the buffer.
2101 ///
2102 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer)
2103 #[wasm_bindgen(constructor)]
2104 pub fn new_with_options(length: usize, options: &ArrayBufferOptions) -> ArrayBuffer;
2105
2106 /// The `byteLength` property of an object which is an instance of type ArrayBuffer
2107 /// it's an accessor property whose set accessor function is undefined,
2108 /// meaning that you can only read this property.
2109 /// The value is established when the array is constructed and cannot be changed.
2110 /// This property returns 0 if this ArrayBuffer has been detached.
2111 ///
2112 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/byteLength)
2113 #[cfg(not(js_sys_unstable_apis))]
2114 #[wasm_bindgen(method, getter, js_name = byteLength)]
2115 pub fn byte_length(this: &ArrayBuffer) -> u32;
2116
2117 /// The `byteLength` property of an object which is an instance of type ArrayBuffer
2118 /// it's an accessor property whose set accessor function is undefined,
2119 /// meaning that you can only read this property.
2120 /// The value is established when the array is constructed and cannot be changed.
2121 /// This property returns 0 if this ArrayBuffer has been detached.
2122 ///
2123 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/byteLength)
2124 #[cfg(js_sys_unstable_apis)]
2125 #[wasm_bindgen(method, getter, js_name = byteLength)]
2126 pub fn byte_length(this: &ArrayBuffer) -> usize;
2127
2128 /// The `detached` accessor property of `ArrayBuffer` instances returns a boolean indicating
2129 /// whether or not this buffer has been detached (transferred).
2130 ///
2131 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/detached)
2132 #[wasm_bindgen(method, getter)]
2133 pub fn detached(this: &ArrayBuffer) -> bool;
2134
2135 /// The `isView()` method returns true if arg is one of the `ArrayBuffer`
2136 /// views, such as typed array objects or a DataView; false otherwise.
2137 ///
2138 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/isView)
2139 #[wasm_bindgen(static_method_of = ArrayBuffer, js_name = isView)]
2140 pub fn is_view(value: &JsValue) -> bool;
2141
2142 /// The `maxByteLength` accessor property of ArrayBuffer instances returns the maximum
2143 /// length (in bytes) that this array buffer can be resized to.
2144 ///
2145 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/maxByteLength)
2146 #[wasm_bindgen(method, getter, js_name = maxByteLength)]
2147 pub fn max_byte_length(this: &ArrayBuffer) -> usize;
2148
2149 /// The `resizable` accessor property of `ArrayBuffer` instances returns whether this array buffer
2150 /// can be resized or not.
2151 ///
2152 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/resizable)
2153 #[wasm_bindgen(method, getter)]
2154 pub fn resizable(this: &ArrayBuffer) -> bool;
2155
2156 /// The `resize()` method of ArrayBuffer instances resizes the ArrayBuffer to the
2157 /// specified size, in bytes.
2158 ///
2159 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/resize)
2160 #[wasm_bindgen(method, catch)]
2161 pub fn resize(this: &ArrayBuffer, new_len: usize) -> Result<(), JsValue>;
2162
2163 /// The `slice()` method returns a new `ArrayBuffer` whose contents
2164 /// are a copy of this `ArrayBuffer`'s bytes from begin, inclusive,
2165 /// up to end, exclusive.
2166 ///
2167 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/slice)
2168 #[cfg(not(js_sys_unstable_apis))]
2169 #[wasm_bindgen(method)]
2170 pub fn slice(this: &ArrayBuffer, begin: u32) -> ArrayBuffer;
2171
2172 /// The `slice()` method returns a new `ArrayBuffer` whose contents
2173 /// are a copy of this `ArrayBuffer`'s bytes from begin, inclusive,
2174 /// up to end, exclusive. Negative indices count from the end.
2175 ///
2176 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/slice)
2177 #[cfg(js_sys_unstable_apis)]
2178 #[wasm_bindgen(method)]
2179 pub fn slice(this: &ArrayBuffer, begin: isize, end: isize) -> ArrayBuffer;
2180
2181 /// The `slice()` method returns a new `ArrayBuffer` whose contents
2182 /// are a copy of this `ArrayBuffer`'s bytes from begin, inclusive,
2183 /// up to end, exclusive.
2184 ///
2185 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/slice)
2186 #[cfg(not(js_sys_unstable_apis))]
2187 #[wasm_bindgen(method, js_name = slice)]
2188 pub fn slice_from(this: &ArrayBuffer, begin: isize) -> ArrayBuffer;
2189
2190 /// The `slice()` method returns a new `ArrayBuffer` whose contents
2191 /// are a copy of this `ArrayBuffer`'s bytes from begin to the end.
2192 /// Negative indices count from the end.
2193 ///
2194 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/slice)
2195 #[cfg(js_sys_unstable_apis)]
2196 #[wasm_bindgen(method, js_name = slice)]
2197 pub fn slice_from(this: &ArrayBuffer, begin: isize) -> ArrayBuffer;
2198
2199 // Next major: deprecate
2200 /// Like `slice()` but with the `end` argument.
2201 ///
2202 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/slice)
2203 #[wasm_bindgen(method, js_name = slice)]
2204 pub fn slice_with_end(this: &ArrayBuffer, begin: u32, end: u32) -> ArrayBuffer;
2205
2206 /// The `transfer()` method of ArrayBuffer instances creates a new `ArrayBuffer`
2207 /// with the same byte content as this buffer, then detaches this buffer.
2208 ///
2209 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/transfer)
2210 #[wasm_bindgen(method, catch)]
2211 pub fn transfer(this: &ArrayBuffer) -> Result<ArrayBuffer, JsValue>;
2212
2213 /// The `transfer()` method of `ArrayBuffer` instances creates a new `ArrayBuffer`
2214 /// with the same byte content as this buffer, then detaches this buffer.
2215 ///
2216 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/transfer)
2217 #[wasm_bindgen(method, catch, js_name = transfer)]
2218 pub fn transfer_with_length(
2219 this: &ArrayBuffer,
2220 new_byte_length: usize,
2221 ) -> Result<ArrayBuffer, JsValue>;
2222
2223 /// The `transferToFixedLength()` method of `ArrayBuffer` instances creates a new non-resizable
2224 /// ArrayBuffer with the same byte content as this buffer, then detaches this buffer.
2225 ///
2226 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/transferToFixedLength)
2227 #[wasm_bindgen(method, catch, js_name = transferToFixedLength)]
2228 pub fn transfer_to_fixed_length(this: &ArrayBuffer) -> Result<ArrayBuffer, JsValue>;
2229
2230 /// The `transferToFixedLength()` method of `ArrayBuffer` instances creates a new non-resizable
2231 /// `ArrayBuffer` with the same byte content as this buffer, then detaches this buffer.
2232 ///
2233 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/transferToFixedLength)
2234 #[wasm_bindgen(method, catch, js_name = transferToFixedLength)]
2235 pub fn transfer_to_fixed_length_with_length(
2236 this: &ArrayBuffer,
2237 new_byte_length: usize,
2238 ) -> Result<ArrayBuffer, JsValue>;
2239}
2240
2241impl UpcastFrom<&[u8]> for ArrayBuffer {}
2242
2243// SharedArrayBuffer
2244#[wasm_bindgen]
2245extern "C" {
2246 #[wasm_bindgen(extends = Object, typescript_type = "SharedArrayBuffer")]
2247 #[derive(Clone, Debug)]
2248 pub type SharedArrayBuffer;
2249
2250 /// The `SharedArrayBuffer` object is used to represent a generic,
2251 /// fixed-length raw binary data buffer, similar to the `ArrayBuffer`
2252 /// object, but in a way that they can be used to create views
2253 /// on shared memory. Unlike an `ArrayBuffer`, a `SharedArrayBuffer`
2254 /// cannot become detached.
2255 ///
2256 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer)
2257 #[cfg(not(js_sys_unstable_apis))]
2258 #[wasm_bindgen(constructor)]
2259 pub fn new(length: u32) -> SharedArrayBuffer;
2260
2261 /// The `SharedArrayBuffer` object is used to represent a generic,
2262 /// fixed-length raw binary data buffer, similar to the `ArrayBuffer`
2263 /// object, but in a way that they can be used to create views
2264 /// on shared memory. Unlike an `ArrayBuffer`, a `SharedArrayBuffer`
2265 /// cannot become detached.
2266 ///
2267 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer)
2268 #[cfg(js_sys_unstable_apis)]
2269 #[wasm_bindgen(constructor)]
2270 pub fn new(length: usize) -> SharedArrayBuffer;
2271
2272 /// The `SharedArrayBuffer` object is used to represent a generic,
2273 /// fixed-length raw binary data buffer, similar to the `ArrayBuffer`
2274 /// object, but in a way that they can be used to create views
2275 /// on shared memory. Unlike an `ArrayBuffer`, a `SharedArrayBuffer`
2276 /// cannot become detached.
2277 ///
2278 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer)
2279 #[wasm_bindgen(constructor)]
2280 pub fn new_with_options(length: usize, options: &ArrayBufferOptions) -> SharedArrayBuffer;
2281
2282 /// The `byteLength` accessor property represents the length of
2283 /// an `SharedArrayBuffer` in bytes. This is established when
2284 /// the `SharedArrayBuffer` is constructed and cannot be changed.
2285 ///
2286 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/byteLength)
2287 #[cfg(not(js_sys_unstable_apis))]
2288 #[wasm_bindgen(method, getter, js_name = byteLength)]
2289 pub fn byte_length(this: &SharedArrayBuffer) -> u32;
2290
2291 /// The `byteLength` accessor property represents the length of
2292 /// an `SharedArrayBuffer` in bytes. This is established when
2293 /// the `SharedArrayBuffer` is constructed and cannot be changed.
2294 ///
2295 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/byteLength)
2296 #[cfg(js_sys_unstable_apis)]
2297 #[wasm_bindgen(method, getter, js_name = byteLength)]
2298 pub fn byte_length(this: &SharedArrayBuffer) -> usize;
2299
2300 /// The `growable` accessor property of `SharedArrayBuffer` instances returns whether
2301 /// this `SharedArrayBuffer` can be grown or not.
2302 ///
2303 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/growable)
2304 #[wasm_bindgen(method, getter)]
2305 pub fn growable(this: &SharedArrayBuffer) -> bool;
2306
2307 /// The `grow()` method of `SharedArrayBuffer` instances grows the
2308 /// `SharedArrayBuffer` to the specified size, in bytes.
2309 ///
2310 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/grow)
2311 #[wasm_bindgen(method, catch)]
2312 pub fn grow(this: &SharedArrayBuffer, new_byte_length: usize) -> Result<(), JsValue>;
2313
2314 /// The `maxByteLength` accessor property of `SharedArrayBuffer` instances returns the maximum
2315 /// length (in bytes) that this `SharedArrayBuffer` can be resized to.
2316 ///
2317 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/maxByteLength)
2318 #[wasm_bindgen(method, getter, js_name = maxByteLength)]
2319 pub fn max_byte_length(this: &SharedArrayBuffer) -> usize;
2320
2321 /// The `slice()` method returns a new `SharedArrayBuffer` whose contents
2322 /// are a copy of this `SharedArrayBuffer`'s bytes from begin, inclusive,
2323 /// up to end, exclusive.
2324 ///
2325 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/slice)
2326 #[cfg(not(js_sys_unstable_apis))]
2327 #[wasm_bindgen(method)]
2328 pub fn slice(this: &SharedArrayBuffer, begin: u32) -> SharedArrayBuffer;
2329
2330 /// The `slice()` method returns a new `SharedArrayBuffer` whose contents
2331 /// are a copy of this `SharedArrayBuffer`'s bytes from begin, inclusive,
2332 /// up to end, exclusive. Negative indices count from the end.
2333 ///
2334 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/slice)
2335 #[cfg(js_sys_unstable_apis)]
2336 #[wasm_bindgen(method)]
2337 pub fn slice(this: &SharedArrayBuffer, begin: isize, end: isize) -> SharedArrayBuffer;
2338
2339 /// The `slice()` method returns a new `SharedArrayBuffer` whose contents
2340 /// are a copy of this `SharedArrayBuffer`'s bytes from begin, inclusive,
2341 /// up to end, exclusive.
2342 ///
2343 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/slice)
2344 #[cfg(not(js_sys_unstable_apis))]
2345 #[wasm_bindgen(method)]
2346 pub fn slice_from(this: &SharedArrayBuffer, begin: isize) -> SharedArrayBuffer;
2347
2348 /// The `slice()` method returns a new `SharedArrayBuffer` whose contents
2349 /// are a copy of this `SharedArrayBuffer`'s bytes from begin to end.
2350 /// Negative indices count from the end.
2351 ///
2352 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/slice)
2353 #[cfg(js_sys_unstable_apis)]
2354 #[wasm_bindgen(method)]
2355 pub fn slice_from(this: &SharedArrayBuffer, begin: isize) -> SharedArrayBuffer;
2356
2357 // Next major: deprecate
2358 /// Like `slice()` but with the `end` argument.
2359 ///
2360 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/slice)
2361 #[wasm_bindgen(method, js_name = slice)]
2362 pub fn slice_with_end(this: &SharedArrayBuffer, begin: u32, end: u32) -> SharedArrayBuffer;
2363}
2364
2365// Array Iterator
2366#[wasm_bindgen]
2367extern "C" {
2368 /// The `keys()` method returns a new Array Iterator object that contains the
2369 /// keys for each index in the array.
2370 ///
2371 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/keys)
2372 #[wasm_bindgen(method)]
2373 pub fn keys<T>(this: &Array<T>) -> Iterator<T>;
2374
2375 /// The `entries()` method returns a new Array Iterator object that contains
2376 /// the key/value pairs for each index in the array.
2377 ///
2378 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries)
2379 #[cfg(not(js_sys_unstable_apis))]
2380 #[wasm_bindgen(method)]
2381 #[deprecated(note = "recommended to use `Array::entries_typed` instead for typing")]
2382 #[allow(deprecated)]
2383 pub fn entries<T>(this: &Array<T>) -> Iterator<T>;
2384
2385 /// The `entries()` method returns a new Array Iterator object that contains
2386 /// the key/value pairs for each index in the array.
2387 ///
2388 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries)
2389 #[cfg(js_sys_unstable_apis)]
2390 #[wasm_bindgen(method)]
2391 pub fn entries<T: JsGeneric>(this: &Array<T>) -> Iterator<ArrayTuple<(Number, T)>>;
2392
2393 // Next major: deprecate
2394 /// The `entries()` method returns a new Array Iterator object that contains
2395 /// the key/value pairs for each index in the array.
2396 ///
2397 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries)
2398 #[wasm_bindgen(method, js_name = entries)]
2399 pub fn entries_typed<T: JsGeneric>(this: &Array<T>) -> Iterator<ArrayTuple<(Number, T)>>;
2400
2401 /// The `values()` method returns a new Array Iterator object that
2402 /// contains the values for each index in the array.
2403 ///
2404 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/values)
2405 #[wasm_bindgen(method)]
2406 pub fn values<T>(this: &Array<T>) -> Iterator<T>;
2407}
2408
2409pub trait TypedArray: JsGeneric {}
2410
2411// Next major: use usize/isize for indices
2412/// The `Atomics` object provides atomic operations as static methods.
2413/// They are used with `SharedArrayBuffer` objects.
2414///
2415/// The Atomic operations are installed on an `Atomics` module. Unlike
2416/// the other global objects, `Atomics` is not a constructor. You cannot
2417/// use it with a new operator or invoke the `Atomics` object as a
2418/// function. All properties and methods of `Atomics` are static
2419/// (as is the case with the Math object, for example).
2420/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics)
2421#[allow(non_snake_case)]
2422pub mod Atomics {
2423 use super::*;
2424
2425 #[wasm_bindgen]
2426 extern "C" {
2427 /// The static `Atomics.add()` method adds a given value at a given
2428 /// position in the array and returns the old value at that position.
2429 /// This atomic operation guarantees that no other write happens
2430 /// until the modified value is written back.
2431 ///
2432 /// You should use `add_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2433 ///
2434 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/add)
2435 #[wasm_bindgen(js_namespace = Atomics, catch)]
2436 pub fn add<T: TypedArray = Int32Array>(
2437 typed_array: &T,
2438 index: u32,
2439 value: i32,
2440 ) -> Result<i32, JsValue>;
2441
2442 /// The static `Atomics.add()` method adds a given value at a given
2443 /// position in the array and returns the old value at that position.
2444 /// This atomic operation guarantees that no other write happens
2445 /// until the modified value is written back.
2446 ///
2447 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2448 ///
2449 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/add)
2450 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = add)]
2451 pub fn add_bigint<T: TypedArray = Int32Array>(
2452 typed_array: &T,
2453 index: u32,
2454 value: i64,
2455 ) -> Result<i64, JsValue>;
2456
2457 /// The static `Atomics.and()` method computes a bitwise AND with a given
2458 /// value at a given position in the array, and returns the old value
2459 /// at that position.
2460 /// This atomic operation guarantees that no other write happens
2461 /// until the modified value is written back.
2462 ///
2463 /// You should use `and_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2464 ///
2465 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/and)
2466 #[wasm_bindgen(js_namespace = Atomics, catch)]
2467 pub fn and<T: TypedArray = Int32Array>(
2468 typed_array: &T,
2469 index: u32,
2470 value: i32,
2471 ) -> Result<i32, JsValue>;
2472
2473 /// The static `Atomics.and()` method computes a bitwise AND with a given
2474 /// value at a given position in the array, and returns the old value
2475 /// at that position.
2476 /// This atomic operation guarantees that no other write happens
2477 /// until the modified value is written back.
2478 ///
2479 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2480 ///
2481 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/and)
2482 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = and)]
2483 pub fn and_bigint<T: TypedArray = Int32Array>(
2484 typed_array: &T,
2485 index: u32,
2486 value: i64,
2487 ) -> Result<i64, JsValue>;
2488
2489 /// The static `Atomics.compareExchange()` method exchanges a given
2490 /// replacement value at a given position in the array, if a given expected
2491 /// value equals the old value. It returns the old value at that position
2492 /// whether it was equal to the expected value or not.
2493 /// This atomic operation guarantees that no other write happens
2494 /// until the modified value is written back.
2495 ///
2496 /// You should use `compare_exchange_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2497 ///
2498 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/compareExchange)
2499 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = compareExchange)]
2500 pub fn compare_exchange<T: TypedArray = Int32Array>(
2501 typed_array: &T,
2502 index: u32,
2503 expected_value: i32,
2504 replacement_value: i32,
2505 ) -> Result<i32, JsValue>;
2506
2507 /// The static `Atomics.compareExchange()` method exchanges a given
2508 /// replacement value at a given position in the array, if a given expected
2509 /// value equals the old value. It returns the old value at that position
2510 /// whether it was equal to the expected value or not.
2511 /// This atomic operation guarantees that no other write happens
2512 /// until the modified value is written back.
2513 ///
2514 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2515 ///
2516 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/compareExchange)
2517 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = compareExchange)]
2518 pub fn compare_exchange_bigint<T: TypedArray = Int32Array>(
2519 typed_array: &T,
2520 index: u32,
2521 expected_value: i64,
2522 replacement_value: i64,
2523 ) -> Result<i64, JsValue>;
2524
2525 /// The static `Atomics.exchange()` method stores a given value at a given
2526 /// position in the array and returns the old value at that position.
2527 /// This atomic operation guarantees that no other write happens
2528 /// until the modified value is written back.
2529 ///
2530 /// You should use `exchange_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2531 ///
2532 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/exchange)
2533 #[wasm_bindgen(js_namespace = Atomics, catch)]
2534 pub fn exchange<T: TypedArray = Int32Array>(
2535 typed_array: &T,
2536 index: u32,
2537 value: i32,
2538 ) -> Result<i32, JsValue>;
2539
2540 /// The static `Atomics.exchange()` method stores a given value at a given
2541 /// position in the array and returns the old value at that position.
2542 /// This atomic operation guarantees that no other write happens
2543 /// until the modified value is written back.
2544 ///
2545 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2546 ///
2547 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/exchange)
2548 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = exchange)]
2549 pub fn exchange_bigint<T: TypedArray = Int32Array>(
2550 typed_array: &T,
2551 index: u32,
2552 value: i64,
2553 ) -> Result<i64, JsValue>;
2554
2555 /// The static `Atomics.isLockFree()` method is used to determine
2556 /// whether to use locks or atomic operations. It returns true,
2557 /// if the given size is one of the `BYTES_PER_ELEMENT` property
2558 /// of integer `TypedArray` types.
2559 ///
2560 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/isLockFree)
2561 #[wasm_bindgen(js_namespace = Atomics, js_name = isLockFree)]
2562 pub fn is_lock_free(size: u32) -> bool;
2563
2564 /// The static `Atomics.load()` method returns a value at a given
2565 /// position in the array.
2566 ///
2567 /// You should use `load_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2568 ///
2569 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/load)
2570 #[wasm_bindgen(js_namespace = Atomics, catch)]
2571 pub fn load<T: TypedArray = Int32Array>(
2572 typed_array: &T,
2573 index: u32,
2574 ) -> Result<i32, JsValue>;
2575
2576 /// The static `Atomics.load()` method returns a value at a given
2577 /// position in the array.
2578 ///
2579 /// This method is used 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/load)
2582 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = load)]
2583 pub fn load_bigint<T: TypedArray = Int32Array>(
2584 typed_array: &T,
2585 index: i64,
2586 ) -> Result<i64, JsValue>;
2587
2588 /// The static `Atomics.notify()` method notifies up some agents that
2589 /// are sleeping in the wait queue.
2590 /// Note: This operation works with a shared `Int32Array` only.
2591 /// If `count` is not provided, notifies all the agents in the queue.
2592 ///
2593 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/notify)
2594 #[wasm_bindgen(js_namespace = Atomics, catch)]
2595 pub fn notify(typed_array: &Int32Array, index: u32) -> Result<u32, JsValue>;
2596
2597 /// The static `Atomics.notify()` method notifies up some agents that
2598 /// are sleeping in the wait queue.
2599 /// Note: This operation works with a shared `Int32Array` only.
2600 /// If `count` is not provided, notifies all the agents in the queue.
2601 ///
2602 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/notify)
2603 #[wasm_bindgen(js_namespace = Atomics, catch)]
2604 pub fn notify_bigint(typed_array: &BigInt64Array, index: u32) -> Result<u32, JsValue>;
2605
2606 /// Notifies up to `count` agents in the wait queue.
2607 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = notify)]
2608 pub fn notify_with_count(
2609 typed_array: &Int32Array,
2610 index: u32,
2611 count: u32,
2612 ) -> Result<u32, JsValue>;
2613
2614 /// Notifies up to `count` agents in the wait queue.
2615 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = notify)]
2616 pub fn notify_bigint_with_count(
2617 typed_array: &BigInt64Array,
2618 index: u32,
2619 count: u32,
2620 ) -> Result<u32, JsValue>;
2621
2622 /// The static `Atomics.or()` method computes a bitwise OR with a given value
2623 /// at a given position in the array, and returns the old value at that position.
2624 /// This atomic operation guarantees that no other write happens
2625 /// until the modified value is written back.
2626 ///
2627 /// You should use `or_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2628 ///
2629 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/or)
2630 #[wasm_bindgen(js_namespace = Atomics, catch)]
2631 pub fn or<T: TypedArray = Int32Array>(
2632 typed_array: &T,
2633 index: u32,
2634 value: i32,
2635 ) -> Result<i32, JsValue>;
2636
2637 /// The static `Atomics.or()` method computes a bitwise OR with a given value
2638 /// at a given position in the array, and returns the old value at that position.
2639 /// This atomic operation guarantees that no other write happens
2640 /// until the modified value is written back.
2641 ///
2642 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2643 ///
2644 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/or)
2645 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = or)]
2646 pub fn or_bigint<T: TypedArray = Int32Array>(
2647 typed_array: &T,
2648 index: u32,
2649 value: i64,
2650 ) -> Result<i64, JsValue>;
2651
2652 /// The static `Atomics.pause()` static method provides a micro-wait primitive that hints to the CPU
2653 /// that the caller is spinning while waiting on access to a shared resource. This allows the system
2654 /// to reduce the resources allocated to the core (such as power) or thread, without yielding the
2655 /// current thread.
2656 ///
2657 /// `pause()` has no observable behavior other than timing. The exact behavior is dependent on the CPU
2658 /// architecture and the operating system. For example, in Intel x86, it may be a pause instruction as
2659 /// per Intel's optimization manual. It could be a no-op in certain platforms.
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/xor)
2664 #[wasm_bindgen(js_namespace = Atomics)]
2665 pub fn pause();
2666
2667 /// The static `Atomics.pause()` static method provides a micro-wait primitive that hints to the CPU
2668 /// that the caller is spinning while waiting on access to a shared resource. This allows the system
2669 /// to reduce the resources allocated to the core (such as power) or thread, without yielding the
2670 /// current thread.
2671 ///
2672 /// `pause()` has no observable behavior other than timing. The exact behavior is dependent on the CPU
2673 /// architecture and the operating system. For example, in Intel x86, it may be a pause instruction as
2674 /// per Intel's optimization manual. It could be a no-op in certain platforms.
2675 ///
2676 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2677 ///
2678 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/xor)
2679 #[wasm_bindgen(js_namespace = Atomics)]
2680 pub fn pause_with_hint(duration_hint: u32);
2681
2682 /// The static `Atomics.store()` method stores a given value at the given
2683 /// position in the array and returns that value.
2684 ///
2685 /// You should use `store_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2686 ///
2687 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/store)
2688 #[wasm_bindgen(js_namespace = Atomics, catch)]
2689 pub fn store<T: TypedArray = Int32Array>(
2690 typed_array: &T,
2691 index: u32,
2692 value: i32,
2693 ) -> Result<i32, JsValue>;
2694
2695 /// The static `Atomics.store()` method stores a given value at the given
2696 /// position in the array and returns that value.
2697 ///
2698 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2699 ///
2700 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/store)
2701 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = store)]
2702 pub fn store_bigint<T: TypedArray = Int32Array>(
2703 typed_array: &T,
2704 index: u32,
2705 value: i64,
2706 ) -> Result<i64, JsValue>;
2707
2708 /// The static `Atomics.sub()` method subtracts a given value at a
2709 /// given position in the array and returns the old value at that position.
2710 /// This atomic operation guarantees that no other write happens
2711 /// until the modified value is written back.
2712 ///
2713 /// You should use `sub_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2714 ///
2715 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/sub)
2716 #[wasm_bindgen(js_namespace = Atomics, catch)]
2717 pub fn sub<T: TypedArray = Int32Array>(
2718 typed_array: &T,
2719 index: u32,
2720 value: i32,
2721 ) -> Result<i32, JsValue>;
2722
2723 /// The static `Atomics.sub()` method subtracts a given value at a
2724 /// given position in the array and returns the old value at that position.
2725 /// This atomic operation guarantees that no other write happens
2726 /// until the modified value is written back.
2727 ///
2728 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2729 ///
2730 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/sub)
2731 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = sub)]
2732 pub fn sub_bigint<T: TypedArray = Int32Array>(
2733 typed_array: &T,
2734 index: u32,
2735 value: i64,
2736 ) -> Result<i64, JsValue>;
2737
2738 /// The static `Atomics.wait()` method verifies that a given
2739 /// position in an `Int32Array` still contains a given value
2740 /// and if so sleeps, awaiting a wakeup or a timeout.
2741 /// It returns a string which is either "ok", "not-equal", or "timed-out".
2742 /// Note: This operation only works with a shared `Int32Array`
2743 /// and may not be allowed on the main thread.
2744 ///
2745 /// You should use `wait_bigint` to operate on a `BigInt64Array`.
2746 ///
2747 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait)
2748 #[wasm_bindgen(js_namespace = Atomics, catch)]
2749 pub fn wait(typed_array: &Int32Array, index: u32, value: i32) -> Result<JsString, JsValue>;
2750
2751 /// The static `Atomics.wait()` method verifies that a given
2752 /// position in an `BigInt64Array` still contains a given value
2753 /// and if so sleeps, awaiting a wakeup or a timeout.
2754 /// It returns a string which is either "ok", "not-equal", or "timed-out".
2755 /// Note: This operation only works with a shared `BigInt64Array`
2756 /// and may not be allowed on the main thread.
2757 ///
2758 /// You should use `wait` to operate on a `Int32Array`.
2759 ///
2760 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait)
2761 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = wait)]
2762 pub fn wait_bigint(
2763 typed_array: &BigInt64Array,
2764 index: u32,
2765 value: i64,
2766 ) -> Result<JsString, JsValue>;
2767
2768 /// Like `wait()`, but with timeout
2769 ///
2770 /// You should use `wait_with_timeout_bigint` to operate on a `BigInt64Array`.
2771 ///
2772 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait)
2773 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = wait)]
2774 pub fn wait_with_timeout(
2775 typed_array: &Int32Array,
2776 index: u32,
2777 value: i32,
2778 timeout: f64,
2779 ) -> Result<JsString, JsValue>;
2780
2781 /// Like `wait()`, but with timeout
2782 ///
2783 /// You should use `wait_with_timeout` to operate on a `Int32Array`.
2784 ///
2785 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait)
2786 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = wait)]
2787 pub fn wait_with_timeout_bigint(
2788 typed_array: &BigInt64Array,
2789 index: u32,
2790 value: i64,
2791 timeout: f64,
2792 ) -> Result<JsString, JsValue>;
2793
2794 /// The static `Atomics.waitAsync()` method verifies that a given position in an
2795 /// `Int32Array` still contains a given value and if so sleeps, awaiting a
2796 /// wakeup or a timeout. It returns an object with two properties. The first
2797 /// property `async` is a boolean which if true indicates that the second
2798 /// property `value` is a promise. If `async` is false then value is a string
2799 /// whether equal to either "not-equal" or "timed-out".
2800 /// Note: This operation only works with a shared `Int32Array` and may be used
2801 /// on the main thread.
2802 ///
2803 /// You should use `wait_async_bigint` to operate on a `BigInt64Array`.
2804 ///
2805 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/waitAsync)
2806 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = waitAsync)]
2807 pub fn wait_async(
2808 typed_array: &Int32Array,
2809 index: u32,
2810 value: i32,
2811 ) -> Result<Object, JsValue>;
2812
2813 /// The static `Atomics.waitAsync()` method verifies that a given position in an
2814 /// `Int32Array` still contains a given value and if so sleeps, awaiting a
2815 /// wakeup or a timeout. It returns an object with two properties. The first
2816 /// property `async` is a boolean which if true indicates that the second
2817 /// property `value` is a promise. If `async` is false then value is a string
2818 /// whether equal to either "not-equal" or "timed-out".
2819 /// Note: This operation only works with a shared `BigInt64Array` and may be used
2820 /// on the main thread.
2821 ///
2822 /// You should use `wait_async` to operate on a `Int32Array`.
2823 ///
2824 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/waitAsync)
2825 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = waitAsync)]
2826 pub fn wait_async_bigint(
2827 typed_array: &BigInt64Array,
2828 index: u32,
2829 value: i64,
2830 ) -> Result<Object, JsValue>;
2831
2832 /// Like `waitAsync()`, but with timeout
2833 ///
2834 /// You should use `wait_async_with_timeout_bigint` to operate on a `BigInt64Array`.
2835 ///
2836 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/waitAsync)
2837 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = waitAsync)]
2838 pub fn wait_async_with_timeout(
2839 typed_array: &Int32Array,
2840 index: u32,
2841 value: i32,
2842 timeout: f64,
2843 ) -> Result<Object, JsValue>;
2844
2845 /// Like `waitAsync()`, but with timeout
2846 ///
2847 /// You should use `wait_async_with_timeout` to operate on a `Int32Array`.
2848 ///
2849 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/waitAsync)
2850 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = waitAsync)]
2851 pub fn wait_async_with_timeout_bigint(
2852 typed_array: &BigInt64Array,
2853 index: u32,
2854 value: i64,
2855 timeout: f64,
2856 ) -> Result<Object, JsValue>;
2857
2858 /// The static `Atomics.xor()` method computes a bitwise XOR
2859 /// with a given value at a given position in the array,
2860 /// and returns the old value at that position.
2861 /// This atomic operation guarantees that no other write happens
2862 /// until the modified value is written back.
2863 ///
2864 /// You should use `xor_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2865 ///
2866 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/xor)
2867 #[wasm_bindgen(js_namespace = Atomics, catch)]
2868 pub fn xor<T: TypedArray = Int32Array>(
2869 typed_array: &T,
2870 index: u32,
2871 value: i32,
2872 ) -> Result<i32, JsValue>;
2873
2874 /// The static `Atomics.xor()` method computes a bitwise XOR
2875 /// with a given value at a given position in the array,
2876 /// and returns the old value at that position.
2877 /// This atomic operation guarantees that no other write happens
2878 /// until the modified value is written back.
2879 ///
2880 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2881 ///
2882 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/xor)
2883 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = xor)]
2884 pub fn xor_bigint<T: TypedArray = Int32Array>(
2885 typed_array: &T,
2886 index: u32,
2887 value: i64,
2888 ) -> Result<i64, JsValue>;
2889 }
2890}
2891
2892// BigInt
2893#[wasm_bindgen]
2894extern "C" {
2895 #[wasm_bindgen(extends = Object, is_type_of = |v| v.is_bigint(), typescript_type = "bigint")]
2896 #[derive(Clone, PartialEq, Eq)]
2897 pub type BigInt;
2898
2899 #[wasm_bindgen(catch, js_name = BigInt)]
2900 fn new_bigint(value: &JsValue) -> Result<BigInt, Error>;
2901
2902 #[wasm_bindgen(js_name = BigInt)]
2903 fn new_bigint_unchecked(value: &JsValue) -> BigInt;
2904
2905 /// Clamps a BigInt value to a signed integer value, and returns that value.
2906 ///
2907 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/asIntN)
2908 #[wasm_bindgen(static_method_of = BigInt, js_name = asIntN)]
2909 pub fn as_int_n(bits: f64, bigint: &BigInt) -> BigInt;
2910
2911 /// Clamps a BigInt value to an unsigned integer value, and returns that value.
2912 ///
2913 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/asUintN)
2914 #[wasm_bindgen(static_method_of = BigInt, js_name = asUintN)]
2915 pub fn as_uint_n(bits: f64, bigint: &BigInt) -> BigInt;
2916
2917 /// 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.
2918 ///
2919 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/toLocaleString)
2920 #[cfg(not(js_sys_unstable_apis))]
2921 #[wasm_bindgen(method, js_name = toLocaleString)]
2922 pub fn to_locale_string(this: &BigInt, locales: &JsValue, options: &JsValue) -> JsString;
2923
2924 /// 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.
2925 ///
2926 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/toLocaleString)
2927 #[cfg(js_sys_unstable_apis)]
2928 #[wasm_bindgen(method, js_name = toLocaleString)]
2929 pub fn to_locale_string(
2930 this: &BigInt,
2931 locales: &[JsString],
2932 options: &Intl::NumberFormatOptions,
2933 ) -> JsString;
2934
2935 // Next major: deprecate
2936 /// 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.
2937 ///
2938 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/toString)
2939 #[wasm_bindgen(catch, method, js_name = toString)]
2940 pub fn to_string(this: &BigInt, radix: u8) -> Result<JsString, RangeError>;
2941
2942 /// Returns a string representing this BigInt value in the specified radix (base).
2943 ///
2944 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/toString)
2945 #[cfg(js_sys_unstable_apis)]
2946 #[wasm_bindgen(catch, method, js_name = toString)]
2947 pub fn to_string_with_radix(this: &BigInt, radix: u8) -> Result<JsString, RangeError>;
2948
2949 #[wasm_bindgen(method, js_name = toString)]
2950 fn to_string_unchecked(this: &BigInt, radix: u8) -> String;
2951
2952 /// Returns this BigInt value. Overrides the [`Object.prototype.valueOf()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf) method.
2953 ///
2954 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/valueOf)
2955 #[wasm_bindgen(method, js_name = valueOf)]
2956 pub fn value_of(this: &BigInt, radix: u8) -> BigInt;
2957}
2958
2959impl BigInt {
2960 /// Creates a new BigInt value.
2961 ///
2962 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/BigInt)
2963 #[inline]
2964 pub fn new(value: &JsValue) -> Result<BigInt, Error> {
2965 new_bigint(value)
2966 }
2967
2968 /// Applies the binary `/` JS operator on two `BigInt`s, catching and returning any `RangeError` thrown.
2969 ///
2970 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Division)
2971 pub fn checked_div(&self, rhs: &Self) -> Result<Self, RangeError> {
2972 let result = JsValue::as_ref(self).checked_div(JsValue::as_ref(rhs));
2973
2974 if result.is_instance_of::<RangeError>() {
2975 Err(result.unchecked_into())
2976 } else {
2977 Ok(result.unchecked_into())
2978 }
2979 }
2980
2981 /// Applies the binary `**` JS operator on the two `BigInt`s.
2982 ///
2983 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Exponentiation)
2984 #[inline]
2985 pub fn pow(&self, rhs: &Self) -> Self {
2986 JsValue::as_ref(self)
2987 .pow(JsValue::as_ref(rhs))
2988 .unchecked_into()
2989 }
2990
2991 /// Returns a tuple of this [`BigInt`]'s absolute value along with a
2992 /// [`bool`] indicating whether the [`BigInt`] was negative.
2993 fn abs(&self) -> (Self, bool) {
2994 if self < &BigInt::from(0) {
2995 (-self, true)
2996 } else {
2997 (self.clone(), false)
2998 }
2999 }
3000}
3001
3002macro_rules! bigint_from {
3003 ($($x:ident)*) => ($(
3004 impl From<$x> for BigInt {
3005 #[inline]
3006 fn from(x: $x) -> BigInt {
3007 new_bigint_unchecked(&JsValue::from(x))
3008 }
3009 }
3010
3011 impl PartialEq<$x> for BigInt {
3012 #[inline]
3013 fn eq(&self, other: &$x) -> bool {
3014 JsValue::from(self) == JsValue::from(BigInt::from(*other))
3015 }
3016 }
3017 )*)
3018}
3019bigint_from!(i8 u8 i16 u16 i32 u32 isize usize);
3020
3021macro_rules! bigint_from_big {
3022 ($($x:ident)*) => ($(
3023 impl From<$x> for BigInt {
3024 #[inline]
3025 fn from(x: $x) -> BigInt {
3026 JsValue::from(x).unchecked_into()
3027 }
3028 }
3029
3030 impl PartialEq<$x> for BigInt {
3031 #[inline]
3032 fn eq(&self, other: &$x) -> bool {
3033 self == &BigInt::from(*other)
3034 }
3035 }
3036
3037 impl TryFrom<BigInt> for $x {
3038 type Error = BigInt;
3039
3040 #[inline]
3041 fn try_from(x: BigInt) -> Result<Self, BigInt> {
3042 Self::try_from(JsValue::from(x)).map_err(JsCast::unchecked_into)
3043 }
3044 }
3045 )*)
3046}
3047bigint_from_big!(i64 u64 i128 u128);
3048
3049impl PartialEq<Number> for BigInt {
3050 #[inline]
3051 fn eq(&self, other: &Number) -> bool {
3052 JsValue::as_ref(self).loose_eq(JsValue::as_ref(other))
3053 }
3054}
3055
3056impl Not for &BigInt {
3057 type Output = BigInt;
3058
3059 #[inline]
3060 fn not(self) -> Self::Output {
3061 JsValue::as_ref(self).bit_not().unchecked_into()
3062 }
3063}
3064
3065forward_deref_unop!(impl Not, not for BigInt);
3066forward_js_unop!(impl Neg, neg for BigInt);
3067forward_js_binop!(impl BitAnd, bitand for BigInt);
3068forward_js_binop!(impl BitOr, bitor for BigInt);
3069forward_js_binop!(impl BitXor, bitxor for BigInt);
3070forward_js_binop!(impl Shl, shl for BigInt);
3071forward_js_binop!(impl Shr, shr for BigInt);
3072forward_js_binop!(impl Add, add for BigInt);
3073forward_js_binop!(impl Sub, sub for BigInt);
3074forward_js_binop!(impl Div, div for BigInt);
3075forward_js_binop!(impl Mul, mul for BigInt);
3076forward_js_binop!(impl Rem, rem for BigInt);
3077sum_product!(BigInt);
3078
3079partialord_ord!(BigInt);
3080
3081impl Default for BigInt {
3082 fn default() -> Self {
3083 BigInt::from(i32::default())
3084 }
3085}
3086
3087impl FromStr for BigInt {
3088 type Err = Error;
3089
3090 #[inline]
3091 fn from_str(s: &str) -> Result<Self, Self::Err> {
3092 BigInt::new(&s.into())
3093 }
3094}
3095
3096impl fmt::Debug for BigInt {
3097 #[inline]
3098 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3099 fmt::Display::fmt(self, f)
3100 }
3101}
3102
3103impl fmt::Display for BigInt {
3104 #[inline]
3105 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3106 let (abs, is_neg) = self.abs();
3107 f.pad_integral(!is_neg, "", &abs.to_string_unchecked(10))
3108 }
3109}
3110
3111impl fmt::Binary for BigInt {
3112 #[inline]
3113 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3114 let (abs, is_neg) = self.abs();
3115 f.pad_integral(!is_neg, "0b", &abs.to_string_unchecked(2))
3116 }
3117}
3118
3119impl fmt::Octal for BigInt {
3120 #[inline]
3121 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3122 let (abs, is_neg) = self.abs();
3123 f.pad_integral(!is_neg, "0o", &abs.to_string_unchecked(8))
3124 }
3125}
3126
3127impl fmt::LowerHex for BigInt {
3128 #[inline]
3129 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3130 let (abs, is_neg) = self.abs();
3131 f.pad_integral(!is_neg, "0x", &abs.to_string_unchecked(16))
3132 }
3133}
3134
3135impl fmt::UpperHex for BigInt {
3136 #[inline]
3137 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3138 let (abs, is_neg) = self.abs();
3139 let mut s: String = abs.to_string_unchecked(16);
3140 s.make_ascii_uppercase();
3141 f.pad_integral(!is_neg, "0x", &s)
3142 }
3143}
3144
3145// Boolean
3146#[wasm_bindgen]
3147extern "C" {
3148 #[wasm_bindgen(extends = Object, is_type_of = |v| v.as_bool().is_some(), typescript_type = "boolean")]
3149 #[derive(Clone, PartialEq, Eq)]
3150 pub type Boolean;
3151
3152 /// The `Boolean()` constructor creates an object wrapper for a boolean value.
3153 ///
3154 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)
3155 #[cfg(not(js_sys_unstable_apis))]
3156 #[wasm_bindgen(constructor)]
3157 #[deprecated(note = "recommended to use `Boolean::from` instead")]
3158 #[allow(deprecated)]
3159 pub fn new(value: &JsValue) -> Boolean;
3160
3161 /// The `valueOf()` method returns the primitive value of a `Boolean` object.
3162 ///
3163 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean/valueOf)
3164 #[wasm_bindgen(method, js_name = valueOf)]
3165 pub fn value_of(this: &Boolean) -> bool;
3166}
3167
3168impl UpcastFrom<bool> for Boolean {}
3169impl UpcastFrom<Boolean> for bool {}
3170
3171impl Boolean {
3172 /// Typed Boolean true constant.
3173 pub const TRUE: Boolean = Self {
3174 obj: Object {
3175 obj: JsValue::TRUE,
3176 generics: PhantomData,
3177 },
3178 };
3179
3180 /// Typed Boolean false constant.
3181 pub const FALSE: Boolean = Self {
3182 obj: Object {
3183 obj: JsValue::FALSE,
3184 generics: PhantomData,
3185 },
3186 };
3187}
3188
3189impl From<bool> for Boolean {
3190 #[inline]
3191 fn from(b: bool) -> Boolean {
3192 Boolean::unchecked_from_js(JsValue::from(b))
3193 }
3194}
3195
3196impl From<Boolean> for bool {
3197 #[inline]
3198 fn from(b: Boolean) -> bool {
3199 b.value_of()
3200 }
3201}
3202
3203impl PartialEq<bool> for Boolean {
3204 #[inline]
3205 fn eq(&self, other: &bool) -> bool {
3206 self.value_of() == *other
3207 }
3208}
3209
3210impl fmt::Debug for Boolean {
3211 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3212 fmt::Debug::fmt(&self.value_of(), f)
3213 }
3214}
3215
3216impl fmt::Display for Boolean {
3217 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3218 fmt::Display::fmt(&self.value_of(), f)
3219 }
3220}
3221
3222impl Default for Boolean {
3223 fn default() -> Self {
3224 Self::from(bool::default())
3225 }
3226}
3227
3228impl Not for &Boolean {
3229 type Output = Boolean;
3230
3231 #[inline]
3232 fn not(self) -> Self::Output {
3233 (!JsValue::as_ref(self)).into()
3234 }
3235}
3236
3237forward_deref_unop!(impl Not, not for Boolean);
3238
3239partialord_ord!(Boolean);
3240
3241// DataView
3242#[wasm_bindgen]
3243extern "C" {
3244 #[wasm_bindgen(extends = Object, typescript_type = "DataView")]
3245 #[derive(Clone, Debug, PartialEq, Eq)]
3246 pub type DataView;
3247
3248 /// The `DataView` view provides a low-level interface for reading and
3249 /// writing multiple number types in an `ArrayBuffer` irrespective of the
3250 /// platform's endianness.
3251 ///
3252 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView)
3253 #[wasm_bindgen(constructor)]
3254 pub fn new(buffer: &ArrayBuffer, byteOffset: usize, byteLength: usize) -> DataView;
3255
3256 /// The `DataView` view provides a low-level interface for reading and
3257 /// writing multiple number types in an `ArrayBuffer` irrespective of the
3258 /// platform's endianness.
3259 ///
3260 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView)
3261 #[wasm_bindgen(constructor)]
3262 pub fn new_with_shared_array_buffer(
3263 buffer: &SharedArrayBuffer,
3264 byteOffset: usize,
3265 byteLength: usize,
3266 ) -> DataView;
3267
3268 /// The ArrayBuffer referenced by this view. Fixed at construction time and thus read only.
3269 ///
3270 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/buffer)
3271 #[wasm_bindgen(method, getter)]
3272 pub fn buffer(this: &DataView) -> ArrayBuffer;
3273
3274 /// The length (in bytes) of this view from the start of its ArrayBuffer.
3275 /// Fixed at construction time and thus read only.
3276 ///
3277 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/byteLength)
3278 #[wasm_bindgen(method, getter, js_name = byteLength)]
3279 pub fn byte_length(this: &DataView) -> usize;
3280
3281 /// The offset (in bytes) of this view from the start of its ArrayBuffer.
3282 /// Fixed at construction time and thus read only.
3283 ///
3284 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/byteOffset)
3285 #[wasm_bindgen(method, getter, js_name = byteOffset)]
3286 pub fn byte_offset(this: &DataView) -> usize;
3287
3288 /// The `getInt8()` method gets a signed 8-bit integer (byte) at the
3289 /// specified byte offset from the start of the DataView.
3290 ///
3291 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt8)
3292 #[wasm_bindgen(method, js_name = getInt8)]
3293 pub fn get_int8(this: &DataView, byte_offset: usize) -> i8;
3294
3295 /// The `getUint8()` method gets a unsigned 8-bit integer (byte) at the specified
3296 /// byte offset from the start of the DataView.
3297 ///
3298 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint8)
3299 #[wasm_bindgen(method, js_name = getUint8)]
3300 pub fn get_uint8(this: &DataView, byte_offset: usize) -> u8;
3301
3302 /// The `getInt16()` method gets a signed 16-bit integer (short) at the specified
3303 /// byte offset from the start of the DataView.
3304 ///
3305 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt16)
3306 #[wasm_bindgen(method, js_name = getInt16)]
3307 pub fn get_int16(this: &DataView, byte_offset: usize) -> i16;
3308
3309 /// The `getInt16()` method gets a signed 16-bit integer (short) at the specified
3310 /// byte offset from the start of the DataView.
3311 ///
3312 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt16)
3313 #[wasm_bindgen(method, js_name = getInt16)]
3314 pub fn get_int16_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> i16;
3315
3316 /// The `getUint16()` method gets an unsigned 16-bit integer (unsigned short) at the specified
3317 /// byte offset from the start of the view.
3318 ///
3319 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint16)
3320 #[wasm_bindgen(method, js_name = getUint16)]
3321 pub fn get_uint16(this: &DataView, byte_offset: usize) -> u16;
3322
3323 /// The `getUint16()` method gets an unsigned 16-bit integer (unsigned short) at the specified
3324 /// byte offset from the start of the view.
3325 ///
3326 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint16)
3327 #[wasm_bindgen(method, js_name = getUint16)]
3328 pub fn get_uint16_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> u16;
3329
3330 /// The `getInt32()` method gets a signed 32-bit integer (long) at the specified
3331 /// byte offset from the start of the DataView.
3332 ///
3333 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt32)
3334 #[wasm_bindgen(method, js_name = getInt32)]
3335 pub fn get_int32(this: &DataView, byte_offset: usize) -> i32;
3336
3337 /// The `getInt32()` method gets a signed 32-bit integer (long) at the specified
3338 /// byte offset from the start of the DataView.
3339 ///
3340 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt32)
3341 #[wasm_bindgen(method, js_name = getInt32)]
3342 pub fn get_int32_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> i32;
3343
3344 /// The `getUint32()` method gets an unsigned 32-bit integer (unsigned long) at the specified
3345 /// byte offset from the start of the view.
3346 ///
3347 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint32)
3348 #[wasm_bindgen(method, js_name = getUint32)]
3349 pub fn get_uint32(this: &DataView, byte_offset: usize) -> u32;
3350
3351 /// The `getUint32()` method gets an unsigned 32-bit integer (unsigned long) at the specified
3352 /// byte offset from the start of the view.
3353 ///
3354 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint32)
3355 #[wasm_bindgen(method, js_name = getUint32)]
3356 pub fn get_uint32_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> u32;
3357
3358 /// The `getFloat32()` method gets a signed 32-bit float (float) at the specified
3359 /// byte offset from the start of the DataView.
3360 ///
3361 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat32)
3362 #[wasm_bindgen(method, js_name = getFloat32)]
3363 pub fn get_float32(this: &DataView, byte_offset: usize) -> f32;
3364
3365 /// The `getFloat32()` method gets a signed 32-bit float (float) at the specified
3366 /// byte offset from the start of the DataView.
3367 ///
3368 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat32)
3369 #[wasm_bindgen(method, js_name = getFloat32)]
3370 pub fn get_float32_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> f32;
3371
3372 /// The `getFloat16()` method gets a signed 16-bit float at the specified
3373 /// byte offset from the start of the DataView as an `f32`.
3374 ///
3375 /// The unsuffixed `get_float16` name is reserved for a future native
3376 /// `f16` binding once Rust stabilizes the type.
3377 ///
3378 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat16)
3379 #[wasm_bindgen(method, js_name = getFloat16)]
3380 pub fn get_float16_as_f32(this: &DataView, byte_offset: usize) -> f32;
3381
3382 /// The `getFloat16()` method gets a signed 16-bit float at the specified
3383 /// byte offset from the start of the DataView as an `f32`.
3384 ///
3385 /// The unsuffixed `get_float16_endian` name is reserved for a future
3386 /// native `f16` binding once Rust stabilizes the type.
3387 ///
3388 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat16)
3389 #[wasm_bindgen(method, js_name = getFloat16)]
3390 pub fn get_float16_endian_as_f32(
3391 this: &DataView,
3392 byte_offset: usize,
3393 little_endian: bool,
3394 ) -> f32;
3395
3396 /// The `getFloat64()` method gets a signed 64-bit float (double) at the specified
3397 /// byte offset from the start of the DataView.
3398 ///
3399 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat64)
3400 #[wasm_bindgen(method, js_name = getFloat64)]
3401 pub fn get_float64(this: &DataView, byte_offset: usize) -> f64;
3402
3403 /// The `getFloat64()` method gets a signed 64-bit float (double) at the specified
3404 /// byte offset from the start of the DataView.
3405 ///
3406 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat64)
3407 #[wasm_bindgen(method, js_name = getFloat64)]
3408 pub fn get_float64_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> f64;
3409
3410 /// The `setInt8()` method stores a signed 8-bit integer (byte) value at the
3411 /// specified byte offset from the start of the DataView.
3412 ///
3413 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt8)
3414 #[wasm_bindgen(method, js_name = setInt8)]
3415 pub fn set_int8(this: &DataView, byte_offset: usize, value: i8);
3416
3417 /// The `setUint8()` method stores an unsigned 8-bit integer (byte) value at the
3418 /// specified byte offset from the start of the DataView.
3419 ///
3420 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint8)
3421 #[wasm_bindgen(method, js_name = setUint8)]
3422 pub fn set_uint8(this: &DataView, byte_offset: usize, value: u8);
3423
3424 /// The `setInt16()` method stores a signed 16-bit integer (short) value at the
3425 /// specified byte offset from the start of the DataView.
3426 ///
3427 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt16)
3428 #[wasm_bindgen(method, js_name = setInt16)]
3429 pub fn set_int16(this: &DataView, byte_offset: usize, value: i16);
3430
3431 /// The `setInt16()` method stores a signed 16-bit integer (short) value at the
3432 /// specified byte offset from the start of the DataView.
3433 ///
3434 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt16)
3435 #[wasm_bindgen(method, js_name = setInt16)]
3436 pub fn set_int16_endian(this: &DataView, byte_offset: usize, value: i16, little_endian: bool);
3437
3438 /// The `setUint16()` method stores an unsigned 16-bit integer (unsigned short) value at the
3439 /// specified byte offset from the start of the DataView.
3440 ///
3441 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint16)
3442 #[wasm_bindgen(method, js_name = setUint16)]
3443 pub fn set_uint16(this: &DataView, byte_offset: usize, value: u16);
3444
3445 /// The `setUint16()` method stores an unsigned 16-bit integer (unsigned short) value at the
3446 /// specified byte offset from the start of the DataView.
3447 ///
3448 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint16)
3449 #[wasm_bindgen(method, js_name = setUint16)]
3450 pub fn set_uint16_endian(this: &DataView, byte_offset: usize, value: u16, little_endian: bool);
3451
3452 /// The `setInt32()` method stores a signed 32-bit integer (long) value at the
3453 /// specified byte offset from the start of the DataView.
3454 ///
3455 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt32)
3456 #[wasm_bindgen(method, js_name = setInt32)]
3457 pub fn set_int32(this: &DataView, byte_offset: usize, value: i32);
3458
3459 /// The `setInt32()` method stores a signed 32-bit integer (long) value at the
3460 /// specified byte offset from the start of the DataView.
3461 ///
3462 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt32)
3463 #[wasm_bindgen(method, js_name = setInt32)]
3464 pub fn set_int32_endian(this: &DataView, byte_offset: usize, value: i32, little_endian: bool);
3465
3466 /// The `setUint32()` method stores an unsigned 32-bit integer (unsigned long) value at the
3467 /// specified byte offset from the start of the DataView.
3468 ///
3469 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint32)
3470 #[wasm_bindgen(method, js_name = setUint32)]
3471 pub fn set_uint32(this: &DataView, byte_offset: usize, value: u32);
3472
3473 /// The `setUint32()` method stores an unsigned 32-bit integer (unsigned long) value at the
3474 /// specified byte offset from the start of the DataView.
3475 ///
3476 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint32)
3477 #[wasm_bindgen(method, js_name = setUint32)]
3478 pub fn set_uint32_endian(this: &DataView, byte_offset: usize, value: u32, little_endian: bool);
3479
3480 /// The `setFloat32()` method stores a signed 32-bit float (float) value at the
3481 /// specified byte offset from the start of the DataView.
3482 ///
3483 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat32)
3484 #[wasm_bindgen(method, js_name = setFloat32)]
3485 pub fn set_float32(this: &DataView, byte_offset: usize, value: f32);
3486
3487 /// The `setFloat32()` method stores a signed 32-bit float (float) value at the
3488 /// specified byte offset from the start of the DataView.
3489 ///
3490 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat32)
3491 #[wasm_bindgen(method, js_name = setFloat32)]
3492 pub fn set_float32_endian(this: &DataView, byte_offset: usize, value: f32, little_endian: bool);
3493
3494 /// The `setFloat16()` method stores a signed 16-bit float value from an
3495 /// `f32` at the specified byte offset from the start of the DataView.
3496 ///
3497 /// The unsuffixed `set_float16` name is reserved for a future native
3498 /// `f16` binding once Rust stabilizes the type.
3499 ///
3500 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat16)
3501 #[wasm_bindgen(method, js_name = setFloat16)]
3502 pub fn set_float16_from_f32(this: &DataView, byte_offset: usize, value: f32);
3503
3504 /// The `setFloat16()` method stores a signed 16-bit float value from an
3505 /// `f32` at the specified byte offset from the start of the DataView.
3506 ///
3507 /// The unsuffixed `set_float16_endian` name is reserved for a future
3508 /// native `f16` binding once Rust stabilizes the type.
3509 ///
3510 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat16)
3511 #[wasm_bindgen(method, js_name = setFloat16)]
3512 pub fn set_float16_endian_from_f32(
3513 this: &DataView,
3514 byte_offset: usize,
3515 value: f32,
3516 little_endian: bool,
3517 );
3518
3519 /// The `setFloat64()` method stores a signed 64-bit float (double) value at the
3520 /// specified 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/setFloat64)
3523 #[wasm_bindgen(method, js_name = setFloat64)]
3524 pub fn set_float64(this: &DataView, byte_offset: usize, value: f64);
3525
3526 /// The `setFloat64()` method stores a signed 64-bit float (double) 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/setFloat64)
3530 #[wasm_bindgen(method, js_name = setFloat64)]
3531 pub fn set_float64_endian(this: &DataView, byte_offset: usize, value: f64, little_endian: bool);
3532}
3533
3534// Error
3535#[wasm_bindgen]
3536extern "C" {
3537 #[wasm_bindgen(extends = Object, typescript_type = "Error")]
3538 #[derive(Clone, Debug, PartialEq, Eq)]
3539 pub type Error;
3540
3541 /// The Error constructor creates an error object.
3542 /// Instances of Error objects are thrown when runtime errors occur.
3543 /// The Error object can also be used as a base object for user-defined exceptions.
3544 /// See below for standard built-in error types.
3545 ///
3546 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)
3547 #[wasm_bindgen(constructor)]
3548 pub fn new(message: &str) -> Error;
3549 #[wasm_bindgen(constructor)]
3550 pub fn new_with_options(message: &str, options: &Object) -> Error;
3551
3552 /// The cause property is the underlying cause of the error.
3553 /// Usually this is used to add context to re-thrown errors.
3554 ///
3555 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error#differentiate_between_similar_errors)
3556 #[wasm_bindgen(method, getter)]
3557 pub fn cause(this: &Error) -> JsValue;
3558 #[wasm_bindgen(method, setter)]
3559 pub fn set_cause(this: &Error, cause: &JsValue);
3560
3561 /// The message property is a human-readable description of the error.
3562 ///
3563 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/message)
3564 #[wasm_bindgen(method, getter)]
3565 pub fn message(this: &Error) -> JsString;
3566 #[wasm_bindgen(method, setter)]
3567 pub fn set_message(this: &Error, message: &str);
3568
3569 /// The name property represents a name for the type of error. The initial value is "Error".
3570 ///
3571 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/name)
3572 #[wasm_bindgen(method, getter)]
3573 pub fn name(this: &Error) -> JsString;
3574 #[wasm_bindgen(method, setter)]
3575 pub fn set_name(this: &Error, name: &str);
3576
3577 /// The `toString()` method returns a string representing the specified Error object
3578 ///
3579 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/toString)
3580 #[cfg(not(js_sys_unstable_apis))]
3581 #[wasm_bindgen(method, js_name = toString)]
3582 pub fn to_string(this: &Error) -> JsString;
3583}
3584
3585partialord_ord!(JsString);
3586
3587// EvalError
3588#[wasm_bindgen]
3589extern "C" {
3590 #[wasm_bindgen(extends = Object, extends = Error, typescript_type = "EvalError")]
3591 #[derive(Clone, Debug, PartialEq, Eq)]
3592 pub type EvalError;
3593
3594 /// The `EvalError` object indicates an error regarding the global eval() function. This
3595 /// exception is not thrown by JavaScript anymore, however the EvalError object remains for
3596 /// compatibility.
3597 ///
3598 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/EvalError)
3599 #[wasm_bindgen(constructor)]
3600 pub fn new(message: &str) -> EvalError;
3601}
3602
3603#[wasm_bindgen]
3604extern "C" {
3605 #[wasm_bindgen(extends = Object, is_type_of = JsValue::is_function, no_upcast, typescript_type = "Function")]
3606 #[derive(Clone, Debug, PartialEq, Eq)]
3607 /// `Function` represents any generic Function in JS, by treating all arguments as `JsValue`.
3608 ///
3609 /// It takes a generic parameter of phantom type `fn (Arg1, ..., Argn) -> Ret` which
3610 /// is used to type the JS function. For example, `Function<fn () -> Number>` represents
3611 /// a function taking no arguments that returns a number.
3612 ///
3613 /// The 8 generic argument parameters (`Arg1` through `Arg8`) are the argument
3614 /// types. Arguments not provided enable strict arity checking at compile time.
3615 ///
3616 /// A void function is represented by `fn (Arg) -> Undefined`, and **not** the `()` unit
3617 /// type. This is because generics must be based on JS values in the JS generic type system.
3618 ///
3619 /// _The default without any parameters is as a void function - no arguments, `Undefined` return._
3620 ///
3621 /// _The default generic for `Function` is `fn (JsValue, JsValue, ...) -> JsValue`,
3622 /// representing any function, since all functions safely upcast into this function._
3623 ///
3624 /// ### Arity Enforcement
3625 ///
3626 /// It is not possible to use `call4` or `bind4` on a function that does not have
3627 /// at least 4 arguments — the compiler will reject this because only arguments that
3628 /// are not `None` support the trait bound for `ErasableGeneric`.
3629 ///
3630 /// ### Examples
3631 ///
3632 /// ```ignore
3633 /// // A function taking no args, returning Number
3634 /// let f: Function<Number> = get_some_fn();
3635 ///
3636 /// // A function taking (String, Number) and returning Boolean
3637 /// let f: Function<Boolean, String, Number> = get_some_fn();
3638 ///
3639 /// ### Upcasting
3640 ///
3641 /// To pass a typed `Function` where a different generic Function is expected, `upcast()` may be used
3642 /// to convert into any generic `Function` at zero cost with type-safety.
3643 ///
3644 /// MDN documentation (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
3645 pub type Function<
3646 T: JsFunction = fn(
3647 JsValue,
3648 JsValue,
3649 JsValue,
3650 JsValue,
3651 JsValue,
3652 JsValue,
3653 JsValue,
3654 JsValue,
3655 ) -> JsValue,
3656 >;
3657}
3658
3659#[wasm_bindgen]
3660extern "C" {
3661 /// The `Function` constructor creates a new `Function` object. Calling the
3662 /// constructor directly can create functions dynamically, but suffers from
3663 /// security and similar (but far less significant) performance issues
3664 /// similar to `eval`. However, unlike `eval`, the `Function` constructor
3665 /// allows executing code in the global scope, prompting better programming
3666 /// habits and allowing for more efficient code minification.
3667 ///
3668 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
3669 #[cfg(all(feature = "unsafe-eval", not(js_sys_unstable_apis)))]
3670 #[wasm_bindgen(constructor)]
3671 pub fn new_with_args(args: &str, body: &str) -> Function;
3672
3673 /// The `Function` constructor creates a new `Function` object. Calling the
3674 /// constructor directly can create functions dynamically, but suffers from
3675 /// security and similar (but far less significant) performance issues
3676 /// similar to `eval`. However, unlike `eval`, the `Function` constructor
3677 /// allows executing code in the global scope, prompting better programming
3678 /// habits and allowing for more efficient code minification.
3679 ///
3680 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
3681 #[cfg(all(feature = "unsafe-eval", js_sys_unstable_apis))]
3682 #[wasm_bindgen(constructor)]
3683 pub fn new_with_args<T: JsFunction = fn() -> JsValue>(args: &str, body: &str) -> Function<T>;
3684
3685 // Next major: deprecate
3686 /// The `Function` constructor creates a new `Function` object. Calling the
3687 /// constructor directly can create functions dynamically, but suffers from
3688 /// security and similar (but far less significant) performance issues
3689 /// similar to `eval`. However, unlike `eval`, the `Function` constructor
3690 /// allows executing code in the global scope, prompting better programming
3691 /// habits and allowing for more efficient code minification.
3692 ///
3693 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
3694 #[cfg(feature = "unsafe-eval")]
3695 #[wasm_bindgen(constructor)]
3696 pub fn new_with_args_typed<T: JsFunction = fn() -> JsValue>(
3697 args: &str,
3698 body: &str,
3699 ) -> Function<T>;
3700
3701 /// The `Function` constructor creates a new `Function` object. Calling the
3702 /// constructor directly can create functions dynamically, but suffers from
3703 /// security and similar (but far less significant) performance issues
3704 /// similar to `eval`. However, unlike `eval`, the `Function` constructor
3705 /// allows executing code in the global scope, prompting better programming
3706 /// habits and allowing for more efficient code minification.
3707 ///
3708 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
3709 #[cfg(all(feature = "unsafe-eval", not(js_sys_unstable_apis)))]
3710 #[wasm_bindgen(constructor)]
3711 pub fn new_no_args(body: &str) -> Function;
3712
3713 /// The `Function` constructor creates a new `Function` object. Calling the
3714 /// constructor directly can create functions dynamically, but suffers from
3715 /// security and similar (but far less significant) performance issues
3716 /// similar to `eval`. However, unlike `eval`, the `Function` constructor
3717 /// allows executing code in the global scope, prompting better programming
3718 /// habits and allowing for more efficient code minification.
3719 ///
3720 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
3721 #[cfg(all(feature = "unsafe-eval", js_sys_unstable_apis))]
3722 #[wasm_bindgen(constructor)]
3723 pub fn new_no_args<T: JsFunction = fn() -> JsValue>(body: &str) -> Function<T>;
3724
3725 // Next major: deprecate
3726 /// The `Function` constructor creates a new `Function` object.
3727 ///
3728 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
3729 #[cfg(feature = "unsafe-eval")]
3730 #[wasm_bindgen(constructor)]
3731 pub fn new_no_args_typed<T: JsFunction = fn() -> JsValue>(body: &str) -> Function<T>;
3732
3733 /// The `apply()` method calls a function with a given this value, and arguments provided as an array
3734 /// (or an array-like object).
3735 ///
3736 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply)
3737 #[wasm_bindgen(method, catch)]
3738 pub fn apply<T: JsFunction = fn() -> JsValue>(
3739 this: &Function<T>,
3740 context: &JsValue,
3741 args: &Array,
3742 ) -> Result<<T as JsFunction>::Ret, JsValue>;
3743
3744 // Next major: Deprecate, and separately provide provide impl
3745 /// The `call()` method calls a function with a given this value and
3746 /// arguments provided individually.
3747 ///
3748 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3749 ///
3750 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3751 #[wasm_bindgen(method, catch, js_name = call)]
3752 pub fn call0<Ret: JsGeneric, F: JsFunction<Ret = Ret> = fn() -> JsValue>(
3753 this: &Function<F>,
3754 context: &JsValue,
3755 ) -> Result<Ret, JsValue>;
3756
3757 // Next major: Deprecate, and separately provide provide impl
3758 /// The `call()` method calls a function with a given this value and
3759 /// arguments provided individually.
3760 ///
3761 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3762 ///
3763 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3764 #[wasm_bindgen(method, catch, js_name = call)]
3765 pub fn call1<
3766 Ret: JsGeneric,
3767 Arg1: JsGeneric,
3768 F: JsFunction<Ret = Ret> + JsFunction1<Arg1 = Arg1> = fn(JsValue) -> JsValue,
3769 >(
3770 this: &Function<F>,
3771 context: &JsValue,
3772 arg1: &Arg1,
3773 ) -> Result<Ret, JsValue>;
3774
3775 // Next major: Deprecate, and separately provide provide impl
3776 /// The `call()` method calls a function with a given this value and
3777 /// arguments provided individually.
3778 ///
3779 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3780 ///
3781 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3782 #[wasm_bindgen(method, catch, js_name = call)]
3783 pub fn call2<
3784 Ret: JsGeneric,
3785 Arg1: JsGeneric,
3786 Arg2: JsGeneric,
3787 F: JsFunction<Ret = Ret> + JsFunction1<Arg1 = Arg1> + JsFunction2<Arg2 = Arg2> = fn(
3788 JsValue,
3789 JsValue,
3790 ) -> JsValue,
3791 >(
3792 this: &Function<F>,
3793 context: &JsValue,
3794 arg1: &Arg1,
3795 arg2: &Arg2,
3796 ) -> Result<Ret, JsValue>;
3797
3798 // Next major: Deprecate, and separately provide provide impl
3799 /// The `call()` method calls a function with a given this value and
3800 /// arguments provided individually.
3801 ///
3802 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3803 ///
3804 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3805 #[wasm_bindgen(method, catch, js_name = call)]
3806 pub fn call3<
3807 Ret: JsGeneric,
3808 Arg1: JsGeneric,
3809 Arg2: JsGeneric,
3810 Arg3: JsGeneric,
3811 F: JsFunction<Ret = Ret> + JsFunction3<Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3> = fn(
3812 JsValue,
3813 JsValue,
3814 JsValue,
3815 ) -> JsValue,
3816 >(
3817 this: &Function<F>,
3818 context: &JsValue,
3819 arg1: &Arg1,
3820 arg2: &Arg2,
3821 arg3: &Arg3,
3822 ) -> Result<Ret, JsValue>;
3823
3824 // Next major: Deprecate, and separately provide provide impl
3825 /// The `call()` method calls a function with a given this value and
3826 /// arguments provided individually.
3827 ///
3828 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3829 ///
3830 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3831 #[wasm_bindgen(method, catch, js_name = call)]
3832 pub fn call4<
3833 Ret: JsGeneric,
3834 Arg1: JsGeneric,
3835 Arg2: JsGeneric,
3836 Arg3: JsGeneric,
3837 Arg4: JsGeneric,
3838 F: JsFunction<Ret = Ret> + JsFunction4<Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3, Arg4 = Arg4> = fn(
3839 JsValue,
3840 JsValue,
3841 JsValue,
3842 JsValue,
3843 ) -> JsValue,
3844 >(
3845 this: &Function<F>,
3846 context: &JsValue,
3847 arg1: &Arg1,
3848 arg2: &Arg2,
3849 arg3: &Arg3,
3850 arg4: &Arg4,
3851 ) -> Result<Ret, JsValue>;
3852
3853 // Next major: Deprecate, and separately provide provide impl
3854 /// The `call()` method calls a function with a given this value and
3855 /// arguments provided individually.
3856 ///
3857 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3858 ///
3859 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3860 #[wasm_bindgen(method, catch, js_name = call)]
3861 pub fn call5<
3862 Ret: JsGeneric,
3863 Arg1: JsGeneric,
3864 Arg2: JsGeneric,
3865 Arg3: JsGeneric,
3866 Arg4: JsGeneric,
3867 Arg5: JsGeneric,
3868 F: JsFunction<Ret = Ret>
3869 + JsFunction5<Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3, Arg4 = Arg4, Arg5 = Arg5> = fn(
3870 JsValue,
3871 JsValue,
3872 JsValue,
3873 JsValue,
3874 JsValue,
3875 ) -> JsValue,
3876 >(
3877 this: &Function<F>,
3878 context: &JsValue,
3879 arg1: &Arg1,
3880 arg2: &Arg2,
3881 arg3: &Arg3,
3882 arg4: &Arg4,
3883 arg5: &Arg5,
3884 ) -> Result<Ret, JsValue>;
3885
3886 // Next major: Deprecate, and separately provide provide impl
3887 /// The `call()` method calls a function with a given this value and
3888 /// arguments provided individually.
3889 ///
3890 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3891 ///
3892 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3893 #[wasm_bindgen(method, catch, js_name = call)]
3894 pub fn call6<
3895 Ret: JsGeneric,
3896 Arg1: JsGeneric,
3897 Arg2: JsGeneric,
3898 Arg3: JsGeneric,
3899 Arg4: JsGeneric,
3900 Arg5: JsGeneric,
3901 Arg6: JsGeneric,
3902 F: JsFunction<Ret = Ret>
3903 + JsFunction6<
3904 Arg1 = Arg1,
3905 Arg2 = Arg2,
3906 Arg3 = Arg3,
3907 Arg4 = Arg4,
3908 Arg5 = Arg5,
3909 Arg6 = Arg6,
3910 > = fn(JsValue, JsValue, JsValue, JsValue, JsValue, JsValue) -> JsValue,
3911 >(
3912 this: &Function<F>,
3913 context: &JsValue,
3914 arg1: &Arg1,
3915 arg2: &Arg2,
3916 arg3: &Arg3,
3917 arg4: &Arg4,
3918 arg5: &Arg5,
3919 arg6: &Arg6,
3920 ) -> Result<Ret, JsValue>;
3921
3922 // Next major: Deprecate, and separately provide provide impl
3923 /// The `call()` method calls a function with a given this value and
3924 /// arguments provided individually.
3925 ///
3926 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3927 ///
3928 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3929 #[wasm_bindgen(method, catch, js_name = call)]
3930 pub fn call7<
3931 Ret: JsGeneric,
3932 Arg1: JsGeneric,
3933 Arg2: JsGeneric,
3934 Arg3: JsGeneric,
3935 Arg4: JsGeneric,
3936 Arg5: JsGeneric,
3937 Arg6: JsGeneric,
3938 Arg7: JsGeneric,
3939 F: JsFunction<Ret = Ret>
3940 + JsFunction7<
3941 Arg1 = Arg1,
3942 Arg2 = Arg2,
3943 Arg3 = Arg3,
3944 Arg4 = Arg4,
3945 Arg5 = Arg5,
3946 Arg6 = Arg6,
3947 Arg7 = Arg7,
3948 > = fn(
3949 JsValue,
3950 JsValue,
3951 JsValue,
3952 JsValue,
3953 JsValue,
3954 JsValue,
3955 JsValue,
3956 ) -> JsValue,
3957 >(
3958 this: &Function<F>,
3959 context: &JsValue,
3960 arg1: &Arg1,
3961 arg2: &Arg2,
3962 arg3: &Arg3,
3963 arg4: &Arg4,
3964 arg5: &Arg5,
3965 arg6: &Arg6,
3966 arg7: &Arg7,
3967 ) -> Result<Ret, JsValue>;
3968
3969 // Next major: Deprecate, and separately provide provide impl
3970 /// The `call()` method calls a function with a given this value and
3971 /// arguments provided individually.
3972 ///
3973 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3974 ///
3975 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3976 #[wasm_bindgen(method, catch, js_name = call)]
3977 pub fn call8<
3978 Ret: JsGeneric,
3979 Arg1: JsGeneric,
3980 Arg2: JsGeneric,
3981 Arg3: JsGeneric,
3982 Arg4: JsGeneric,
3983 Arg5: JsGeneric,
3984 Arg6: JsGeneric,
3985 Arg7: JsGeneric,
3986 Arg8: JsGeneric,
3987 F: JsFunction8<
3988 Ret = Ret,
3989 Arg1 = Arg1,
3990 Arg2 = Arg2,
3991 Arg3 = Arg3,
3992 Arg4 = Arg4,
3993 Arg5 = Arg5,
3994 Arg6 = Arg6,
3995 Arg7 = Arg7,
3996 Arg8 = Arg8,
3997 > = fn(
3998 JsValue,
3999 JsValue,
4000 JsValue,
4001 JsValue,
4002 JsValue,
4003 JsValue,
4004 JsValue,
4005 JsValue,
4006 ) -> JsValue,
4007 >(
4008 this: &Function<F>,
4009 context: &JsValue,
4010 arg1: &Arg1,
4011 arg2: &Arg2,
4012 arg3: &Arg3,
4013 arg4: &Arg4,
4014 arg5: &Arg5,
4015 arg6: &Arg6,
4016 arg7: &Arg7,
4017 arg8: &Arg8,
4018 ) -> Result<Ret, JsValue>;
4019
4020 /// The `call()` method calls a function with a given this value and
4021 /// arguments provided individually.
4022 ///
4023 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
4024 ///
4025 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
4026 #[deprecated]
4027 #[allow(deprecated)]
4028 #[wasm_bindgen(method, catch, js_name = call)]
4029 pub fn call9<
4030 Ret: JsGeneric,
4031 Arg1: JsGeneric,
4032 Arg2: JsGeneric,
4033 Arg3: JsGeneric,
4034 Arg4: JsGeneric,
4035 Arg5: JsGeneric,
4036 Arg6: JsGeneric,
4037 Arg7: JsGeneric,
4038 Arg8: JsGeneric,
4039 F: JsFunction8<
4040 Ret = Ret,
4041 Arg1 = Arg1,
4042 Arg2 = Arg2,
4043 Arg3 = Arg3,
4044 Arg4 = Arg4,
4045 Arg5 = Arg5,
4046 Arg6 = Arg6,
4047 Arg7 = Arg7,
4048 Arg8 = Arg8,
4049 > = fn(
4050 JsValue,
4051 JsValue,
4052 JsValue,
4053 JsValue,
4054 JsValue,
4055 JsValue,
4056 JsValue,
4057 JsValue,
4058 ) -> JsValue,
4059 >(
4060 this: &Function<F>,
4061 context: &JsValue,
4062 arg1: &Arg1,
4063 arg2: &Arg2,
4064 arg3: &Arg3,
4065 arg4: &Arg4,
4066 arg5: &Arg5,
4067 arg6: &Arg6,
4068 arg7: &Arg7,
4069 arg8: &Arg8,
4070 arg9: &JsValue,
4071 ) -> Result<Ret, JsValue>;
4072
4073 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4074 /// with a given sequence of arguments preceding any provided when the new function is called.
4075 ///
4076 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4077 #[cfg(not(js_sys_unstable_apis))]
4078 #[deprecated(note = "Use `Function::bind0` instead.")]
4079 #[allow(deprecated)]
4080 #[wasm_bindgen(method, js_name = bind)]
4081 pub fn bind<T: JsFunction = fn() -> JsValue>(
4082 this: &Function<T>,
4083 context: &JsValue,
4084 ) -> Function<T>;
4085
4086 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4087 /// with a given sequence of arguments preceding any provided when the new function is called.
4088 ///
4089 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4090 ///
4091 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4092 #[wasm_bindgen(method, js_name = bind)]
4093 pub fn bind0<T: JsFunction = fn() -> JsValue>(
4094 this: &Function<T>,
4095 context: &JsValue,
4096 ) -> Function<T>;
4097
4098 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4099 /// with a given sequence of arguments preceding any provided when the new function is called.
4100 ///
4101 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4102 ///
4103 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4104 #[wasm_bindgen(method, js_name = bind)]
4105 pub fn bind1<
4106 Ret: JsGeneric,
4107 Arg1: JsGeneric,
4108 F: JsFunction1<Ret = Ret, Arg1 = Arg1> = fn(JsValue) -> JsValue,
4109 >(
4110 this: &Function<F>,
4111 context: &JsValue,
4112 arg1: &Arg1,
4113 ) -> Function<<F as JsFunction1>::Bind1>;
4114
4115 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4116 /// with a given sequence of arguments preceding any provided when the new function is called.
4117 ///
4118 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4119 ///
4120 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4121 #[wasm_bindgen(method, js_name = bind)]
4122 pub fn bind2<
4123 Ret: JsGeneric,
4124 Arg1: JsGeneric,
4125 Arg2: JsGeneric,
4126 F: JsFunction2<Ret = Ret, Arg1 = Arg1, Arg2 = Arg2> = fn(JsValue, JsValue) -> JsValue,
4127 >(
4128 this: &Function<F>,
4129 context: &JsValue,
4130 arg1: &Arg1,
4131 arg2: &Arg2,
4132 ) -> Function<<F as JsFunction2>::Bind2>;
4133
4134 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4135 /// with a given sequence of arguments preceding any provided when the new function is called.
4136 ///
4137 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4138 ///
4139 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4140 #[wasm_bindgen(method, js_name = bind)]
4141 pub fn bind3<
4142 Ret: JsGeneric,
4143 Arg1: JsGeneric,
4144 Arg2: JsGeneric,
4145 Arg3: JsGeneric,
4146 F: JsFunction3<Ret = Ret, Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3> = fn(
4147 JsValue,
4148 JsValue,
4149 JsValue,
4150 ) -> JsValue,
4151 >(
4152 this: &Function<F>,
4153 context: &JsValue,
4154 arg1: &Arg1,
4155 arg2: &Arg2,
4156 arg3: &Arg3,
4157 ) -> Function<<F as JsFunction3>::Bind3>;
4158
4159 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4160 /// with a given sequence of arguments preceding any provided when the new function is called.
4161 ///
4162 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4163 ///
4164 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4165 #[wasm_bindgen(method, js_name = bind)]
4166 pub fn bind4<
4167 Ret: JsGeneric,
4168 Arg1: JsGeneric,
4169 Arg2: JsGeneric,
4170 Arg3: JsGeneric,
4171 Arg4: JsGeneric,
4172 F: JsFunction4<Ret = Ret, Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3, Arg4 = Arg4> = fn(
4173 JsValue,
4174 JsValue,
4175 JsValue,
4176 JsValue,
4177 ) -> JsValue,
4178 >(
4179 this: &Function<F>,
4180 context: &JsValue,
4181 arg1: &Arg1,
4182 arg2: &Arg2,
4183 arg3: &Arg3,
4184 arg4: &Arg4,
4185 ) -> Function<<F as JsFunction4>::Bind4>;
4186
4187 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4188 /// with a given sequence of arguments preceding any provided when the new function is called.
4189 ///
4190 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4191 ///
4192 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4193 #[wasm_bindgen(method, js_name = bind)]
4194 pub fn bind5<
4195 Ret: JsGeneric,
4196 Arg1: JsGeneric,
4197 Arg2: JsGeneric,
4198 Arg3: JsGeneric,
4199 Arg4: JsGeneric,
4200 Arg5: JsGeneric,
4201 F: JsFunction5<Ret = Ret, Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3, Arg4 = Arg4, Arg5 = Arg5> = fn(
4202 JsValue,
4203 JsValue,
4204 JsValue,
4205 JsValue,
4206 JsValue,
4207 ) -> JsValue,
4208 >(
4209 this: &Function<F>,
4210 context: &JsValue,
4211 arg1: &Arg1,
4212 arg2: &Arg2,
4213 arg3: &Arg3,
4214 arg4: &Arg4,
4215 arg5: &Arg5,
4216 ) -> Function<<F as JsFunction5>::Bind5>;
4217
4218 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4219 /// with a given sequence of arguments preceding any provided when the new function is called.
4220 ///
4221 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4222 ///
4223 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4224 #[wasm_bindgen(method, js_name = bind)]
4225 pub fn bind6<
4226 Ret: JsGeneric,
4227 Arg1: JsGeneric,
4228 Arg2: JsGeneric,
4229 Arg3: JsGeneric,
4230 Arg4: JsGeneric,
4231 Arg5: JsGeneric,
4232 Arg6: JsGeneric,
4233 F: JsFunction6<
4234 Ret = Ret,
4235 Arg1 = Arg1,
4236 Arg2 = Arg2,
4237 Arg3 = Arg3,
4238 Arg4 = Arg4,
4239 Arg5 = Arg5,
4240 Arg6 = Arg6,
4241 > = fn(JsValue, JsValue, JsValue, JsValue, JsValue, JsValue) -> JsValue,
4242 >(
4243 this: &Function<F>,
4244 context: &JsValue,
4245 arg1: &Arg1,
4246 arg2: &Arg2,
4247 arg3: &Arg3,
4248 arg4: &Arg4,
4249 arg5: &Arg5,
4250 arg6: &Arg6,
4251 ) -> Function<<F as JsFunction6>::Bind6>;
4252
4253 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4254 /// with a given sequence of arguments preceding any provided when the new function is called.
4255 ///
4256 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4257 ///
4258 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4259 #[wasm_bindgen(method, js_name = bind)]
4260 pub fn bind7<
4261 Ret: JsGeneric,
4262 Arg1: JsGeneric,
4263 Arg2: JsGeneric,
4264 Arg3: JsGeneric,
4265 Arg4: JsGeneric,
4266 Arg5: JsGeneric,
4267 Arg6: JsGeneric,
4268 Arg7: JsGeneric,
4269 F: JsFunction7<
4270 Ret = Ret,
4271 Arg1 = Arg1,
4272 Arg2 = Arg2,
4273 Arg3 = Arg3,
4274 Arg4 = Arg4,
4275 Arg5 = Arg5,
4276 Arg6 = Arg6,
4277 Arg7 = Arg7,
4278 > = fn(
4279 JsValue,
4280 JsValue,
4281 JsValue,
4282 JsValue,
4283 JsValue,
4284 JsValue,
4285 JsValue,
4286 ) -> JsValue,
4287 >(
4288 this: &Function<F>,
4289 context: &JsValue,
4290 arg1: &Arg1,
4291 arg2: &Arg2,
4292 arg3: &Arg3,
4293 arg4: &Arg4,
4294 arg5: &Arg5,
4295 arg6: &Arg6,
4296 arg7: &Arg7,
4297 ) -> Function<<F as JsFunction7>::Bind7>;
4298
4299 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4300 /// with a given sequence of arguments preceding any provided when the new function is called.
4301 ///
4302 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4303 ///
4304 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4305 #[wasm_bindgen(method, js_name = bind)]
4306 pub fn bind8<
4307 Ret: JsGeneric,
4308 Arg1: JsGeneric,
4309 Arg2: JsGeneric,
4310 Arg3: JsGeneric,
4311 Arg4: JsGeneric,
4312 Arg5: JsGeneric,
4313 Arg6: JsGeneric,
4314 Arg7: JsGeneric,
4315 Arg8: JsGeneric,
4316 F: JsFunction8<
4317 Ret = Ret,
4318 Arg1 = Arg1,
4319 Arg2 = Arg2,
4320 Arg3 = Arg3,
4321 Arg4 = Arg4,
4322 Arg5 = Arg5,
4323 Arg6 = Arg6,
4324 Arg7 = Arg7,
4325 Arg8 = Arg8,
4326 > = fn(
4327 JsValue,
4328 JsValue,
4329 JsValue,
4330 JsValue,
4331 JsValue,
4332 JsValue,
4333 JsValue,
4334 JsValue,
4335 ) -> JsValue,
4336 >(
4337 this: &Function<F>,
4338 context: &JsValue,
4339 arg1: &Arg1,
4340 arg2: &Arg2,
4341 arg3: &Arg3,
4342 arg4: &Arg4,
4343 arg5: &Arg5,
4344 arg6: &Arg6,
4345 arg7: &Arg7,
4346 arg8: &Arg8,
4347 ) -> Function<<F as JsFunction8>::Bind8>;
4348
4349 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4350 /// with a given sequence of arguments preceding any provided when the new function is called.
4351 ///
4352 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4353 ///
4354 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4355 #[deprecated]
4356 #[allow(deprecated)]
4357 #[wasm_bindgen(method, js_name = bind)]
4358 pub fn bind9<
4359 Ret: JsGeneric,
4360 Arg1: JsGeneric,
4361 Arg2: JsGeneric,
4362 Arg3: JsGeneric,
4363 Arg4: JsGeneric,
4364 Arg5: JsGeneric,
4365 Arg6: JsGeneric,
4366 Arg7: JsGeneric,
4367 Arg8: JsGeneric,
4368 F: JsFunction8<
4369 Ret = Ret,
4370 Arg1 = Arg1,
4371 Arg2 = Arg2,
4372 Arg3 = Arg3,
4373 Arg4 = Arg4,
4374 Arg5 = Arg5,
4375 Arg6 = Arg6,
4376 Arg7 = Arg7,
4377 Arg8 = Arg8,
4378 > = fn(
4379 JsValue,
4380 JsValue,
4381 JsValue,
4382 JsValue,
4383 JsValue,
4384 JsValue,
4385 JsValue,
4386 JsValue,
4387 ) -> JsValue,
4388 >(
4389 this: &Function<F>,
4390 context: &JsValue,
4391 arg1: &Arg1,
4392 arg2: &Arg2,
4393 arg3: &Arg3,
4394 arg4: &Arg4,
4395 arg5: &Arg5,
4396 arg6: &Arg6,
4397 arg7: &Arg7,
4398 arg8: &Arg8,
4399 arg9: &JsValue,
4400 ) -> Function<fn() -> Ret>;
4401
4402 /// The length property indicates the number of arguments expected by the function.
4403 ///
4404 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/length)
4405 #[wasm_bindgen(method, getter)]
4406 pub fn length<T: JsFunction = fn() -> JsValue>(this: &Function<T>) -> u32;
4407
4408 /// A Function object's read-only name property indicates the function's
4409 /// name as specified when it was created or "anonymous" for functions
4410 /// created anonymously.
4411 ///
4412 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name)
4413 #[wasm_bindgen(method, getter)]
4414 pub fn name<T: JsFunction = fn() -> JsValue>(this: &Function<T>) -> JsString;
4415
4416 /// The `toString()` method returns a string representing the source code of the function.
4417 ///
4418 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/toString)
4419 #[cfg(not(js_sys_unstable_apis))]
4420 #[wasm_bindgen(method, js_name = toString)]
4421 pub fn to_string<T: JsFunction = fn() -> JsValue>(this: &Function<T>) -> JsString;
4422}
4423
4424// Basic UpcastFrom impls for Function<T>
4425impl<T: JsFunction> UpcastFrom<Function<T>> for JsValue {}
4426impl<T: JsFunction> UpcastFrom<Function<T>> for JsOption<JsValue> {}
4427impl<T: JsFunction> UpcastFrom<Function<T>> for Object {}
4428impl<T: JsFunction> UpcastFrom<Function<T>> for JsOption<Object> {}
4429
4430// Blanket trait for Function upcast
4431// Function<T> upcasts to Function<U> when the underlying fn type T upcasts to U.
4432// The fn signature UpcastFrom impls already encode correct variance (covariant return, contravariant args).
4433impl<T: JsFunction, U: JsFunction> UpcastFrom<Function<T>> for Function<U> where U: UpcastFrom<T> {}
4434
4435// len() method for Function<T> using JsFunction::ARITY
4436impl<T: JsFunction> Function<T> {
4437 /// Get the static arity of this function type.
4438 #[allow(clippy::len_without_is_empty)]
4439 pub fn len(&self) -> usize {
4440 T::ARITY
4441 }
4442
4443 /// Returns true if this is a zero-argument function.
4444 pub fn is_empty(&self) -> bool {
4445 T::ARITY == 0
4446 }
4447}
4448
4449// Base traits for function signature types.
4450pub trait JsFunction {
4451 type Ret: JsGeneric;
4452 const ARITY: usize;
4453}
4454
4455pub trait JsFunction1: JsFunction {
4456 type Arg1: JsGeneric;
4457 type Bind1: JsFunction;
4458}
4459pub trait JsFunction2: JsFunction1 {
4460 type Arg2: JsGeneric;
4461 type Bind2: JsFunction;
4462}
4463pub trait JsFunction3: JsFunction2 {
4464 type Arg3: JsGeneric;
4465 type Bind3: JsFunction;
4466}
4467pub trait JsFunction4: JsFunction3 {
4468 type Arg4: JsGeneric;
4469 type Bind4: JsFunction;
4470}
4471pub trait JsFunction5: JsFunction4 {
4472 type Arg5: JsGeneric;
4473 type Bind5: JsFunction;
4474}
4475pub trait JsFunction6: JsFunction5 {
4476 type Arg6: JsGeneric;
4477 type Bind6: JsFunction;
4478}
4479pub trait JsFunction7: JsFunction6 {
4480 type Arg7: JsGeneric;
4481 type Bind7: JsFunction;
4482}
4483pub trait JsFunction8: JsFunction7 {
4484 type Arg8: JsGeneric;
4485 type Bind8: JsFunction;
4486}
4487
4488// Manual impl for fn() -> R
4489impl<Ret: JsGeneric> JsFunction for fn() -> Ret {
4490 type Ret = Ret;
4491 const ARITY: usize = 0;
4492}
4493
4494macro_rules! impl_fn {
4495 () => {
4496 impl_fn!(@impl 1 [Arg1] [
4497 JsFunction1 Arg1 Bind1 {fn() -> Ret}
4498 ]);
4499 impl_fn!(@impl 2 [Arg1 Arg2] [
4500 JsFunction1 Arg1 Bind1 {fn(Arg2) -> Ret}
4501 JsFunction2 Arg2 Bind2 {fn() -> Ret}
4502 ]);
4503 impl_fn!(@impl 3 [Arg1 Arg2 Arg3] [
4504 JsFunction1 Arg1 Bind1 {fn(Arg2, Arg3) -> Ret}
4505 JsFunction2 Arg2 Bind2 {fn(Arg3) -> Ret}
4506 JsFunction3 Arg3 Bind3 {fn() -> Ret}
4507 ]);
4508 impl_fn!(@impl 4 [Arg1 Arg2 Arg3 Arg4] [
4509 JsFunction1 Arg1 Bind1 {fn(Arg2, Arg3, Arg4) -> Ret}
4510 JsFunction2 Arg2 Bind2 {fn(Arg3, Arg4) -> Ret}
4511 JsFunction3 Arg3 Bind3 {fn(Arg4) -> Ret}
4512 JsFunction4 Arg4 Bind4 {fn() -> Ret}
4513 ]);
4514 impl_fn!(@impl 5 [Arg1 Arg2 Arg3 Arg4 Arg5] [
4515 JsFunction1 Arg1 Bind1 {fn(Arg2, Arg3, Arg4, Arg5) -> Ret}
4516 JsFunction2 Arg2 Bind2 {fn(Arg3, Arg4, Arg5) -> Ret}
4517 JsFunction3 Arg3 Bind3 {fn(Arg4, Arg5) -> Ret}
4518 JsFunction4 Arg4 Bind4 {fn(Arg5) -> Ret}
4519 JsFunction5 Arg5 Bind5 {fn() -> Ret}
4520 ]);
4521 impl_fn!(@impl 6 [Arg1 Arg2 Arg3 Arg4 Arg5 Arg6] [
4522 JsFunction1 Arg1 Bind1 {fn(Arg2, Arg3, Arg4, Arg5, Arg6) -> Ret}
4523 JsFunction2 Arg2 Bind2 {fn(Arg3, Arg4, Arg5, Arg6) -> Ret}
4524 JsFunction3 Arg3 Bind3 {fn(Arg4, Arg5, Arg6) -> Ret}
4525 JsFunction4 Arg4 Bind4 {fn(Arg5, Arg6) -> Ret}
4526 JsFunction5 Arg5 Bind5 {fn(Arg6) -> Ret}
4527 JsFunction6 Arg6 Bind6 {fn() -> Ret}
4528 ]);
4529 impl_fn!(@impl 7 [Arg1 Arg2 Arg3 Arg4 Arg5 Arg6 Arg7] [
4530 JsFunction1 Arg1 Bind1 {fn(Arg2, Arg3, Arg4, Arg5, Arg6, Arg7) -> Ret}
4531 JsFunction2 Arg2 Bind2 {fn(Arg3, Arg4, Arg5, Arg6, Arg7) -> Ret}
4532 JsFunction3 Arg3 Bind3 {fn(Arg4, Arg5, Arg6, Arg7) -> Ret}
4533 JsFunction4 Arg4 Bind4 {fn(Arg5, Arg6, Arg7) -> Ret}
4534 JsFunction5 Arg5 Bind5 {fn(Arg6, Arg7) -> Ret}
4535 JsFunction6 Arg6 Bind6 {fn(Arg7) -> Ret}
4536 JsFunction7 Arg7 Bind7 {fn() -> Ret}
4537 ]);
4538 impl_fn!(@impl 8 [Arg1 Arg2 Arg3 Arg4 Arg5 Arg6 Arg7 Arg8] [
4539 JsFunction1 Arg1 Bind1 {fn(Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8) -> Ret}
4540 JsFunction2 Arg2 Bind2 {fn(Arg3, Arg4, Arg5, Arg6, Arg7, Arg8) -> Ret}
4541 JsFunction3 Arg3 Bind3 {fn(Arg4, Arg5, Arg6, Arg7, Arg8) -> Ret}
4542 JsFunction4 Arg4 Bind4 {fn(Arg5, Arg6, Arg7, Arg8) -> Ret}
4543 JsFunction5 Arg5 Bind5 {fn(Arg6, Arg7, Arg8) -> Ret}
4544 JsFunction6 Arg6 Bind6 {fn(Arg7, Arg8) -> Ret}
4545 JsFunction7 Arg7 Bind7 {fn(Arg8) -> Ret}
4546 JsFunction8 Arg8 Bind8 {fn() -> Ret}
4547 ]);
4548 };
4549
4550 (@impl $arity:literal [$($A:ident)+] [$($trait:ident $arg:ident $bind:ident {$bind_ty:ty})+]) => {
4551 impl<Ret: JsGeneric $(, $A: JsGeneric)+> JsFunction for fn($($A),+) -> Ret {
4552 type Ret = Ret;
4553 const ARITY: usize = $arity;
4554 }
4555
4556 impl_fn!(@traits [$($A)+] [$($trait $arg $bind {$bind_ty})+]);
4557 };
4558
4559 (@traits [$($A:ident)+] []) => {};
4560
4561 (@traits [$($A:ident)+] [$trait:ident $arg:ident $bind:ident {$bind_ty:ty} $($rest:tt)*]) => {
4562 impl<Ret: JsGeneric $(, $A: JsGeneric)+> $trait for fn($($A),+) -> Ret {
4563 type $arg = $arg;
4564 type $bind = $bind_ty;
4565 }
4566
4567 impl_fn!(@traits [$($A)+] [$($rest)*]);
4568 };
4569}
4570
4571impl_fn!();
4572
4573/// Trait for argument tuples that can call or bind a `Function<T>`.
4574pub trait JsArgs<T: JsFunction> {
4575 type BindOutput;
4576 fn apply_call(self, func: &Function<T>, context: &JsValue) -> Result<T::Ret, JsValue>;
4577 fn apply_bind(self, func: &Function<T>, context: &JsValue) -> Self::BindOutput;
4578}
4579
4580// Manual impl for 0-arg
4581impl<Ret: JsGeneric, F: JsFunction<Ret = Ret>> JsArgs<F> for () {
4582 type BindOutput = Function<F>;
4583
4584 #[inline]
4585 fn apply_call(self, func: &Function<F>, context: &JsValue) -> Result<Ret, JsValue> {
4586 func.call0(context)
4587 }
4588
4589 #[inline]
4590 fn apply_bind(self, func: &Function<F>, context: &JsValue) -> Self::BindOutput {
4591 func.bind0(context)
4592 }
4593}
4594
4595macro_rules! impl_js_args {
4596 ($arity:literal $trait:ident $bind_output:ident [$($A:ident)+] [$($idx:tt)+] $call:ident $bind:ident) => {
4597 impl<Ret: JsGeneric, $($A: JsGeneric,)+ F: $trait<Ret = Ret, $($A = $A,)*>> JsArgs<F> for ($(&$A,)+)
4598 {
4599 type BindOutput = Function<<F as $trait>::$bind_output>;
4600
4601 #[inline]
4602 fn apply_call(self, func: &Function<F>, context: &JsValue) -> Result<Ret, JsValue> {
4603 func.$call(context, $(self.$idx),+)
4604 }
4605
4606 #[inline]
4607 fn apply_bind(self, func: &Function<F>, context: &JsValue) -> Self::BindOutput {
4608 func.$bind(context, $(self.$idx),+)
4609 }
4610 }
4611 };
4612}
4613
4614impl_js_args!(1 JsFunction1 Bind1 [Arg1] [0] call1 bind1);
4615impl_js_args!(2 JsFunction2 Bind2 [Arg1 Arg2] [0 1] call2 bind2);
4616impl_js_args!(3 JsFunction3 Bind3 [Arg1 Arg2 Arg3] [0 1 2] call3 bind3);
4617impl_js_args!(4 JsFunction4 Bind4 [Arg1 Arg2 Arg3 Arg4] [0 1 2 3] call4 bind4);
4618impl_js_args!(5 JsFunction5 Bind5 [Arg1 Arg2 Arg3 Arg4 Arg5] [0 1 2 3 4] call5 bind5);
4619impl_js_args!(6 JsFunction6 Bind6 [Arg1 Arg2 Arg3 Arg4 Arg5 Arg6] [0 1 2 3 4 5] call6 bind6);
4620impl_js_args!(7 JsFunction7 Bind7 [Arg1 Arg2 Arg3 Arg4 Arg5 Arg6 Arg7] [0 1 2 3 4 5 6] call7 bind7);
4621impl_js_args!(8 JsFunction8 Bind8 [Arg1 Arg2 Arg3 Arg4 Arg5 Arg6 Arg7 Arg8] [0 1 2 3 4 5 6 7] call8 bind8);
4622
4623impl<T: JsFunction> Function<T> {
4624 /// The `call()` method calls a function with a given `this` value and
4625 /// arguments provided as a tuple.
4626 ///
4627 /// This method accepts a tuple of references matching the function's
4628 /// argument types.
4629 ///
4630 /// # Example
4631 ///
4632 /// ```ignore
4633 /// // 0-arg function
4634 /// let f: Function<fn() -> Number> = get_fn();
4635 /// let result = f.call(&JsValue::NULL, ())?;
4636 ///
4637 /// // 1-arg function (note trailing comma for 1-tuple)
4638 /// let f: Function<fn(JsString) -> Number> = get_fn();
4639 /// let result = f.call(&JsValue::NULL, (&name,))?;
4640 ///
4641 /// // 2-arg function
4642 /// let f: Function<fn(JsString, Boolean) -> Number> = get_fn();
4643 /// let result = f.call(&JsValue::NULL, (&name, &flag))?;
4644 /// ```
4645 ///
4646 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
4647 #[inline]
4648 pub fn call<Args: JsArgs<T>>(&self, context: &JsValue, args: Args) -> Result<T::Ret, JsValue> {
4649 args.apply_call(self, context)
4650 }
4651
4652 /// The `bind()` method creates a new function that, when called, has its
4653 /// `this` keyword set to the provided value, with a given sequence of
4654 /// arguments preceding any provided when the new function is called.
4655 ///
4656 /// This method accepts a tuple of references to bind.
4657 ///
4658 /// # Example
4659 ///
4660 /// ```ignore
4661 /// let f: Function<fn(JsString, Boolean) -> Number> = get_fn();
4662 ///
4663 /// // Bind no args - same signature
4664 /// let bound: Function<fn(JsString, Boolean) -> Number> = f.bind(&ctx, ());
4665 ///
4666 /// // Bind one arg (use 1-tuple of references)
4667 /// let bound: Function<fn(Boolean) -> Number> = f.bind(&ctx, (&my_string,));
4668 ///
4669 /// // Bind two args - becomes 0-arg function
4670 /// let bound: Function<fn() -> Number> = f.bind(&ctx, (&my_string, &my_bool));
4671 /// ```
4672 ///
4673 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4674 #[inline]
4675 pub fn bindn<Args: JsArgs<T>>(&self, context: &JsValue, args: Args) -> Args::BindOutput {
4676 args.apply_bind(self, context)
4677 }
4678
4679 /// The `bind()` method creates a new function that, when called, has its
4680 /// `this` keyword set to the provided value, with a given sequence of
4681 /// arguments preceding any provided when the new function is called.
4682 ///
4683 /// This method accepts a tuple of references to bind.
4684 ///
4685 /// # Example
4686 ///
4687 /// ```ignore
4688 /// let f: Function<fn(JsString, Boolean) -> Number> = get_fn();
4689 ///
4690 /// // Bind no args - same signature
4691 /// let bound: Function<fn(JsString, Boolean) -> Number> = f.bind(&ctx, ());
4692 ///
4693 /// // Bind one arg (use 1-tuple of references)
4694 /// let bound: Function<fn(Boolean) -> Number> = f.bind(&ctx, (&my_string,));
4695 ///
4696 /// // Bind two args - becomes 0-arg function
4697 /// let bound: Function<fn() -> Number> = f.bind(&ctx, (&my_string, &my_bool));
4698 /// ```
4699 ///
4700 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4701 #[cfg(js_sys_unstable_apis)]
4702 #[inline]
4703 pub fn bind<Args: JsArgs<T>>(&self, context: &JsValue, args: Args) -> Args::BindOutput {
4704 args.apply_bind(self, context)
4705 }
4706}
4707
4708pub trait FunctionIntoClosure: JsFunction {
4709 type ClosureTypeMut: WasmClosure + ?Sized;
4710}
4711
4712macro_rules! impl_function_into_closure {
4713 ( $(($($var:ident)*))* ) => {$(
4714 impl<$($var: FromWasmAbi + JsGeneric,)* R: IntoWasmAbi + JsGeneric> FunctionIntoClosure for fn($($var),*) -> R {
4715 type ClosureTypeMut = dyn FnMut($($var),*) -> R;
4716 }
4717 )*};
4718}
4719
4720impl_function_into_closure! {
4721 ()
4722 (A)
4723 (A B)
4724 (A B C)
4725 (A B C D)
4726 (A B C D E)
4727 (A B C D E F)
4728 (A B C D E F G)
4729 (A B C D E F G H)
4730}
4731
4732impl<F: JsFunction> Function<F> {
4733 /// Convert a borrowed `ScopedClosure` into a typed JavaScript Function reference.
4734 ///
4735 /// The conversion is a direct type-safe conversion and upcast of a
4736 /// closure into its corresponding typed JavaScript Function,
4737 /// based on covariance and contravariance [`Upcast`] trait hierarchy.
4738 ///
4739 /// For transferring ownership to JS, use [`Function::from_closure`].
4740 #[inline]
4741 pub fn closure_ref<'a, C>(closure: &'a ScopedClosure<'_, C>) -> &'a Self
4742 where
4743 F: FunctionIntoClosure,
4744 C: WasmClosure + ?Sized,
4745 <F as FunctionIntoClosure>::ClosureTypeMut: UpcastFrom<<C as WasmClosure>::AsMut>,
4746 {
4747 closure.as_js_value().unchecked_ref()
4748 }
4749
4750 /// Convert a Rust closure into a typed JavaScript Function.
4751 ///
4752 /// This function releases ownership of the closure to JS, and provides
4753 /// an owned function handle for the same closure.
4754 ///
4755 /// The conversion is a direct type-safe conversion and upcast of a
4756 /// closure into its corresponding typed JavaScript Function,
4757 /// based on covariance and contravariance [`Upcast`] trait hierarchy.
4758 ///
4759 /// This method is only supported for static closures which do not have
4760 /// borrowed lifetime data, and thus can be released into JS.
4761 ///
4762 /// For borrowed closures, which cannot cede ownership to JS,
4763 /// instead use [`Function::closure_ref`].
4764 #[inline]
4765 pub fn from_closure<C>(closure: ScopedClosure<'static, C>) -> Self
4766 where
4767 F: FunctionIntoClosure,
4768 C: WasmClosure + ?Sized,
4769 <F as FunctionIntoClosure>::ClosureTypeMut: UpcastFrom<<C as WasmClosure>::AsMut>,
4770 {
4771 closure.into_js_value().unchecked_into()
4772 }
4773}
4774
4775#[cfg(not(js_sys_unstable_apis))]
4776impl Function {
4777 /// Returns the `Function` value of this JS value if it's an instance of a
4778 /// function.
4779 ///
4780 /// If this JS value is not an instance of a function then this returns
4781 /// `None`.
4782 #[deprecated(note = "recommended to use dyn_ref instead which is now equivalent")]
4783 pub fn try_from(val: &JsValue) -> Option<&Function> {
4784 val.dyn_ref()
4785 }
4786}
4787
4788#[cfg(feature = "unsafe-eval")]
4789impl Default for Function {
4790 fn default() -> Self {
4791 Self::new_no_args("")
4792 }
4793}
4794
4795// Generator
4796#[wasm_bindgen]
4797extern "C" {
4798 #[wasm_bindgen(extends = Object, typescript_type = "Generator<any, any, any>")]
4799 #[derive(Clone, Debug, PartialEq, Eq)]
4800 pub type Generator<T = JsValue>;
4801
4802 /// The `next()` method returns an object with two properties done and value.
4803 /// You can also provide a parameter to the next method to send a value to the generator.
4804 ///
4805 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/next)
4806 #[cfg(not(js_sys_unstable_apis))]
4807 #[wasm_bindgen(method, catch)]
4808 pub fn next<T>(this: &Generator<T>, value: &T) -> Result<JsValue, JsValue>;
4809
4810 /// The `next()` method returns an object with two properties done and value.
4811 /// You can also provide a parameter to the next method to send a value to the generator.
4812 ///
4813 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/next)
4814 #[cfg(js_sys_unstable_apis)]
4815 #[wasm_bindgen(method, catch, js_name = next)]
4816 pub fn next<T: FromWasmAbi>(this: &Generator<T>, value: &T)
4817 -> Result<IteratorNext<T>, JsValue>;
4818
4819 // Next major: deprecate
4820 /// The `next()` method returns an object with two properties done and value.
4821 /// You can also provide a parameter to the next method to send a value to the generator.
4822 ///
4823 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/next)
4824 #[wasm_bindgen(method, catch)]
4825 pub fn next_iterator<T: FromWasmAbi>(
4826 this: &Generator<T>,
4827 value: &T,
4828 ) -> Result<IteratorNext<T>, JsValue>;
4829
4830 /// The `return()` method returns the given value and finishes the generator.
4831 ///
4832 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/return)
4833 #[cfg(not(js_sys_unstable_apis))]
4834 #[wasm_bindgen(method, js_name = "return")]
4835 pub fn return_<T>(this: &Generator<T>, value: &T) -> JsValue;
4836
4837 /// The `return()` method returns the given value and finishes the generator.
4838 ///
4839 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/return)
4840 #[cfg(js_sys_unstable_apis)]
4841 #[wasm_bindgen(method, catch, js_name = "return")]
4842 pub fn return_<T: FromWasmAbi>(
4843 this: &Generator<T>,
4844 value: &T,
4845 ) -> Result<IteratorNext<T>, JsValue>;
4846
4847 // Next major: deprecate
4848 /// The `return()` method returns the given value and finishes the generator.
4849 ///
4850 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/return)
4851 #[wasm_bindgen(method, catch, js_name = "return")]
4852 pub fn try_return<T: FromWasmAbi>(
4853 this: &Generator<T>,
4854 value: &T,
4855 ) -> Result<IteratorNext<T>, JsValue>;
4856
4857 /// The `throw()` method resumes the execution of a generator by throwing an error into it
4858 /// and returns an object with two properties done and value.
4859 ///
4860 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/throw)
4861 #[cfg(not(js_sys_unstable_apis))]
4862 #[wasm_bindgen(method, catch)]
4863 pub fn throw<T>(this: &Generator<T>, error: &Error) -> Result<JsValue, JsValue>;
4864
4865 /// The `throw()` method resumes the execution of a generator by throwing an error into it
4866 /// and returns an object with two properties done and value.
4867 ///
4868 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/throw)
4869 #[cfg(js_sys_unstable_apis)]
4870 #[wasm_bindgen(method, catch, js_name = throw)]
4871 pub fn throw<T: FromWasmAbi>(
4872 this: &Generator<T>,
4873 error: &JsValue,
4874 ) -> Result<IteratorNext<T>, JsValue>;
4875
4876 // Next major: deprecate
4877 /// The `throw()` method resumes the execution of a generator by throwing an error into it
4878 /// and returns an object with two properties done and value.
4879 ///
4880 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/throw)
4881 #[wasm_bindgen(method, catch, js_name = throw)]
4882 pub fn throw_value<T: FromWasmAbi>(
4883 this: &Generator<T>,
4884 error: &JsValue,
4885 ) -> Result<IteratorNext<T>, JsValue>;
4886}
4887
4888impl<T: FromWasmAbi> Iterable for Generator<T> {
4889 type Item = T;
4890}
4891
4892// AsyncGenerator
4893#[wasm_bindgen]
4894extern "C" {
4895 #[wasm_bindgen(extends = Object, typescript_type = "AsyncGenerator<any, any, any>")]
4896 #[derive(Clone, Debug, PartialEq, Eq)]
4897 pub type AsyncGenerator<T = JsValue>;
4898
4899 /// The `next()` method returns an object with two properties done and value.
4900 /// You can also provide a parameter to the next method to send a value to the generator.
4901 ///
4902 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncGenerator/next)
4903 #[wasm_bindgen(method, catch)]
4904 pub fn next<T>(
4905 this: &AsyncGenerator<T>,
4906 value: &T,
4907 ) -> Result<Promise<IteratorNext<T>>, JsValue>;
4908
4909 /// The `return()` method returns the given value and finishes the generator.
4910 ///
4911 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncGenerator/return)
4912 #[wasm_bindgen(method, js_name = "return", catch)]
4913 pub fn return_<T>(
4914 this: &AsyncGenerator<T>,
4915 value: &T,
4916 ) -> Result<Promise<IteratorNext<T>>, JsValue>;
4917
4918 /// The `throw()` method resumes the execution of a generator by throwing an error into it
4919 /// and returns an object with two properties done and value.
4920 ///
4921 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncGenerator/throw)
4922 #[wasm_bindgen(method, catch)]
4923 pub fn throw<T>(
4924 this: &AsyncGenerator<T>,
4925 error: &JsValue,
4926 ) -> Result<Promise<IteratorNext<T>>, JsValue>;
4927}
4928
4929impl<T: FromWasmAbi> AsyncIterable for AsyncGenerator<T> {
4930 type Item = T;
4931}
4932
4933// Map
4934#[wasm_bindgen]
4935extern "C" {
4936 #[wasm_bindgen(extends = Object, typescript_type = "Map<any, any>")]
4937 #[derive(Clone, Debug, PartialEq, Eq)]
4938 pub type Map<K = JsValue, V = JsValue>;
4939
4940 /// The Map object holds key-value pairs. Any value (both objects and
4941 /// primitive values) maybe used as either a key or a value.
4942 ///
4943 /// **Note:** Consider using [`Map::new_typed`] for typing support.
4944 ///
4945 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)
4946 #[cfg(not(js_sys_unstable_apis))]
4947 #[wasm_bindgen(constructor)]
4948 pub fn new() -> Map;
4949
4950 /// The Map object holds key-value pairs. Any value (both objects and
4951 /// primitive values) maybe used as either a key or a value.
4952 ///
4953 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)
4954 #[cfg(js_sys_unstable_apis)]
4955 #[wasm_bindgen(constructor)]
4956 pub fn new<K, V>() -> Map<K, V>;
4957
4958 // Next major: deprecate
4959 /// The Map object holds key-value pairs. Any value (both objects and
4960 /// primitive values) maybe used as either a key or a value.
4961 ///
4962 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)
4963 #[wasm_bindgen(constructor)]
4964 pub fn new_typed<K, V>() -> Map<K, V>;
4965
4966 /// The Map object holds key-value pairs. Any value (both objects and
4967 /// primitive values) maybe used as either a key or a value.
4968 ///
4969 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)
4970 #[wasm_bindgen(constructor, js_name = new)]
4971 pub fn new_from_entries<K, V, I: Iterable<Item = ArrayTuple<(K, V)>>>(entries: &I)
4972 -> Map<K, V>;
4973
4974 /// The `clear()` method removes all elements from a Map object.
4975 ///
4976 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/clear)
4977 #[wasm_bindgen(method)]
4978 pub fn clear<K, V>(this: &Map<K, V>);
4979
4980 /// The `delete()` method removes the specified element from a Map object.
4981 ///
4982 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/delete)
4983 #[wasm_bindgen(method)]
4984 pub fn delete<K, V>(this: &Map<K, V>, key: &K) -> bool;
4985
4986 /// The `forEach()` method executes a provided function once per each
4987 /// key/value pair in the Map object, in insertion order.
4988 /// Note that in Javascript land the `Key` and `Value` are reversed compared to normal expectations:
4989 /// # Examples
4990 /// ```
4991 /// let js_map = Map::new();
4992 /// js_map.for_each(&mut |value, key| {
4993 /// // Do something here...
4994 /// })
4995 /// ```
4996 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/forEach)
4997 #[wasm_bindgen(method, js_name = forEach)]
4998 pub fn for_each<K, V>(this: &Map<K, V>, callback: &mut dyn FnMut(V, K));
4999
5000 /// The `forEach()` method executes a provided function once per each
5001 /// key/value pair in the Map object, in insertion order. _(Fallible variation)_
5002 /// Note that in Javascript land the `Key` and `Value` are reversed compared to normal expectations:
5003 /// # Examples
5004 /// ```
5005 /// let js_map = Map::new();
5006 /// js_map.for_each(&mut |value, key| {
5007 /// // Do something here...
5008 /// })
5009 /// ```
5010 ///
5011 /// **Note:** Consider using [`Map::try_for_each`] if the callback might throw an error.
5012 ///
5013 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/forEach)
5014 #[wasm_bindgen(method, js_name = forEach, catch)]
5015 pub fn try_for_each<K, V>(
5016 this: &Map<K, V>,
5017 callback: &mut dyn FnMut(V, K) -> Result<(), JsError>,
5018 ) -> Result<(), JsValue>;
5019
5020 /// The `get()` method returns a specified element from a Map object.
5021 /// Returns `undefined` if the key is not found.
5022 ///
5023 /// **Note:** Consider using [`Map::get_checked`] to get an `Option<V>` instead.
5024 ///
5025 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get)
5026 #[cfg(not(js_sys_unstable_apis))]
5027 #[wasm_bindgen(method)]
5028 pub fn get<K, V>(this: &Map<K, V>, key: &K) -> V;
5029
5030 /// The `get()` method returns a specified element from a Map object.
5031 /// Returns `None` if the key is not found.
5032 ///
5033 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get)
5034 #[cfg(js_sys_unstable_apis)]
5035 #[wasm_bindgen(method)]
5036 pub fn get<K, V>(this: &Map<K, V>, key: &K) -> Option<V>;
5037
5038 /// The `get()` method returns a specified element from a Map object.
5039 /// Returns `None` if the key is not found.
5040 ///
5041 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get)
5042 #[wasm_bindgen(method, js_name = get)]
5043 pub fn get_checked<K, V>(this: &Map<K, V>, key: &K) -> Option<V>;
5044
5045 /// The `has()` method returns a boolean indicating whether an element with
5046 /// the specified key exists or not.
5047 ///
5048 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/has)
5049 #[wasm_bindgen(method)]
5050 pub fn has<K, V>(this: &Map<K, V>, key: &K) -> bool;
5051
5052 /// The `set()` method adds or updates an element with a specified key
5053 /// and value to a Map object.
5054 ///
5055 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/set)
5056 #[wasm_bindgen(method)]
5057 pub fn set<K, V>(this: &Map<K, V>, key: &K, value: &V) -> Map<K, V>;
5058
5059 /// The value of size is an integer representing how many entries
5060 /// the Map object has. A set accessor function for size is undefined;
5061 /// you can not change this property.
5062 ///
5063 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/size)
5064 #[wasm_bindgen(method, getter)]
5065 pub fn size<K, V>(this: &Map<K, V>) -> u32;
5066}
5067
5068impl Default for Map<JsValue, JsValue> {
5069 fn default() -> Self {
5070 Self::new()
5071 }
5072}
5073
5074// Map Iterator
5075#[wasm_bindgen]
5076extern "C" {
5077 /// The `entries()` method returns a new Iterator object that contains
5078 /// the [key, value] pairs for each element in the Map object in
5079 /// insertion order.
5080 ///
5081 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries)
5082 #[cfg(not(js_sys_unstable_apis))]
5083 #[wasm_bindgen(method)]
5084 pub fn entries<K, V: FromWasmAbi>(this: &Map<K, V>) -> Iterator;
5085
5086 /// The `entries()` method returns a new Iterator object that contains
5087 /// the [key, value] pairs for each element in the Map object in
5088 /// insertion order.
5089 ///
5090 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries)
5091 #[cfg(js_sys_unstable_apis)]
5092 #[wasm_bindgen(method, js_name = entries)]
5093 pub fn entries<K: JsGeneric, V: FromWasmAbi + JsGeneric>(
5094 this: &Map<K, V>,
5095 ) -> Iterator<ArrayTuple<(K, V)>>;
5096
5097 // Next major: deprecate
5098 /// The `entries()` method returns a new Iterator object that contains
5099 /// the [key, value] pairs for each element in the Map object in
5100 /// insertion order.
5101 ///
5102 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries)
5103 #[wasm_bindgen(method, js_name = entries)]
5104 pub fn entries_typed<K: JsGeneric, V: FromWasmAbi + JsGeneric>(
5105 this: &Map<K, V>,
5106 ) -> Iterator<ArrayTuple<(K, V)>>;
5107
5108 /// The `keys()` method returns a new Iterator object that contains the
5109 /// keys for each element in the Map object in insertion order.
5110 ///
5111 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/keys)
5112 #[wasm_bindgen(method)]
5113 pub fn keys<K: FromWasmAbi, V: FromWasmAbi>(this: &Map<K, V>) -> Iterator<K>;
5114
5115 /// The `values()` method returns a new Iterator object that contains the
5116 /// values for each element in the Map object in insertion order.
5117 ///
5118 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/values)
5119 #[wasm_bindgen(method)]
5120 pub fn values<K, V: FromWasmAbi>(this: &Map<K, V>) -> Iterator<V>;
5121}
5122
5123impl<K, V> Iterable for Map<K, V> {
5124 type Item = ArrayTuple<(K, V)>;
5125}
5126
5127// Iterator
5128#[wasm_bindgen]
5129extern "C" {
5130 /// Any object that conforms to the JS iterator protocol. For example,
5131 /// something returned by `myArray[Symbol.iterator]()`.
5132 ///
5133 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols)
5134 #[derive(Clone, Debug)]
5135 #[wasm_bindgen(is_type_of = Iterator::looks_like_iterator, typescript_type = "Iterator<any>")]
5136 pub type Iterator<T = JsValue>;
5137
5138 /// The `next()` method always has to return an object with appropriate
5139 /// properties including done and value. If a non-object value gets returned
5140 /// (such as false or undefined), a TypeError ("iterator.next() returned a
5141 /// non-object value") will be thrown.
5142 #[wasm_bindgen(catch, method)]
5143 pub fn next<T: FromWasmAbi>(this: &Iterator<T>) -> Result<IteratorNext<T>, JsValue>;
5144}
5145
5146impl<T> UpcastFrom<Iterator<T>> for Object {}
5147
5148impl Iterator {
5149 fn looks_like_iterator(it: &JsValue) -> bool {
5150 #[wasm_bindgen]
5151 extern "C" {
5152 type MaybeIterator;
5153
5154 #[wasm_bindgen(method, getter)]
5155 fn next(this: &MaybeIterator) -> JsValue;
5156 }
5157
5158 if !it.is_object() {
5159 return false;
5160 }
5161
5162 let it = it.unchecked_ref::<MaybeIterator>();
5163
5164 it.next().is_function()
5165 }
5166}
5167
5168// iterators in JS are themselves iterable
5169impl<T> Iterable for Iterator<T> {
5170 type Item = T;
5171}
5172
5173// Async Iterator
5174#[wasm_bindgen]
5175extern "C" {
5176 /// Any object that conforms to the JS async iterator protocol. For example,
5177 /// something returned by `myObject[Symbol.asyncIterator]()`.
5178 ///
5179 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of)
5180 #[derive(Clone, Debug)]
5181 #[wasm_bindgen(is_type_of = Iterator::looks_like_iterator, typescript_type = "AsyncIterator<any>")]
5182 pub type AsyncIterator<T = JsValue>;
5183
5184 /// The `next()` method always has to return a Promise which resolves to an object
5185 /// with appropriate properties including done and value. If a non-object value
5186 /// gets returned (such as false or undefined), a TypeError ("iterator.next()
5187 /// returned a non-object value") will be thrown.
5188 #[cfg(not(js_sys_unstable_apis))]
5189 #[wasm_bindgen(catch, method)]
5190 pub fn next<T>(this: &AsyncIterator<T>) -> Result<Promise, JsValue>;
5191
5192 /// The `next()` method always has to return a Promise which resolves to an object
5193 /// with appropriate properties including done and value. If a non-object value
5194 /// gets returned (such as false or undefined), a TypeError ("iterator.next()
5195 /// returned a non-object value") will be thrown.
5196 #[cfg(js_sys_unstable_apis)]
5197 #[wasm_bindgen(catch, method, js_name = next)]
5198 pub fn next<T: FromWasmAbi>(
5199 this: &AsyncIterator<T>,
5200 ) -> Result<Promise<IteratorNext<T>>, JsValue>;
5201
5202 // Next major: deprecate
5203 /// The `next()` method always has to return a Promise which resolves to an object
5204 /// with appropriate properties including done and value. If a non-object value
5205 /// gets returned (such as false or undefined), a TypeError ("iterator.next()
5206 /// returned a non-object value") will be thrown.
5207 #[wasm_bindgen(catch, method, js_name = next)]
5208 pub fn next_iterator<T: FromWasmAbi>(
5209 this: &AsyncIterator<T>,
5210 ) -> Result<Promise<IteratorNext<T>>, JsValue>;
5211}
5212
5213impl<T> UpcastFrom<AsyncIterator<T>> for Object {}
5214
5215// iterators in JS are themselves iterable
5216impl<T> AsyncIterable for AsyncIterator<T> {
5217 type Item = T;
5218}
5219
5220/// An iterator over the JS `Symbol.iterator` iteration protocol.
5221///
5222/// Use the `IntoIterator for &js_sys::Iterator` implementation to create this.
5223pub struct Iter<'a, T = JsValue> {
5224 js: &'a Iterator<T>,
5225 state: IterState,
5226}
5227
5228/// An iterator over the JS `Symbol.iterator` iteration protocol.
5229///
5230/// Use the `IntoIterator for js_sys::Iterator` implementation to create this.
5231pub struct IntoIter<T = JsValue> {
5232 js: Iterator<T>,
5233 state: IterState,
5234}
5235
5236struct IterState {
5237 done: bool,
5238}
5239
5240impl<'a, T: FromWasmAbi + JsGeneric> IntoIterator for &'a Iterator<T> {
5241 type Item = Result<T, JsValue>;
5242 type IntoIter = Iter<'a, T>;
5243
5244 fn into_iter(self) -> Iter<'a, T> {
5245 Iter {
5246 js: self,
5247 state: IterState::new(),
5248 }
5249 }
5250}
5251
5252impl<T: FromWasmAbi + JsGeneric> core::iter::Iterator for Iter<'_, T> {
5253 type Item = Result<T, JsValue>;
5254
5255 fn next(&mut self) -> Option<Self::Item> {
5256 self.state.next(self.js)
5257 }
5258}
5259
5260impl<T: FromWasmAbi + JsGeneric> IntoIterator for Iterator<T> {
5261 type Item = Result<T, JsValue>;
5262 type IntoIter = IntoIter<T>;
5263
5264 fn into_iter(self) -> IntoIter<T> {
5265 IntoIter {
5266 js: self,
5267 state: IterState::new(),
5268 }
5269 }
5270}
5271
5272impl<T: FromWasmAbi + JsGeneric> core::iter::Iterator for IntoIter<T> {
5273 type Item = Result<T, JsValue>;
5274
5275 fn next(&mut self) -> Option<Self::Item> {
5276 self.state.next(&self.js)
5277 }
5278}
5279
5280impl IterState {
5281 fn new() -> IterState {
5282 IterState { done: false }
5283 }
5284
5285 fn next<T: FromWasmAbi + JsGeneric>(&mut self, js: &Iterator<T>) -> Option<Result<T, JsValue>> {
5286 if self.done {
5287 return None;
5288 }
5289 let next = match js.next() {
5290 Ok(val) => val,
5291 Err(e) => {
5292 self.done = true;
5293 return Some(Err(e));
5294 }
5295 };
5296 if next.done() {
5297 self.done = true;
5298 None
5299 } else {
5300 Some(Ok(next.value()))
5301 }
5302 }
5303}
5304
5305/// Create an iterator over `val` using the JS iteration protocol and
5306/// `Symbol.iterator`.
5307// #[cfg(not(js_sys_unstable_apis))]
5308pub fn try_iter(val: &JsValue) -> Result<Option<IntoIter<JsValue>>, JsValue> {
5309 let iter_sym = Symbol::iterator();
5310
5311 let iter_fn = Reflect::get_symbol::<Object>(val.unchecked_ref(), iter_sym.as_ref())?;
5312 let iter_fn: Function = match iter_fn.dyn_into() {
5313 Ok(iter_fn) => iter_fn,
5314 Err(_) => return Ok(None),
5315 };
5316
5317 let it: Iterator = match iter_fn.call0(val)?.dyn_into() {
5318 Ok(it) => it,
5319 Err(_) => return Ok(None),
5320 };
5321
5322 Ok(Some(it.into_iter()))
5323}
5324
5325/// Trait for JavaScript types that implement the iterable protocol via `Symbol.iterator`.
5326///
5327/// Types implementing this trait can be iterated over using JavaScript's iteration
5328/// protocol. The `Item` associated type specifies the type of values yielded.
5329///
5330/// ## Built-in Iterables
5331///
5332/// Many `js-sys` collection types implement `Iterable` out of the box:
5333///
5334/// ```ignore
5335/// use js_sys::{Array, Map, Set};
5336///
5337/// // Array<T> yields T
5338/// let arr: Array<Number> = get_numbers();
5339/// for value in arr.iter() {
5340/// let num: Number = value?;
5341/// }
5342///
5343/// // Map<K, V> yields Array (key-value pairs)
5344/// let map: Map<JsString, Number> = get_map();
5345/// for entry in map.iter() {
5346/// let pair: Array = entry?;
5347/// }
5348///
5349/// // Set<T> yields T
5350/// let set: Set<JsString> = get_set();
5351/// for value in set.iter() {
5352/// let s: JsString = value?;
5353/// }
5354/// ```
5355///
5356/// ## Typing Foreign Iterators
5357///
5358/// If you have a JavaScript value that implements the iterator protocol (has a `next()`
5359/// method) but isn't a built-in type, you can use [`JsCast`] to cast it to [`Iterator<T>`]:
5360///
5361/// ```ignore
5362/// use js_sys::Iterator;
5363/// use wasm_bindgen::JsCast;
5364///
5365/// // For a value you know implements the iterator protocol
5366/// fn process_iterator(js_iter: JsValue) {
5367/// // Checked cast - returns None if not an iterator
5368/// if let Some(iter) = js_iter.dyn_ref::<Iterator<Number>>() {
5369/// for value in iter.into_iter() {
5370/// let num: Number = value.unwrap();
5371/// // ...
5372/// }
5373/// }
5374/// }
5375///
5376/// // Or with unchecked cast when you're certain of the type
5377/// fn process_known_iterator(js_iter: JsValue) {
5378/// let iter: &Iterator<JsString> = js_iter.unchecked_ref();
5379/// for value in iter.into_iter() {
5380/// let s: JsString = value.unwrap();
5381/// // ...
5382/// }
5383/// }
5384/// ```
5385///
5386/// ## Using with `JsValue`
5387///
5388/// For dynamic or unknown iterables, use [`try_iter`] which returns an untyped iterator:
5389///
5390/// ```ignore
5391/// fn iterate_unknown(val: &JsValue) -> Result<(), JsValue> {
5392/// if let Some(iter) = js_sys::try_iter(val)? {
5393/// for item in iter {
5394/// let value: JsValue = item?;
5395/// // Handle dynamically...
5396/// }
5397/// }
5398/// Ok(())
5399/// }
5400/// ```
5401///
5402/// [`JsCast`]: wasm_bindgen::JsCast
5403/// [`Iterator<T>`]: Iterator
5404/// [`try_iter`]: crate::try_iter
5405pub trait Iterable {
5406 /// The type of values yielded by this iterable.
5407 type Item;
5408}
5409
5410impl<T: Iterable> Iterable for &T {
5411 type Item = T::Item;
5412}
5413
5414/// Trait for types known to implement the iterator protocol on Symbol.asyncIterator
5415pub trait AsyncIterable {
5416 type Item;
5417}
5418
5419impl<T: AsyncIterable> AsyncIterable for &T {
5420 type Item = T::Item;
5421}
5422
5423impl AsyncIterable for JsValue {
5424 type Item = JsValue;
5425}
5426
5427// IteratorNext
5428#[wasm_bindgen]
5429extern "C" {
5430 /// The result of calling `next()` on a JS iterator.
5431 ///
5432 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols)
5433 #[wasm_bindgen(extends = Object, typescript_type = "IteratorResult<any>")]
5434 #[derive(Clone, Debug, PartialEq, Eq)]
5435 pub type IteratorNext<T = JsValue>;
5436
5437 /// Has the value `true` if the iterator is past the end of the iterated
5438 /// sequence. In this case value optionally specifies the return value of
5439 /// the iterator.
5440 ///
5441 /// Has the value `false` if the iterator was able to produce the next value
5442 /// in the sequence. This is equivalent of not specifying the done property
5443 /// altogether.
5444 #[wasm_bindgen(method, getter)]
5445 pub fn done<T>(this: &IteratorNext<T>) -> bool;
5446
5447 /// Any JavaScript value returned by the iterator. Can be omitted when done
5448 /// is true.
5449 #[wasm_bindgen(method, getter)]
5450 pub fn value<T>(this: &IteratorNext<T>) -> T;
5451}
5452
5453#[allow(non_snake_case)]
5454pub mod Math {
5455 use super::*;
5456
5457 // Math
5458 #[wasm_bindgen]
5459 extern "C" {
5460 /// The `Math.abs()` function returns the absolute value of a number, that is
5461 /// Math.abs(x) = |x|
5462 ///
5463 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/abs)
5464 #[wasm_bindgen(js_namespace = Math)]
5465 pub fn abs(x: f64) -> f64;
5466
5467 /// The `Math.acos()` function returns the arccosine (in radians) of a
5468 /// number, that is ∀x∊[-1;1]
5469 /// Math.acos(x) = arccos(x) = the unique y∊[0;π] such that cos(y)=x
5470 ///
5471 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/acos)
5472 #[wasm_bindgen(js_namespace = Math)]
5473 pub fn acos(x: f64) -> f64;
5474
5475 /// The `Math.acosh()` function returns the hyperbolic arc-cosine of a
5476 /// number, that is ∀x ≥ 1
5477 /// Math.acosh(x) = arcosh(x) = the unique y ≥ 0 such that cosh(y) = x
5478 ///
5479 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/acosh)
5480 #[wasm_bindgen(js_namespace = Math)]
5481 pub fn acosh(x: f64) -> f64;
5482
5483 /// The `Math.asin()` function returns the arcsine (in radians) of a
5484 /// number, that is ∀x ∊ [-1;1]
5485 /// Math.asin(x) = arcsin(x) = the unique y∊[-π2;π2] such that sin(y) = x
5486 ///
5487 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/asin)
5488 #[wasm_bindgen(js_namespace = Math)]
5489 pub fn asin(x: f64) -> f64;
5490
5491 /// The `Math.asinh()` function returns the hyperbolic arcsine of a
5492 /// number, that is Math.asinh(x) = arsinh(x) = the unique y such that sinh(y) = x
5493 ///
5494 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/asinh)
5495 #[wasm_bindgen(js_namespace = Math)]
5496 pub fn asinh(x: f64) -> f64;
5497
5498 /// The `Math.atan()` function returns the arctangent (in radians) of a
5499 /// number, that is Math.atan(x) = arctan(x) = the unique y ∊ [-π2;π2]such that
5500 /// tan(y) = x
5501 #[wasm_bindgen(js_namespace = Math)]
5502 pub fn atan(x: f64) -> f64;
5503
5504 /// The `Math.atan2()` function returns the arctangent of the quotient of
5505 /// its arguments.
5506 ///
5507 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/atan2)
5508 #[wasm_bindgen(js_namespace = Math)]
5509 pub fn atan2(y: f64, x: f64) -> f64;
5510
5511 /// The `Math.atanh()` function returns the hyperbolic arctangent of a number,
5512 /// that is ∀x ∊ (-1,1), Math.atanh(x) = arctanh(x) = the unique y such that
5513 /// tanh(y) = x
5514 ///
5515 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/atanh)
5516 #[wasm_bindgen(js_namespace = Math)]
5517 pub fn atanh(x: f64) -> f64;
5518
5519 /// The `Math.cbrt() `function returns the cube root of a number, that is
5520 /// Math.cbrt(x) = ∛x = the unique y such that y^3 = x
5521 ///
5522 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/cbrt)
5523 #[wasm_bindgen(js_namespace = Math)]
5524 pub fn cbrt(x: f64) -> f64;
5525
5526 /// The `Math.ceil()` function returns the smallest integer greater than
5527 /// or equal to a given number.
5528 ///
5529 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/ceil)
5530 #[wasm_bindgen(js_namespace = Math)]
5531 pub fn ceil(x: f64) -> f64;
5532
5533 /// The `Math.clz32()` function returns the number of leading zero bits in
5534 /// the 32-bit binary representation of a number.
5535 ///
5536 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/clz32)
5537 #[wasm_bindgen(js_namespace = Math)]
5538 pub fn clz32(x: i32) -> u32;
5539
5540 /// The `Math.cos()` static function returns the cosine of the specified angle,
5541 /// which must be specified in radians. This value is length(adjacent)/length(hypotenuse).
5542 ///
5543 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/cos)
5544 #[wasm_bindgen(js_namespace = Math)]
5545 pub fn cos(x: f64) -> f64;
5546
5547 /// The `Math.cosh()` function returns the hyperbolic cosine of a number,
5548 /// that can be expressed using the constant e.
5549 ///
5550 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/cosh)
5551 #[wasm_bindgen(js_namespace = Math)]
5552 pub fn cosh(x: f64) -> f64;
5553
5554 /// The `Math.exp()` function returns e^x, where x is the argument, and e is Euler's number
5555 /// (also known as Napier's constant), the base of the natural logarithms.
5556 ///
5557 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/exp)
5558 #[wasm_bindgen(js_namespace = Math)]
5559 pub fn exp(x: f64) -> f64;
5560
5561 /// The `Math.expm1()` function returns e^x - 1, where x is the argument, and e the base of the
5562 /// natural logarithms.
5563 ///
5564 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/expm1)
5565 #[wasm_bindgen(js_namespace = Math)]
5566 pub fn expm1(x: f64) -> f64;
5567
5568 /// The `Math.floor()` function returns the largest integer less than or
5569 /// equal to a given number.
5570 ///
5571 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/floor)
5572 #[wasm_bindgen(js_namespace = Math)]
5573 pub fn floor(x: f64) -> f64;
5574
5575 /// The `Math.fround()` function returns the nearest 32-bit single precision float representation
5576 /// of a Number.
5577 ///
5578 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/fround)
5579 #[wasm_bindgen(js_namespace = Math)]
5580 pub fn fround(x: f64) -> f32;
5581
5582 /// The `Math.hypot()` function returns the square root of the sum of squares of its arguments.
5583 ///
5584 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/hypot)
5585 #[wasm_bindgen(js_namespace = Math)]
5586 pub fn hypot(x: f64, y: f64) -> f64;
5587
5588 /// The `Math.imul()` function returns the result of the C-like 32-bit multiplication of the
5589 /// two parameters.
5590 ///
5591 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/imul)
5592 #[wasm_bindgen(js_namespace = Math)]
5593 pub fn imul(x: i32, y: i32) -> i32;
5594
5595 /// The `Math.log()` function returns the natural logarithm (base e) of a number.
5596 /// The JavaScript `Math.log()` function is equivalent to ln(x) in mathematics.
5597 ///
5598 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log)
5599 #[wasm_bindgen(js_namespace = Math)]
5600 pub fn log(x: f64) -> f64;
5601
5602 /// The `Math.log10()` function returns the base 10 logarithm of a number.
5603 ///
5604 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log10)
5605 #[wasm_bindgen(js_namespace = Math)]
5606 pub fn log10(x: f64) -> f64;
5607
5608 /// The `Math.log1p()` function returns the natural logarithm (base e) of 1 + a number.
5609 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log1p)
5610 #[wasm_bindgen(js_namespace = Math)]
5611 pub fn log1p(x: f64) -> f64;
5612
5613 /// The `Math.log2()` function returns the base 2 logarithm of a number.
5614 ///
5615 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log2)
5616 #[wasm_bindgen(js_namespace = Math)]
5617 pub fn log2(x: f64) -> f64;
5618
5619 /// The `Math.max()` function returns the largest of two numbers.
5620 ///
5621 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/max)
5622 #[wasm_bindgen(js_namespace = Math)]
5623 pub fn max(x: f64, y: f64) -> f64;
5624
5625 /// The static function `Math.min()` returns the lowest-valued number passed into it.
5626 ///
5627 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/min)
5628 #[wasm_bindgen(js_namespace = Math)]
5629 pub fn min(x: f64, y: f64) -> f64;
5630
5631 /// The `Math.pow()` function returns the base to the exponent power, that is, base^exponent.
5632 ///
5633 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/pow)
5634 #[wasm_bindgen(js_namespace = Math)]
5635 pub fn pow(base: f64, exponent: f64) -> f64;
5636
5637 /// The `Math.random()` function returns a floating-point, pseudo-random number
5638 /// in the range 0–1 (inclusive of 0, but not 1) with approximately uniform distribution
5639 /// over that range — which you can then scale to your desired range.
5640 /// The implementation selects the initial seed to the random number generation algorithm;
5641 /// it cannot be chosen or reset by the user.
5642 ///
5643 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random)
5644 #[wasm_bindgen(js_namespace = Math)]
5645 pub fn random() -> f64;
5646
5647 /// The `Math.round()` function returns the value of a number rounded to the nearest integer.
5648 ///
5649 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round)
5650 #[wasm_bindgen(js_namespace = Math)]
5651 pub fn round(x: f64) -> f64;
5652
5653 /// The `Math.sign()` function returns the sign of a number, indicating whether the number is
5654 /// positive, negative or zero.
5655 ///
5656 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign)
5657 #[wasm_bindgen(js_namespace = Math)]
5658 pub fn sign(x: f64) -> f64;
5659
5660 /// The `Math.sin()` function returns the sine of a number.
5661 ///
5662 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sin)
5663 #[wasm_bindgen(js_namespace = Math)]
5664 pub fn sin(x: f64) -> f64;
5665
5666 /// The `Math.sinh()` function returns the hyperbolic sine of a number, that can be expressed
5667 /// using the constant e: Math.sinh(x) = (e^x - e^-x)/2
5668 ///
5669 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sinh)
5670 #[wasm_bindgen(js_namespace = Math)]
5671 pub fn sinh(x: f64) -> f64;
5672
5673 /// The `Math.sqrt()` function returns the square root of a number, that is
5674 /// ∀x ≥ 0, Math.sqrt(x) = √x = the unique y ≥ 0 such that y^2 = x
5675 ///
5676 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sqrt)
5677 #[wasm_bindgen(js_namespace = Math)]
5678 pub fn sqrt(x: f64) -> f64;
5679
5680 /// The `Math.tan()` function returns the tangent of a number.
5681 ///
5682 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/tan)
5683 #[wasm_bindgen(js_namespace = Math)]
5684 pub fn tan(x: f64) -> f64;
5685
5686 /// The `Math.tanh()` function returns the hyperbolic tangent of a number, that is
5687 /// tanh x = sinh x / cosh x = (e^x - e^-x)/(e^x + e^-x) = (e^2x - 1)/(e^2x + 1)
5688 ///
5689 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/tanh)
5690 #[wasm_bindgen(js_namespace = Math)]
5691 pub fn tanh(x: f64) -> f64;
5692
5693 /// The `Math.trunc()` function returns the integer part of a number by removing any fractional
5694 /// digits.
5695 ///
5696 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/trunc)
5697 #[wasm_bindgen(js_namespace = Math)]
5698 pub fn trunc(x: f64) -> f64;
5699
5700 /// The `Math.PI` property represents the ratio of the circumference of a circle to its diameter,
5701 /// approximately 3.14159.
5702 ///
5703 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/PI)
5704 #[wasm_bindgen(thread_local_v2, js_namespace = Math)]
5705 pub static PI: f64;
5706 }
5707}
5708
5709// Number.
5710#[wasm_bindgen]
5711extern "C" {
5712 #[wasm_bindgen(extends = Object, is_type_of = |v| v.as_f64().is_some(), typescript_type = "number")]
5713 #[derive(Clone, PartialEq)]
5714 pub type Number;
5715
5716 /// The `Number.isFinite()` method determines whether the passed value is a finite number.
5717 ///
5718 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isFinite)
5719 #[wasm_bindgen(static_method_of = Number, js_name = isFinite)]
5720 pub fn is_finite(value: &JsValue) -> bool;
5721
5722 /// The `Number.isInteger()` method determines whether the passed value is an integer.
5723 ///
5724 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isInteger)
5725 #[wasm_bindgen(static_method_of = Number, js_name = isInteger)]
5726 pub fn is_integer(value: &JsValue) -> bool;
5727
5728 /// The `Number.isNaN()` method determines whether the passed value is `NaN` and its type is Number.
5729 /// It is a more robust version of the original, global isNaN().
5730 ///
5731 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isNaN)
5732 #[wasm_bindgen(static_method_of = Number, js_name = isNaN)]
5733 pub fn is_nan(value: &JsValue) -> bool;
5734
5735 /// The `Number.isSafeInteger()` method determines whether the provided value is a number
5736 /// that is a safe integer.
5737 ///
5738 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isSafeInteger)
5739 #[wasm_bindgen(static_method_of = Number, js_name = isSafeInteger)]
5740 pub fn is_safe_integer(value: &JsValue) -> bool;
5741
5742 /// The `Number` JavaScript object is a wrapper object allowing
5743 /// you to work with numerical values. A `Number` object is
5744 /// created using the `Number()` constructor.
5745 ///
5746 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
5747 #[cfg(not(js_sys_unstable_apis))]
5748 #[wasm_bindgen(constructor)]
5749 #[deprecated(note = "recommended to use `Number::from` instead")]
5750 #[allow(deprecated)]
5751 pub fn new(value: &JsValue) -> Number;
5752
5753 #[wasm_bindgen(constructor)]
5754 fn new_from_str(value: &str) -> Number;
5755
5756 /// The `Number.parseInt()` method parses a string argument and returns an
5757 /// integer of the specified radix or base.
5758 ///
5759 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/parseInt)
5760 #[wasm_bindgen(static_method_of = Number, js_name = parseInt)]
5761 pub fn parse_int(text: &str, radix: u8) -> f64;
5762
5763 /// The `Number.parseFloat()` method parses a string argument and returns a
5764 /// floating point number.
5765 ///
5766 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/parseFloat)
5767 #[wasm_bindgen(static_method_of = Number, js_name = parseFloat)]
5768 pub fn parse_float(text: &str) -> f64;
5769
5770 /// The `toLocaleString()` method returns a string with a language sensitive
5771 /// representation of this number.
5772 ///
5773 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString)
5774 #[cfg(not(js_sys_unstable_apis))]
5775 #[wasm_bindgen(method, js_name = toLocaleString)]
5776 pub fn to_locale_string(this: &Number, locale: &str) -> JsString;
5777
5778 /// The `toLocaleString()` method returns a string with a language sensitive
5779 /// representation of this number.
5780 ///
5781 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString)
5782 #[cfg(js_sys_unstable_apis)]
5783 #[wasm_bindgen(method, js_name = toLocaleString)]
5784 pub fn to_locale_string(
5785 this: &Number,
5786 locales: &[JsString],
5787 options: &Intl::NumberFormatOptions,
5788 ) -> JsString;
5789
5790 /// The `toPrecision()` method returns a string representing the Number
5791 /// object to the specified precision.
5792 ///
5793 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision)
5794 #[wasm_bindgen(catch, method, js_name = toPrecision)]
5795 pub fn to_precision(this: &Number, precision: u8) -> Result<JsString, JsValue>;
5796
5797 /// The `toFixed()` method returns a string representing the Number
5798 /// object using fixed-point notation.
5799 ///
5800 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed)
5801 #[wasm_bindgen(catch, method, js_name = toFixed)]
5802 pub fn to_fixed(this: &Number, digits: u8) -> Result<JsString, JsValue>;
5803
5804 /// The `toExponential()` method returns a string representing the Number
5805 /// object in exponential notation.
5806 ///
5807 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toExponential)
5808 #[wasm_bindgen(catch, method, js_name = toExponential)]
5809 pub fn to_exponential(this: &Number, fraction_digits: u8) -> Result<JsString, JsValue>;
5810
5811 /// The `toString()` method returns a string representing the
5812 /// specified Number object.
5813 ///
5814 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString)
5815 #[cfg(not(js_sys_unstable_apis))]
5816 #[deprecated(note = "Use `Number::to_string_with_radix` instead.")]
5817 #[allow(deprecated)]
5818 #[wasm_bindgen(catch, method, js_name = toString)]
5819 pub fn to_string(this: &Number, radix: u8) -> Result<JsString, JsValue>;
5820
5821 /// The `toString()` method returns a string representing the
5822 /// specified Number object.
5823 ///
5824 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString)
5825 #[wasm_bindgen(catch, method, js_name = toString)]
5826 pub fn to_string_with_radix(this: &Number, radix: u8) -> Result<JsString, JsValue>;
5827
5828 /// The `valueOf()` method returns the wrapped primitive value of
5829 /// a Number object.
5830 ///
5831 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/valueOf)
5832 #[wasm_bindgen(method, js_name = valueOf)]
5833 pub fn value_of(this: &Number) -> f64;
5834}
5835
5836impl Number {
5837 /// The smallest interval between two representable numbers.
5838 ///
5839 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/EPSILON)
5840 pub const EPSILON: f64 = f64::EPSILON;
5841 /// The maximum safe integer in JavaScript (2^53 - 1).
5842 ///
5843 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER)
5844 pub const MAX_SAFE_INTEGER: f64 = 9007199254740991.0;
5845 /// The largest positive representable number.
5846 ///
5847 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_VALUE)
5848 pub const MAX_VALUE: f64 = f64::MAX;
5849 /// The minimum safe integer in JavaScript (-(2^53 - 1)).
5850 ///
5851 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MIN_SAFE_INTEGER)
5852 pub const MIN_SAFE_INTEGER: f64 = -9007199254740991.0;
5853 /// The smallest positive representable number—that is, the positive number closest to zero
5854 /// (without actually being zero).
5855 ///
5856 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MIN_VALUE)
5857 // Cannot use f64::MIN_POSITIVE since that is the smallest **normal** positive number.
5858 pub const MIN_VALUE: f64 = 5E-324;
5859 /// Special "Not a Number" value.
5860 ///
5861 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/NaN)
5862 pub const NAN: f64 = f64::NAN;
5863 /// Special value representing negative infinity. Returned on overflow.
5864 ///
5865 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/NEGATIVE_INFINITY)
5866 pub const NEGATIVE_INFINITY: f64 = f64::NEG_INFINITY;
5867 /// Special value representing infinity. Returned on overflow.
5868 ///
5869 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/POSITIVE_INFINITY)
5870 pub const POSITIVE_INFINITY: f64 = f64::INFINITY;
5871
5872 /// Applies the binary `**` JS operator on the two `Number`s.
5873 ///
5874 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Exponentiation)
5875 #[inline]
5876 pub fn pow(&self, rhs: &Self) -> Self {
5877 JsValue::as_ref(self)
5878 .pow(JsValue::as_ref(rhs))
5879 .unchecked_into()
5880 }
5881
5882 /// Applies the binary `>>>` JS operator on the two `Number`s.
5883 ///
5884 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Unsigned_right_shift)
5885 #[inline]
5886 pub fn unsigned_shr(&self, rhs: &Self) -> Self {
5887 Number::from(JsValue::as_ref(self).unsigned_shr(JsValue::as_ref(rhs)))
5888 }
5889}
5890
5891macro_rules! number_from {
5892 ($($x:ident)*) => ($(
5893 impl From<$x> for Number {
5894 #[inline]
5895 fn from(x: $x) -> Number {
5896 Number::unchecked_from_js(JsValue::from(x))
5897 }
5898 }
5899
5900 impl PartialEq<$x> for Number {
5901 #[inline]
5902 fn eq(&self, other: &$x) -> bool {
5903 self.value_of() == f64::from(*other)
5904 }
5905 }
5906
5907 impl UpcastFrom<$x> for Number {}
5908 )*)
5909}
5910number_from!(i8 u8 i16 u16 i32 u32 f32 f64);
5911
5912// The only guarantee for a JS number
5913impl UpcastFrom<Number> for f64 {}
5914
5915/// The error type returned when a checked integral type conversion fails.
5916#[derive(Debug, Copy, Clone, PartialEq, Eq)]
5917pub struct TryFromIntError(());
5918
5919impl fmt::Display for TryFromIntError {
5920 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
5921 fmt.write_str("out of range integral type conversion attempted")
5922 }
5923}
5924
5925#[cfg(feature = "std")]
5926impl std::error::Error for TryFromIntError {}
5927
5928macro_rules! number_try_from {
5929 ($($x:ident)*) => ($(
5930 impl TryFrom<$x> for Number {
5931 type Error = TryFromIntError;
5932
5933 #[inline]
5934 fn try_from(x: $x) -> Result<Number, Self::Error> {
5935 let x_f64 = x as f64;
5936 if (Number::MIN_SAFE_INTEGER..=Number::MAX_SAFE_INTEGER).contains(&x_f64) {
5937 Ok(Number::from(x_f64))
5938 } else {
5939 Err(TryFromIntError(()))
5940 }
5941 }
5942 }
5943 )*)
5944}
5945number_try_from!(i64 u64 i128 u128);
5946
5947impl From<&Number> for f64 {
5948 #[inline]
5949 fn from(n: &Number) -> f64 {
5950 n.value_of()
5951 }
5952}
5953
5954impl From<Number> for f64 {
5955 #[inline]
5956 fn from(n: Number) -> f64 {
5957 <f64 as From<&'_ Number>>::from(&n)
5958 }
5959}
5960
5961impl fmt::Debug for Number {
5962 #[inline]
5963 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5964 fmt::Debug::fmt(&self.value_of(), f)
5965 }
5966}
5967
5968impl fmt::Display for Number {
5969 #[inline]
5970 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5971 fmt::Display::fmt(&self.value_of(), f)
5972 }
5973}
5974
5975impl Default for Number {
5976 fn default() -> Self {
5977 Self::from(f64::default())
5978 }
5979}
5980
5981impl PartialEq<BigInt> for Number {
5982 #[inline]
5983 fn eq(&self, other: &BigInt) -> bool {
5984 JsValue::as_ref(self).loose_eq(JsValue::as_ref(other))
5985 }
5986}
5987
5988impl Not for &Number {
5989 type Output = BigInt;
5990
5991 #[inline]
5992 fn not(self) -> Self::Output {
5993 JsValue::as_ref(self).bit_not().unchecked_into()
5994 }
5995}
5996
5997forward_deref_unop!(impl Not, not for Number);
5998forward_js_unop!(impl Neg, neg for Number);
5999forward_js_binop!(impl BitAnd, bitand for Number);
6000forward_js_binop!(impl BitOr, bitor for Number);
6001forward_js_binop!(impl BitXor, bitxor for Number);
6002forward_js_binop!(impl Shl, shl for Number);
6003forward_js_binop!(impl Shr, shr for Number);
6004forward_js_binop!(impl Add, add for Number);
6005forward_js_binop!(impl Sub, sub for Number);
6006forward_js_binop!(impl Div, div for Number);
6007forward_js_binop!(impl Mul, mul for Number);
6008forward_js_binop!(impl Rem, rem for Number);
6009
6010sum_product!(Number);
6011
6012impl PartialOrd for Number {
6013 #[inline]
6014 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
6015 if Number::is_nan(self) || Number::is_nan(other) {
6016 None
6017 } else if self == other {
6018 Some(Ordering::Equal)
6019 } else if self.lt(other) {
6020 Some(Ordering::Less)
6021 } else {
6022 Some(Ordering::Greater)
6023 }
6024 }
6025
6026 #[inline]
6027 fn lt(&self, other: &Self) -> bool {
6028 JsValue::as_ref(self).lt(JsValue::as_ref(other))
6029 }
6030
6031 #[inline]
6032 fn le(&self, other: &Self) -> bool {
6033 JsValue::as_ref(self).le(JsValue::as_ref(other))
6034 }
6035
6036 #[inline]
6037 fn ge(&self, other: &Self) -> bool {
6038 JsValue::as_ref(self).ge(JsValue::as_ref(other))
6039 }
6040
6041 #[inline]
6042 fn gt(&self, other: &Self) -> bool {
6043 JsValue::as_ref(self).gt(JsValue::as_ref(other))
6044 }
6045}
6046
6047#[cfg(not(js_sys_unstable_apis))]
6048impl FromStr for Number {
6049 type Err = Infallible;
6050
6051 #[allow(deprecated)]
6052 #[inline]
6053 fn from_str(s: &str) -> Result<Self, Self::Err> {
6054 Ok(Number::new_from_str(s))
6055 }
6056}
6057
6058// Date.
6059#[wasm_bindgen]
6060extern "C" {
6061 #[wasm_bindgen(extends = Object, typescript_type = "Date")]
6062 #[derive(Clone, Debug, PartialEq, Eq)]
6063 pub type Date;
6064
6065 /// The `getDate()` method returns the day of the month for the
6066 /// specified date according to local time.
6067 ///
6068 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getDate)
6069 #[wasm_bindgen(method, js_name = getDate)]
6070 pub fn get_date(this: &Date) -> u32;
6071
6072 /// The `getDay()` method returns the day of the week for the specified date according to local time,
6073 /// where 0 represents Sunday. For the day of the month see getDate().
6074 ///
6075 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getDay)
6076 #[wasm_bindgen(method, js_name = getDay)]
6077 pub fn get_day(this: &Date) -> u32;
6078
6079 /// The `getFullYear()` method returns the year of the specified date according to local time.
6080 ///
6081 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getFullYear)
6082 #[wasm_bindgen(method, js_name = getFullYear)]
6083 pub fn get_full_year(this: &Date) -> u32;
6084
6085 /// The `getHours()` method returns the hour for the specified date, according to local time.
6086 ///
6087 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getHours)
6088 #[wasm_bindgen(method, js_name = getHours)]
6089 pub fn get_hours(this: &Date) -> u32;
6090
6091 /// The `getMilliseconds()` method returns the milliseconds in the specified date according to local time.
6092 ///
6093 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMilliseconds)
6094 #[wasm_bindgen(method, js_name = getMilliseconds)]
6095 pub fn get_milliseconds(this: &Date) -> u32;
6096
6097 /// The `getMinutes()` method returns the minutes in the specified date according to local time.
6098 ///
6099 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMinutes)
6100 #[wasm_bindgen(method, js_name = getMinutes)]
6101 pub fn get_minutes(this: &Date) -> u32;
6102
6103 /// The `getMonth()` method returns the month in the specified date according to local time,
6104 /// as a zero-based value (where zero indicates the first month of the year).
6105 ///
6106 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMonth)
6107 #[wasm_bindgen(method, js_name = getMonth)]
6108 pub fn get_month(this: &Date) -> u32;
6109
6110 /// The `getSeconds()` method returns the seconds in the specified date according to local time.
6111 ///
6112 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getSeconds)
6113 #[wasm_bindgen(method, js_name = getSeconds)]
6114 pub fn get_seconds(this: &Date) -> u32;
6115
6116 /// The `getTime()` method returns the numeric value corresponding to the time for the specified date
6117 /// according to universal time.
6118 ///
6119 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTime)
6120 #[wasm_bindgen(method, js_name = getTime)]
6121 pub fn get_time(this: &Date) -> f64;
6122
6123 /// The `getTimezoneOffset()` method returns the time zone difference, in minutes,
6124 /// from current locale (host system settings) to UTC.
6125 ///
6126 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTimezoneOffset)
6127 #[wasm_bindgen(method, js_name = getTimezoneOffset)]
6128 pub fn get_timezone_offset(this: &Date) -> f64;
6129
6130 /// The `getUTCDate()` method returns the day (date) of the month in the specified date
6131 /// according to universal time.
6132 ///
6133 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCDate)
6134 #[wasm_bindgen(method, js_name = getUTCDate)]
6135 pub fn get_utc_date(this: &Date) -> u32;
6136
6137 /// The `getUTCDay()` method returns the day of the week in the specified date according to universal time,
6138 /// where 0 represents Sunday.
6139 ///
6140 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCDay)
6141 #[wasm_bindgen(method, js_name = getUTCDay)]
6142 pub fn get_utc_day(this: &Date) -> u32;
6143
6144 /// The `getUTCFullYear()` method returns the year in the specified date according to universal time.
6145 ///
6146 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCFullYear)
6147 #[wasm_bindgen(method, js_name = getUTCFullYear)]
6148 pub fn get_utc_full_year(this: &Date) -> u32;
6149
6150 /// The `getUTCHours()` method returns the hours in the specified date according to universal time.
6151 ///
6152 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCHours)
6153 #[wasm_bindgen(method, js_name = getUTCHours)]
6154 pub fn get_utc_hours(this: &Date) -> u32;
6155
6156 /// The `getUTCMilliseconds()` method returns the milliseconds in the specified date
6157 /// according to universal time.
6158 ///
6159 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCMilliseconds)
6160 #[wasm_bindgen(method, js_name = getUTCMilliseconds)]
6161 pub fn get_utc_milliseconds(this: &Date) -> u32;
6162
6163 /// The `getUTCMinutes()` method returns the minutes in the specified date according to universal time.
6164 ///
6165 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCMinutes)
6166 #[wasm_bindgen(method, js_name = getUTCMinutes)]
6167 pub fn get_utc_minutes(this: &Date) -> u32;
6168
6169 /// The `getUTCMonth()` returns the month of the specified date according to universal time,
6170 /// as a zero-based value (where zero indicates the first month of the year).
6171 ///
6172 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCMonth)
6173 #[wasm_bindgen(method, js_name = getUTCMonth)]
6174 pub fn get_utc_month(this: &Date) -> u32;
6175
6176 /// The `getUTCSeconds()` method returns the seconds in the specified date according to universal time.
6177 ///
6178 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCSeconds)
6179 #[wasm_bindgen(method, js_name = getUTCSeconds)]
6180 pub fn get_utc_seconds(this: &Date) -> u32;
6181
6182 /// Creates a JavaScript `Date` instance that represents
6183 /// a single moment in time. `Date` objects are based on a time value that is
6184 /// the number of milliseconds since 1 January 1970 UTC.
6185 ///
6186 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6187 #[wasm_bindgen(constructor)]
6188 pub fn new(init: &JsValue) -> Date;
6189
6190 /// Creates a JavaScript `Date` instance that represents the current moment in
6191 /// time.
6192 ///
6193 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6194 #[wasm_bindgen(constructor)]
6195 pub fn new_0() -> Date;
6196
6197 /// Creates a JavaScript `Date` instance that represents
6198 /// a single moment in time. `Date` objects are based on a time value that is
6199 /// the number of milliseconds since 1 January 1970 UTC.
6200 ///
6201 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6202 #[wasm_bindgen(constructor)]
6203 pub fn new_with_year_month(year: u32, month: i32) -> Date;
6204
6205 /// Creates a JavaScript `Date` instance that represents
6206 /// a single moment in time. `Date` objects are based on a time value that is
6207 /// the number of milliseconds since 1 January 1970 UTC.
6208 ///
6209 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6210 #[wasm_bindgen(constructor)]
6211 pub fn new_with_year_month_day(year: u32, month: i32, day: i32) -> Date;
6212
6213 /// Creates a JavaScript `Date` instance that represents
6214 /// a single moment in time. `Date` objects are based on a time value that is
6215 /// the number of milliseconds since 1 January 1970 UTC.
6216 ///
6217 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6218 #[wasm_bindgen(constructor)]
6219 pub fn new_with_year_month_day_hr(year: u32, month: i32, day: i32, hr: i32) -> Date;
6220
6221 /// Creates a JavaScript `Date` instance that represents
6222 /// a single moment in time. `Date` objects are based on a time value that is
6223 /// the number of milliseconds since 1 January 1970 UTC.
6224 ///
6225 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6226 #[wasm_bindgen(constructor)]
6227 pub fn new_with_year_month_day_hr_min(
6228 year: u32,
6229 month: i32,
6230 day: i32,
6231 hr: i32,
6232 min: i32,
6233 ) -> Date;
6234
6235 /// Creates a JavaScript `Date` instance that represents
6236 /// a single moment in time. `Date` objects are based on a time value that is
6237 /// the number of milliseconds since 1 January 1970 UTC.
6238 ///
6239 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6240 #[wasm_bindgen(constructor)]
6241 pub fn new_with_year_month_day_hr_min_sec(
6242 year: u32,
6243 month: i32,
6244 day: i32,
6245 hr: i32,
6246 min: i32,
6247 sec: i32,
6248 ) -> Date;
6249
6250 /// Creates a JavaScript `Date` instance that represents
6251 /// a single moment in time. `Date` objects are based on a time value that is
6252 /// the number of milliseconds since 1 January 1970 UTC.
6253 ///
6254 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6255 #[wasm_bindgen(constructor)]
6256 pub fn new_with_year_month_day_hr_min_sec_milli(
6257 year: u32,
6258 month: i32,
6259 day: i32,
6260 hr: i32,
6261 min: i32,
6262 sec: i32,
6263 milli: i32,
6264 ) -> Date;
6265
6266 /// The `Date.now()` method returns the number of milliseconds
6267 /// elapsed since January 1, 1970 00:00:00 UTC.
6268 ///
6269 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/now)
6270 #[wasm_bindgen(static_method_of = Date)]
6271 pub fn now() -> f64;
6272
6273 /// The `Date.parse()` method parses a string representation of a date, and returns the number of milliseconds
6274 /// since January 1, 1970, 00:00:00 UTC or `NaN` if the string is unrecognized or, in some cases,
6275 /// contains illegal date values (e.g. 2015-02-31).
6276 ///
6277 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse)
6278 #[wasm_bindgen(static_method_of = Date)]
6279 pub fn parse(date: &str) -> f64;
6280
6281 /// The `setDate()` method sets the day of the Date object relative to the beginning of the currently set month.
6282 ///
6283 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setDate)
6284 #[wasm_bindgen(method, js_name = setDate)]
6285 pub fn set_date(this: &Date, day: u32) -> f64;
6286
6287 /// The `setFullYear()` method sets the full year for a specified date according to local time.
6288 /// Returns new timestamp.
6289 ///
6290 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setFullYear)
6291 #[wasm_bindgen(method, js_name = setFullYear)]
6292 pub fn set_full_year(this: &Date, year: u32) -> f64;
6293
6294 /// The `setFullYear()` method sets the full year for a specified date according to local time.
6295 /// Returns new timestamp.
6296 ///
6297 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setFullYear)
6298 #[wasm_bindgen(method, js_name = setFullYear)]
6299 pub fn set_full_year_with_month(this: &Date, year: u32, month: i32) -> f64;
6300
6301 /// The `setFullYear()` method sets the full year for a specified date according to local time.
6302 /// Returns new timestamp.
6303 ///
6304 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setFullYear)
6305 #[wasm_bindgen(method, js_name = setFullYear)]
6306 pub fn set_full_year_with_month_date(this: &Date, year: u32, month: i32, date: i32) -> f64;
6307
6308 /// The `setHours()` method sets the hours for a specified date according to local time,
6309 /// and returns the number of milliseconds since January 1, 1970 00:00:00 UTC until the time represented
6310 /// by the updated Date instance.
6311 ///
6312 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setHours)
6313 #[wasm_bindgen(method, js_name = setHours)]
6314 pub fn set_hours(this: &Date, hours: u32) -> f64;
6315
6316 /// The `setMilliseconds()` method sets the milliseconds for a specified date according to local time.
6317 ///
6318 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setMilliseconds)
6319 #[wasm_bindgen(method, js_name = setMilliseconds)]
6320 pub fn set_milliseconds(this: &Date, milliseconds: u32) -> f64;
6321
6322 /// The `setMinutes()` method sets the minutes for a specified date according to local time.
6323 ///
6324 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setMinutes)
6325 #[wasm_bindgen(method, js_name = setMinutes)]
6326 pub fn set_minutes(this: &Date, minutes: u32) -> f64;
6327
6328 /// The `setMonth()` method sets the month for a specified date according to the currently set year.
6329 ///
6330 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setMonth)
6331 #[wasm_bindgen(method, js_name = setMonth)]
6332 pub fn set_month(this: &Date, month: u32) -> f64;
6333
6334 /// The `setSeconds()` method sets the seconds for a specified date according to local time.
6335 ///
6336 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setSeconds)
6337 #[wasm_bindgen(method, js_name = setSeconds)]
6338 pub fn set_seconds(this: &Date, seconds: u32) -> f64;
6339
6340 /// The `setTime()` method sets the Date object to the time represented by a number of milliseconds
6341 /// since January 1, 1970, 00:00:00 UTC.
6342 ///
6343 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setTime)
6344 #[wasm_bindgen(method, js_name = setTime)]
6345 pub fn set_time(this: &Date, time: f64) -> f64;
6346
6347 /// The `setUTCDate()` method sets the day of the month for a specified date
6348 /// according to universal time.
6349 ///
6350 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCDate)
6351 #[wasm_bindgen(method, js_name = setUTCDate)]
6352 pub fn set_utc_date(this: &Date, day: u32) -> f64;
6353
6354 /// The `setUTCFullYear()` method sets the full year for a specified date according to universal time.
6355 ///
6356 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCFullYear)
6357 #[wasm_bindgen(method, js_name = setUTCFullYear)]
6358 pub fn set_utc_full_year(this: &Date, year: u32) -> f64;
6359
6360 /// The `setUTCFullYear()` method sets the full year for a specified date according to universal time.
6361 ///
6362 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCFullYear)
6363 #[wasm_bindgen(method, js_name = setUTCFullYear)]
6364 pub fn set_utc_full_year_with_month(this: &Date, year: u32, month: i32) -> f64;
6365
6366 /// The `setUTCFullYear()` method sets the full year for a specified date according to universal time.
6367 ///
6368 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCFullYear)
6369 #[wasm_bindgen(method, js_name = setUTCFullYear)]
6370 pub fn set_utc_full_year_with_month_date(this: &Date, year: u32, month: i32, date: i32) -> f64;
6371
6372 /// The `setUTCHours()` method sets the hour for a specified date according to universal time,
6373 /// and returns the number of milliseconds since January 1, 1970 00:00:00 UTC until the time
6374 /// represented by the updated Date instance.
6375 ///
6376 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCHours)
6377 #[wasm_bindgen(method, js_name = setUTCHours)]
6378 pub fn set_utc_hours(this: &Date, hours: u32) -> f64;
6379
6380 /// The `setUTCMilliseconds()` method sets the milliseconds for a specified date
6381 /// according to universal time.
6382 ///
6383 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCMilliseconds)
6384 #[wasm_bindgen(method, js_name = setUTCMilliseconds)]
6385 pub fn set_utc_milliseconds(this: &Date, milliseconds: u32) -> f64;
6386
6387 /// The `setUTCMinutes()` method sets the minutes for a specified date according to universal time.
6388 ///
6389 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCMinutes)
6390 #[wasm_bindgen(method, js_name = setUTCMinutes)]
6391 pub fn set_utc_minutes(this: &Date, minutes: u32) -> f64;
6392
6393 /// The `setUTCMonth()` method sets the month for a specified date according to universal time.
6394 ///
6395 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCMonth)
6396 #[wasm_bindgen(method, js_name = setUTCMonth)]
6397 pub fn set_utc_month(this: &Date, month: u32) -> f64;
6398
6399 /// The `setUTCSeconds()` method sets the seconds for a specified date according to universal time.
6400 ///
6401 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCSeconds)
6402 #[wasm_bindgen(method, js_name = setUTCSeconds)]
6403 pub fn set_utc_seconds(this: &Date, seconds: u32) -> f64;
6404
6405 /// The `toDateString()` method returns the date portion of a Date object
6406 /// in human readable form in American English.
6407 ///
6408 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toDateString)
6409 #[wasm_bindgen(method, js_name = toDateString)]
6410 pub fn to_date_string(this: &Date) -> JsString;
6411
6412 /// The `toISOString()` method returns a string in simplified extended ISO format (ISO
6413 /// 8601), which is always 24 or 27 characters long (YYYY-MM-DDTHH:mm:ss.sssZ or
6414 /// ±YYYYYY-MM-DDTHH:mm:ss.sssZ, respectively). The timezone is always zero UTC offset,
6415 /// as denoted by the suffix "Z"
6416 ///
6417 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString)
6418 #[wasm_bindgen(method, js_name = toISOString)]
6419 pub fn to_iso_string(this: &Date) -> JsString;
6420
6421 /// The `toJSON()` method returns a string representation of the Date object.
6422 ///
6423 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toJSON)
6424 #[wasm_bindgen(method, js_name = toJSON)]
6425 pub fn to_json(this: &Date) -> JsString;
6426
6427 /// The `toLocaleDateString()` method returns a string with a language sensitive
6428 /// representation of the date portion of this date. The new locales and options
6429 /// arguments let applications specify the language whose formatting conventions
6430 /// should be used and allow to customize the behavior of the function.
6431 /// In older implementations, which ignore the locales and options arguments,
6432 /// the locale used and the form of the string
6433 /// returned are entirely implementation dependent.
6434 ///
6435 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString)
6436 #[cfg(not(js_sys_unstable_apis))]
6437 #[wasm_bindgen(method, js_name = toLocaleDateString)]
6438 pub fn to_locale_date_string(this: &Date, locale: &str, options: &JsValue) -> JsString;
6439
6440 /// The `toLocaleDateString()` method returns a string with a language sensitive
6441 /// representation of the date portion of this date.
6442 ///
6443 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString)
6444 #[cfg(js_sys_unstable_apis)]
6445 #[wasm_bindgen(method, js_name = toLocaleDateString)]
6446 pub fn to_locale_date_string(
6447 this: &Date,
6448 locales: &[JsString],
6449 options: &Intl::DateTimeFormatOptions,
6450 ) -> JsString;
6451
6452 /// The `toLocaleString()` method returns a string with a language sensitive
6453 /// representation of this date. The new locales and options arguments
6454 /// let applications specify the language whose formatting conventions
6455 /// should be used and customize the behavior of the function.
6456 /// In older implementations, which ignore the locales
6457 /// and options arguments, the locale used and the form of the string
6458 /// returned are entirely implementation dependent.
6459 ///
6460 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString)
6461 #[cfg(not(js_sys_unstable_apis))]
6462 #[wasm_bindgen(method, js_name = toLocaleString)]
6463 pub fn to_locale_string(this: &Date, locale: &str, options: &JsValue) -> JsString;
6464
6465 /// The `toLocaleString()` method returns a string with a language sensitive
6466 /// representation of this date.
6467 ///
6468 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString)
6469 #[cfg(js_sys_unstable_apis)]
6470 #[wasm_bindgen(method, js_name = toLocaleString)]
6471 pub fn to_locale_string(
6472 this: &Date,
6473 locales: &[JsString],
6474 options: &Intl::DateTimeFormatOptions,
6475 ) -> JsString;
6476
6477 /// The `toLocaleTimeString()` method returns a string with a language sensitive
6478 /// representation of the time portion of this date. The new locales and options
6479 /// arguments let applications specify the language whose formatting conventions should be
6480 /// used and customize the behavior of the function. In older implementations, which ignore
6481 /// the locales and options arguments, the locale used and the form of the string
6482 /// returned are entirely implementation dependent.
6483 ///
6484 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleTimeString)
6485 #[cfg(not(js_sys_unstable_apis))]
6486 #[wasm_bindgen(method, js_name = toLocaleTimeString)]
6487 pub fn to_locale_time_string(this: &Date, locale: &str) -> JsString;
6488
6489 /// The `toLocaleTimeString()` method returns a string with a language sensitive
6490 /// representation of the time portion of this date.
6491 ///
6492 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleTimeString)
6493 #[cfg(js_sys_unstable_apis)]
6494 #[wasm_bindgen(method, js_name = toLocaleTimeString)]
6495 pub fn to_locale_time_string(
6496 this: &Date,
6497 locales: &[JsString],
6498 options: &Intl::DateTimeFormatOptions,
6499 ) -> JsString;
6500
6501 #[cfg(not(js_sys_unstable_apis))]
6502 #[wasm_bindgen(method, js_name = toLocaleTimeString)]
6503 pub fn to_locale_time_string_with_options(
6504 this: &Date,
6505 locale: &str,
6506 options: &JsValue,
6507 ) -> JsString;
6508
6509 /// The `toString()` method returns a string representing
6510 /// the specified Date object.
6511 ///
6512 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toString)
6513 #[cfg(not(js_sys_unstable_apis))]
6514 #[wasm_bindgen(method, js_name = toString)]
6515 pub fn to_string(this: &Date) -> JsString;
6516
6517 /// The `toTimeString()` method returns the time portion of a Date object in human
6518 /// readable form in American English.
6519 ///
6520 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toTimeString)
6521 #[wasm_bindgen(method, js_name = toTimeString)]
6522 pub fn to_time_string(this: &Date) -> JsString;
6523
6524 /// The `toUTCString()` method converts a date to a string,
6525 /// using the UTC time zone.
6526 ///
6527 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toUTCString)
6528 #[wasm_bindgen(method, js_name = toUTCString)]
6529 pub fn to_utc_string(this: &Date) -> JsString;
6530
6531 /// The `Date.UTC()` method accepts the same parameters as the
6532 /// longest form of the constructor, and returns the number of
6533 /// milliseconds in a `Date` object since January 1, 1970,
6534 /// 00:00:00, universal time.
6535 ///
6536 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/UTC)
6537 #[wasm_bindgen(static_method_of = Date, js_name = UTC)]
6538 pub fn utc(year: f64, month: f64) -> f64;
6539
6540 /// The `valueOf()` method returns the primitive value of
6541 /// a Date object.
6542 ///
6543 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/valueOf)
6544 #[wasm_bindgen(method, js_name = valueOf)]
6545 pub fn value_of(this: &Date) -> f64;
6546
6547 /// The `toTemporalInstant()` method converts a legacy `Date` object to a
6548 /// `Temporal.Instant` object representing the same moment in time.
6549 ///
6550 /// This method is added by the Temporal proposal to facilitate migration
6551 /// from legacy `Date` to the new Temporal API.
6552 ///
6553 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toTemporalInstant)
6554 #[cfg(js_sys_unstable_apis)]
6555 #[wasm_bindgen(method, js_name = toTemporalInstant)]
6556 pub fn to_temporal_instant(this: &Date) -> Temporal::Instant;
6557}
6558
6559// Property Descriptor.
6560#[wasm_bindgen]
6561extern "C" {
6562 #[wasm_bindgen(extends = Object)]
6563 #[derive(Clone, Debug)]
6564 pub type PropertyDescriptor<T = JsValue>;
6565
6566 #[wasm_bindgen(method, getter = writable)]
6567 pub fn get_writable<T>(this: &PropertyDescriptor<T>) -> Option<bool>;
6568
6569 #[wasm_bindgen(method, setter = writable)]
6570 pub fn set_writable<T>(this: &PropertyDescriptor<T>, writable: bool);
6571
6572 #[wasm_bindgen(method, getter = enumerable)]
6573 pub fn get_enumerable<T>(this: &PropertyDescriptor<T>) -> Option<bool>;
6574
6575 #[wasm_bindgen(method, setter = enumerable)]
6576 pub fn set_enumerable<T>(this: &PropertyDescriptor<T>, enumerable: bool);
6577
6578 #[wasm_bindgen(method, getter = configurable)]
6579 pub fn get_configurable<T>(this: &PropertyDescriptor<T>) -> Option<bool>;
6580
6581 #[wasm_bindgen(method, setter = configurable)]
6582 pub fn set_configurable<T>(this: &PropertyDescriptor<T>, configurable: bool);
6583
6584 #[wasm_bindgen(method, getter = get)]
6585 pub fn get_get<T: JsGeneric>(this: &PropertyDescriptor<T>) -> Option<Function<fn() -> T>>;
6586
6587 #[wasm_bindgen(method, setter = get)]
6588 pub fn set_get<T: JsGeneric>(this: &PropertyDescriptor<T>, get: Function<fn() -> T>);
6589
6590 #[wasm_bindgen(method, getter = set)]
6591 pub fn get_set<T: JsGeneric>(
6592 this: &PropertyDescriptor<T>,
6593 ) -> Option<Function<fn(T) -> JsValue>>;
6594
6595 #[wasm_bindgen(method, setter = set)]
6596 pub fn set_set<T: JsGeneric>(this: &PropertyDescriptor<T>, set: Function<fn(T) -> JsValue>);
6597
6598 #[wasm_bindgen(method, getter = value)]
6599 pub fn get_value<T>(this: &PropertyDescriptor<T>) -> Option<T>;
6600
6601 #[wasm_bindgen(method, setter = value)]
6602 pub fn set_value<T>(this: &PropertyDescriptor<T>, value: &T);
6603}
6604
6605impl PropertyDescriptor {
6606 #[cfg(not(js_sys_unstable_apis))]
6607 pub fn new<T>() -> PropertyDescriptor<T> {
6608 JsCast::unchecked_into(Object::new())
6609 }
6610
6611 #[cfg(js_sys_unstable_apis)]
6612 pub fn new<T>() -> PropertyDescriptor<T> {
6613 JsCast::unchecked_into(Object::<JsValue>::new())
6614 }
6615
6616 #[cfg(not(js_sys_unstable_apis))]
6617 pub fn new_value<T: JsGeneric>(value: &T) -> PropertyDescriptor<T> {
6618 let desc: PropertyDescriptor<T> = JsCast::unchecked_into(Object::new());
6619 desc.set_value(value);
6620 desc
6621 }
6622
6623 #[cfg(js_sys_unstable_apis)]
6624 pub fn new_value<T: JsGeneric>(value: &T) -> PropertyDescriptor<T> {
6625 let desc: PropertyDescriptor<T> = JsCast::unchecked_into(Object::<JsValue>::new());
6626 desc.set_value(value);
6627 desc
6628 }
6629}
6630
6631impl Default for PropertyDescriptor {
6632 fn default() -> Self {
6633 PropertyDescriptor::new()
6634 }
6635}
6636
6637// Object.
6638#[wasm_bindgen]
6639extern "C" {
6640 #[wasm_bindgen(typescript_type = "object")]
6641 #[derive(Clone, Debug)]
6642 pub type Object<T = JsValue>;
6643
6644 // Next major: deprecate
6645 /// The `Object.assign()` method is used to copy the values of all enumerable
6646 /// own properties from one or more source objects to a target object. It
6647 /// will return the target object.
6648 ///
6649 /// **Note:** Consider using [`Object::try_assign`] to support error handling.
6650 ///
6651 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
6652 #[wasm_bindgen(static_method_of = Object)]
6653 pub fn assign<T>(target: &Object<T>, source: &Object<T>) -> Object<T>;
6654
6655 // Next major: deprecate
6656 /// The `Object.assign()` method is used to copy the values of all enumerable
6657 /// own properties from one or more source objects to a target object. It
6658 /// will return the target object.
6659 ///
6660 /// **Note:** Consider using [`Object::try_assign`] to support error handling.
6661 ///
6662 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
6663 #[wasm_bindgen(static_method_of = Object, js_name = assign, catch)]
6664 pub fn try_assign<T>(target: &Object<T>, source: &Object<T>) -> Result<Object<T>, JsValue>;
6665
6666 /// The `Object.assign()` method is used to copy the values of all enumerable
6667 /// own properties from one or more source objects to a target object. It
6668 /// will return the target object.
6669 ///
6670 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
6671 #[cfg(not(js_sys_unstable_apis))]
6672 #[wasm_bindgen(static_method_of = Object, js_name = assign)]
6673 #[deprecated(note = "use `assign_many` for arbitrary assign arguments instead")]
6674 #[allow(deprecated)]
6675 pub fn assign2<T>(target: &Object<T>, source1: &Object<T>, source2: &Object<T>) -> Object<T>;
6676
6677 /// The `Object.assign()` method is used to copy the values of all enumerable
6678 /// own properties from one or more source objects to a target object. It
6679 /// will return the target object.
6680 ///
6681 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
6682 #[cfg(not(js_sys_unstable_apis))]
6683 #[wasm_bindgen(static_method_of = Object, js_name = assign)]
6684 #[deprecated(note = "use `assign_many` for arbitrary assign arguments instead")]
6685 #[allow(deprecated)]
6686 pub fn assign3<T>(
6687 target: &Object<T>,
6688 source1: &Object<T>,
6689 source2: &Object<T>,
6690 source3: &Object<T>,
6691 ) -> Object<T>;
6692
6693 /// The `Object.assign()` method is used to copy the values of all enumerable
6694 /// own properties from one or more source objects to a target object. It
6695 /// will return the target object.
6696 ///
6697 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
6698 #[wasm_bindgen(static_method_of = Object, js_name = assign, catch, variadic)]
6699 pub fn assign_many<T>(target: &Object<T>, sources: &[Object<T>]) -> Result<Object<T>, JsValue>;
6700
6701 /// The constructor property returns a reference to the `Object` constructor
6702 /// function that created the instance object.
6703 ///
6704 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/constructor)
6705 #[wasm_bindgen(method, getter)]
6706 pub fn constructor<T>(this: &Object<T>) -> Function;
6707
6708 /// The `Object.create()` method creates a new object, using an existing
6709 /// object to provide the newly created object's prototype.
6710 ///
6711 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/create)
6712 #[wasm_bindgen(static_method_of = Object)]
6713 pub fn create<T>(prototype: &Object<T>) -> Object<T>;
6714
6715 /// The static method `Object.defineProperty()` defines a new
6716 /// property directly on an object, or modifies an existing
6717 /// property on an object, and returns the object.
6718 ///
6719 /// **Note:** Consider using [`Object::define_property_str`] to support typing and error handling.
6720 ///
6721 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty)
6722 #[cfg(not(js_sys_unstable_apis))]
6723 #[wasm_bindgen(static_method_of = Object, js_name = defineProperty)]
6724 pub fn define_property<T>(obj: &Object<T>, prop: &JsValue, descriptor: &Object) -> Object<T>;
6725
6726 /// The static method `Object.defineProperty()` defines a new
6727 /// property directly on an object, or modifies an existing
6728 /// property on an object, and returns the object.
6729 ///
6730 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty)
6731 #[cfg(js_sys_unstable_apis)]
6732 #[wasm_bindgen(static_method_of = Object, js_name = defineProperty, catch)]
6733 pub fn define_property<T>(
6734 obj: &Object<T>,
6735 prop: &JsString,
6736 descriptor: &PropertyDescriptor<T>,
6737 ) -> Result<Object<T>, JsValue>;
6738
6739 // Next major: deprecate
6740 /// The static method `Object.defineProperty()` defines a new
6741 /// property directly on an object, or modifies an existing
6742 /// property on an object, and returns the object.
6743 ///
6744 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty)
6745 #[wasm_bindgen(static_method_of = Object, js_name = defineProperty, catch)]
6746 pub fn define_property_str<T>(
6747 obj: &Object<T>,
6748 prop: &JsString,
6749 descriptor: &PropertyDescriptor<T>,
6750 ) -> Result<Object<T>, JsValue>;
6751
6752 /// The static method `Object.defineProperty()` defines a new
6753 /// property directly on an object, or modifies an existing
6754 /// property on an object, and returns the object.
6755 ///
6756 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty)
6757 #[wasm_bindgen(static_method_of = Object, js_name = defineProperty, catch)]
6758 pub fn define_property_symbol<T>(
6759 obj: &Object<T>,
6760 prop: &Symbol,
6761 descriptor: &PropertyDescriptor<JsValue>,
6762 ) -> Result<Object<T>, JsValue>;
6763
6764 /// The `Object.defineProperties()` method defines new or modifies
6765 /// existing properties directly on an object, returning the
6766 /// object.
6767 ///
6768 /// **Note:** Consider using [`Object::try_define_properties`] to support typing and error handling.
6769 ///
6770 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperties)
6771 #[wasm_bindgen(static_method_of = Object, js_name = defineProperties)]
6772 pub fn define_properties<T>(obj: &Object<T>, props: &Object) -> Object<T>;
6773
6774 /// The `Object.defineProperties()` method defines new or modifies
6775 /// existing properties directly on an object, returning the
6776 /// object.
6777 ///
6778 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperties)
6779 #[cfg(js_sys_unstable_apis)]
6780 #[wasm_bindgen(static_method_of = Object, js_name = defineProperties, catch)]
6781 pub fn try_define_properties<T>(
6782 obj: &Object<T>,
6783 props: &Object<PropertyDescriptor<T>>,
6784 ) -> Result<Object<T>, JsValue>;
6785
6786 /// The `Object.entries()` method returns an array of a given
6787 /// object's own enumerable property [key, value] pairs, in the
6788 /// same order as that provided by a for...in loop (the difference
6789 /// being that a for-in loop enumerates properties in the
6790 /// prototype chain as well).
6791 ///
6792 /// **Note:** Consider using [`Object::entries_typed`] to support typing and error handling.
6793 ///
6794 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries)
6795 #[cfg(not(js_sys_unstable_apis))]
6796 #[wasm_bindgen(static_method_of = Object)]
6797 pub fn entries(object: &Object) -> Array;
6798
6799 /// The `Object.entries()` method returns an array of a given
6800 /// object's own enumerable property [key, value] pairs, in the
6801 /// same order as that provided by a for...in loop (the difference
6802 /// being that a for-in loop enumerates properties in the
6803 /// prototype chain as well).
6804 ///
6805 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries)
6806 #[cfg(js_sys_unstable_apis)]
6807 #[wasm_bindgen(static_method_of = Object, js_name = entries, catch)]
6808 pub fn entries<T: JsGeneric>(
6809 object: &Object<T>,
6810 ) -> Result<Array<ArrayTuple<(JsString, T)>>, JsValue>;
6811
6812 // Next major: deprecate
6813 /// The `Object.entries()` method returns an array of a given
6814 /// object's own enumerable property [key, value] pairs, in the
6815 /// same order as that provided by a for...in loop (the difference
6816 /// being that a for-in loop enumerates properties in the
6817 /// prototype chain as well).
6818 ///
6819 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries)
6820 #[wasm_bindgen(static_method_of = Object, js_name = entries, catch)]
6821 pub fn entries_typed<T: JsGeneric>(
6822 object: &Object<T>,
6823 ) -> Result<Array<ArrayTuple<(JsString, T)>>, JsValue>;
6824
6825 /// The `Object.freeze()` method freezes an object: that is, prevents new
6826 /// properties from being added to it; prevents existing properties from
6827 /// being removed; and prevents existing properties, or their enumerability,
6828 /// configurability, or writability, from being changed, it also prevents
6829 /// the prototype from being changed. The method returns the passed object.
6830 ///
6831 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze)
6832 #[wasm_bindgen(static_method_of = Object)]
6833 pub fn freeze<T>(value: &Object<T>) -> Object<T>;
6834
6835 /// The `Object.fromEntries()` method transforms a list of key-value pairs
6836 /// into an object.
6837 ///
6838 /// **Note:** Consider using [`Object::from_entries_typed`] to support typing and error handling.
6839 ///
6840 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/fromEntries)
6841 #[cfg(not(js_sys_unstable_apis))]
6842 #[wasm_bindgen(static_method_of = Object, catch, js_name = fromEntries)]
6843 pub fn from_entries(entries: &JsValue) -> Result<Object, JsValue>;
6844
6845 /// The `Object.fromEntries()` method transforms a list of key-value pairs
6846 /// into an object.
6847 ///
6848 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/fromEntries)
6849 #[cfg(js_sys_unstable_apis)]
6850 #[wasm_bindgen(static_method_of = Object, catch, js_name = fromEntries)]
6851 pub fn from_entries<T: JsGeneric, I: Iterable<Item = ArrayTuple<(JsString, T)>>>(
6852 entries: &I,
6853 ) -> Result<Object<T>, JsValue>;
6854
6855 // Next major: deprecate
6856 /// The `Object.fromEntries()` method transforms a list of key-value pairs
6857 /// into an object.
6858 ///
6859 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/fromEntries)
6860 #[wasm_bindgen(static_method_of = Object, catch, js_name = fromEntries)]
6861 pub fn from_entries_typed<T: JsGeneric, I: Iterable<Item = ArrayTuple<(JsString, T)>>>(
6862 entries: &I,
6863 ) -> Result<Object<T>, JsValue>;
6864
6865 /// The `Object.getOwnPropertyDescriptor()` method returns a
6866 /// property descriptor for an own property (that is, one directly
6867 /// present on an object and not in the object's prototype chain)
6868 /// of a given object.
6869 ///
6870 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor)
6871 #[cfg(not(js_sys_unstable_apis))]
6872 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptor)]
6873 pub fn get_own_property_descriptor<T>(obj: &Object<T>, prop: &JsValue) -> JsValue;
6874
6875 /// The `Object.getOwnPropertyDescriptor()` method returns a
6876 /// property descriptor for an own property (that is, one directly
6877 /// present on an object and not in the object's prototype chain)
6878 /// of a given object.
6879 ///
6880 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor)
6881 #[cfg(js_sys_unstable_apis)]
6882 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptor, catch)]
6883 pub fn get_own_property_descriptor<T>(
6884 obj: &Object<T>,
6885 prop: &JsString,
6886 ) -> Result<PropertyDescriptor<T>, JsValue>;
6887
6888 // Next major: deprecate
6889 /// The `Object.getOwnPropertyDescriptor()` method returns a
6890 /// property descriptor for an own property (that is, one directly
6891 /// present on an object and not in the object's prototype chain)
6892 /// of a given object.
6893 ///
6894 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor)
6895 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptor, catch)]
6896 pub fn get_own_property_descriptor_str<T>(
6897 obj: &Object<T>,
6898 prop: &JsString,
6899 ) -> Result<PropertyDescriptor<T>, JsValue>;
6900
6901 /// The `Object.getOwnPropertyDescriptor()` method returns a
6902 /// property descriptor for an own property (that is, one directly
6903 /// present on an object and not in the object's prototype chain)
6904 /// of a given object.
6905 ///
6906 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor)
6907 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptor, catch)]
6908 pub fn get_own_property_descriptor_symbol<T>(
6909 obj: &Object<T>,
6910 prop: &Symbol,
6911 ) -> Result<PropertyDescriptor<JsValue>, JsValue>;
6912
6913 /// The `Object.getOwnPropertyDescriptors()` method returns all own
6914 /// property descriptors of a given object.
6915 ///
6916 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptors)
6917 #[cfg(not(js_sys_unstable_apis))]
6918 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptors)]
6919 pub fn get_own_property_descriptors<T>(obj: &Object<T>) -> JsValue;
6920
6921 /// The `Object.getOwnPropertyDescriptors()` method returns all own
6922 /// property descriptors of a given object.
6923 ///
6924 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptors)
6925 #[cfg(js_sys_unstable_apis)]
6926 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptors, catch)]
6927 pub fn get_own_property_descriptors<T>(
6928 obj: &Object<T>,
6929 ) -> Result<Object<PropertyDescriptor<T>>, JsValue>;
6930
6931 /// The `Object.getOwnPropertyNames()` method returns an array of
6932 /// all properties (including non-enumerable properties except for
6933 /// those which use Symbol) found directly upon a given object.
6934 ///
6935 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyNames)
6936 #[cfg(not(js_sys_unstable_apis))]
6937 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyNames)]
6938 pub fn get_own_property_names<T>(obj: &Object<T>) -> Array;
6939
6940 /// The `Object.getOwnPropertyNames()` method returns an array of
6941 /// all properties (including non-enumerable properties except for
6942 /// those which use Symbol) found directly upon a given object.
6943 ///
6944 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyNames)
6945 #[cfg(js_sys_unstable_apis)]
6946 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyNames, catch)]
6947 pub fn get_own_property_names<T>(obj: &Object<T>) -> Result<Array<JsString>, JsValue>;
6948
6949 /// The `Object.getOwnPropertySymbols()` method returns an array of
6950 /// all symbol properties found directly upon a given object.
6951 ///
6952 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertySymbols)
6953 #[cfg(not(js_sys_unstable_apis))]
6954 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertySymbols)]
6955 pub fn get_own_property_symbols<T>(obj: &Object<T>) -> Array;
6956
6957 /// The `Object.getOwnPropertySymbols()` method returns an array of
6958 /// all symbol properties found directly upon a given object.
6959 ///
6960 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertySymbols)
6961 #[cfg(js_sys_unstable_apis)]
6962 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertySymbols, catch)]
6963 pub fn get_own_property_symbols<T>(obj: &Object<T>) -> Result<Array<Symbol>, JsValue>;
6964
6965 /// The `Object.getPrototypeOf()` method returns the prototype
6966 /// (i.e. the value of the internal [[Prototype]] property) of the
6967 /// specified object.
6968 ///
6969 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getPrototypeOf)
6970 #[wasm_bindgen(static_method_of = Object, js_name = getPrototypeOf)]
6971 pub fn get_prototype_of(obj: &JsValue) -> Object;
6972
6973 /// The `hasOwnProperty()` method returns a boolean indicating whether the
6974 /// object has the specified property as its own property (as opposed to
6975 /// inheriting it).
6976 ///
6977 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty)
6978 #[deprecated(note = "Use `Object::hasOwn` instead.")]
6979 #[allow(deprecated)]
6980 #[wasm_bindgen(method, js_name = hasOwnProperty)]
6981 pub fn has_own_property<T>(this: &Object<T>, property: &JsValue) -> bool;
6982
6983 /// The `Object.hasOwn()` method returns a boolean indicating whether the
6984 /// object passed in has the specified property as its own property (as
6985 /// opposed to inheriting it).
6986 ///
6987 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn)
6988 #[cfg(not(js_sys_unstable_apis))]
6989 #[wasm_bindgen(static_method_of = Object, js_name = hasOwn)]
6990 pub fn has_own<T>(instance: &Object<T>, property: &JsValue) -> bool;
6991
6992 /// The `Object.hasOwn()` method returns a boolean indicating whether the
6993 /// object passed in has the specified property as its own property (as
6994 /// opposed to inheriting it).
6995 ///
6996 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn)
6997 #[cfg(js_sys_unstable_apis)]
6998 #[wasm_bindgen(static_method_of = Object, js_name = hasOwn, catch)]
6999 pub fn has_own<T>(instance: &Object<T>, property: &JsString) -> Result<bool, JsValue>;
7000
7001 // Next major: deprecate
7002 /// The `Object.hasOwn()` method returns a boolean indicating whether the
7003 /// object passed in has the specified property as its own property (as
7004 /// opposed to inheriting it).
7005 ///
7006 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn)
7007 #[wasm_bindgen(static_method_of = Object, js_name = hasOwn, catch)]
7008 pub fn has_own_str<T>(instance: &Object<T>, property: &JsString) -> Result<bool, JsValue>;
7009
7010 /// The `Object.hasOwn()` method returns a boolean indicating whether the
7011 /// object passed in has the specified property as its own property (as
7012 /// opposed to inheriting it).
7013 ///
7014 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn)
7015 #[wasm_bindgen(static_method_of = Object, js_name = hasOwn, catch)]
7016 pub fn has_own_symbol<T>(instance: &Object<T>, property: &Symbol) -> Result<bool, JsValue>;
7017
7018 /// The `Object.is()` method determines whether two values are the same value.
7019 ///
7020 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is)
7021 #[wasm_bindgen(static_method_of = Object)]
7022 pub fn is(value1: &JsValue, value_2: &JsValue) -> bool;
7023
7024 /// The `Object.isExtensible()` method determines if an object is extensible
7025 /// (whether it can have new properties added to it).
7026 ///
7027 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isExtensible)
7028 #[wasm_bindgen(static_method_of = Object, js_name = isExtensible)]
7029 pub fn is_extensible<T>(object: &Object<T>) -> bool;
7030
7031 /// The `Object.isFrozen()` determines if an object is frozen.
7032 ///
7033 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isFrozen)
7034 #[wasm_bindgen(static_method_of = Object, js_name = isFrozen)]
7035 pub fn is_frozen<T>(object: &Object<T>) -> bool;
7036
7037 /// The `Object.isSealed()` method determines if an object is sealed.
7038 ///
7039 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isSealed)
7040 #[wasm_bindgen(static_method_of = Object, js_name = isSealed)]
7041 pub fn is_sealed<T>(object: &Object<T>) -> bool;
7042
7043 /// The `isPrototypeOf()` method checks if an object exists in another
7044 /// object's prototype chain.
7045 ///
7046 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isPrototypeOf)
7047 #[wasm_bindgen(method, js_name = isPrototypeOf)]
7048 pub fn is_prototype_of<T>(this: &Object<T>, value: &JsValue) -> bool;
7049
7050 /// The `Object.keys()` method returns an array of a given object's property
7051 /// names, in the same order as we get with a normal loop.
7052 ///
7053 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys)
7054 #[cfg(not(js_sys_unstable_apis))]
7055 #[wasm_bindgen(static_method_of = Object)]
7056 pub fn keys<T>(object: &Object<T>) -> Array;
7057
7058 /// The `Object.keys()` method returns an array of a given object's property
7059 /// names, in the same order as we get with a normal loop.
7060 ///
7061 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys)
7062 #[cfg(js_sys_unstable_apis)]
7063 #[wasm_bindgen(static_method_of = Object)]
7064 pub fn keys<T>(object: &Object<T>) -> Array<JsString>;
7065
7066 /// The [`Object`] constructor creates an object wrapper.
7067 ///
7068 /// **Note:** Consider using [`Object::new_typed`] for typed object records.
7069 ///
7070 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)
7071 #[wasm_bindgen(constructor)]
7072 pub fn new() -> Object;
7073
7074 // Next major: deprecate
7075 /// The [`Object`] constructor creates an object wrapper.
7076 ///
7077 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)
7078 #[wasm_bindgen(constructor)]
7079 pub fn new_typed<T>() -> Object<T>;
7080
7081 /// The `Object.preventExtensions()` method prevents new properties from
7082 /// ever being added to an object (i.e. prevents future extensions to the
7083 /// object).
7084 ///
7085 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/preventExtensions)
7086 #[wasm_bindgen(static_method_of = Object, js_name = preventExtensions)]
7087 pub fn prevent_extensions<T>(object: &Object<T>);
7088
7089 /// The `propertyIsEnumerable()` method returns a Boolean indicating
7090 /// whether the specified property is enumerable.
7091 ///
7092 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/propertyIsEnumerable)
7093 #[wasm_bindgen(method, js_name = propertyIsEnumerable)]
7094 pub fn property_is_enumerable<T>(this: &Object<T>, property: &JsValue) -> bool;
7095
7096 /// The `Object.seal()` method seals an object, preventing new properties
7097 /// from being added to it and marking all existing properties as
7098 /// non-configurable. Values of present properties can still be changed as
7099 /// long as they are writable.
7100 ///
7101 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/seal)
7102 #[wasm_bindgen(static_method_of = Object)]
7103 pub fn seal<T>(value: &Object<T>) -> Object<T>;
7104
7105 /// The `Object.setPrototypeOf()` method sets the prototype (i.e., the
7106 /// internal `[[Prototype]]` property) of a specified object to another
7107 /// object or `null`.
7108 ///
7109 /// **Note:** Consider using [`Object::try_set_prototype_of`] to support errors.
7110 ///
7111 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/setPrototypeOf)
7112 #[wasm_bindgen(static_method_of = Object, js_name = setPrototypeOf)]
7113 pub fn set_prototype_of<T>(object: &Object<T>, prototype: &Object) -> Object<T>;
7114
7115 /// The `Object.setPrototypeOf()` method sets the prototype (i.e., the
7116 /// internal `[[Prototype]]` property) of a specified object to another
7117 /// object or `null`.
7118 ///
7119 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/setPrototypeOf)
7120 #[wasm_bindgen(static_method_of = Object, js_name = setPrototypeOf, catch)]
7121 pub fn try_set_prototype_of<T>(
7122 object: &Object<T>,
7123 prototype: &Object,
7124 ) -> Result<Object<T>, JsValue>;
7125
7126 /// The `toLocaleString()` method returns a string representing the object.
7127 /// This method is meant to be overridden by derived objects for
7128 /// locale-specific purposes.
7129 ///
7130 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toLocaleString)
7131 #[wasm_bindgen(method, js_name = toLocaleString)]
7132 pub fn to_locale_string<T>(this: &Object<T>) -> JsString;
7133
7134 // Next major: deprecate
7135 /// The `toString()` method returns a string representing the object.
7136 ///
7137 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString)
7138 #[wasm_bindgen(method, js_name = toString)]
7139 pub fn to_string<T>(this: &Object<T>) -> JsString;
7140
7141 /// The `toString()` method returns a string representing the object.
7142 ///
7143 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString)
7144 #[wasm_bindgen(method, js_name = toString)]
7145 pub fn to_js_string<T>(this: &Object<T>) -> JsString;
7146
7147 /// The `valueOf()` method returns the primitive value of the
7148 /// specified object.
7149 ///
7150 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf)
7151 #[wasm_bindgen(method, js_name = valueOf)]
7152 pub fn value_of<T>(this: &Object<T>) -> Object;
7153
7154 /// The `Object.values()` method returns an array of a given object's own
7155 /// enumerable property values, in the same order as that provided by a
7156 /// `for...in` loop (the difference being that a for-in loop enumerates
7157 /// properties in the prototype chain as well).
7158 ///
7159 /// **Note:** Consider using [`Object::try_values`] to support errors.
7160 ///
7161 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values)
7162 #[cfg(not(js_sys_unstable_apis))]
7163 #[wasm_bindgen(static_method_of = Object)]
7164 pub fn values<T>(object: &Object<T>) -> Array<T>;
7165
7166 /// The `Object.values()` method returns an array of a given object's own
7167 /// enumerable property values, in the same order as that provided by a
7168 /// `for...in` loop (the difference being that a for-in loop enumerates
7169 /// properties in the prototype chain as well).
7170 ///
7171 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values)
7172 #[cfg(js_sys_unstable_apis)]
7173 #[wasm_bindgen(static_method_of = Object, catch, js_name = values)]
7174 pub fn values<T>(object: &Object<T>) -> Result<Array<T>, JsValue>;
7175
7176 // Next major: deprecate
7177 /// The `Object.values()` method returns an array of a given object's own
7178 /// enumerable property values, in the same order as that provided by a
7179 /// `for...in` loop (the difference being that a for-in loop enumerates
7180 /// properties in the prototype chain as well).
7181 ///
7182 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values)
7183 #[cfg(not(js_sys_unstable_apis))]
7184 #[wasm_bindgen(static_method_of = Object, catch, js_name = values)]
7185 pub fn try_values<T>(object: &Object<T>) -> Result<Array<T>, JsValue>;
7186}
7187
7188impl Object {
7189 /// Returns the `Object` value of this JS value if it's an instance of an
7190 /// object.
7191 ///
7192 /// If this JS value is not an instance of an object then this returns
7193 /// `None`.
7194 pub fn try_from(val: &JsValue) -> Option<&Object> {
7195 if val.is_object() {
7196 Some(val.unchecked_ref())
7197 } else {
7198 None
7199 }
7200 }
7201}
7202
7203impl PartialEq for Object {
7204 #[inline]
7205 fn eq(&self, other: &Object) -> bool {
7206 Object::is(self.as_ref(), other.as_ref())
7207 }
7208}
7209
7210impl Eq for Object {}
7211
7212impl Default for Object<JsValue> {
7213 fn default() -> Self {
7214 Self::new()
7215 }
7216}
7217
7218// Proxy
7219#[wasm_bindgen]
7220extern "C" {
7221 #[wasm_bindgen(typescript_type = "ProxyConstructor")]
7222 #[derive(Clone, Debug)]
7223 pub type Proxy;
7224
7225 /// The [`Proxy`] object is used to define custom behavior for fundamental
7226 /// operations (e.g. property lookup, assignment, enumeration, function
7227 /// invocation, etc).
7228 ///
7229 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy)
7230 #[wasm_bindgen(constructor)]
7231 pub fn new(target: &JsValue, handler: &Object) -> Proxy;
7232
7233 /// The `Proxy.revocable()` method is used to create a revocable [`Proxy`]
7234 /// object.
7235 ///
7236 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy/revocable)
7237 #[wasm_bindgen(static_method_of = Proxy)]
7238 pub fn revocable(target: &JsValue, handler: &Object) -> Object;
7239}
7240
7241// RangeError
7242#[wasm_bindgen]
7243extern "C" {
7244 /// The `RangeError` object indicates an error when a value is not in the set
7245 /// or range of allowed values.
7246 ///
7247 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError)
7248 #[wasm_bindgen(extends = Error, extends = Object, typescript_type = "RangeError")]
7249 #[derive(Clone, Debug, PartialEq, Eq)]
7250 pub type RangeError;
7251
7252 /// The `RangeError` object indicates an error when a value is not in the set
7253 /// or range of allowed values.
7254 ///
7255 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError)
7256 #[wasm_bindgen(constructor)]
7257 pub fn new(message: &str) -> RangeError;
7258}
7259
7260// ReferenceError
7261#[wasm_bindgen]
7262extern "C" {
7263 /// The `ReferenceError` object represents an error when a non-existent
7264 /// variable is referenced.
7265 ///
7266 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError)
7267 #[wasm_bindgen(extends = Error, extends = Object, typescript_type = "ReferenceError")]
7268 #[derive(Clone, Debug, PartialEq, Eq)]
7269 pub type ReferenceError;
7270
7271 /// The `ReferenceError` object represents an error when a non-existent
7272 /// variable is referenced.
7273 ///
7274 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError)
7275 #[wasm_bindgen(constructor)]
7276 pub fn new(message: &str) -> ReferenceError;
7277}
7278
7279#[allow(non_snake_case)]
7280pub mod Reflect {
7281 use super::*;
7282
7283 // Reflect
7284 #[wasm_bindgen]
7285 extern "C" {
7286 /// The static `Reflect.apply()` method calls a target function with
7287 /// arguments as specified.
7288 ///
7289 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/apply)
7290 #[wasm_bindgen(js_namespace = Reflect, catch)]
7291 pub fn apply<T: JsFunction = fn() -> JsValue>(
7292 target: &Function<T>,
7293 this_argument: &JsValue,
7294 arguments_list: &Array,
7295 ) -> Result<<T as JsFunction>::Ret, JsValue>;
7296
7297 /// The static `Reflect.construct()` method acts like the new operator, but
7298 /// as a function. It is equivalent to calling `new target(...args)`. It
7299 /// gives also the added option to specify a different prototype.
7300 ///
7301 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/construct)
7302 #[cfg(not(js_sys_unstable_apis))]
7303 #[wasm_bindgen(js_namespace = Reflect, catch)]
7304 pub fn construct<T: JsFunction = fn() -> JsValue>(
7305 target: &Function<T>,
7306 arguments_list: &Array,
7307 ) -> Result<JsValue, JsValue>;
7308
7309 /// The static `Reflect.construct()` method acts like the new operator, but
7310 /// as a function. It is equivalent to calling `new target(...args)`. It
7311 /// gives also the added option to specify a different prototype.
7312 ///
7313 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/construct)
7314 #[cfg(js_sys_unstable_apis)]
7315 #[wasm_bindgen(js_namespace = Reflect, catch)]
7316 pub fn construct<T: JsFunction = fn() -> JsValue>(
7317 target: &Function<T>,
7318 arguments_list: &ArrayTuple, // DOTO: <A1, A2, A3, A4, A5, A6, A7, A8>,
7319 ) -> Result<JsValue, JsValue>;
7320
7321 /// The static `Reflect.construct()` method acts like the new operator, but
7322 /// as a function. It is equivalent to calling `new target(...args)`. It
7323 /// gives also the added option to specify a different prototype.
7324 ///
7325 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/construct)
7326 #[wasm_bindgen(js_namespace = Reflect, js_name = construct, catch)]
7327 pub fn construct_with_new_target(
7328 target: &Function,
7329 arguments_list: &Array,
7330 new_target: &Function,
7331 ) -> Result<JsValue, JsValue>;
7332
7333 /// The static `Reflect.defineProperty()` method is like
7334 /// `Object.defineProperty()` but returns a `Boolean`.
7335 ///
7336 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/defineProperty)
7337 #[cfg(not(js_sys_unstable_apis))]
7338 #[wasm_bindgen(js_namespace = Reflect, js_name = defineProperty, catch)]
7339 pub fn define_property<T>(
7340 target: &Object<T>,
7341 property_key: &JsValue,
7342 attributes: &Object,
7343 ) -> Result<bool, JsValue>;
7344
7345 /// The static `Reflect.defineProperty()` method is like
7346 /// `Object.defineProperty()` but returns a `Boolean`.
7347 ///
7348 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/defineProperty)
7349 #[cfg(js_sys_unstable_apis)]
7350 #[wasm_bindgen(js_namespace = Reflect, js_name = defineProperty, catch)]
7351 pub fn define_property<T>(
7352 target: &Object<T>,
7353 property_key: &JsValue,
7354 attributes: &PropertyDescriptor<T>,
7355 ) -> Result<bool, JsValue>;
7356
7357 /// The static `Reflect.defineProperty()` method is like
7358 /// `Object.defineProperty()` but returns a `Boolean`.
7359 ///
7360 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/defineProperty)
7361 #[wasm_bindgen(js_namespace = Reflect, js_name = defineProperty, catch)]
7362 pub fn define_property_str<T>(
7363 target: &Object<T>,
7364 property_key: &JsString,
7365 attributes: &PropertyDescriptor<T>,
7366 ) -> Result<bool, JsValue>;
7367
7368 /// The static `Reflect.deleteProperty()` method allows to delete
7369 /// properties. It is like the `delete` operator as a function.
7370 ///
7371 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/deleteProperty)
7372 #[wasm_bindgen(js_namespace = Reflect, js_name = deleteProperty, catch)]
7373 pub fn delete_property<T>(target: &Object<T>, key: &JsValue) -> Result<bool, JsValue>;
7374
7375 /// The static `Reflect.deleteProperty()` method allows to delete
7376 /// properties. It is like the `delete` operator as a function.
7377 ///
7378 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/deleteProperty)
7379 #[wasm_bindgen(js_namespace = Reflect, js_name = deleteProperty, catch)]
7380 pub fn delete_property_str<T>(target: &Object<T>, key: &JsString) -> Result<bool, JsValue>;
7381
7382 /// The static `Reflect.get()` method works like getting a property from
7383 /// an object (`target[propertyKey]`) as a function.
7384 ///
7385 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/get)
7386 #[cfg(not(js_sys_unstable_apis))]
7387 #[wasm_bindgen(js_namespace = Reflect, catch)]
7388 pub fn get(target: &JsValue, key: &JsValue) -> Result<JsValue, JsValue>;
7389
7390 /// The static `Reflect.get()` method works like getting a property from
7391 /// an object (`target[propertyKey]`) as a function.
7392 ///
7393 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/get)
7394 #[cfg(js_sys_unstable_apis)]
7395 #[wasm_bindgen(js_namespace = Reflect, catch)]
7396 pub fn get<T>(target: &Object<T>, key: &JsString) -> Result<Option<T>, JsValue>;
7397
7398 /// The static `Reflect.get()` method works like getting a property from
7399 /// an object (`target[propertyKey]`) as a function.
7400 ///
7401 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/get)
7402 #[wasm_bindgen(js_namespace = Reflect, js_name = get, catch)]
7403 pub fn get_str<T>(target: &Object<T>, key: &JsString) -> Result<Option<T>, JsValue>;
7404
7405 /// The static `Reflect.get()` method works like getting a property from
7406 /// an object (`target[propertyKey]`) as a function.
7407 ///
7408 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/get)
7409 #[wasm_bindgen(js_namespace = Reflect, js_name = get, catch)]
7410 pub fn get_symbol<T>(target: &Object<T>, key: &Symbol) -> Result<JsValue, JsValue>;
7411
7412 /// The same as [`get`](fn.get.html)
7413 /// except the key is an `f64`, which is slightly faster.
7414 #[wasm_bindgen(js_namespace = Reflect, js_name = get, catch)]
7415 pub fn get_f64(target: &JsValue, key: f64) -> Result<JsValue, JsValue>;
7416
7417 /// The same as [`get`](fn.get.html)
7418 /// except the key is a `u32`, which is slightly faster.
7419 #[wasm_bindgen(js_namespace = Reflect, js_name = get, catch)]
7420 pub fn get_u32(target: &JsValue, key: u32) -> Result<JsValue, JsValue>;
7421
7422 /// The static `Reflect.getOwnPropertyDescriptor()` method is similar to
7423 /// `Object.getOwnPropertyDescriptor()`. It returns a property descriptor
7424 /// of the given property if it exists on the object, `undefined` otherwise.
7425 ///
7426 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getOwnPropertyDescriptor)
7427 #[wasm_bindgen(js_namespace = Reflect, js_name = getOwnPropertyDescriptor, catch)]
7428 pub fn get_own_property_descriptor<T>(
7429 target: &Object<T>,
7430 property_key: &JsValue,
7431 ) -> Result<JsValue, JsValue>;
7432
7433 /// The static `Reflect.getOwnPropertyDescriptor()` method is similar to
7434 /// `Object.getOwnPropertyDescriptor()`. It returns a property descriptor
7435 /// of the given property if it exists on the object, `undefined` otherwise.
7436 ///
7437 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getOwnPropertyDescriptor)
7438 #[wasm_bindgen(js_namespace = Reflect, js_name = getOwnPropertyDescriptor, catch)]
7439 pub fn get_own_property_descriptor_str<T>(
7440 target: &Object<T>,
7441 property_key: &JsString,
7442 ) -> Result<PropertyDescriptor<T>, JsValue>;
7443
7444 /// The static `Reflect.getPrototypeOf()` method is almost the same
7445 /// method as `Object.getPrototypeOf()`. It returns the prototype
7446 /// (i.e. the value of the internal `[[Prototype]]` property) of
7447 /// the specified object.
7448 ///
7449 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getPrototypeOf)
7450 #[cfg(not(js_sys_unstable_apis))]
7451 #[wasm_bindgen(js_namespace = Reflect, js_name = getPrototypeOf, catch)]
7452 pub fn get_prototype_of(target: &JsValue) -> Result<Object, JsValue>;
7453
7454 /// The static `Reflect.getPrototypeOf()` method is almost the same
7455 /// method as `Object.getPrototypeOf()`. It returns the prototype
7456 /// (i.e. the value of the internal `[[Prototype]]` property) of
7457 /// the specified object.
7458 ///
7459 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getPrototypeOf)
7460 #[cfg(js_sys_unstable_apis)]
7461 #[wasm_bindgen(js_namespace = Reflect, js_name = getPrototypeOf, catch)]
7462 pub fn get_prototype_of(target: &Object) -> Result<Object, JsValue>;
7463
7464 /// The static `Reflect.has()` method works like the in operator as a
7465 /// function.
7466 ///
7467 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/has)
7468 #[cfg(not(js_sys_unstable_apis))]
7469 #[wasm_bindgen(js_namespace = Reflect, catch)]
7470 pub fn has(target: &JsValue, property_key: &JsValue) -> Result<bool, JsValue>;
7471
7472 /// The static `Reflect.has()` method works like the in operator as a
7473 /// function.
7474 ///
7475 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/has)
7476 #[cfg(js_sys_unstable_apis)]
7477 #[wasm_bindgen(js_namespace = Reflect, catch)]
7478 pub fn has(target: &JsValue, property_key: &Symbol) -> Result<bool, JsValue>;
7479
7480 // Next major: deprecate
7481 /// The static `Reflect.has()` method works like the in operator as a
7482 /// function.
7483 ///
7484 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/has)
7485 #[wasm_bindgen(js_namespace = Reflect, js_name = has, catch)]
7486 pub fn has_str<T>(target: &Object<T>, property_key: &JsString) -> Result<bool, JsValue>;
7487
7488 /// The static `Reflect.has()` method works like the in operator as a
7489 /// function.
7490 ///
7491 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/has)
7492 #[wasm_bindgen(js_namespace = Reflect, js_name = has, catch)]
7493 pub fn has_symbol<T>(target: &Object<T>, property_key: &Symbol) -> Result<bool, JsValue>;
7494
7495 /// The static `Reflect.isExtensible()` method determines if an object is
7496 /// extensible (whether it can have new properties added to it). It is
7497 /// similar to `Object.isExtensible()`, but with some differences.
7498 ///
7499 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/isExtensible)
7500 #[wasm_bindgen(js_namespace = Reflect, js_name = isExtensible, catch)]
7501 pub fn is_extensible<T>(target: &Object<T>) -> Result<bool, JsValue>;
7502
7503 /// The static `Reflect.ownKeys()` method returns an array of the
7504 /// target object's own property keys.
7505 ///
7506 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/ownKeys)
7507 #[wasm_bindgen(js_namespace = Reflect, js_name = ownKeys, catch)]
7508 pub fn own_keys(target: &JsValue) -> Result<Array, JsValue>;
7509
7510 /// The static `Reflect.preventExtensions()` method prevents new
7511 /// properties from ever being added to an object (i.e. prevents
7512 /// future extensions to the object). It is similar to
7513 /// `Object.preventExtensions()`, but with some differences.
7514 ///
7515 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/preventExtensions)
7516 #[wasm_bindgen(js_namespace = Reflect, js_name = preventExtensions, catch)]
7517 pub fn prevent_extensions<T>(target: &Object<T>) -> Result<bool, JsValue>;
7518
7519 /// The static `Reflect.set()` method works like setting a
7520 /// property on an object.
7521 ///
7522 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
7523 #[cfg(not(js_sys_unstable_apis))]
7524 #[wasm_bindgen(js_namespace = Reflect, catch)]
7525 pub fn set(
7526 target: &JsValue,
7527 property_key: &JsValue,
7528 value: &JsValue,
7529 ) -> Result<bool, JsValue>;
7530
7531 /// The static `Reflect.set()` method works like setting a
7532 /// property on an object.
7533 ///
7534 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
7535 #[cfg(js_sys_unstable_apis)]
7536 #[wasm_bindgen(js_namespace = Reflect, catch)]
7537 pub fn set<T>(
7538 target: &Object<T>,
7539 property_key: &JsString,
7540 value: &T,
7541 ) -> Result<bool, JsValue>;
7542
7543 /// The static `Reflect.set()` method works like setting a
7544 /// property on an object.
7545 ///
7546 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
7547 #[cfg(js_sys_unstable_apis)]
7548 #[wasm_bindgen(js_namespace = Reflect, catch)]
7549 pub fn set_symbol<T>(
7550 target: &Object<T>,
7551 property_key: &Symbol,
7552 value: &JsValue,
7553 ) -> Result<bool, JsValue>;
7554
7555 // Next major: deprecate
7556 /// The static `Reflect.set()` method works like setting a
7557 /// property on an object.
7558 ///
7559 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
7560 #[wasm_bindgen(js_namespace = Reflect, js_name = set, catch)]
7561 pub fn set_str<T>(
7562 target: &Object<T>,
7563 property_key: &JsString,
7564 value: &T,
7565 ) -> Result<bool, JsValue>;
7566
7567 /// The same as [`set`](fn.set.html)
7568 /// except the key is an `f64`, which is slightly faster.
7569 #[wasm_bindgen(js_namespace = Reflect, js_name = set, catch)]
7570 pub fn set_f64(
7571 target: &JsValue,
7572 property_key: f64,
7573 value: &JsValue,
7574 ) -> Result<bool, JsValue>;
7575
7576 /// The same as [`set`](fn.set.html)
7577 /// except the key is a `u32`, which is slightly faster.
7578 #[wasm_bindgen(js_namespace = Reflect, js_name = set, catch)]
7579 pub fn set_u32(
7580 target: &JsValue,
7581 property_key: u32,
7582 value: &JsValue,
7583 ) -> Result<bool, JsValue>;
7584
7585 /// The static `Reflect.set()` method works like setting a
7586 /// property on an object.
7587 ///
7588 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
7589 #[wasm_bindgen(js_namespace = Reflect, js_name = set, catch)]
7590 pub fn set_with_receiver(
7591 target: &JsValue,
7592 property_key: &JsValue,
7593 value: &JsValue,
7594 receiver: &JsValue,
7595 ) -> Result<bool, JsValue>;
7596
7597 /// The static `Reflect.setPrototypeOf()` method is the same
7598 /// method as `Object.setPrototypeOf()`. It sets the prototype
7599 /// (i.e., the internal `[[Prototype]]` property) of a specified
7600 /// object to another object or to null.
7601 ///
7602 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/setPrototypeOf)
7603 #[wasm_bindgen(js_namespace = Reflect, js_name = setPrototypeOf, catch)]
7604 pub fn set_prototype_of<T>(
7605 target: &Object<T>,
7606 prototype: &JsValue,
7607 ) -> Result<bool, JsValue>;
7608 }
7609}
7610
7611// RegExp
7612#[wasm_bindgen]
7613extern "C" {
7614 #[wasm_bindgen(extends = Object, typescript_type = "RegExp")]
7615 #[derive(Clone, Debug, PartialEq, Eq)]
7616 pub type RegExp;
7617
7618 /// The `exec()` method executes a search for a match in a specified
7619 /// string. Returns a result array, or null.
7620 ///
7621 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec)
7622 #[cfg(not(js_sys_unstable_apis))]
7623 #[wasm_bindgen(method)]
7624 pub fn exec(this: &RegExp, text: &str) -> Option<Array<JsString>>;
7625
7626 /// The `exec()` method executes a search for a match in a specified
7627 /// string. Returns a result array, or null.
7628 ///
7629 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec)
7630 #[cfg(js_sys_unstable_apis)]
7631 #[wasm_bindgen(method)]
7632 pub fn exec(this: &RegExp, text: &str) -> Option<RegExpMatchArray>;
7633
7634 /// The flags property returns a string consisting of the flags of
7635 /// the current regular expression object.
7636 ///
7637 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/flags)
7638 #[wasm_bindgen(method, getter)]
7639 pub fn flags(this: &RegExp) -> JsString;
7640
7641 /// The global property indicates whether or not the "g" flag is
7642 /// used with the regular expression. global is a read-only
7643 /// property of an individual regular expression instance.
7644 ///
7645 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/global)
7646 #[wasm_bindgen(method, getter)]
7647 pub fn global(this: &RegExp) -> bool;
7648
7649 /// The ignoreCase property indicates whether or not the "i" flag
7650 /// is used with the regular expression. ignoreCase is a read-only
7651 /// property of an individual regular expression instance.
7652 ///
7653 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/ignoreCase)
7654 #[wasm_bindgen(method, getter, js_name = ignoreCase)]
7655 pub fn ignore_case(this: &RegExp) -> bool;
7656
7657 /// The non-standard input property is a static property of
7658 /// regular expressions that contains the string against which a
7659 /// regular expression is matched. RegExp.$_ is an alias for this
7660 /// property.
7661 ///
7662 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/input)
7663 #[wasm_bindgen(static_method_of = RegExp, getter)]
7664 pub fn input() -> JsString;
7665
7666 /// The lastIndex is a read/write integer property of regular expression
7667 /// instances that specifies the index at which to start the next match.
7668 ///
7669 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex)
7670 #[wasm_bindgen(structural, getter = lastIndex, method)]
7671 pub fn last_index(this: &RegExp) -> u32;
7672
7673 /// The lastIndex is a read/write integer property of regular expression
7674 /// instances that specifies the index at which to start the next match.
7675 ///
7676 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex)
7677 #[wasm_bindgen(structural, setter = lastIndex, method)]
7678 pub fn set_last_index(this: &RegExp, index: u32);
7679
7680 /// The non-standard lastMatch property is a static and read-only
7681 /// property of regular expressions that contains the last matched
7682 /// characters. `RegExp.$&` is an alias for this property.
7683 ///
7684 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastMatch)
7685 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = lastMatch)]
7686 pub fn last_match() -> JsString;
7687
7688 /// The non-standard lastParen property is a static and read-only
7689 /// property of regular expressions that contains the last
7690 /// parenthesized substring match, if any. `RegExp.$+` is an alias
7691 /// for this property.
7692 ///
7693 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastParen)
7694 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = lastParen)]
7695 pub fn last_paren() -> JsString;
7696
7697 /// The non-standard leftContext property is a static and
7698 /// read-only property of regular expressions that contains the
7699 /// substring preceding the most recent match. `RegExp.$`` is an
7700 /// alias for this property.
7701 ///
7702 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/leftContext)
7703 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = leftContext)]
7704 pub fn left_context() -> JsString;
7705
7706 /// The multiline property indicates whether or not the "m" flag
7707 /// is used with the regular expression. multiline is a read-only
7708 /// property of an individual regular expression instance.
7709 ///
7710 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/multiline)
7711 #[wasm_bindgen(method, getter)]
7712 pub fn multiline(this: &RegExp) -> bool;
7713
7714 /// The non-standard $1, $2, $3, $4, $5, $6, $7, $8, $9 properties
7715 /// are static and read-only properties of regular expressions
7716 /// that contain parenthesized substring matches.
7717 ///
7718 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/n)
7719 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$1")]
7720 pub fn n1() -> JsString;
7721 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$2")]
7722 pub fn n2() -> JsString;
7723 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$3")]
7724 pub fn n3() -> JsString;
7725 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$4")]
7726 pub fn n4() -> JsString;
7727 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$5")]
7728 pub fn n5() -> JsString;
7729 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$6")]
7730 pub fn n6() -> JsString;
7731 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$7")]
7732 pub fn n7() -> JsString;
7733 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$8")]
7734 pub fn n8() -> JsString;
7735 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$9")]
7736 pub fn n9() -> JsString;
7737
7738 /// The `RegExp` constructor creates a regular expression object for matching text with a pattern.
7739 ///
7740 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp)
7741 #[wasm_bindgen(constructor)]
7742 pub fn new(pattern: &str, flags: &str) -> RegExp;
7743 #[wasm_bindgen(constructor)]
7744 pub fn new_regexp(pattern: &RegExp, flags: &str) -> RegExp;
7745
7746 /// The non-standard rightContext property is a static and
7747 /// read-only property of regular expressions that contains the
7748 /// substring following the most recent match. `RegExp.$'` is an
7749 /// alias for this property.
7750 ///
7751 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/rightContext)
7752 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = rightContext)]
7753 pub fn right_context() -> JsString;
7754
7755 /// The source property returns a String containing the source
7756 /// text of the regexp object, and it doesn't contain the two
7757 /// forward slashes on both sides and any flags.
7758 ///
7759 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/source)
7760 #[wasm_bindgen(method, getter)]
7761 pub fn source(this: &RegExp) -> JsString;
7762
7763 /// The sticky property reflects whether or not the search is
7764 /// sticky (searches in strings only from the index indicated by
7765 /// the lastIndex property of this regular expression). sticky is
7766 /// a read-only property of an individual regular expression
7767 /// object.
7768 ///
7769 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/sticky)
7770 #[wasm_bindgen(method, getter)]
7771 pub fn sticky(this: &RegExp) -> bool;
7772
7773 /// The `test()` method executes a search for a match between a
7774 /// regular expression and a specified string. Returns true or
7775 /// false.
7776 ///
7777 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/test)
7778 #[wasm_bindgen(method)]
7779 pub fn test(this: &RegExp, text: &str) -> bool;
7780
7781 /// The `toString()` method returns a string representing the
7782 /// regular expression.
7783 ///
7784 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/toString)
7785 #[cfg(not(js_sys_unstable_apis))]
7786 #[wasm_bindgen(method, js_name = toString)]
7787 pub fn to_string(this: &RegExp) -> JsString;
7788
7789 /// The unicode property indicates whether or not the "u" flag is
7790 /// used with a regular expression. unicode is a read-only
7791 /// property of an individual regular expression instance.
7792 ///
7793 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/unicode)
7794 #[wasm_bindgen(method, getter)]
7795 pub fn unicode(this: &RegExp) -> bool;
7796}
7797
7798// RegExpMatchArray
7799#[wasm_bindgen]
7800extern "C" {
7801 /// The result array from `RegExp.exec()` or `String.matchAll()`.
7802 ///
7803 /// This is an array of strings with additional properties `index`, `input`, and `groups`.
7804 ///
7805 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec#return_value)
7806 #[wasm_bindgen(extends = Object, extends = Array, typescript_type = "RegExpMatchArray")]
7807 #[derive(Clone, Debug, PartialEq, Eq)]
7808 pub type RegExpMatchArray;
7809
7810 /// The 0-based index of the match in the string.
7811 #[wasm_bindgen(method, getter)]
7812 pub fn index(this: &RegExpMatchArray) -> u32;
7813
7814 /// The original string that was matched against.
7815 #[wasm_bindgen(method, getter)]
7816 pub fn input(this: &RegExpMatchArray) -> JsString;
7817
7818 /// An object of named capturing groups whose keys are the names and valuestype Array
7819 /// are the capturing groups, or `undefined` if no named capturing groups were defined.
7820 #[wasm_bindgen(method, getter)]
7821 pub fn groups(this: &RegExpMatchArray) -> Option<Object>;
7822
7823 /// The number of elements in the match array (full match + capture groups).
7824 #[wasm_bindgen(method, getter)]
7825 pub fn length(this: &RegExpMatchArray) -> u32;
7826
7827 /// Gets the matched string or capture group at the given index.
7828 /// Index 0 is the full match, indices 1+ are capture groups.
7829 #[wasm_bindgen(method, indexing_getter)]
7830 pub fn get(this: &RegExpMatchArray, index: u32) -> Option<JsString>;
7831}
7832
7833// Set
7834#[wasm_bindgen]
7835extern "C" {
7836 #[wasm_bindgen(extends = Object, typescript_type = "Set<any>")]
7837 #[derive(Clone, Debug, PartialEq, Eq)]
7838 pub type Set<T = JsValue>;
7839
7840 /// The [`Set`] object lets you store unique values of any type, whether
7841 /// primitive values or object references.
7842 ///
7843 /// **Note:** Consider using [`Set::new_typed`] to support typing.
7844 ///
7845 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
7846 #[cfg(not(js_sys_unstable_apis))]
7847 #[wasm_bindgen(constructor)]
7848 pub fn new(init: &JsValue) -> Set;
7849
7850 /// The [`Set`] object lets you store unique values of any type, whether
7851 /// primitive values or object references.
7852 ///
7853 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
7854 #[cfg(js_sys_unstable_apis)]
7855 #[wasm_bindgen(constructor)]
7856 pub fn new<T>() -> Set<T>;
7857
7858 // Next major: deprecate
7859 /// The [`Set`] object lets you store unique values of any type, whether
7860 /// primitive values or object references.
7861 ///
7862 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
7863 #[wasm_bindgen(constructor)]
7864 pub fn new_typed<T>() -> Set<T>;
7865
7866 /// The [`Set`] object lets you store unique values of any type, whether
7867 /// primitive values or object references.
7868 ///
7869 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
7870 #[wasm_bindgen(constructor, js_name = new)]
7871 pub fn new_empty<T>() -> Set<T>;
7872
7873 /// The [`Set`] object lets you store unique values of any type, whether
7874 /// primitive values or object references.
7875 ///
7876 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
7877 #[wasm_bindgen(constructor, js_name = new)]
7878 pub fn new_from_items<T>(items: &[T]) -> Set<T>;
7879
7880 /// The [`Set`] object lets you store unique values of any type, whether
7881 /// primitive values or object references.
7882 ///
7883 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
7884 #[wasm_bindgen(constructor, js_name = new, catch)]
7885 pub fn new_from_iterable<T, I: Iterable<Item = T>>(iterable: I) -> Result<Set<T>, JsValue>;
7886
7887 /// The `add()` method appends a new element with a specified value to the
7888 /// end of a [`Set`] object.
7889 ///
7890 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/add)
7891 #[wasm_bindgen(method)]
7892 pub fn add<T>(this: &Set<T>, value: &T) -> Set<T>;
7893
7894 /// The `clear()` method removes all elements from a [`Set`] object.
7895 ///
7896 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/clear)
7897 #[wasm_bindgen(method)]
7898 pub fn clear<T>(this: &Set<T>);
7899
7900 /// The `delete()` method removes the specified element from a [`Set`]
7901 /// object.
7902 ///
7903 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/delete)
7904 #[wasm_bindgen(method)]
7905 pub fn delete<T>(this: &Set<T>, value: &T) -> bool;
7906
7907 /// The `forEach()` method executes a provided function once for each value
7908 /// in the Set object, in insertion order.
7909 ///
7910 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/forEach)
7911 #[cfg(not(js_sys_unstable_apis))]
7912 #[wasm_bindgen(method, js_name = forEach)]
7913 pub fn for_each<T>(this: &Set<T>, callback: &mut dyn FnMut(T, T, Set<T>));
7914
7915 /// The `forEach()` method executes a provided function once for each value
7916 /// in the Set object, in insertion order.
7917 ///
7918 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/forEach)
7919 #[cfg(js_sys_unstable_apis)]
7920 #[wasm_bindgen(method, js_name = forEach)]
7921 pub fn for_each<T>(this: &Set<T>, callback: &mut dyn FnMut(T));
7922
7923 /// The `forEach()` method executes a provided function once for each value
7924 /// in the Set object, in insertion order.
7925 ///
7926 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/forEach)
7927 #[wasm_bindgen(method, js_name = forEach, catch)]
7928 pub fn try_for_each<T>(
7929 this: &Set<T>,
7930 callback: &mut dyn FnMut(T) -> Result<(), JsError>,
7931 ) -> Result<(), JsValue>;
7932
7933 /// The `has()` method returns a boolean indicating whether an element with
7934 /// the specified value exists in a [`Set`] object or not.
7935 ///
7936 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/has)
7937 #[wasm_bindgen(method)]
7938 pub fn has<T>(this: &Set<T>, value: &T) -> bool;
7939
7940 /// The size accessor property returns the number of elements in a [`Set`]
7941 /// object.
7942 ///
7943 /// [MDN documentation](https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Set/size)
7944 #[wasm_bindgen(method, getter)]
7945 pub fn size<T>(this: &Set<T>) -> u32;
7946
7947 /// The `union()` method returns a new set containing elements which are in
7948 /// either or both of this set and the given set.
7949 ///
7950 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/union)
7951 #[wasm_bindgen(method)]
7952 pub fn union<T>(this: &Set<T>, other: &Set<T>) -> Set<T>;
7953
7954 /// The `intersection()` method returns a new set containing elements which are
7955 /// in both this set and the given set.
7956 ///
7957 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/intersection)
7958 #[wasm_bindgen(method)]
7959 pub fn intersection<T>(this: &Set<T>, other: &Set<T>) -> Set<T>;
7960
7961 /// The `difference()` method returns a new set containing elements which are
7962 /// in this set but not in the given set.
7963 ///
7964 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/difference)
7965 #[wasm_bindgen(method)]
7966 pub fn difference<T>(this: &Set<T>, other: &Set<T>) -> Set<T>;
7967
7968 /// The `symmetricDifference()` method returns a new set containing elements
7969 /// which are in either this set or the given set, but not in both.
7970 ///
7971 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/symmetricDifference)
7972 #[wasm_bindgen(method, js_name = symmetricDifference)]
7973 pub fn symmetric_difference<T>(this: &Set<T>, other: &Set<T>) -> Set<T>;
7974
7975 /// The `isSubsetOf()` method returns a boolean indicating whether all elements
7976 /// of this set are in the given set.
7977 ///
7978 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/isSubsetOf)
7979 #[wasm_bindgen(method, js_name = isSubsetOf)]
7980 pub fn is_subset_of<T>(this: &Set<T>, other: &Set<T>) -> bool;
7981
7982 /// The `isSupersetOf()` method returns a boolean indicating whether all elements
7983 /// of the given set are in this set.
7984 ///
7985 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/isSupersetOf)
7986 #[wasm_bindgen(method, js_name = isSupersetOf)]
7987 pub fn is_superset_of<T>(this: &Set<T>, other: &Set<T>) -> bool;
7988
7989 /// The `isDisjointFrom()` method returns a boolean indicating whether this set
7990 /// has no elements in common with the given set.
7991 ///
7992 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/isDisjointFrom)
7993 #[wasm_bindgen(method, js_name = isDisjointFrom)]
7994 pub fn is_disjoint_from<T>(this: &Set<T>, other: &Set<T>) -> bool;
7995}
7996
7997impl Default for Set<JsValue> {
7998 fn default() -> Self {
7999 Self::new_typed()
8000 }
8001}
8002
8003impl<T> Iterable for Set<T> {
8004 type Item = T;
8005}
8006
8007// SetIterator
8008#[wasm_bindgen]
8009extern "C" {
8010 /// The `entries()` method returns a new Iterator object that contains an
8011 /// array of [value, value] for each element in the Set object, in insertion
8012 /// order. For Set objects there is no key like in Map objects. However, to
8013 /// keep the API similar to the Map object, each entry has the same value
8014 /// for its key and value here, so that an array [value, value] is returned.
8015 ///
8016 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/entries)
8017 #[cfg(not(js_sys_unstable_apis))]
8018 #[wasm_bindgen(method)]
8019 pub fn entries<T>(set: &Set<T>) -> Iterator;
8020
8021 /// The `entries()` method returns a new Iterator object that contains an
8022 /// array of [value, value] for each element in the Set object, in insertion
8023 /// order. For Set objects there is no key like in Map objects. However, to
8024 /// keep the API similar to the Map object, each entry has the same value
8025 /// for its key and value here, so that an array [value, value] is returned.
8026 ///
8027 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/entries)
8028 #[cfg(js_sys_unstable_apis)]
8029 #[wasm_bindgen(method, js_name = entries)]
8030 pub fn entries<T: JsGeneric>(set: &Set<T>) -> Iterator<ArrayTuple<(T, T)>>;
8031
8032 // Next major: deprecate
8033 /// The `entries()` method returns a new Iterator object that contains an
8034 /// array of [value, value] for each element in the Set object, in insertion
8035 /// order. For Set objects there is no key like in Map objects. However, to
8036 /// keep the API similar to the Map object, each entry has the same value
8037 /// for its key and value here, so that an array [value, value] is returned.
8038 ///
8039 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/entries)
8040 #[wasm_bindgen(method, js_name = entries)]
8041 pub fn entries_typed<T: JsGeneric>(set: &Set<T>) -> Iterator<ArrayTuple<(T, T)>>;
8042
8043 /// The `keys()` method is an alias for this method (for similarity with
8044 /// Map objects); it behaves exactly the same and returns values
8045 /// of Set elements.
8046 ///
8047 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/values)
8048 #[wasm_bindgen(method)]
8049 pub fn keys<T>(set: &Set<T>) -> Iterator<T>;
8050
8051 /// The `values()` method returns a new Iterator object that contains the
8052 /// values for each element in the Set object in insertion order.
8053 ///
8054 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/values)
8055 #[wasm_bindgen(method)]
8056 pub fn values<T>(set: &Set<T>) -> Iterator<T>;
8057}
8058
8059// SyntaxError
8060#[wasm_bindgen]
8061extern "C" {
8062 /// A `SyntaxError` is thrown when the JavaScript engine encounters tokens or
8063 /// token order that does not conform to the syntax of the language when
8064 /// parsing code.
8065 ///
8066 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError)
8067 #[wasm_bindgen(extends = Error, extends = Object, typescript_type = "SyntaxError")]
8068 #[derive(Clone, Debug, PartialEq, Eq)]
8069 pub type SyntaxError;
8070
8071 /// A `SyntaxError` is thrown when the JavaScript engine encounters tokens or
8072 /// token order that does not conform to the syntax of the language when
8073 /// parsing code.
8074 ///
8075 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError)
8076 #[wasm_bindgen(constructor)]
8077 pub fn new(message: &str) -> SyntaxError;
8078}
8079
8080// TypeError
8081#[wasm_bindgen]
8082extern "C" {
8083 /// The `TypeError` object represents an error when a value is not of the
8084 /// expected type.
8085 ///
8086 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError)
8087 #[wasm_bindgen(extends = Error, extends = Object, typescript_type = "TypeError")]
8088 #[derive(Clone, Debug, PartialEq, Eq)]
8089 pub type TypeError;
8090
8091 /// The `TypeError` object represents an error when a value is not of the
8092 /// expected type.
8093 ///
8094 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError)
8095 #[wasm_bindgen(constructor)]
8096 pub fn new(message: &str) -> TypeError;
8097}
8098
8099// URIError
8100#[wasm_bindgen]
8101extern "C" {
8102 /// The `URIError` object represents an error when a global URI handling
8103 /// function was used in a wrong way.
8104 ///
8105 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError)
8106 #[wasm_bindgen(extends = Error, extends = Object, js_name = URIError, typescript_type = "URIError")]
8107 #[derive(Clone, Debug, PartialEq, Eq)]
8108 pub type UriError;
8109
8110 /// The `URIError` object represents an error when a global URI handling
8111 /// function was used in a wrong way.
8112 ///
8113 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError)
8114 #[wasm_bindgen(constructor, js_class = "URIError")]
8115 pub fn new(message: &str) -> UriError;
8116}
8117
8118// WeakMap
8119#[wasm_bindgen]
8120extern "C" {
8121 #[wasm_bindgen(extends = Object, typescript_type = "WeakMap<object, any>")]
8122 #[derive(Clone, Debug, PartialEq, Eq)]
8123 pub type WeakMap<K = Object, V = JsValue>;
8124
8125 /// The [`WeakMap`] object is a collection of key/value pairs in which the
8126 /// keys are weakly referenced. The keys must be objects and the values can
8127 /// be arbitrary values.
8128 ///
8129 /// **Note:** Consider using [`WeakMap::new_typed`] to support typing.
8130 ///
8131 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap)
8132 #[cfg(not(js_sys_unstable_apis))]
8133 #[wasm_bindgen(constructor)]
8134 pub fn new() -> WeakMap;
8135
8136 /// The [`WeakMap`] object is a collection of key/value pairs in which the
8137 /// keys are weakly referenced. The keys must be objects and the values can
8138 /// be arbitrary values.
8139 ///
8140 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap)
8141 #[cfg(js_sys_unstable_apis)]
8142 #[wasm_bindgen(constructor)]
8143 pub fn new<K: JsGeneric = Object, V: JsGeneric = Object>() -> WeakMap<K, V>;
8144
8145 // Next major: deprecate
8146 /// The [`WeakMap`] object is a collection of key/value pairs in which the
8147 /// keys are weakly referenced. The keys must be objects and the values can
8148 /// be arbitrary values.
8149 ///
8150 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap)
8151 #[wasm_bindgen(constructor)]
8152 pub fn new_typed<K: JsGeneric = Object, V: JsGeneric = Object>() -> WeakMap<K, V>;
8153
8154 /// The `set()` method sets the value for the key in the [`WeakMap`] object.
8155 /// Returns the [`WeakMap`] object.
8156 ///
8157 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/set)
8158 #[wasm_bindgen(method, js_class = "WeakMap")]
8159 pub fn set<K, V>(this: &WeakMap<K, V>, key: &K, value: &V) -> WeakMap<K, V>;
8160
8161 /// The `get()` method returns a specified by key element
8162 /// from a [`WeakMap`] object. Returns `undefined` if the key is not found.
8163 ///
8164 /// **Note:** Consider using [`WeakMap::get_checked`] to get an `Option<V>` instead.
8165 ///
8166 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/get)
8167 #[cfg(not(js_sys_unstable_apis))]
8168 #[wasm_bindgen(method)]
8169 pub fn get<K, V>(this: &WeakMap<K, V>, key: &K) -> V;
8170
8171 /// The `get()` method returns a specified by key element
8172 /// from a [`WeakMap`] object. Returns `None` if the key is not found.
8173 ///
8174 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/get)
8175 #[cfg(js_sys_unstable_apis)]
8176 #[wasm_bindgen(method)]
8177 pub fn get<K, V>(this: &WeakMap<K, V>, key: &K) -> Option<V>;
8178
8179 /// The `get()` method returns a specified by key element
8180 /// from a [`WeakMap`] object. Returns `None` if the key is not found.
8181 ///
8182 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/get)
8183 #[wasm_bindgen(method, js_name = get)]
8184 pub fn get_checked<K, V>(this: &WeakMap<K, V>, key: &K) -> Option<V>;
8185
8186 /// The `has()` method returns a boolean indicating whether an element with
8187 /// the specified key exists in the [`WeakMap`] object or not.
8188 ///
8189 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/has)
8190 #[wasm_bindgen(method)]
8191 pub fn has<K, V>(this: &WeakMap<K, V>, key: &K) -> bool;
8192
8193 /// The `delete()` method removes the specified element from a [`WeakMap`]
8194 /// object.
8195 ///
8196 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/delete)
8197 #[wasm_bindgen(method)]
8198 pub fn delete<K, V>(this: &WeakMap<K, V>, key: &K) -> bool;
8199}
8200
8201impl Default for WeakMap {
8202 fn default() -> Self {
8203 Self::new()
8204 }
8205}
8206
8207// WeakSet
8208#[wasm_bindgen]
8209extern "C" {
8210 #[wasm_bindgen(extends = Object, typescript_type = "WeakSet<object>")]
8211 #[derive(Clone, Debug, PartialEq, Eq)]
8212 pub type WeakSet<T = Object>;
8213
8214 /// The `WeakSet` object lets you store weakly held objects in a collection.
8215 ///
8216 /// **Note:** Consider using [`WeakSet::new_typed`] for typed sets.
8217 ///
8218 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet)
8219 #[cfg(not(js_sys_unstable_apis))]
8220 #[wasm_bindgen(constructor)]
8221 pub fn new() -> WeakSet;
8222
8223 /// The `WeakSet` object lets you store weakly held objects in a collection.
8224 ///
8225 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet)
8226 #[cfg(js_sys_unstable_apis)]
8227 #[wasm_bindgen(constructor)]
8228 pub fn new<T = Object>() -> WeakSet<T>;
8229
8230 // Next major: deprecate
8231 /// The `WeakSet` object lets you store weakly held objects in a collection.
8232 ///
8233 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet)
8234 #[wasm_bindgen(constructor)]
8235 pub fn new_typed<T = Object>() -> WeakSet<T>;
8236
8237 /// The `has()` method returns a boolean indicating whether an object exists
8238 /// in a WeakSet or not.
8239 ///
8240 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet/has)
8241 #[wasm_bindgen(method)]
8242 pub fn has<T>(this: &WeakSet<T>, value: &T) -> bool;
8243
8244 /// The `add()` method appends a new object to the end of a WeakSet object.
8245 ///
8246 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet/add)
8247 #[wasm_bindgen(method)]
8248 pub fn add<T>(this: &WeakSet<T>, value: &T) -> WeakSet<T>;
8249
8250 /// The `delete()` method removes the specified element from a WeakSet
8251 /// object.
8252 ///
8253 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet/delete)
8254 #[wasm_bindgen(method)]
8255 pub fn delete<T>(this: &WeakSet<T>, value: &T) -> bool;
8256}
8257
8258impl Default for WeakSet {
8259 fn default() -> Self {
8260 Self::new()
8261 }
8262}
8263
8264// WeakRef
8265#[wasm_bindgen]
8266extern "C" {
8267 #[wasm_bindgen(extends = Object, typescript_type = "WeakRef<object>")]
8268 #[derive(Clone, Debug, PartialEq, Eq)]
8269 pub type WeakRef<T = Object>;
8270
8271 /// The `WeakRef` object contains a weak reference to an object. A weak
8272 /// reference to an object is a reference that does not prevent the object
8273 /// from being reclaimed by the garbage collector.
8274 ///
8275 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef)
8276 #[wasm_bindgen(constructor)]
8277 pub fn new<T = Object>(target: &T) -> WeakRef<T>;
8278
8279 /// Returns the `Object` this `WeakRef` points to, or `None` if the
8280 /// object has been garbage collected.
8281 ///
8282 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef/deref)
8283 #[wasm_bindgen(method)]
8284 pub fn deref<T>(this: &WeakRef<T>) -> Option<T>;
8285}
8286
8287#[cfg(js_sys_unstable_apis)]
8288#[allow(non_snake_case)]
8289pub mod Temporal;
8290
8291#[allow(non_snake_case)]
8292pub mod WebAssembly {
8293 use super::*;
8294
8295 // WebAssembly
8296 #[wasm_bindgen]
8297 extern "C" {
8298 /// The `WebAssembly.compile()` function compiles a `WebAssembly.Module`
8299 /// from WebAssembly binary code. This function is useful if it is
8300 /// necessary to a compile a module before it can be instantiated
8301 /// (otherwise, the `WebAssembly.instantiate()` function should be used).
8302 ///
8303 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compile)
8304 #[cfg(not(js_sys_unstable_apis))]
8305 #[wasm_bindgen(js_namespace = WebAssembly)]
8306 pub fn compile(buffer_source: &JsValue) -> Promise<JsValue>;
8307
8308 /// The `WebAssembly.compile()` function compiles a `WebAssembly.Module`
8309 /// from WebAssembly binary code. This function is useful if it is
8310 /// necessary to a compile a module before it can be instantiated
8311 /// (otherwise, the `WebAssembly.instantiate()` function should be used).
8312 ///
8313 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compile)
8314 #[cfg(js_sys_unstable_apis)]
8315 #[wasm_bindgen(js_namespace = WebAssembly)]
8316 pub fn compile(buffer_source: &JsValue) -> Promise<Module>;
8317
8318 /// The `WebAssembly.compileStreaming()` function compiles a
8319 /// `WebAssembly.Module` module directly from a streamed underlying
8320 /// source. This function is useful if it is necessary to a compile a
8321 /// module before it can be instantiated (otherwise, the
8322 /// `WebAssembly.instantiateStreaming()` function should be used).
8323 ///
8324 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compileStreaming)
8325 #[cfg(not(js_sys_unstable_apis))]
8326 #[wasm_bindgen(js_namespace = WebAssembly, js_name = compileStreaming)]
8327 pub fn compile_streaming(response: &Promise) -> Promise<JsValue>;
8328
8329 /// The `WebAssembly.compileStreaming()` function compiles a
8330 /// `WebAssembly.Module` module directly from a streamed underlying
8331 /// source. This function is useful if it is necessary to a compile a
8332 /// module before it can be instantiated (otherwise, the
8333 /// `WebAssembly.instantiateStreaming()` function should be used).
8334 ///
8335 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compileStreaming)
8336 #[cfg(js_sys_unstable_apis)]
8337 #[wasm_bindgen(js_namespace = WebAssembly, js_name = compileStreaming)]
8338 pub fn compile_streaming(response: &Promise) -> Promise<Module>;
8339
8340 /// The `WebAssembly.instantiate()` function allows you to compile and
8341 /// instantiate WebAssembly code.
8342 ///
8343 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate)
8344 #[cfg(not(js_sys_unstable_apis))]
8345 #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiate)]
8346 pub fn instantiate_buffer(buffer: &[u8], imports: &Object) -> Promise<JsValue>;
8347
8348 /// The `WebAssembly.instantiate()` function allows you to compile and
8349 /// instantiate WebAssembly code.
8350 ///
8351 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate)
8352 #[cfg(js_sys_unstable_apis)]
8353 #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiate)]
8354 pub fn instantiate_buffer(buffer: &[u8], imports: &Object) -> Promise<Instance>;
8355
8356 /// The `WebAssembly.instantiate()` function allows you to compile and
8357 /// instantiate WebAssembly code.
8358 ///
8359 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate)
8360 #[cfg(not(js_sys_unstable_apis))]
8361 #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiate)]
8362 pub fn instantiate_module(module: &Module, imports: &Object) -> Promise<JsValue>;
8363
8364 /// The `WebAssembly.instantiate()` function allows you to compile and
8365 /// instantiate WebAssembly code.
8366 ///
8367 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate)
8368 #[cfg(js_sys_unstable_apis)]
8369 #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiate)]
8370 pub fn instantiate_module(module: &Module, imports: &Object) -> Promise<Instance>;
8371
8372 /// The `WebAssembly.instantiateStreaming()` function compiles and
8373 /// instantiates a WebAssembly module directly from a streamed
8374 /// underlying source. This is the most efficient, optimized way to load
8375 /// Wasm code.
8376 ///
8377 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiateStreaming)
8378 #[cfg(not(js_sys_unstable_apis))]
8379 #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiateStreaming)]
8380 pub fn instantiate_streaming(response: &JsValue, imports: &Object) -> Promise<JsValue>;
8381
8382 /// The `WebAssembly.instantiateStreaming()` function compiles and
8383 /// instantiates a WebAssembly module directly from a streamed
8384 /// underlying source. This is the most efficient, optimized way to load
8385 /// Wasm code.
8386 ///
8387 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiateStreaming)
8388 #[cfg(js_sys_unstable_apis)]
8389 #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiateStreaming)]
8390 pub fn instantiate_streaming(response: &JsValue, imports: &Object) -> Promise<Instance>;
8391
8392 /// The `WebAssembly.validate()` function validates a given typed
8393 /// array of WebAssembly binary code, returning whether the bytes
8394 /// form a valid Wasm module (`true`) or not (`false`).
8395 ///
8396 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/validate)
8397 #[wasm_bindgen(js_namespace = WebAssembly, catch)]
8398 pub fn validate(buffer_source: &JsValue) -> Result<bool, JsValue>;
8399 }
8400
8401 // WebAssembly.CompileError
8402 #[wasm_bindgen]
8403 extern "C" {
8404 /// The `WebAssembly.CompileError()` constructor creates a new
8405 /// WebAssembly `CompileError` object, which indicates an error during
8406 /// WebAssembly decoding or validation.
8407 ///
8408 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/CompileError)
8409 #[wasm_bindgen(extends = Error, js_namespace = WebAssembly, typescript_type = "WebAssembly.CompileError")]
8410 #[derive(Clone, Debug, PartialEq, Eq)]
8411 pub type CompileError;
8412
8413 /// The `WebAssembly.CompileError()` constructor creates a new
8414 /// WebAssembly `CompileError` object, which indicates an error during
8415 /// WebAssembly decoding or validation.
8416 ///
8417 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/CompileError)
8418 #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
8419 pub fn new(message: &str) -> CompileError;
8420 }
8421
8422 // WebAssembly.Instance
8423 #[wasm_bindgen]
8424 extern "C" {
8425 /// A `WebAssembly.Instance` object is a stateful, executable instance
8426 /// of a `WebAssembly.Module`. Instance objects contain all the exported
8427 /// WebAssembly functions that allow calling into WebAssembly code from
8428 /// JavaScript.
8429 ///
8430 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance)
8431 #[wasm_bindgen(extends = Object, js_namespace = WebAssembly, typescript_type = "WebAssembly.Instance")]
8432 #[derive(Clone, Debug, PartialEq, Eq)]
8433 pub type Instance;
8434
8435 /// The `WebAssembly.Instance()` constructor function can be called to
8436 /// synchronously instantiate a given `WebAssembly.Module`
8437 /// object. However, the primary way to get an `Instance` is through the
8438 /// asynchronous `WebAssembly.instantiateStreaming()` function.
8439 ///
8440 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance)
8441 #[wasm_bindgen(catch, constructor, js_namespace = WebAssembly)]
8442 pub fn new(module: &Module, imports: &Object) -> Result<Instance, JsValue>;
8443
8444 /// The `exports` readonly property of the `WebAssembly.Instance` object
8445 /// prototype returns an object containing as its members all the
8446 /// functions exported from the WebAssembly module instance, to allow
8447 /// them to be accessed and used by JavaScript.
8448 ///
8449 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance/exports)
8450 #[wasm_bindgen(getter, method, js_namespace = WebAssembly)]
8451 pub fn exports(this: &Instance) -> Object;
8452 }
8453
8454 // WebAssembly.LinkError
8455 #[wasm_bindgen]
8456 extern "C" {
8457 /// The `WebAssembly.LinkError()` constructor creates a new WebAssembly
8458 /// LinkError object, which indicates an error during module
8459 /// instantiation (besides traps from the start function).
8460 ///
8461 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/LinkError)
8462 #[wasm_bindgen(extends = Error, js_namespace = WebAssembly, typescript_type = "WebAssembly.LinkError")]
8463 #[derive(Clone, Debug, PartialEq, Eq)]
8464 pub type LinkError;
8465
8466 /// The `WebAssembly.LinkError()` constructor creates a new WebAssembly
8467 /// LinkError object, which indicates an error during module
8468 /// instantiation (besides traps from the start function).
8469 ///
8470 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/LinkError)
8471 #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
8472 pub fn new(message: &str) -> LinkError;
8473 }
8474
8475 // WebAssembly.RuntimeError
8476 #[wasm_bindgen]
8477 extern "C" {
8478 /// The `WebAssembly.RuntimeError()` constructor creates a new WebAssembly
8479 /// `RuntimeError` object — the type that is thrown whenever WebAssembly
8480 /// specifies a trap.
8481 ///
8482 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/RuntimeError)
8483 #[wasm_bindgen(extends = Error, js_namespace = WebAssembly, typescript_type = "WebAssembly.RuntimeError")]
8484 #[derive(Clone, Debug, PartialEq, Eq)]
8485 pub type RuntimeError;
8486
8487 /// The `WebAssembly.RuntimeError()` constructor creates a new WebAssembly
8488 /// `RuntimeError` object — the type that is thrown whenever WebAssembly
8489 /// specifies a trap.
8490 ///
8491 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/RuntimeError)
8492 #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
8493 pub fn new(message: &str) -> RuntimeError;
8494 }
8495
8496 // WebAssembly.Module
8497 #[wasm_bindgen]
8498 extern "C" {
8499 /// A `WebAssembly.Module` object contains stateless WebAssembly code
8500 /// that has already been compiled by the browser and can be
8501 /// efficiently shared with Workers, and instantiated multiple times.
8502 ///
8503 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module)
8504 #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Module")]
8505 #[derive(Clone, Debug, PartialEq, Eq)]
8506 pub type Module;
8507
8508 /// A `WebAssembly.Module` object contains stateless WebAssembly code
8509 /// that has already been compiled by the browser and can be
8510 /// efficiently shared with Workers, and instantiated multiple times.
8511 ///
8512 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module)
8513 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
8514 pub fn new(buffer_source: &JsValue) -> Result<Module, JsValue>;
8515
8516 /// The `WebAssembly.customSections()` function returns a copy of the
8517 /// contents of all custom sections in the given module with the given
8518 /// string name.
8519 ///
8520 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/customSections)
8521 #[wasm_bindgen(static_method_of = Module, js_namespace = WebAssembly, js_name = customSections)]
8522 pub fn custom_sections(module: &Module, sectionName: &str) -> Array;
8523
8524 /// The `WebAssembly.exports()` function returns an array containing
8525 /// descriptions of all the declared exports of the given `Module`.
8526 ///
8527 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/exports)
8528 #[wasm_bindgen(static_method_of = Module, js_namespace = WebAssembly)]
8529 pub fn exports(module: &Module) -> Array;
8530
8531 /// The `WebAssembly.imports()` function returns an array containing
8532 /// descriptions of all the declared imports of the given `Module`.
8533 ///
8534 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/imports)
8535 #[wasm_bindgen(static_method_of = Module, js_namespace = WebAssembly)]
8536 pub fn imports(module: &Module) -> Array;
8537 }
8538
8539 // WebAssembly.Table
8540 #[wasm_bindgen]
8541 extern "C" {
8542 /// The `WebAssembly.Table()` constructor creates a new `Table` object
8543 /// of the given size and element type.
8544 ///
8545 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table)
8546 #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Table")]
8547 #[derive(Clone, Debug, PartialEq, Eq)]
8548 pub type Table;
8549
8550 /// The `WebAssembly.Table()` constructor creates a new `Table` object
8551 /// of the given size and element type.
8552 ///
8553 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table)
8554 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
8555 pub fn new(table_descriptor: &Object) -> Result<Table, JsValue>;
8556
8557 /// The `WebAssembly.Table()` constructor creates a new `Table` object
8558 /// of the given size and element type.
8559 ///
8560 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table)
8561 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
8562 pub fn new_with_value(table_descriptor: &Object, value: JsValue) -> Result<Table, JsValue>;
8563
8564 /// The length prototype property of the `WebAssembly.Table` object
8565 /// returns the length of the table, i.e. the number of elements in the
8566 /// table.
8567 ///
8568 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/length)
8569 #[wasm_bindgen(method, getter, js_namespace = WebAssembly)]
8570 pub fn length(this: &Table) -> u32;
8571
8572 /// The `get()` prototype method of the `WebAssembly.Table()` object
8573 /// retrieves a function reference stored at a given index.
8574 ///
8575 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/get)
8576 #[wasm_bindgen(method, catch, js_namespace = WebAssembly)]
8577 pub fn get(this: &Table, index: u32) -> Result<Function, JsValue>;
8578
8579 /// The `get()` prototype method of the `WebAssembly.Table()` object
8580 /// retrieves a function reference stored at a given index.
8581 ///
8582 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/get)
8583 #[wasm_bindgen(method, catch, js_namespace = WebAssembly, js_name = get)]
8584 pub fn get_raw(this: &Table, index: u32) -> Result<JsValue, JsValue>;
8585
8586 /// The `grow()` prototype method of the `WebAssembly.Table` object
8587 /// increases the size of the `Table` instance by a specified number of
8588 /// elements.
8589 ///
8590 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/grow)
8591 #[wasm_bindgen(method, catch, js_namespace = WebAssembly)]
8592 pub fn grow(this: &Table, additional_capacity: u32) -> Result<u32, JsValue>;
8593
8594 /// The `grow()` prototype method of the `WebAssembly.Table` object
8595 /// increases the size of the `Table` instance by a specified number of
8596 /// elements.
8597 ///
8598 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/grow)
8599 #[wasm_bindgen(method, catch, js_namespace = WebAssembly, js_name = grow)]
8600 pub fn grow_with_value(
8601 this: &Table,
8602 additional_capacity: u32,
8603 value: JsValue,
8604 ) -> Result<u32, JsValue>;
8605
8606 /// The `set()` prototype method of the `WebAssembly.Table` object mutates a
8607 /// reference stored at a given index to a different value.
8608 ///
8609 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/set)
8610 #[wasm_bindgen(method, catch, js_namespace = WebAssembly)]
8611 pub fn set(this: &Table, index: u32, function: &Function) -> Result<(), JsValue>;
8612
8613 /// The `set()` prototype method of the `WebAssembly.Table` object mutates a
8614 /// reference stored at a given index to a different value.
8615 ///
8616 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/set)
8617 #[wasm_bindgen(method, catch, js_namespace = WebAssembly, js_name = set)]
8618 pub fn set_raw(this: &Table, index: u32, value: &JsValue) -> Result<(), JsValue>;
8619 }
8620
8621 // WebAssembly.Tag
8622 #[wasm_bindgen]
8623 extern "C" {
8624 /// The `WebAssembly.Tag()` constructor creates a new `Tag` object
8625 ///
8626 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Tag)
8627 #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Tag")]
8628 #[derive(Clone, Debug, PartialEq, Eq)]
8629 pub type Tag;
8630
8631 /// The `WebAssembly.Tag()` constructor creates a new `Tag` object
8632 ///
8633 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Tag)
8634 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
8635 pub fn new(tag_descriptor: &Object) -> Result<Tag, JsValue>;
8636 }
8637
8638 // WebAssembly.Exception
8639 #[wasm_bindgen]
8640 extern "C" {
8641 /// The `WebAssembly.Exception()` constructor creates a new `Exception` object
8642 ///
8643 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception)
8644 #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Exception")]
8645 #[derive(Clone, Debug, PartialEq, Eq)]
8646 pub type Exception;
8647
8648 /// The `WebAssembly.Exception()` constructor creates a new `Exception` object
8649 ///
8650 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception)
8651 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
8652 pub fn new(tag: &Tag, payload: &Array) -> Result<Exception, JsValue>;
8653
8654 /// The `WebAssembly.Exception()` constructor creates a new `Exception` object
8655 ///
8656 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception)
8657 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
8658 pub fn new_with_options(
8659 tag: &Tag,
8660 payload: &Array,
8661 options: &Object,
8662 ) -> Result<Exception, JsValue>;
8663
8664 /// The `is()` prototype method of the `WebAssembly.Exception` can be used to
8665 /// test if the Exception matches a given tag.
8666 ///
8667 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception/is)
8668 #[wasm_bindgen(method, js_namespace = WebAssembly)]
8669 pub fn is(this: &Exception, tag: &Tag) -> bool;
8670
8671 /// The `getArg()` prototype method of the `WebAssembly.Exception` can be used
8672 /// to get the value of a specified item in the exception's data arguments
8673 ///
8674 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception/getArg)
8675 #[wasm_bindgen(method, js_namespace = WebAssembly, js_name = getArg, catch)]
8676 pub fn get_arg(this: &Exception, tag: &Tag, index: u32) -> Result<JsValue, JsValue>;
8677 }
8678
8679 // WebAssembly.Global
8680 #[wasm_bindgen]
8681 extern "C" {
8682 /// The `WebAssembly.Global()` constructor creates a new `Global` object
8683 /// of the given type and value.
8684 ///
8685 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global)
8686 #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Global")]
8687 #[derive(Clone, Debug, PartialEq, Eq)]
8688 pub type Global;
8689
8690 /// The `WebAssembly.Global()` constructor creates a new `Global` object
8691 /// of the given type and value.
8692 ///
8693 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global)
8694 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
8695 pub fn new(global_descriptor: &Object, value: &JsValue) -> Result<Global, JsValue>;
8696
8697 /// The value prototype property of the `WebAssembly.Global` object
8698 /// returns the value of the global.
8699 ///
8700 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global)
8701 #[wasm_bindgen(method, getter, js_namespace = WebAssembly)]
8702 pub fn value(this: &Global) -> JsValue;
8703 #[wasm_bindgen(method, setter = value, js_namespace = WebAssembly)]
8704 pub fn set_value(this: &Global, value: &JsValue);
8705 }
8706
8707 // WebAssembly.Memory
8708 #[wasm_bindgen]
8709 extern "C" {
8710 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory)
8711 #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Memory")]
8712 #[derive(Clone, Debug, PartialEq, Eq)]
8713 pub type Memory;
8714
8715 /// The `WebAssembly.Memory()` constructor creates a new `Memory` object
8716 /// which is a resizable `ArrayBuffer` that holds the raw bytes of
8717 /// memory accessed by a WebAssembly `Instance`.
8718 ///
8719 /// A memory created by JavaScript or in WebAssembly code will be
8720 /// accessible and mutable from both JavaScript and WebAssembly.
8721 ///
8722 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory)
8723 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
8724 pub fn new(descriptor: &Object) -> Result<Memory, JsValue>;
8725
8726 /// An accessor property that returns the buffer contained in the
8727 /// memory.
8728 ///
8729 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory/buffer)
8730 #[wasm_bindgen(method, getter, js_namespace = WebAssembly)]
8731 pub fn buffer(this: &Memory) -> JsValue;
8732
8733 /// The `grow()` prototype method of the `Memory` object increases the
8734 /// size of the memory instance by a specified number of WebAssembly
8735 /// pages.
8736 ///
8737 /// Takes the number of pages to grow (64KiB in size) and returns the
8738 /// previous size of memory, in pages.
8739 ///
8740 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory/grow)
8741 #[wasm_bindgen(method, js_namespace = WebAssembly)]
8742 pub fn grow(this: &Memory, pages: u32) -> u32;
8743 }
8744}
8745
8746/// The `JSON` object contains methods for parsing [JavaScript Object
8747/// Notation (JSON)](https://json.org/) and converting values to JSON. It
8748/// can't be called or constructed, and aside from its two method
8749/// properties, it has no interesting functionality of its own.
8750#[allow(non_snake_case)]
8751pub mod JSON {
8752 use super::*;
8753
8754 // JSON
8755 #[wasm_bindgen]
8756 extern "C" {
8757 /// The `JSON.parse()` method parses a JSON string, constructing the
8758 /// JavaScript value or object described by the string.
8759 ///
8760 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse)
8761 #[wasm_bindgen(catch, js_namespace = JSON)]
8762 pub fn parse(text: &str) -> Result<JsValue, JsValue>;
8763
8764 /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
8765 ///
8766 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
8767 #[wasm_bindgen(catch, js_namespace = JSON)]
8768 pub fn stringify(obj: &JsValue) -> Result<JsString, JsValue>;
8769
8770 /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
8771 ///
8772 /// The `replacer` argument is a function that alters the behavior of the stringification
8773 /// process, or an array of String and Number objects that serve as a whitelist
8774 /// for selecting/filtering the properties of the value object to be included
8775 /// in the JSON string. If this value is null or not provided, all properties
8776 /// of the object are included in the resulting JSON string.
8777 ///
8778 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
8779 #[cfg(not(js_sys_unstable_apis))]
8780 #[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
8781 pub fn stringify_with_replacer(
8782 obj: &JsValue,
8783 replacer: &JsValue,
8784 ) -> Result<JsString, JsValue>;
8785
8786 /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
8787 ///
8788 /// The `replacer` argument is a function that alters the behavior of the stringification
8789 /// process, or an array of String and Number objects that serve as a whitelist
8790 /// for selecting/filtering the properties of the value object to be included
8791 /// in the JSON string. If this value is null or not provided, all properties
8792 /// of the object are included in the resulting JSON string.
8793 ///
8794 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
8795 #[cfg(js_sys_unstable_apis)]
8796 #[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
8797 pub fn stringify_with_replacer<'a>(
8798 obj: &JsValue,
8799 replacer: &mut dyn FnMut(JsString, JsValue) -> Result<Option<JsValue>, JsError>,
8800 space: Option<u32>,
8801 ) -> Result<JsString, JsValue>;
8802
8803 // Next major: deprecate
8804 /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
8805 ///
8806 /// The `replacer` argument is a function that alters the behavior of the stringification
8807 /// process, or an array of String and Number objects that serve as a whitelist
8808 /// for selecting/filtering the properties of the value object to be included
8809 /// in the JSON string. If this value is null or not provided, all properties
8810 /// of the object are included in the resulting JSON string.
8811 ///
8812 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
8813 #[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
8814 pub fn stringify_with_replacer_func<'a>(
8815 obj: &JsValue,
8816 replacer: &mut dyn FnMut(JsString, JsValue) -> Result<Option<JsValue>, JsError>,
8817 space: Option<u32>,
8818 ) -> Result<JsString, JsValue>;
8819
8820 /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
8821 ///
8822 /// The `replacer` argument is a function that alters the behavior of the stringification
8823 /// process, or an array of String and Number objects that serve as a whitelist
8824 /// for selecting/filtering the properties of the value object to be included
8825 /// in the JSON string. If this value is null or not provided, all properties
8826 /// of the object are included in the resulting JSON string.
8827 ///
8828 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
8829 #[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
8830 pub fn stringify_with_replacer_list(
8831 obj: &JsValue,
8832 replacer: Vec<String>,
8833 space: Option<u32>,
8834 ) -> Result<JsString, JsValue>;
8835
8836 // Next major: deprecate
8837 /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
8838 ///
8839 /// The `replacer` argument is a function that alters the behavior of the stringification
8840 /// process, or an array of String and Number objects that serve as a whitelist
8841 /// for selecting/filtering the properties of the value object to be included
8842 /// in the JSON string. If this value is null or not provided, all properties
8843 /// of the object are included in the resulting JSON string.
8844 ///
8845 /// The `space` argument is a String or Number object that's used to insert white space into
8846 /// the output JSON string for readability purposes. If this is a Number, it
8847 /// indicates the number of space characters to use as white space; this number
8848 /// is capped at 10 (if it is greater, the value is just 10). Values less than
8849 /// 1 indicate that no space should be used. If this is a String, the string
8850 /// (or the first 10 characters of the string, if it's longer than that) is
8851 /// used as white space. If this parameter is not provided (or is null), no
8852 /// white space is used.
8853 ///
8854 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
8855 #[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
8856 pub fn stringify_with_replacer_and_space(
8857 obj: &JsValue,
8858 replacer: &JsValue,
8859 space: &JsValue,
8860 ) -> Result<JsString, JsValue>;
8861 }
8862}
8863// JsString
8864#[wasm_bindgen]
8865extern "C" {
8866 #[wasm_bindgen(js_name = String, extends = Object, is_type_of = JsValue::is_string, typescript_type = "string")]
8867 #[derive(Clone, PartialEq, Eq)]
8868 pub type JsString;
8869
8870 /// The length property of a String object indicates the length of a string,
8871 /// in UTF-16 code units.
8872 ///
8873 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/length)
8874 #[wasm_bindgen(method, getter)]
8875 pub fn length(this: &JsString) -> u32;
8876
8877 /// The 'at()' method returns a new string consisting of the single UTF-16
8878 /// code unit located at the specified offset into the string, counting from
8879 /// the end if it's negative.
8880 ///
8881 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/at)
8882 #[wasm_bindgen(method, js_class = "String")]
8883 pub fn at(this: &JsString, index: i32) -> Option<JsString>;
8884
8885 /// The String object's `charAt()` method returns a new string consisting of
8886 /// the single UTF-16 code unit located at the specified offset into the
8887 /// string.
8888 ///
8889 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charAt)
8890 #[wasm_bindgen(method, js_class = "String", js_name = charAt)]
8891 pub fn char_at(this: &JsString, index: u32) -> JsString;
8892
8893 /// The `charCodeAt()` method returns an integer between 0 and 65535
8894 /// representing the UTF-16 code unit at the given index (the UTF-16 code
8895 /// unit matches the Unicode code point for code points representable in a
8896 /// single UTF-16 code unit, but might also be the first code unit of a
8897 /// surrogate pair for code points not representable in a single UTF-16 code
8898 /// unit, e.g. Unicode code points > 0x10000). If you want the entire code
8899 /// point value, use `codePointAt()`.
8900 ///
8901 /// Returns `NaN` if index is out of range.
8902 ///
8903 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charCodeAt)
8904 #[wasm_bindgen(method, js_class = "String", js_name = charCodeAt)]
8905 pub fn char_code_at(this: &JsString, index: u32) -> f64;
8906
8907 /// The `codePointAt()` method returns a non-negative integer that is the
8908 /// Unicode code point value.
8909 ///
8910 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/codePointAt)
8911 #[cfg(not(js_sys_unstable_apis))]
8912 #[wasm_bindgen(method, js_class = "String", js_name = codePointAt)]
8913 pub fn code_point_at(this: &JsString, pos: u32) -> JsValue;
8914
8915 /// The `codePointAt()` method returns a non-negative integer that is the
8916 /// Unicode code point value.
8917 ///
8918 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/codePointAt)
8919 #[cfg(js_sys_unstable_apis)]
8920 #[wasm_bindgen(method, js_class = "String", js_name = codePointAt)]
8921 pub fn code_point_at(this: &JsString, pos: u32) -> Option<u32>;
8922
8923 // Next major: deprecate
8924 /// The `codePointAt()` method returns a non-negative integer that is the
8925 /// Unicode code point value.
8926 ///
8927 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/codePointAt)
8928 #[wasm_bindgen(method, js_class = "String", js_name = codePointAt)]
8929 pub fn try_code_point_at(this: &JsString, pos: u32) -> Option<u16>;
8930
8931 /// The `concat()` method concatenates the string arguments to the calling
8932 /// string and returns a new string.
8933 ///
8934 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/concat)
8935 #[cfg(not(js_sys_unstable_apis))]
8936 #[wasm_bindgen(method, js_class = "String")]
8937 pub fn concat(this: &JsString, string_2: &JsValue) -> JsString;
8938
8939 /// The `concat()` method concatenates the string arguments to the calling
8940 /// string and returns a new string.
8941 ///
8942 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/concat)
8943 #[cfg(js_sys_unstable_apis)]
8944 #[wasm_bindgen(method, js_class = "String")]
8945 pub fn concat(this: &JsString, string: &JsString) -> JsString;
8946
8947 /// The `concat()` method concatenates the string arguments to the calling
8948 /// string and returns a new string.
8949 ///
8950 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/concat)
8951 #[wasm_bindgen(method, js_class = "String")]
8952 pub fn concat_many(this: &JsString, strings: &[JsString]) -> JsString;
8953
8954 /// The `endsWith()` method determines whether a string ends with the characters of a
8955 /// specified string, returning true or false as appropriate.
8956 ///
8957 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith)
8958 #[cfg(not(js_sys_unstable_apis))]
8959 #[wasm_bindgen(method, js_class = "String", js_name = endsWith)]
8960 pub fn ends_with(this: &JsString, search_string: &str, length: i32) -> bool;
8961
8962 /// The `endsWith()` method determines whether a string ends with the characters of a
8963 /// specified string, returning true or false as appropriate.
8964 ///
8965 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith)
8966 #[cfg(js_sys_unstable_apis)]
8967 #[wasm_bindgen(method, js_class = "String", js_name = endsWith)]
8968 pub fn ends_with(this: &JsString, search_string: &str) -> bool;
8969
8970 /// The static `String.fromCharCode()` method returns a string created from
8971 /// the specified sequence of UTF-16 code units.
8972 ///
8973 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
8974 ///
8975 /// # Notes
8976 ///
8977 /// There are a few bindings to `from_char_code` in `js-sys`: `from_char_code1`, `from_char_code2`, etc...
8978 /// with different arities.
8979 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode, variadic)]
8980 pub fn from_char_code(char_codes: &[u16]) -> JsString;
8981
8982 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
8983 #[cfg(not(js_sys_unstable_apis))]
8984 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
8985 pub fn from_char_code1(a: u32) -> JsString;
8986
8987 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
8988 #[cfg(js_sys_unstable_apis)]
8989 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
8990 pub fn from_char_code1(a: u16) -> JsString;
8991
8992 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
8993 #[cfg(not(js_sys_unstable_apis))]
8994 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
8995 pub fn from_char_code2(a: u32, b: u32) -> JsString;
8996
8997 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
8998 #[cfg(js_sys_unstable_apis)]
8999 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
9000 pub fn from_char_code2(a: u16, b: u16) -> JsString;
9001
9002 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
9003 #[cfg(not(js_sys_unstable_apis))]
9004 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
9005 pub fn from_char_code3(a: u32, b: u32, c: u32) -> JsString;
9006
9007 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
9008 #[cfg(js_sys_unstable_apis)]
9009 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
9010 pub fn from_char_code3(a: u16, b: u16, c: u16) -> JsString;
9011
9012 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
9013 #[cfg(not(js_sys_unstable_apis))]
9014 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
9015 pub fn from_char_code4(a: u32, b: u32, c: u32, d: u32) -> JsString;
9016
9017 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
9018 #[cfg(js_sys_unstable_apis)]
9019 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
9020 pub fn from_char_code4(a: u16, b: u16, c: u16, d: u16) -> JsString;
9021
9022 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
9023 #[cfg(not(js_sys_unstable_apis))]
9024 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
9025 pub fn from_char_code5(a: u32, b: u32, c: u32, d: u32, e: u32) -> JsString;
9026
9027 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
9028 #[cfg(js_sys_unstable_apis)]
9029 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
9030 pub fn from_char_code5(a: u16, b: u16, c: u16, d: u16, e: u16) -> JsString;
9031
9032 /// The static `String.fromCodePoint()` method returns a string created by
9033 /// using the specified sequence of code points.
9034 ///
9035 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
9036 ///
9037 /// # Exceptions
9038 ///
9039 /// A RangeError is thrown if an invalid Unicode code point is given
9040 ///
9041 /// # Notes
9042 ///
9043 /// There are a few bindings to `from_code_point` in `js-sys`: `from_code_point1`, `from_code_point2`, etc...
9044 /// with different arities.
9045 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint, variadic)]
9046 pub fn from_code_point(code_points: &[u32]) -> Result<JsString, JsValue>;
9047
9048 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
9049 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
9050 pub fn from_code_point1(a: u32) -> Result<JsString, JsValue>;
9051
9052 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
9053 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
9054 pub fn from_code_point2(a: u32, b: u32) -> Result<JsString, JsValue>;
9055
9056 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
9057 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
9058 pub fn from_code_point3(a: u32, b: u32, c: u32) -> Result<JsString, JsValue>;
9059
9060 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
9061 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
9062 pub fn from_code_point4(a: u32, b: u32, c: u32, d: u32) -> Result<JsString, JsValue>;
9063
9064 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
9065 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
9066 pub fn from_code_point5(a: u32, b: u32, c: u32, d: u32, e: u32) -> Result<JsString, JsValue>;
9067
9068 /// The `includes()` method determines whether one string may be found
9069 /// within another string, returning true or false as appropriate.
9070 ///
9071 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes)
9072 #[wasm_bindgen(method, js_class = "String")]
9073 pub fn includes(this: &JsString, search_string: &str, position: i32) -> bool;
9074
9075 /// The `indexOf()` method returns the index within the calling String
9076 /// object of the first occurrence of the specified value, starting the
9077 /// search at fromIndex. Returns -1 if the value is not found.
9078 ///
9079 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf)
9080 #[wasm_bindgen(method, js_class = "String", js_name = indexOf)]
9081 pub fn index_of(this: &JsString, search_value: &str, from_index: i32) -> i32;
9082
9083 /// The `lastIndexOf()` method returns the index within the calling String
9084 /// object of the last occurrence of the specified value, searching
9085 /// backwards from fromIndex. Returns -1 if the value is not found.
9086 ///
9087 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/lastIndexOf)
9088 #[wasm_bindgen(method, js_class = "String", js_name = lastIndexOf)]
9089 pub fn last_index_of(this: &JsString, search_value: &str, from_index: i32) -> i32;
9090
9091 /// The `localeCompare()` method returns a number indicating whether
9092 /// a reference string comes before or after or is the same as
9093 /// the given string in sort order.
9094 ///
9095 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare)
9096 #[cfg(not(js_sys_unstable_apis))]
9097 #[wasm_bindgen(method, js_class = "String", js_name = localeCompare)]
9098 pub fn locale_compare(
9099 this: &JsString,
9100 compare_string: &str,
9101 locales: &Array,
9102 options: &Object,
9103 ) -> i32;
9104
9105 /// The `localeCompare()` method returns a number indicating whether
9106 /// a reference string comes before or after or is the same as
9107 /// the given string in sort order.
9108 ///
9109 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare)
9110 #[cfg(js_sys_unstable_apis)]
9111 #[wasm_bindgen(method, js_class = "String", js_name = localeCompare)]
9112 pub fn locale_compare(
9113 this: &JsString,
9114 compare_string: &str,
9115 locales: &[JsString],
9116 options: &Intl::CollatorOptions,
9117 ) -> i32;
9118
9119 /// The `match()` method retrieves the matches when matching a string against a regular expression.
9120 ///
9121 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match)
9122 #[wasm_bindgen(method, js_class = "String", js_name = match)]
9123 pub fn match_(this: &JsString, pattern: &RegExp) -> Option<Object>;
9124
9125 /// The `match_all()` method is similar to `match()`, but gives an iterator of `exec()` arrays, which preserve capture groups.
9126 ///
9127 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/matchAll)
9128 #[cfg(not(js_sys_unstable_apis))]
9129 #[wasm_bindgen(method, js_class = "String", js_name = matchAll)]
9130 pub fn match_all(this: &JsString, pattern: &RegExp) -> Iterator;
9131
9132 /// The `match_all()` method is similar to `match()`, but gives an iterator of `exec()` arrays, which preserve capture groups.
9133 ///
9134 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/matchAll)
9135 #[cfg(js_sys_unstable_apis)]
9136 #[wasm_bindgen(method, js_class = "String", js_name = matchAll)]
9137 pub fn match_all(this: &JsString, pattern: &RegExp) -> Iterator<RegExpMatchArray>;
9138
9139 /// The `normalize()` method returns the Unicode Normalization Form
9140 /// of a given string (if the value isn't a string, it will be converted to one first).
9141 ///
9142 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize)
9143 #[wasm_bindgen(method, js_class = "String")]
9144 pub fn normalize(this: &JsString, form: &str) -> JsString;
9145
9146 /// The `padEnd()` method pads the current string with a given string
9147 /// (repeated, if needed) so that the resulting string reaches a given
9148 /// length. The padding is applied from the end (right) of the current
9149 /// string.
9150 ///
9151 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padEnd)
9152 #[wasm_bindgen(method, js_class = "String", js_name = padEnd)]
9153 pub fn pad_end(this: &JsString, target_length: u32, pad_string: &str) -> JsString;
9154
9155 /// The `padStart()` method pads the current string with another string
9156 /// (repeated, if needed) so that the resulting string reaches the given
9157 /// length. The padding is applied from the start (left) of the current
9158 /// string.
9159 ///
9160 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padStart)
9161 #[wasm_bindgen(method, js_class = "String", js_name = padStart)]
9162 pub fn pad_start(this: &JsString, target_length: u32, pad_string: &str) -> JsString;
9163
9164 /// The `repeat()` method constructs and returns a new string which contains the specified
9165 /// number of copies of the string on which it was called, concatenated together.
9166 ///
9167 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat)
9168 #[wasm_bindgen(method, js_class = "String")]
9169 pub fn repeat(this: &JsString, count: i32) -> JsString;
9170
9171 /// The `replace()` method returns a new string with some or all matches of a pattern
9172 /// replaced by a replacement. The pattern can be a string or a RegExp, and
9173 /// the replacement can be a string or a function to be called for each match.
9174 ///
9175 /// Note: The original string will remain unchanged.
9176 ///
9177 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
9178 #[wasm_bindgen(method, js_class = "String")]
9179 pub fn replace(this: &JsString, pattern: &str, replacement: &str) -> JsString;
9180
9181 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
9182 #[cfg(not(js_sys_unstable_apis))]
9183 #[wasm_bindgen(method, js_class = "String", js_name = replace)]
9184 pub fn replace_with_function(
9185 this: &JsString,
9186 pattern: &str,
9187 replacement: &Function,
9188 ) -> JsString;
9189
9190 /// The replacer function signature is `(match, offset, string) -> replacement`
9191 /// for patterns without capture groups, or `(match, p1, p2, ..., pN, offset, string, groups) -> replacement`
9192 /// when capture groups are present.
9193 ///
9194 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
9195 #[cfg(js_sys_unstable_apis)]
9196 #[wasm_bindgen(method, js_class = "String", js_name = replace)]
9197 pub fn replace_with_function(
9198 this: &JsString,
9199 pattern: &str,
9200 replacement: &Function<fn(JsString) -> JsString>,
9201 ) -> JsString;
9202
9203 #[wasm_bindgen(method, js_class = "String", js_name = replace)]
9204 pub fn replace_by_pattern(this: &JsString, pattern: &RegExp, replacement: &str) -> JsString;
9205
9206 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
9207 #[cfg(not(js_sys_unstable_apis))]
9208 #[wasm_bindgen(method, js_class = "String", js_name = replace)]
9209 pub fn replace_by_pattern_with_function(
9210 this: &JsString,
9211 pattern: &RegExp,
9212 replacement: &Function,
9213 ) -> JsString;
9214
9215 /// The replacer function signature is `(match, offset, string) -> replacement`
9216 /// for patterns without capture groups, or `(match, p1, p2, ..., pN, offset, string, groups) -> replacement`
9217 /// when capture groups are present.
9218 ///
9219 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
9220 #[cfg(js_sys_unstable_apis)]
9221 #[wasm_bindgen(method, js_class = "String", js_name = replace)]
9222 pub fn replace_by_pattern_with_function(
9223 this: &JsString,
9224 pattern: &RegExp,
9225 replacement: &Function<fn(JsString) -> JsString>,
9226 ) -> JsString;
9227
9228 /// The `replace_all()` method returns a new string with all matches of a pattern
9229 /// replaced by a replacement. The pattern can be a string or a global RegExp, and
9230 /// the replacement can be a string or a function to be called for each match.
9231 ///
9232 /// Note: The original string will remain unchanged.
9233 ///
9234 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)
9235 #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
9236 pub fn replace_all(this: &JsString, pattern: &str, replacement: &str) -> JsString;
9237
9238 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)
9239 #[cfg(not(js_sys_unstable_apis))]
9240 #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
9241 pub fn replace_all_with_function(
9242 this: &JsString,
9243 pattern: &str,
9244 replacement: &Function,
9245 ) -> JsString;
9246
9247 /// The replacer function signature is `(match, offset, string) -> replacement`
9248 /// for patterns without capture groups, or `(match, p1, p2, ..., pN, offset, string, groups) -> replacement`
9249 /// when capture groups are present.
9250 ///
9251 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)
9252 #[cfg(js_sys_unstable_apis)]
9253 #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
9254 pub fn replace_all_with_function(
9255 this: &JsString,
9256 pattern: &str,
9257 replacement: &Function<fn(JsString) -> JsString>,
9258 ) -> JsString;
9259
9260 #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
9261 pub fn replace_all_by_pattern(this: &JsString, pattern: &RegExp, replacement: &str)
9262 -> JsString;
9263
9264 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)
9265 #[cfg(not(js_sys_unstable_apis))]
9266 #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
9267 pub fn replace_all_by_pattern_with_function(
9268 this: &JsString,
9269 pattern: &RegExp,
9270 replacement: &Function,
9271 ) -> JsString;
9272
9273 /// The replacer function signature is `(match, offset, string) -> replacement`
9274 /// for patterns without capture groups, or `(match, p1, p2, ..., pN, offset, string, groups) -> replacement`
9275 /// when capture groups are present.
9276 ///
9277 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)
9278 #[cfg(js_sys_unstable_apis)]
9279 #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
9280 pub fn replace_all_by_pattern_with_function(
9281 this: &JsString,
9282 pattern: &RegExp,
9283 replacement: &Function<fn(JsString) -> JsString>,
9284 ) -> JsString;
9285
9286 /// The `search()` method executes a search for a match between
9287 /// a regular expression and this String object.
9288 ///
9289 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/search)
9290 #[wasm_bindgen(method, js_class = "String")]
9291 pub fn search(this: &JsString, pattern: &RegExp) -> i32;
9292
9293 /// The `slice()` method extracts a section of a string and returns it as a
9294 /// new string, without modifying the original string.
9295 ///
9296 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice)
9297 #[wasm_bindgen(method, js_class = "String")]
9298 pub fn slice(this: &JsString, start: u32, end: u32) -> JsString;
9299
9300 /// The `split()` method splits a String object into an array of strings by separating the string
9301 /// into substrings, using a specified separator string to determine where to make each split.
9302 ///
9303 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)
9304 #[wasm_bindgen(method, js_class = "String")]
9305 pub fn split(this: &JsString, separator: &str) -> Array;
9306
9307 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)
9308 #[wasm_bindgen(method, js_class = "String", js_name = split)]
9309 pub fn split_limit(this: &JsString, separator: &str, limit: u32) -> Array;
9310
9311 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)
9312 #[wasm_bindgen(method, js_class = "String", js_name = split)]
9313 pub fn split_by_pattern(this: &JsString, pattern: &RegExp) -> Array;
9314
9315 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)
9316 #[wasm_bindgen(method, js_class = "String", js_name = split)]
9317 pub fn split_by_pattern_limit(this: &JsString, pattern: &RegExp, limit: u32) -> Array;
9318
9319 /// The `startsWith()` method determines whether a string begins with the
9320 /// characters of a specified string, returning true or false as
9321 /// appropriate.
9322 ///
9323 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith)
9324 #[wasm_bindgen(method, js_class = "String", js_name = startsWith)]
9325 pub fn starts_with(this: &JsString, search_string: &str, position: u32) -> bool;
9326
9327 /// The `substring()` method returns the part of the string between the
9328 /// start and end indexes, or to the end of the string.
9329 ///
9330 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring)
9331 #[wasm_bindgen(method, js_class = "String")]
9332 pub fn substring(this: &JsString, index_start: u32, index_end: u32) -> JsString;
9333
9334 /// The `substr()` method returns the part of a string between
9335 /// the start index and a number of characters after it.
9336 ///
9337 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr)
9338 #[wasm_bindgen(method, js_class = "String")]
9339 pub fn substr(this: &JsString, start: i32, length: i32) -> JsString;
9340
9341 /// The `toLocaleLowerCase()` method returns the calling string value converted to lower case,
9342 /// according to any locale-specific case mappings.
9343 ///
9344 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLocaleLowerCase)
9345 #[wasm_bindgen(method, js_class = "String", js_name = toLocaleLowerCase)]
9346 pub fn to_locale_lower_case(this: &JsString, locale: Option<&str>) -> JsString;
9347
9348 /// The `toLocaleUpperCase()` method returns the calling string value converted to upper case,
9349 /// according to any locale-specific case mappings.
9350 ///
9351 /// [MDN documentation](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/String/toLocaleUpperCase)
9352 #[wasm_bindgen(method, js_class = "String", js_name = toLocaleUpperCase)]
9353 pub fn to_locale_upper_case(this: &JsString, locale: Option<&str>) -> JsString;
9354
9355 /// The `toLowerCase()` method returns the calling string value
9356 /// converted to lower case.
9357 ///
9358 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLowerCase)
9359 #[wasm_bindgen(method, js_class = "String", js_name = toLowerCase)]
9360 pub fn to_lower_case(this: &JsString) -> JsString;
9361
9362 /// The `toString()` method returns a string representing the specified
9363 /// object.
9364 ///
9365 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toString)
9366 #[cfg(not(js_sys_unstable_apis))]
9367 #[wasm_bindgen(method, js_class = "String", js_name = toString)]
9368 pub fn to_string(this: &JsString) -> JsString;
9369
9370 /// The `toUpperCase()` method returns the calling string value converted to
9371 /// uppercase (the value will be converted to a string if it isn't one).
9372 ///
9373 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase)
9374 #[wasm_bindgen(method, js_class = "String", js_name = toUpperCase)]
9375 pub fn to_upper_case(this: &JsString) -> JsString;
9376
9377 /// The `trim()` method removes whitespace from both ends of a string.
9378 /// Whitespace in this context is all the whitespace characters (space, tab,
9379 /// no-break space, etc.) and all the line terminator characters (LF, CR,
9380 /// etc.).
9381 ///
9382 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trim)
9383 #[wasm_bindgen(method, js_class = "String")]
9384 pub fn trim(this: &JsString) -> JsString;
9385
9386 /// The `trimEnd()` method removes whitespace from the end of a string.
9387 /// `trimRight()` is an alias of this method.
9388 ///
9389 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimEnd)
9390 #[wasm_bindgen(method, js_class = "String", js_name = trimEnd)]
9391 pub fn trim_end(this: &JsString) -> JsString;
9392
9393 /// The `trimEnd()` method removes whitespace from the end of a string.
9394 /// `trimRight()` is an alias of this method.
9395 ///
9396 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimEnd)
9397 #[wasm_bindgen(method, js_class = "String", js_name = trimRight)]
9398 pub fn trim_right(this: &JsString) -> JsString;
9399
9400 /// The `trimStart()` method removes whitespace from the beginning of a
9401 /// string. `trimLeft()` is an alias of this method.
9402 ///
9403 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimStart)
9404 #[wasm_bindgen(method, js_class = "String", js_name = trimStart)]
9405 pub fn trim_start(this: &JsString) -> JsString;
9406
9407 /// The `trimStart()` method removes whitespace from the beginning of a
9408 /// string. `trimLeft()` is an alias of this method.
9409 ///
9410 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimStart)
9411 #[wasm_bindgen(method, js_class = "String", js_name = trimLeft)]
9412 pub fn trim_left(this: &JsString) -> JsString;
9413
9414 /// The `valueOf()` method returns the primitive value of a `String` object.
9415 ///
9416 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/valueOf)
9417 #[wasm_bindgen(method, js_class = "String", js_name = valueOf)]
9418 pub fn value_of(this: &JsString) -> JsString;
9419
9420 /// The static `raw()` method is a tag function of template literals,
9421 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9422 ///
9423 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9424 #[wasm_bindgen(catch, variadic, static_method_of = JsString, js_class = "String")]
9425 pub fn raw(call_site: &Object, substitutions: &Array) -> Result<JsString, JsValue>;
9426
9427 /// The static `raw()` method is a tag function of template literals,
9428 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9429 ///
9430 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9431 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9432 pub fn raw_0(call_site: &Object) -> Result<JsString, JsValue>;
9433
9434 /// The static `raw()` method is a tag function of template literals,
9435 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9436 ///
9437 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9438 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9439 pub fn raw_1(call_site: &Object, substitutions_1: &str) -> Result<JsString, JsValue>;
9440
9441 /// The static `raw()` method is a tag function of template literals,
9442 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9443 ///
9444 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9445 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9446 pub fn raw_2(
9447 call_site: &Object,
9448 substitutions1: &str,
9449 substitutions2: &str,
9450 ) -> Result<JsString, JsValue>;
9451
9452 /// The static `raw()` method is a tag function of template literals,
9453 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9454 ///
9455 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9456 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9457 pub fn raw_3(
9458 call_site: &Object,
9459 substitutions1: &str,
9460 substitutions2: &str,
9461 substitutions3: &str,
9462 ) -> Result<JsString, JsValue>;
9463
9464 /// The static `raw()` method is a tag function of template literals,
9465 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9466 ///
9467 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9468 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9469 pub fn raw_4(
9470 call_site: &Object,
9471 substitutions1: &str,
9472 substitutions2: &str,
9473 substitutions3: &str,
9474 substitutions4: &str,
9475 ) -> Result<JsString, JsValue>;
9476
9477 /// The static `raw()` method is a tag function of template literals,
9478 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9479 ///
9480 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9481 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9482 pub fn raw_5(
9483 call_site: &Object,
9484 substitutions1: &str,
9485 substitutions2: &str,
9486 substitutions3: &str,
9487 substitutions4: &str,
9488 substitutions5: &str,
9489 ) -> Result<JsString, JsValue>;
9490
9491 /// The static `raw()` method is a tag function of template literals,
9492 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9493 ///
9494 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9495 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9496 pub fn raw_6(
9497 call_site: &Object,
9498 substitutions1: &str,
9499 substitutions2: &str,
9500 substitutions3: &str,
9501 substitutions4: &str,
9502 substitutions5: &str,
9503 substitutions6: &str,
9504 ) -> Result<JsString, JsValue>;
9505
9506 /// The static `raw()` method is a tag function of template literals,
9507 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9508 ///
9509 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9510 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9511 pub fn raw_7(
9512 call_site: &Object,
9513 substitutions1: &str,
9514 substitutions2: &str,
9515 substitutions3: &str,
9516 substitutions4: &str,
9517 substitutions5: &str,
9518 substitutions6: &str,
9519 substitutions7: &str,
9520 ) -> Result<JsString, JsValue>;
9521}
9522
9523// These upcasts are non-castable due to the constraints on the function
9524// but the UpcastFrom covariance must still extend through closure types.
9525// (impl UpcastFrom really just means CovariantGeneric relation)
9526impl UpcastFrom<String> for JsString {}
9527impl UpcastFrom<JsString> for String {}
9528
9529impl UpcastFrom<&str> for JsString {}
9530impl UpcastFrom<JsString> for &str {}
9531
9532impl UpcastFrom<char> for JsString {}
9533impl UpcastFrom<JsString> for char {}
9534
9535impl JsString {
9536 /// Returns the `JsString` value of this JS value if it's an instance of a
9537 /// string.
9538 ///
9539 /// If this JS value is not an instance of a string then this returns
9540 /// `None`.
9541 #[cfg(not(js_sys_unstable_apis))]
9542 #[deprecated(note = "recommended to use dyn_ref instead which is now equivalent")]
9543 pub fn try_from(val: &JsValue) -> Option<&JsString> {
9544 val.dyn_ref()
9545 }
9546
9547 /// Returns whether this string is a valid UTF-16 string.
9548 ///
9549 /// This is useful for learning whether `String::from(..)` will return a
9550 /// lossless representation of the JS string. If this string contains
9551 /// unpaired surrogates then `String::from` will succeed but it will be a
9552 /// lossy representation of the JS string because unpaired surrogates will
9553 /// become replacement characters.
9554 ///
9555 /// If this function returns `false` then to get a lossless representation
9556 /// of the string you'll need to manually use the `iter` method (or the
9557 /// `char_code_at` accessor) to view the raw character codes.
9558 ///
9559 /// For more information, see the documentation on [JS strings vs Rust
9560 /// strings][docs]
9561 ///
9562 /// [docs]: https://wasm-bindgen.github.io/wasm-bindgen/reference/types/str.html
9563 pub fn is_valid_utf16(&self) -> bool {
9564 core::char::decode_utf16(self.iter()).all(|i| i.is_ok())
9565 }
9566
9567 /// Returns an iterator over the `u16` character codes that make up this JS
9568 /// string.
9569 ///
9570 /// This method will call `char_code_at` for each code in this JS string,
9571 /// returning an iterator of the codes in sequence.
9572 pub fn iter(
9573 &self,
9574 ) -> impl ExactSizeIterator<Item = u16> + DoubleEndedIterator<Item = u16> + '_ {
9575 (0..self.length()).map(move |i| self.char_code_at(i) as u16)
9576 }
9577
9578 /// If this string consists of a single Unicode code point, then this method
9579 /// converts it into a Rust `char` without doing any allocations.
9580 ///
9581 /// If this JS value is not a valid UTF-8 or consists of more than a single
9582 /// codepoint, then this returns `None`.
9583 ///
9584 /// Note that a single Unicode code point might be represented as more than
9585 /// one code unit on the JavaScript side. For example, a JavaScript string
9586 /// `"\uD801\uDC37"` is actually a single Unicode code point U+10437 which
9587 /// corresponds to a character '𐐷'.
9588 pub fn as_char(&self) -> Option<char> {
9589 let len = self.length();
9590
9591 if len == 0 || len > 2 {
9592 return None;
9593 }
9594
9595 #[cfg(not(js_sys_unstable_apis))]
9596 let cp = self.code_point_at(0).as_f64().unwrap_throw() as u32;
9597 #[cfg(js_sys_unstable_apis)]
9598 let cp = self.code_point_at(0)?;
9599
9600 let c = core::char::from_u32(cp)?;
9601
9602 if c.len_utf16() as u32 == len {
9603 Some(c)
9604 } else {
9605 None
9606 }
9607 }
9608}
9609
9610impl PartialEq<str> for JsString {
9611 #[allow(clippy::cmp_owned)] // prevent infinite recursion
9612 fn eq(&self, other: &str) -> bool {
9613 String::from(self) == other
9614 }
9615}
9616
9617impl<'a> PartialEq<&'a str> for JsString {
9618 fn eq(&self, other: &&'a str) -> bool {
9619 <JsString as PartialEq<str>>::eq(self, other)
9620 }
9621}
9622
9623impl PartialEq<String> for JsString {
9624 fn eq(&self, other: &String) -> bool {
9625 <JsString as PartialEq<str>>::eq(self, other)
9626 }
9627}
9628
9629impl<'a> PartialEq<&'a String> for JsString {
9630 fn eq(&self, other: &&'a String) -> bool {
9631 <JsString as PartialEq<str>>::eq(self, other)
9632 }
9633}
9634
9635impl Default for JsString {
9636 fn default() -> Self {
9637 Self::from("")
9638 }
9639}
9640
9641impl<'a> From<&'a str> for JsString {
9642 fn from(s: &'a str) -> Self {
9643 JsString::unchecked_from_js(JsValue::from_str(s))
9644 }
9645}
9646
9647impl From<String> for JsString {
9648 fn from(s: String) -> Self {
9649 From::from(&*s)
9650 }
9651}
9652
9653impl From<char> for JsString {
9654 #[inline]
9655 fn from(c: char) -> Self {
9656 JsString::from_code_point1(c as u32).unwrap_throw()
9657 }
9658}
9659
9660impl<'a> From<&'a JsString> for String {
9661 fn from(s: &'a JsString) -> Self {
9662 s.obj.as_string().unwrap_throw()
9663 }
9664}
9665
9666impl From<JsString> for String {
9667 fn from(s: JsString) -> Self {
9668 From::from(&s)
9669 }
9670}
9671
9672impl fmt::Debug for JsString {
9673 #[inline]
9674 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9675 fmt::Debug::fmt(&String::from(self), f)
9676 }
9677}
9678
9679impl fmt::Display for JsString {
9680 #[inline]
9681 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9682 fmt::Display::fmt(&String::from(self), f)
9683 }
9684}
9685
9686impl str::FromStr for JsString {
9687 type Err = convert::Infallible;
9688 fn from_str(s: &str) -> Result<Self, Self::Err> {
9689 Ok(JsString::from(s))
9690 }
9691}
9692
9693// Symbol
9694#[wasm_bindgen]
9695extern "C" {
9696 #[wasm_bindgen(is_type_of = JsValue::is_symbol, typescript_type = "Symbol")]
9697 #[derive(Clone, Debug)]
9698 pub type Symbol;
9699
9700 /// The `Symbol.hasInstance` well-known symbol is used to determine
9701 /// if a constructor object recognizes an object as its instance.
9702 /// The `instanceof` operator's behavior can be customized by this symbol.
9703 ///
9704 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/hasInstance)
9705 #[wasm_bindgen(static_method_of = Symbol, getter, js_name = hasInstance)]
9706 pub fn has_instance() -> Symbol;
9707
9708 /// The `Symbol.isConcatSpreadable` well-known symbol is used to configure
9709 /// if an object should be flattened to its array elements when using the
9710 /// `Array.prototype.concat()` method.
9711 ///
9712 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/isConcatSpreadable)
9713 #[wasm_bindgen(static_method_of = Symbol, getter, js_name = isConcatSpreadable)]
9714 pub fn is_concat_spreadable() -> Symbol;
9715
9716 /// The `Symbol.asyncIterator` well-known symbol specifies the default AsyncIterator for an object.
9717 /// If this property is set on an object, it is an async iterable and can be used in a `for await...of` loop.
9718 ///
9719 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/asyncIterator)
9720 #[wasm_bindgen(static_method_of = Symbol, getter, js_name = asyncIterator)]
9721 pub fn async_iterator() -> Symbol;
9722
9723 /// The `Symbol.iterator` well-known symbol specifies the default iterator
9724 /// for an object. Used by `for...of`.
9725 ///
9726 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/iterator)
9727 #[wasm_bindgen(static_method_of = Symbol, getter)]
9728 pub fn iterator() -> Symbol;
9729
9730 /// The `Symbol.match` well-known symbol specifies the matching of a regular
9731 /// expression against a string. This function is called by the
9732 /// `String.prototype.match()` method.
9733 ///
9734 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/match)
9735 #[wasm_bindgen(static_method_of = Symbol, getter, js_name = match)]
9736 pub fn match_() -> Symbol;
9737
9738 /// The `Symbol.replace` well-known symbol specifies the method that
9739 /// replaces matched substrings of a string. This function is called by the
9740 /// `String.prototype.replace()` method.
9741 ///
9742 /// For more information, see `RegExp.prototype[@@replace]()` and
9743 /// `String.prototype.replace()`.
9744 ///
9745 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/replace)
9746 #[wasm_bindgen(static_method_of = Symbol, getter)]
9747 pub fn replace() -> Symbol;
9748
9749 /// The `Symbol.search` well-known symbol specifies the method that returns
9750 /// the index within a string that matches the regular expression. This
9751 /// function is called by the `String.prototype.search()` method.
9752 ///
9753 /// For more information, see `RegExp.prototype[@@search]()` and
9754 /// `String.prototype.search()`.
9755 ///
9756 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/search)
9757 #[wasm_bindgen(static_method_of = Symbol, getter)]
9758 pub fn search() -> Symbol;
9759
9760 /// The well-known symbol `Symbol.species` specifies a function-valued
9761 /// property that the constructor function uses to create derived objects.
9762 ///
9763 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/species)
9764 #[wasm_bindgen(static_method_of = Symbol, getter)]
9765 pub fn species() -> Symbol;
9766
9767 /// The `Symbol.split` well-known symbol specifies the method that splits a
9768 /// string at the indices that match a regular expression. This function is
9769 /// called by the `String.prototype.split()` method.
9770 ///
9771 /// For more information, see `RegExp.prototype[@@split]()` and
9772 /// `String.prototype.split()`.
9773 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/split)
9774 #[wasm_bindgen(static_method_of = Symbol, getter)]
9775 pub fn split() -> Symbol;
9776
9777 /// The `Symbol.toPrimitive` is a symbol that specifies a function valued
9778 /// property that is called to convert an object to a corresponding
9779 /// primitive value.
9780 ///
9781 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toPrimitive)
9782 #[wasm_bindgen(static_method_of = Symbol, getter, js_name = toPrimitive)]
9783 pub fn to_primitive() -> Symbol;
9784
9785 /// The `Symbol.toStringTag` well-known symbol is a string valued property
9786 /// that is used in the creation of the default string description of an
9787 /// object. It is accessed internally by the `Object.prototype.toString()`
9788 /// method.
9789 ///
9790 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toString)
9791 #[wasm_bindgen(static_method_of = Symbol, getter, js_name = toStringTag)]
9792 pub fn to_string_tag() -> Symbol;
9793
9794 /// The `Symbol.for(key)` method searches for existing symbols in a runtime-wide symbol registry with
9795 /// the given key and returns it if found.
9796 /// Otherwise a new symbol gets created in the global symbol registry with this key.
9797 ///
9798 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/for)
9799 #[wasm_bindgen(static_method_of = Symbol, js_name = for)]
9800 pub fn for_(key: &str) -> Symbol;
9801
9802 /// The `Symbol.keyFor(sym)` method retrieves a shared symbol key from the global symbol registry for the given symbol.
9803 ///
9804 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/keyFor)
9805 #[wasm_bindgen(static_method_of = Symbol, js_name = keyFor)]
9806 pub fn key_for(sym: &Symbol) -> JsValue;
9807
9808 // Next major: deprecate
9809 /// The `toString()` method returns a string representing the specified Symbol object.
9810 ///
9811 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toString)
9812 #[wasm_bindgen(method, js_name = toString)]
9813 pub fn to_string(this: &Symbol) -> JsString;
9814
9815 /// The `toString()` method returns a string representing the specified Symbol object.
9816 ///
9817 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toString)
9818 #[wasm_bindgen(method, js_name = toString)]
9819 pub fn to_js_string(this: &Symbol) -> JsString;
9820
9821 /// The `Symbol.unscopables` well-known symbol is used to specify an object
9822 /// value of whose own and inherited property names are excluded from the
9823 /// with environment bindings of the associated object.
9824 ///
9825 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/unscopables)
9826 #[wasm_bindgen(static_method_of = Symbol, getter)]
9827 pub fn unscopables() -> Symbol;
9828
9829 /// The `valueOf()` method returns the primitive value of a Symbol object.
9830 ///
9831 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/valueOf)
9832 #[wasm_bindgen(method, js_name = valueOf)]
9833 pub fn value_of(this: &Symbol) -> Symbol;
9834}
9835
9836#[allow(non_snake_case)]
9837pub mod Intl {
9838 use super::*;
9839
9840 // Intl
9841 #[wasm_bindgen]
9842 extern "C" {
9843 /// The `Intl.getCanonicalLocales()` method returns an array containing
9844 /// the canonical locale names. Duplicates will be omitted and elements
9845 /// will be validated as structurally valid language tags.
9846 ///
9847 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/getCanonicalLocales)
9848 #[cfg(not(js_sys_unstable_apis))]
9849 #[wasm_bindgen(js_name = getCanonicalLocales, js_namespace = Intl)]
9850 pub fn get_canonical_locales(s: &JsValue) -> Array;
9851
9852 /// The `Intl.getCanonicalLocales()` method returns an array containing
9853 /// the canonical locale names. Duplicates will be omitted and elements
9854 /// will be validated as structurally valid language tags.
9855 ///
9856 /// Throws a `RangeError` if any of the strings are not valid locale identifiers.
9857 ///
9858 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/getCanonicalLocales)
9859 #[cfg(js_sys_unstable_apis)]
9860 #[wasm_bindgen(js_name = getCanonicalLocales, js_namespace = Intl, catch)]
9861 pub fn get_canonical_locales(s: &[JsString]) -> Result<Array<JsString>, JsValue>;
9862
9863 /// The `Intl.supportedValuesOf()` method returns an array containing the
9864 /// supported calendar, collation, currency, numbering system, or unit values
9865 /// supported by the implementation.
9866 ///
9867 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/supportedValuesOf)
9868 #[wasm_bindgen(js_name = supportedValuesOf, js_namespace = Intl)]
9869 pub fn supported_values_of(key: SupportedValuesKey) -> Array<JsString>;
9870 }
9871
9872 // Intl string enums
9873
9874 /// Key for `Intl.supportedValuesOf()`.
9875 #[wasm_bindgen]
9876 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9877 pub enum SupportedValuesKey {
9878 Calendar = "calendar",
9879 Collation = "collation",
9880 Currency = "currency",
9881 NumberingSystem = "numberingSystem",
9882 TimeZone = "timeZone",
9883 Unit = "unit",
9884 }
9885
9886 /// Locale matching algorithm for Intl constructors.
9887 #[wasm_bindgen]
9888 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9889 pub enum LocaleMatcher {
9890 Lookup = "lookup",
9891 BestFit = "best fit",
9892 }
9893
9894 /// Usage for `Intl.Collator`.
9895 #[wasm_bindgen]
9896 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9897 pub enum CollatorUsage {
9898 Sort = "sort",
9899 Search = "search",
9900 }
9901
9902 /// Sensitivity for `Intl.Collator`.
9903 #[wasm_bindgen]
9904 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9905 pub enum CollatorSensitivity {
9906 Base = "base",
9907 Accent = "accent",
9908 Case = "case",
9909 Variant = "variant",
9910 }
9911
9912 /// Case first option for `Intl.Collator`.
9913 #[wasm_bindgen]
9914 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9915 pub enum CollatorCaseFirst {
9916 Upper = "upper",
9917 Lower = "lower",
9918 False = "false",
9919 }
9920
9921 /// Style for `Intl.NumberFormat`.
9922 #[wasm_bindgen]
9923 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9924 pub enum NumberFormatStyle {
9925 Decimal = "decimal",
9926 Currency = "currency",
9927 Percent = "percent",
9928 Unit = "unit",
9929 }
9930
9931 /// Currency display for `Intl.NumberFormat`.
9932 #[wasm_bindgen]
9933 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9934 pub enum CurrencyDisplay {
9935 Code = "code",
9936 Symbol = "symbol",
9937 NarrowSymbol = "narrowSymbol",
9938 Name = "name",
9939 }
9940
9941 /// Currency sign for `Intl.NumberFormat`.
9942 #[wasm_bindgen]
9943 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9944 pub enum CurrencySign {
9945 Standard = "standard",
9946 Accounting = "accounting",
9947 }
9948
9949 /// Unit display for `Intl.NumberFormat`.
9950 #[wasm_bindgen]
9951 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9952 pub enum UnitDisplay {
9953 Short = "short",
9954 Narrow = "narrow",
9955 Long = "long",
9956 }
9957
9958 /// Notation for `Intl.NumberFormat`.
9959 #[wasm_bindgen]
9960 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9961 pub enum NumberFormatNotation {
9962 Standard = "standard",
9963 Scientific = "scientific",
9964 Engineering = "engineering",
9965 Compact = "compact",
9966 }
9967
9968 /// Compact display for `Intl.NumberFormat`.
9969 #[wasm_bindgen]
9970 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9971 pub enum CompactDisplay {
9972 Short = "short",
9973 Long = "long",
9974 }
9975
9976 /// Sign display for `Intl.NumberFormat`.
9977 #[wasm_bindgen]
9978 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9979 pub enum SignDisplay {
9980 Auto = "auto",
9981 Never = "never",
9982 Always = "always",
9983 ExceptZero = "exceptZero",
9984 }
9985
9986 /// Rounding mode for `Intl.NumberFormat`.
9987 #[wasm_bindgen]
9988 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9989 pub enum RoundingMode {
9990 Ceil = "ceil",
9991 Floor = "floor",
9992 Expand = "expand",
9993 Trunc = "trunc",
9994 HalfCeil = "halfCeil",
9995 HalfFloor = "halfFloor",
9996 HalfExpand = "halfExpand",
9997 HalfTrunc = "halfTrunc",
9998 HalfEven = "halfEven",
9999 }
10000
10001 /// Rounding priority for `Intl.NumberFormat`.
10002 #[wasm_bindgen]
10003 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10004 pub enum RoundingPriority {
10005 Auto = "auto",
10006 MorePrecision = "morePrecision",
10007 LessPrecision = "lessPrecision",
10008 }
10009
10010 /// Trailing zero display for `Intl.NumberFormat`.
10011 #[wasm_bindgen]
10012 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10013 pub enum TrailingZeroDisplay {
10014 Auto = "auto",
10015 StripIfInteger = "stripIfInteger",
10016 }
10017
10018 /// Use grouping option for `Intl.NumberFormat`.
10019 ///
10020 /// Determines whether to use grouping separators, such as thousands
10021 /// separators or thousand/lakh/crore separators.
10022 ///
10023 /// The default is `Min2` if notation is "compact", and `Auto` otherwise.
10024 ///
10025 /// Note: The string values `"true"` and `"false"` are accepted by JavaScript
10026 /// but are always converted to the default value. Use `True` and `False`
10027 /// variants for the boolean behavior.
10028 ///
10029 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#usegrouping)
10030 #[wasm_bindgen]
10031 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10032 pub enum UseGrouping {
10033 /// Display grouping separators even if the locale prefers otherwise.
10034 Always = "always",
10035 /// Display grouping separators based on the locale preference,
10036 /// which may also be dependent on the currency.
10037 Auto = "auto",
10038 /// Display grouping separators when there are at least 2 digits in a group.
10039 Min2 = "min2",
10040 /// Same as `Always`. Display grouping separators even if the locale prefers otherwise.
10041 True = "true",
10042 /// Display no grouping separators.
10043 False = "false",
10044 }
10045
10046 /// Date/time style for `Intl.DateTimeFormat`.
10047 #[wasm_bindgen]
10048 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10049 pub enum DateTimeStyle {
10050 Full = "full",
10051 Long = "long",
10052 Medium = "medium",
10053 Short = "short",
10054 }
10055
10056 /// Hour cycle for `Intl.DateTimeFormat`.
10057 #[wasm_bindgen]
10058 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10059 pub enum HourCycle {
10060 H11 = "h11",
10061 H12 = "h12",
10062 H23 = "h23",
10063 H24 = "h24",
10064 }
10065
10066 /// Weekday format for `Intl.DateTimeFormat`.
10067 #[wasm_bindgen]
10068 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10069 pub enum WeekdayFormat {
10070 Narrow = "narrow",
10071 Short = "short",
10072 Long = "long",
10073 }
10074
10075 /// Era format for `Intl.DateTimeFormat`.
10076 #[wasm_bindgen]
10077 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10078 pub enum EraFormat {
10079 Narrow = "narrow",
10080 Short = "short",
10081 Long = "long",
10082 }
10083
10084 /// Year format for `Intl.DateTimeFormat`.
10085 #[wasm_bindgen]
10086 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10087 pub enum YearFormat {
10088 Numeric = "numeric",
10089 TwoDigit = "2-digit",
10090 }
10091
10092 /// Month format for `Intl.DateTimeFormat`.
10093 #[wasm_bindgen]
10094 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10095 pub enum MonthFormat {
10096 #[wasm_bindgen]
10097 Numeric = "numeric",
10098 #[wasm_bindgen]
10099 TwoDigit = "2-digit",
10100 #[wasm_bindgen]
10101 Narrow = "narrow",
10102 #[wasm_bindgen]
10103 Short = "short",
10104 #[wasm_bindgen]
10105 Long = "long",
10106 }
10107
10108 /// Day format for `Intl.DateTimeFormat`.
10109 #[wasm_bindgen]
10110 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10111 pub enum DayFormat {
10112 #[wasm_bindgen]
10113 Numeric = "numeric",
10114 #[wasm_bindgen]
10115 TwoDigit = "2-digit",
10116 }
10117
10118 /// Hour/minute/second format for `Intl.DateTimeFormat`.
10119 #[wasm_bindgen]
10120 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10121 pub enum NumericFormat {
10122 #[wasm_bindgen]
10123 Numeric = "numeric",
10124 #[wasm_bindgen]
10125 TwoDigit = "2-digit",
10126 }
10127
10128 /// Time zone name format for `Intl.DateTimeFormat`.
10129 #[wasm_bindgen]
10130 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10131 pub enum TimeZoneNameFormat {
10132 Short = "short",
10133 Long = "long",
10134 ShortOffset = "shortOffset",
10135 LongOffset = "longOffset",
10136 ShortGeneric = "shortGeneric",
10137 LongGeneric = "longGeneric",
10138 }
10139
10140 /// Day period format for `Intl.DateTimeFormat`.
10141 #[wasm_bindgen]
10142 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10143 pub enum DayPeriodFormat {
10144 Narrow = "narrow",
10145 Short = "short",
10146 Long = "long",
10147 }
10148
10149 /// Part type for `DateTimeFormat.formatToParts()`.
10150 #[wasm_bindgen]
10151 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10152 pub enum DateTimeFormatPartType {
10153 Day = "day",
10154 DayPeriod = "dayPeriod",
10155 Era = "era",
10156 FractionalSecond = "fractionalSecond",
10157 Hour = "hour",
10158 Literal = "literal",
10159 Minute = "minute",
10160 Month = "month",
10161 RelatedYear = "relatedYear",
10162 Second = "second",
10163 TimeZoneName = "timeZoneName",
10164 Weekday = "weekday",
10165 Year = "year",
10166 YearName = "yearName",
10167 }
10168
10169 /// Part type for `NumberFormat.formatToParts()`.
10170 #[wasm_bindgen]
10171 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10172 pub enum NumberFormatPartType {
10173 Compact = "compact",
10174 Currency = "currency",
10175 Decimal = "decimal",
10176 ExponentInteger = "exponentInteger",
10177 ExponentMinusSign = "exponentMinusSign",
10178 ExponentSeparator = "exponentSeparator",
10179 Fraction = "fraction",
10180 Group = "group",
10181 Infinity = "infinity",
10182 Integer = "integer",
10183 Literal = "literal",
10184 MinusSign = "minusSign",
10185 Nan = "nan",
10186 PercentSign = "percentSign",
10187 PlusSign = "plusSign",
10188 Unit = "unit",
10189 Unknown = "unknown",
10190 }
10191
10192 /// Type for `Intl.PluralRules` (cardinal or ordinal).
10193 #[wasm_bindgen]
10194 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10195 pub enum PluralRulesType {
10196 Cardinal = "cardinal",
10197 Ordinal = "ordinal",
10198 }
10199
10200 /// Plural category returned by `PluralRules.select()`.
10201 #[wasm_bindgen]
10202 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10203 pub enum PluralCategory {
10204 Zero = "zero",
10205 One = "one",
10206 Two = "two",
10207 Few = "few",
10208 Many = "many",
10209 Other = "other",
10210 }
10211
10212 /// Numeric option for `Intl.RelativeTimeFormat`.
10213 #[wasm_bindgen]
10214 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10215 pub enum RelativeTimeFormatNumeric {
10216 Always = "always",
10217 Auto = "auto",
10218 }
10219
10220 /// Style for `Intl.RelativeTimeFormat`.
10221 #[wasm_bindgen]
10222 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10223 pub enum RelativeTimeFormatStyle {
10224 Long = "long",
10225 Short = "short",
10226 Narrow = "narrow",
10227 }
10228
10229 /// Unit for `RelativeTimeFormat.format()`.
10230 #[wasm_bindgen]
10231 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10232 pub enum RelativeTimeFormatUnit {
10233 Year = "year",
10234 Years = "years",
10235 Quarter = "quarter",
10236 Quarters = "quarters",
10237 Month = "month",
10238 Months = "months",
10239 Week = "week",
10240 Weeks = "weeks",
10241 Day = "day",
10242 Days = "days",
10243 Hour = "hour",
10244 Hours = "hours",
10245 Minute = "minute",
10246 Minutes = "minutes",
10247 Second = "second",
10248 Seconds = "seconds",
10249 }
10250
10251 /// Part type for `RelativeTimeFormat.formatToParts()`.
10252 #[wasm_bindgen]
10253 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10254 pub enum RelativeTimeFormatPartType {
10255 Literal = "literal",
10256 Integer = "integer",
10257 Decimal = "decimal",
10258 Fraction = "fraction",
10259 }
10260
10261 /// Source indicator for range format parts.
10262 ///
10263 /// Indicates which part of the range (start, end, or shared) a formatted
10264 /// part belongs to when using `formatRangeToParts()`.
10265 ///
10266 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatRangeToParts#description)
10267 #[wasm_bindgen]
10268 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10269 pub enum RangeSource {
10270 /// The part is from the start of the range.
10271 StartRange = "startRange",
10272 /// The part is from the end of the range.
10273 EndRange = "endRange",
10274 /// The part is shared between start and end (e.g., a separator or common element).
10275 Shared = "shared",
10276 }
10277
10278 /// Type for `Intl.ListFormat`.
10279 #[wasm_bindgen]
10280 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10281 pub enum ListFormatType {
10282 /// For lists of standalone items (default).
10283 Conjunction = "conjunction",
10284 /// For lists representing alternatives.
10285 Disjunction = "disjunction",
10286 /// For lists of values with units.
10287 Unit = "unit",
10288 }
10289
10290 /// Style for `Intl.ListFormat`.
10291 #[wasm_bindgen]
10292 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10293 pub enum ListFormatStyle {
10294 /// "A, B, and C" (default).
10295 Long = "long",
10296 /// "A, B, C".
10297 Short = "short",
10298 /// "A B C".
10299 Narrow = "narrow",
10300 }
10301
10302 /// Part type for `Intl.ListFormat.formatToParts()`.
10303 #[wasm_bindgen]
10304 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10305 pub enum ListFormatPartType {
10306 /// A value from the list.
10307 Element = "element",
10308 /// A linguistic construct (e.g., ", ", " and ").
10309 Literal = "literal",
10310 }
10311
10312 /// Type for `Intl.Segmenter`.
10313 #[wasm_bindgen]
10314 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10315 pub enum SegmenterGranularity {
10316 /// Segment by grapheme clusters (user-perceived characters).
10317 Grapheme = "grapheme",
10318 /// Segment by words.
10319 Word = "word",
10320 /// Segment by sentences.
10321 Sentence = "sentence",
10322 }
10323
10324 /// Type for `Intl.DisplayNames`.
10325 #[wasm_bindgen]
10326 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10327 pub enum DisplayNamesType {
10328 /// Language display names.
10329 Language = "language",
10330 /// Region display names.
10331 Region = "region",
10332 /// Script display names.
10333 Script = "script",
10334 /// Currency display names.
10335 Currency = "currency",
10336 /// Calendar display names.
10337 Calendar = "calendar",
10338 /// Date/time field display names.
10339 DateTimeField = "dateTimeField",
10340 }
10341
10342 /// Style for `Intl.DisplayNames`.
10343 #[wasm_bindgen]
10344 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10345 pub enum DisplayNamesStyle {
10346 /// Full display name (default).
10347 Long = "long",
10348 /// Abbreviated display name.
10349 Short = "short",
10350 /// Minimal display name.
10351 Narrow = "narrow",
10352 }
10353
10354 /// Fallback for `Intl.DisplayNames`.
10355 #[wasm_bindgen]
10356 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10357 pub enum DisplayNamesFallback {
10358 /// Return the input code if no display name is available (default).
10359 Code = "code",
10360 /// Return undefined if no display name is available.
10361 None = "none",
10362 }
10363
10364 /// Language display for `Intl.DisplayNames`.
10365 #[wasm_bindgen]
10366 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10367 pub enum DisplayNamesLanguageDisplay {
10368 /// Use dialect names (e.g., "British English").
10369 Dialect = "dialect",
10370 /// Use standard names (e.g., "English (United Kingdom)").
10371 Standard = "standard",
10372 }
10373
10374 // Intl.RelativeTimeFormatOptions
10375 #[wasm_bindgen]
10376 extern "C" {
10377 /// Options for `Intl.RelativeTimeFormat` constructor.
10378 ///
10379 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/RelativeTimeFormat#options)
10380 #[wasm_bindgen(extends = Object)]
10381 #[derive(Clone, Debug)]
10382 pub type RelativeTimeFormatOptions;
10383
10384 #[wasm_bindgen(method, getter = localeMatcher)]
10385 pub fn get_locale_matcher(this: &RelativeTimeFormatOptions) -> Option<LocaleMatcher>;
10386 #[wasm_bindgen(method, setter = localeMatcher)]
10387 pub fn set_locale_matcher(this: &RelativeTimeFormatOptions, value: LocaleMatcher);
10388
10389 #[wasm_bindgen(method, getter = numeric)]
10390 pub fn get_numeric(this: &RelativeTimeFormatOptions) -> Option<RelativeTimeFormatNumeric>;
10391 #[wasm_bindgen(method, setter = numeric)]
10392 pub fn set_numeric(this: &RelativeTimeFormatOptions, value: RelativeTimeFormatNumeric);
10393
10394 #[wasm_bindgen(method, getter = style)]
10395 pub fn get_style(this: &RelativeTimeFormatOptions) -> Option<RelativeTimeFormatStyle>;
10396 #[wasm_bindgen(method, setter = style)]
10397 pub fn set_style(this: &RelativeTimeFormatOptions, value: RelativeTimeFormatStyle);
10398 }
10399
10400 impl RelativeTimeFormatOptions {
10401 pub fn new() -> RelativeTimeFormatOptions {
10402 JsCast::unchecked_into(Object::new())
10403 }
10404 }
10405
10406 impl Default for RelativeTimeFormatOptions {
10407 fn default() -> Self {
10408 RelativeTimeFormatOptions::new()
10409 }
10410 }
10411
10412 // Intl.ResolvedRelativeTimeFormatOptions
10413 #[wasm_bindgen]
10414 extern "C" {
10415 /// Resolved options returned by `Intl.RelativeTimeFormat.prototype.resolvedOptions()`.
10416 ///
10417 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/resolvedOptions)
10418 #[wasm_bindgen(extends = RelativeTimeFormatOptions)]
10419 #[derive(Clone, Debug)]
10420 pub type ResolvedRelativeTimeFormatOptions;
10421
10422 /// The resolved locale string.
10423 #[wasm_bindgen(method, getter = locale)]
10424 pub fn get_locale(this: &ResolvedRelativeTimeFormatOptions) -> JsString;
10425
10426 /// The numbering system used.
10427 #[wasm_bindgen(method, getter = numberingSystem)]
10428 pub fn get_numbering_system(this: &ResolvedRelativeTimeFormatOptions) -> JsString;
10429 }
10430
10431 // Intl.RelativeTimeFormatPart
10432 #[wasm_bindgen]
10433 extern "C" {
10434 /// A part of the formatted relative time returned by `formatToParts()`.
10435 ///
10436 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/formatToParts)
10437 #[wasm_bindgen(extends = Object)]
10438 #[derive(Clone, Debug)]
10439 pub type RelativeTimeFormatPart;
10440
10441 /// The type of this part.
10442 #[wasm_bindgen(method, getter = type)]
10443 pub fn type_(this: &RelativeTimeFormatPart) -> RelativeTimeFormatPartType;
10444
10445 /// The string value of this part.
10446 #[wasm_bindgen(method, getter = value)]
10447 pub fn value(this: &RelativeTimeFormatPart) -> JsString;
10448
10449 /// The unit used in this part (only for integer parts).
10450 #[wasm_bindgen(method, getter = unit)]
10451 pub fn unit(this: &RelativeTimeFormatPart) -> Option<JsString>;
10452 }
10453
10454 // Intl.LocaleMatcherOptions
10455 #[wasm_bindgen]
10456 extern "C" {
10457 /// Options for `supportedLocalesOf` methods.
10458 #[wasm_bindgen(extends = Object)]
10459 #[derive(Clone, Debug)]
10460 pub type LocaleMatcherOptions;
10461
10462 #[wasm_bindgen(method, getter = localeMatcher)]
10463 pub fn get_locale_matcher(this: &LocaleMatcherOptions) -> Option<LocaleMatcher>;
10464
10465 #[wasm_bindgen(method, setter = localeMatcher)]
10466 pub fn set_locale_matcher(this: &LocaleMatcherOptions, value: LocaleMatcher);
10467 }
10468
10469 impl LocaleMatcherOptions {
10470 pub fn new() -> LocaleMatcherOptions {
10471 JsCast::unchecked_into(Object::new())
10472 }
10473 }
10474
10475 impl Default for LocaleMatcherOptions {
10476 fn default() -> Self {
10477 LocaleMatcherOptions::new()
10478 }
10479 }
10480
10481 // Intl.Collator Options
10482 #[wasm_bindgen]
10483 extern "C" {
10484 /// Options for `Intl.Collator` and `String.prototype.localeCompare`.
10485 ///
10486 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Collator/Collator#options)
10487 #[wasm_bindgen(extends = Object)]
10488 #[derive(Clone, Debug)]
10489 pub type CollatorOptions;
10490
10491 #[wasm_bindgen(method, getter = localeMatcher)]
10492 pub fn get_locale_matcher(this: &CollatorOptions) -> Option<LocaleMatcher>;
10493 #[wasm_bindgen(method, setter = localeMatcher)]
10494 pub fn set_locale_matcher(this: &CollatorOptions, value: LocaleMatcher);
10495
10496 #[wasm_bindgen(method, getter = usage)]
10497 pub fn get_usage(this: &CollatorOptions) -> Option<CollatorUsage>;
10498 #[wasm_bindgen(method, setter = usage)]
10499 pub fn set_usage(this: &CollatorOptions, value: CollatorUsage);
10500
10501 #[wasm_bindgen(method, getter = sensitivity)]
10502 pub fn get_sensitivity(this: &CollatorOptions) -> Option<CollatorSensitivity>;
10503 #[wasm_bindgen(method, setter = sensitivity)]
10504 pub fn set_sensitivity(this: &CollatorOptions, value: CollatorSensitivity);
10505
10506 #[wasm_bindgen(method, getter = ignorePunctuation)]
10507 pub fn get_ignore_punctuation(this: &CollatorOptions) -> Option<bool>;
10508 #[wasm_bindgen(method, setter = ignorePunctuation)]
10509 pub fn set_ignore_punctuation(this: &CollatorOptions, value: bool);
10510
10511 #[wasm_bindgen(method, getter = numeric)]
10512 pub fn get_numeric(this: &CollatorOptions) -> Option<bool>;
10513 #[wasm_bindgen(method, setter = numeric)]
10514 pub fn set_numeric(this: &CollatorOptions, value: bool);
10515
10516 #[wasm_bindgen(method, getter = caseFirst)]
10517 pub fn get_case_first(this: &CollatorOptions) -> Option<CollatorCaseFirst>;
10518 #[wasm_bindgen(method, setter = caseFirst)]
10519 pub fn set_case_first(this: &CollatorOptions, value: CollatorCaseFirst);
10520 }
10521 impl CollatorOptions {
10522 pub fn new() -> CollatorOptions {
10523 JsCast::unchecked_into(Object::new())
10524 }
10525 }
10526 impl Default for CollatorOptions {
10527 fn default() -> Self {
10528 CollatorOptions::new()
10529 }
10530 }
10531
10532 // Intl.Collator ResolvedCollatorOptions
10533 #[wasm_bindgen]
10534 extern "C" {
10535 #[wasm_bindgen(extends = CollatorOptions)]
10536 pub type ResolvedCollatorOptions;
10537
10538 #[wasm_bindgen(method, getter = locale)]
10539 pub fn get_locale(this: &ResolvedCollatorOptions) -> JsString; // not Option, always present
10540 #[wasm_bindgen(method, getter = collation)]
10541 pub fn get_collation(this: &ResolvedCollatorOptions) -> JsString;
10542 }
10543
10544 // Intl.Collator
10545 #[wasm_bindgen]
10546 extern "C" {
10547 /// The `Intl.Collator` object is a constructor for collators, objects
10548 /// that enable language sensitive string comparison.
10549 ///
10550 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator)
10551 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.Collator")]
10552 #[derive(Clone, Debug)]
10553 pub type Collator;
10554
10555 /// The `Intl.Collator` object is a constructor for collators, objects
10556 /// that enable language sensitive string comparison.
10557 ///
10558 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator)
10559 #[cfg(not(js_sys_unstable_apis))]
10560 #[wasm_bindgen(constructor, js_namespace = Intl)]
10561 pub fn new(locales: &Array, options: &Object) -> Collator;
10562
10563 /// The `Intl.Collator` object is a constructor for collators, objects
10564 /// that enable language sensitive string comparison.
10565 ///
10566 /// Throws a `RangeError` if locales contain invalid values.
10567 ///
10568 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator)
10569 #[cfg(js_sys_unstable_apis)]
10570 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
10571 pub fn new(locales: &[JsString], options: &CollatorOptions) -> Result<Collator, JsValue>;
10572
10573 /// The Intl.Collator.prototype.compare property returns a function that
10574 /// compares two strings according to the sort order of this Collator
10575 /// object.
10576 ///
10577 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/compare)
10578 #[cfg(not(js_sys_unstable_apis))]
10579 #[wasm_bindgen(method, getter, js_class = "Intl.Collator")]
10580 pub fn compare(this: &Collator) -> Function;
10581
10582 /// Compares two strings according to the sort order of this Collator.
10583 ///
10584 /// Returns a negative value if `a` comes before `b`, positive if `a` comes
10585 /// after `b`, and zero if they are equal.
10586 ///
10587 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Collator/compare)
10588 #[cfg(js_sys_unstable_apis)]
10589 #[wasm_bindgen(method, js_class = "Intl.Collator")]
10590 pub fn compare(this: &Collator, a: &str, b: &str) -> i32;
10591
10592 /// The `Intl.Collator.prototype.resolvedOptions()` method returns a new
10593 /// object with properties reflecting the locale and collation options
10594 /// computed during initialization of this Collator object.
10595 ///
10596 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/resolvedOptions)
10597 #[cfg(not(js_sys_unstable_apis))]
10598 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
10599 pub fn resolved_options(this: &Collator) -> Object;
10600
10601 /// The `Intl.Collator.prototype.resolvedOptions()` method returns a new
10602 /// object with properties reflecting the locale and collation options
10603 /// computed during initialization of this Collator object.
10604 ///
10605 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/resolvedOptions)
10606 #[cfg(js_sys_unstable_apis)]
10607 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
10608 pub fn resolved_options(this: &Collator) -> ResolvedCollatorOptions;
10609
10610 /// The `Intl.Collator.supportedLocalesOf()` method returns an array
10611 /// containing those of the provided locales that are supported in
10612 /// collation without having to fall back to the runtime's default
10613 /// locale.
10614 ///
10615 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/supportedLocalesOf)
10616 #[cfg(not(js_sys_unstable_apis))]
10617 #[wasm_bindgen(static_method_of = Collator, js_namespace = Intl, js_name = supportedLocalesOf)]
10618 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
10619
10620 /// The `Intl.Collator.supportedLocalesOf()` method returns an array
10621 /// containing those of the provided locales that are supported in
10622 /// collation without having to fall back to the runtime's default
10623 /// locale.
10624 ///
10625 /// Throws a `RangeError` if locales contain invalid values.
10626 ///
10627 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/supportedLocalesOf)
10628 #[cfg(js_sys_unstable_apis)]
10629 #[wasm_bindgen(static_method_of = Collator, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
10630 pub fn supported_locales_of(
10631 locales: &[JsString],
10632 options: &LocaleMatcherOptions,
10633 ) -> Result<Array<JsString>, JsValue>;
10634 }
10635
10636 #[cfg(not(js_sys_unstable_apis))]
10637 impl Default for Collator {
10638 fn default() -> Self {
10639 Self::new(
10640 &JsValue::UNDEFINED.unchecked_into(),
10641 &JsValue::UNDEFINED.unchecked_into(),
10642 )
10643 }
10644 }
10645
10646 #[cfg(js_sys_unstable_apis)]
10647 impl Default for Collator {
10648 fn default() -> Self {
10649 Self::new(&[], &Default::default()).unwrap()
10650 }
10651 }
10652
10653 // Intl.DateTimeFormatOptions
10654 #[wasm_bindgen]
10655 extern "C" {
10656 /// Options for `Intl.DateTimeFormat` constructor.
10657 ///
10658 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat#options)
10659 #[wasm_bindgen(extends = Object)]
10660 #[derive(Clone, Debug)]
10661 pub type DateTimeFormatOptions;
10662
10663 // Locale matching
10664 #[wasm_bindgen(method, getter = localeMatcher)]
10665 pub fn get_locale_matcher(this: &DateTimeFormatOptions) -> Option<LocaleMatcher>;
10666 #[wasm_bindgen(method, setter = localeMatcher)]
10667 pub fn set_locale_matcher(this: &DateTimeFormatOptions, value: LocaleMatcher);
10668
10669 // Calendar/numbering (free-form strings, no enum)
10670 #[wasm_bindgen(method, getter = calendar)]
10671 pub fn get_calendar(this: &DateTimeFormatOptions) -> Option<JsString>;
10672 #[wasm_bindgen(method, setter = calendar)]
10673 pub fn set_calendar(this: &DateTimeFormatOptions, value: &str);
10674
10675 #[wasm_bindgen(method, getter = numberingSystem)]
10676 pub fn get_numbering_system(this: &DateTimeFormatOptions) -> Option<JsString>;
10677 #[wasm_bindgen(method, setter = numberingSystem)]
10678 pub fn set_numbering_system(this: &DateTimeFormatOptions, value: &str);
10679
10680 // Timezone (free-form string)
10681 #[wasm_bindgen(method, getter = timeZone)]
10682 pub fn get_time_zone(this: &DateTimeFormatOptions) -> Option<JsString>;
10683 #[wasm_bindgen(method, setter = timeZone)]
10684 pub fn set_time_zone(this: &DateTimeFormatOptions, value: &str);
10685
10686 // Hour cycle
10687 #[wasm_bindgen(method, getter = hour12)]
10688 pub fn get_hour12(this: &DateTimeFormatOptions) -> Option<bool>;
10689 #[wasm_bindgen(method, setter = hour12)]
10690 pub fn set_hour12(this: &DateTimeFormatOptions, value: bool);
10691
10692 #[wasm_bindgen(method, getter = hourCycle)]
10693 pub fn get_hour_cycle(this: &DateTimeFormatOptions) -> Option<HourCycle>;
10694 #[wasm_bindgen(method, setter = hourCycle)]
10695 pub fn set_hour_cycle(this: &DateTimeFormatOptions, value: HourCycle);
10696
10697 // Style shortcuts
10698 #[wasm_bindgen(method, getter = dateStyle)]
10699 pub fn get_date_style(this: &DateTimeFormatOptions) -> Option<DateTimeStyle>;
10700 #[wasm_bindgen(method, setter = dateStyle)]
10701 pub fn set_date_style(this: &DateTimeFormatOptions, value: DateTimeStyle);
10702
10703 #[wasm_bindgen(method, getter = timeStyle)]
10704 pub fn get_time_style(this: &DateTimeFormatOptions) -> Option<DateTimeStyle>;
10705 #[wasm_bindgen(method, setter = timeStyle)]
10706 pub fn set_time_style(this: &DateTimeFormatOptions, value: DateTimeStyle);
10707
10708 // Component options
10709 #[wasm_bindgen(method, getter = weekday)]
10710 pub fn get_weekday(this: &DateTimeFormatOptions) -> Option<WeekdayFormat>;
10711 #[wasm_bindgen(method, setter = weekday)]
10712 pub fn set_weekday(this: &DateTimeFormatOptions, value: WeekdayFormat);
10713
10714 #[wasm_bindgen(method, getter = era)]
10715 pub fn get_era(this: &DateTimeFormatOptions) -> Option<EraFormat>;
10716 #[wasm_bindgen(method, setter = era)]
10717 pub fn set_era(this: &DateTimeFormatOptions, value: EraFormat);
10718
10719 #[wasm_bindgen(method, getter = year)]
10720 pub fn get_year(this: &DateTimeFormatOptions) -> Option<YearFormat>;
10721 #[wasm_bindgen(method, setter = year)]
10722 pub fn set_year(this: &DateTimeFormatOptions, value: YearFormat);
10723
10724 #[wasm_bindgen(method, getter = month)]
10725 pub fn get_month(this: &DateTimeFormatOptions) -> Option<MonthFormat>;
10726 #[wasm_bindgen(method, setter = month)]
10727 pub fn set_month(this: &DateTimeFormatOptions, value: MonthFormat);
10728
10729 #[wasm_bindgen(method, getter = day)]
10730 pub fn get_day(this: &DateTimeFormatOptions) -> Option<DayFormat>;
10731 #[wasm_bindgen(method, setter = day)]
10732 pub fn set_day(this: &DateTimeFormatOptions, value: DayFormat);
10733
10734 #[wasm_bindgen(method, getter = hour)]
10735 pub fn get_hour(this: &DateTimeFormatOptions) -> Option<NumericFormat>;
10736 #[wasm_bindgen(method, setter = hour)]
10737 pub fn set_hour(this: &DateTimeFormatOptions, value: NumericFormat);
10738
10739 #[wasm_bindgen(method, getter = minute)]
10740 pub fn get_minute(this: &DateTimeFormatOptions) -> Option<NumericFormat>;
10741 #[wasm_bindgen(method, setter = minute)]
10742 pub fn set_minute(this: &DateTimeFormatOptions, value: NumericFormat);
10743
10744 #[wasm_bindgen(method, getter = second)]
10745 pub fn get_second(this: &DateTimeFormatOptions) -> Option<NumericFormat>;
10746 #[wasm_bindgen(method, setter = second)]
10747 pub fn set_second(this: &DateTimeFormatOptions, value: NumericFormat);
10748
10749 #[wasm_bindgen(method, getter = fractionalSecondDigits)]
10750 pub fn get_fractional_second_digits(this: &DateTimeFormatOptions) -> Option<u8>;
10751 #[wasm_bindgen(method, setter = fractionalSecondDigits)]
10752 pub fn set_fractional_second_digits(this: &DateTimeFormatOptions, value: u8);
10753
10754 #[wasm_bindgen(method, getter = timeZoneName)]
10755 pub fn get_time_zone_name(this: &DateTimeFormatOptions) -> Option<TimeZoneNameFormat>;
10756 #[wasm_bindgen(method, setter = timeZoneName)]
10757 pub fn set_time_zone_name(this: &DateTimeFormatOptions, value: TimeZoneNameFormat);
10758
10759 #[wasm_bindgen(method, getter = dayPeriod)]
10760 pub fn get_day_period(this: &DateTimeFormatOptions) -> Option<DayPeriodFormat>;
10761 #[wasm_bindgen(method, setter = dayPeriod)]
10762 pub fn set_day_period(this: &DateTimeFormatOptions, value: DayPeriodFormat);
10763 }
10764
10765 impl DateTimeFormatOptions {
10766 pub fn new() -> DateTimeFormatOptions {
10767 JsCast::unchecked_into(Object::new())
10768 }
10769 }
10770
10771 impl Default for DateTimeFormatOptions {
10772 fn default() -> Self {
10773 DateTimeFormatOptions::new()
10774 }
10775 }
10776
10777 // Intl.ResolvedDateTimeFormatOptions
10778 #[wasm_bindgen]
10779 extern "C" {
10780 /// Resolved options returned by `Intl.DateTimeFormat.prototype.resolvedOptions()`.
10781 ///
10782 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/resolvedOptions)
10783 #[wasm_bindgen(extends = DateTimeFormatOptions)]
10784 #[derive(Clone, Debug)]
10785 pub type ResolvedDateTimeFormatOptions;
10786
10787 /// The resolved locale string.
10788 #[wasm_bindgen(method, getter = locale)]
10789 pub fn get_locale(this: &ResolvedDateTimeFormatOptions) -> JsString;
10790 }
10791
10792 // Intl.DateTimeFormatPart
10793 #[wasm_bindgen]
10794 extern "C" {
10795 /// A part of the formatted date returned by `formatToParts()`.
10796 ///
10797 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatToParts)
10798 #[wasm_bindgen(extends = Object)]
10799 #[derive(Clone, Debug)]
10800 pub type DateTimeFormatPart;
10801
10802 /// The type of the part (e.g., "day", "month", "year", "literal", etc.)
10803 #[wasm_bindgen(method, getter = type)]
10804 pub fn type_(this: &DateTimeFormatPart) -> DateTimeFormatPartType;
10805
10806 /// The value of the part.
10807 #[wasm_bindgen(method, getter)]
10808 pub fn value(this: &DateTimeFormatPart) -> JsString;
10809 }
10810
10811 // Intl.DateTimeRangeFormatPart
10812 #[wasm_bindgen]
10813 extern "C" {
10814 /// A part of the formatted date range returned by `formatRangeToParts()`.
10815 ///
10816 /// Extends `DateTimeFormatPart` with a `source` property indicating whether
10817 /// the part is from the start date, end date, or shared between them.
10818 ///
10819 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatRangeToParts)
10820 #[wasm_bindgen(extends = DateTimeFormatPart)]
10821 #[derive(Clone, Debug)]
10822 pub type DateTimeRangeFormatPart;
10823
10824 /// The source of the part: "startRange", "endRange", or "shared".
10825 #[wasm_bindgen(method, getter)]
10826 pub fn source(this: &DateTimeRangeFormatPart) -> RangeSource;
10827 }
10828
10829 // Intl.DateTimeFormat
10830 #[wasm_bindgen]
10831 extern "C" {
10832 /// The `Intl.DateTimeFormat` object is a constructor for objects
10833 /// that enable language-sensitive date and time formatting.
10834 ///
10835 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat)
10836 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.DateTimeFormat")]
10837 #[derive(Clone, Debug)]
10838 pub type DateTimeFormat;
10839
10840 /// The `Intl.DateTimeFormat` object is a constructor for objects
10841 /// that enable language-sensitive date and time formatting.
10842 ///
10843 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat)
10844 #[cfg(not(js_sys_unstable_apis))]
10845 #[wasm_bindgen(constructor, js_namespace = Intl)]
10846 pub fn new(locales: &Array, options: &Object) -> DateTimeFormat;
10847
10848 /// The `Intl.DateTimeFormat` object is a constructor for objects
10849 /// that enable language-sensitive date and time formatting.
10850 ///
10851 /// Throws a `RangeError` if locales contain invalid values.
10852 ///
10853 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat)
10854 #[cfg(js_sys_unstable_apis)]
10855 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
10856 pub fn new(
10857 locales: &[JsString],
10858 options: &DateTimeFormatOptions,
10859 ) -> Result<DateTimeFormat, JsValue>;
10860
10861 /// The Intl.DateTimeFormat.prototype.format property returns a getter function that
10862 /// formats a date according to the locale and formatting options of this
10863 /// Intl.DateTimeFormat object.
10864 ///
10865 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/format)
10866 #[cfg(not(js_sys_unstable_apis))]
10867 #[wasm_bindgen(method, getter, js_class = "Intl.DateTimeFormat")]
10868 pub fn format(this: &DateTimeFormat) -> Function;
10869
10870 /// Formats a date according to the locale and formatting options of this
10871 /// `Intl.DateTimeFormat` object.
10872 ///
10873 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/format)
10874 #[cfg(js_sys_unstable_apis)]
10875 #[wasm_bindgen(method, js_class = "Intl.DateTimeFormat")]
10876 pub fn format(this: &DateTimeFormat, date: &Date) -> JsString;
10877
10878 /// The `Intl.DateTimeFormat.prototype.formatToParts()` method allows locale-aware
10879 /// formatting of strings produced by DateTimeFormat formatters.
10880 ///
10881 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/formatToParts)
10882 #[cfg(not(js_sys_unstable_apis))]
10883 #[wasm_bindgen(method, js_class = "Intl.DateTimeFormat", js_name = formatToParts)]
10884 pub fn format_to_parts(this: &DateTimeFormat, date: &Date) -> Array;
10885
10886 /// The `Intl.DateTimeFormat.prototype.formatToParts()` method allows locale-aware
10887 /// formatting of strings produced by DateTimeFormat formatters.
10888 ///
10889 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/formatToParts)
10890 #[cfg(js_sys_unstable_apis)]
10891 #[wasm_bindgen(method, js_class = "Intl.DateTimeFormat", js_name = formatToParts)]
10892 pub fn format_to_parts(this: &DateTimeFormat, date: &Date) -> Array<DateTimeFormatPart>;
10893
10894 /// The `Intl.DateTimeFormat.prototype.formatRange()` method formats a date range
10895 /// in the most concise way based on the locales and options provided when
10896 /// instantiating this `Intl.DateTimeFormat` object.
10897 ///
10898 /// Throws a `TypeError` if the dates are invalid.
10899 ///
10900 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatRange)
10901 #[wasm_bindgen(method, js_class = "Intl.DateTimeFormat", js_name = formatRange, catch)]
10902 pub fn format_range(
10903 this: &DateTimeFormat,
10904 start_date: &Date,
10905 end_date: &Date,
10906 ) -> Result<JsString, JsValue>;
10907
10908 /// The `Intl.DateTimeFormat.prototype.formatRangeToParts()` method returns an array
10909 /// of locale-specific tokens representing each part of the formatted date range
10910 /// produced by `Intl.DateTimeFormat` formatters.
10911 ///
10912 /// Throws a `TypeError` if the dates are invalid.
10913 ///
10914 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatRangeToParts)
10915 #[wasm_bindgen(method, js_class = "Intl.DateTimeFormat", js_name = formatRangeToParts, catch)]
10916 pub fn format_range_to_parts(
10917 this: &DateTimeFormat,
10918 start_date: &Date,
10919 end_date: &Date,
10920 ) -> Result<Array<DateTimeRangeFormatPart>, JsValue>;
10921
10922 /// The `Intl.DateTimeFormat.prototype.resolvedOptions()` method returns a new
10923 /// object with properties reflecting the locale and date and time formatting
10924 /// options computed during initialization of this DateTimeFormat object.
10925 ///
10926 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/resolvedOptions)
10927 #[cfg(not(js_sys_unstable_apis))]
10928 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
10929 pub fn resolved_options(this: &DateTimeFormat) -> Object;
10930
10931 /// The `Intl.DateTimeFormat.prototype.resolvedOptions()` method returns a new
10932 /// object with properties reflecting the locale and date and time formatting
10933 /// options computed during initialization of this DateTimeFormat object.
10934 ///
10935 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/resolvedOptions)
10936 #[cfg(js_sys_unstable_apis)]
10937 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
10938 pub fn resolved_options(this: &DateTimeFormat) -> ResolvedDateTimeFormatOptions;
10939
10940 /// The `Intl.DateTimeFormat.supportedLocalesOf()` method returns an array
10941 /// containing those of the provided locales that are supported in date
10942 /// and time formatting without having to fall back to the runtime's default
10943 /// locale.
10944 ///
10945 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/supportedLocalesOf)
10946 #[cfg(not(js_sys_unstable_apis))]
10947 #[wasm_bindgen(static_method_of = DateTimeFormat, js_namespace = Intl, js_name = supportedLocalesOf)]
10948 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
10949
10950 /// The `Intl.DateTimeFormat.supportedLocalesOf()` method returns an array
10951 /// containing those of the provided locales that are supported in date
10952 /// and time formatting without having to fall back to the runtime's default
10953 /// locale.
10954 ///
10955 /// Throws a `RangeError` if locales contain invalid values.
10956 ///
10957 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/supportedLocalesOf)
10958 #[cfg(js_sys_unstable_apis)]
10959 #[wasm_bindgen(static_method_of = DateTimeFormat, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
10960 pub fn supported_locales_of(
10961 locales: &[JsString],
10962 options: &LocaleMatcherOptions,
10963 ) -> Result<Array<JsString>, JsValue>;
10964 }
10965
10966 #[cfg(not(js_sys_unstable_apis))]
10967 impl Default for DateTimeFormat {
10968 fn default() -> Self {
10969 Self::new(
10970 &JsValue::UNDEFINED.unchecked_into(),
10971 &JsValue::UNDEFINED.unchecked_into(),
10972 )
10973 }
10974 }
10975
10976 #[cfg(js_sys_unstable_apis)]
10977 impl Default for DateTimeFormat {
10978 fn default() -> Self {
10979 Self::new(&[], &Default::default()).unwrap()
10980 }
10981 }
10982
10983 // Intl.NumberFormatOptions
10984 #[wasm_bindgen]
10985 extern "C" {
10986 /// Options for `Intl.NumberFormat` constructor.
10987 ///
10988 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#options)
10989 #[wasm_bindgen(extends = Object)]
10990 #[derive(Clone, Debug)]
10991 pub type NumberFormatOptions;
10992
10993 // Locale matching
10994 #[wasm_bindgen(method, getter = localeMatcher)]
10995 pub fn get_locale_matcher(this: &NumberFormatOptions) -> Option<LocaleMatcher>;
10996 #[wasm_bindgen(method, setter = localeMatcher)]
10997 pub fn set_locale_matcher(this: &NumberFormatOptions, value: LocaleMatcher);
10998
10999 // Numbering system (free-form string)
11000 #[wasm_bindgen(method, getter = numberingSystem)]
11001 pub fn get_numbering_system(this: &NumberFormatOptions) -> Option<JsString>;
11002 #[wasm_bindgen(method, setter = numberingSystem)]
11003 pub fn set_numbering_system(this: &NumberFormatOptions, value: &str);
11004
11005 // Style
11006 #[wasm_bindgen(method, getter = style)]
11007 pub fn get_style(this: &NumberFormatOptions) -> Option<NumberFormatStyle>;
11008 #[wasm_bindgen(method, setter = style)]
11009 pub fn set_style(this: &NumberFormatOptions, value: NumberFormatStyle);
11010
11011 // Currency options (currency code is free-form ISO 4217 string)
11012 #[wasm_bindgen(method, getter = currency)]
11013 pub fn get_currency(this: &NumberFormatOptions) -> Option<JsString>;
11014 #[wasm_bindgen(method, setter = currency)]
11015 pub fn set_currency(this: &NumberFormatOptions, value: &str);
11016
11017 #[wasm_bindgen(method, getter = currencyDisplay)]
11018 pub fn get_currency_display(this: &NumberFormatOptions) -> Option<CurrencyDisplay>;
11019 #[wasm_bindgen(method, setter = currencyDisplay)]
11020 pub fn set_currency_display(this: &NumberFormatOptions, value: CurrencyDisplay);
11021
11022 #[wasm_bindgen(method, getter = currencySign)]
11023 pub fn get_currency_sign(this: &NumberFormatOptions) -> Option<CurrencySign>;
11024 #[wasm_bindgen(method, setter = currencySign)]
11025 pub fn set_currency_sign(this: &NumberFormatOptions, value: CurrencySign);
11026
11027 // Unit options (unit name is free-form string)
11028 #[wasm_bindgen(method, getter = unit)]
11029 pub fn get_unit(this: &NumberFormatOptions) -> Option<JsString>;
11030 #[wasm_bindgen(method, setter = unit)]
11031 pub fn set_unit(this: &NumberFormatOptions, value: &str);
11032
11033 #[wasm_bindgen(method, getter = unitDisplay)]
11034 pub fn get_unit_display(this: &NumberFormatOptions) -> Option<UnitDisplay>;
11035 #[wasm_bindgen(method, setter = unitDisplay)]
11036 pub fn set_unit_display(this: &NumberFormatOptions, value: UnitDisplay);
11037
11038 // Notation
11039 #[wasm_bindgen(method, getter = notation)]
11040 pub fn get_notation(this: &NumberFormatOptions) -> Option<NumberFormatNotation>;
11041 #[wasm_bindgen(method, setter = notation)]
11042 pub fn set_notation(this: &NumberFormatOptions, value: NumberFormatNotation);
11043
11044 #[wasm_bindgen(method, getter = compactDisplay)]
11045 pub fn get_compact_display(this: &NumberFormatOptions) -> Option<CompactDisplay>;
11046 #[wasm_bindgen(method, setter = compactDisplay)]
11047 pub fn set_compact_display(this: &NumberFormatOptions, value: CompactDisplay);
11048
11049 // Sign display
11050 #[wasm_bindgen(method, getter = signDisplay)]
11051 pub fn get_sign_display(this: &NumberFormatOptions) -> Option<SignDisplay>;
11052 #[wasm_bindgen(method, setter = signDisplay)]
11053 pub fn set_sign_display(this: &NumberFormatOptions, value: SignDisplay);
11054
11055 // Digit options
11056 #[wasm_bindgen(method, getter = minimumIntegerDigits)]
11057 pub fn get_minimum_integer_digits(this: &NumberFormatOptions) -> Option<u8>;
11058 #[wasm_bindgen(method, setter = minimumIntegerDigits)]
11059 pub fn set_minimum_integer_digits(this: &NumberFormatOptions, value: u8);
11060
11061 #[wasm_bindgen(method, getter = minimumFractionDigits)]
11062 pub fn get_minimum_fraction_digits(this: &NumberFormatOptions) -> Option<u8>;
11063 #[wasm_bindgen(method, setter = minimumFractionDigits)]
11064 pub fn set_minimum_fraction_digits(this: &NumberFormatOptions, value: u8);
11065
11066 #[wasm_bindgen(method, getter = maximumFractionDigits)]
11067 pub fn get_maximum_fraction_digits(this: &NumberFormatOptions) -> Option<u8>;
11068 #[wasm_bindgen(method, setter = maximumFractionDigits)]
11069 pub fn set_maximum_fraction_digits(this: &NumberFormatOptions, value: u8);
11070
11071 #[wasm_bindgen(method, getter = minimumSignificantDigits)]
11072 pub fn get_minimum_significant_digits(this: &NumberFormatOptions) -> Option<u8>;
11073 #[wasm_bindgen(method, setter = minimumSignificantDigits)]
11074 pub fn set_minimum_significant_digits(this: &NumberFormatOptions, value: u8);
11075
11076 #[wasm_bindgen(method, getter = maximumSignificantDigits)]
11077 pub fn get_maximum_significant_digits(this: &NumberFormatOptions) -> Option<u8>;
11078 #[wasm_bindgen(method, setter = maximumSignificantDigits)]
11079 pub fn set_maximum_significant_digits(this: &NumberFormatOptions, value: u8);
11080
11081 // Grouping
11082 #[wasm_bindgen(method, getter = useGrouping)]
11083 pub fn get_use_grouping(this: &NumberFormatOptions) -> Option<UseGrouping>;
11084 #[wasm_bindgen(method, setter = useGrouping)]
11085 pub fn set_use_grouping(this: &NumberFormatOptions, value: UseGrouping);
11086
11087 // Rounding
11088 #[wasm_bindgen(method, getter = roundingMode)]
11089 pub fn get_rounding_mode(this: &NumberFormatOptions) -> Option<RoundingMode>;
11090 #[wasm_bindgen(method, setter = roundingMode)]
11091 pub fn set_rounding_mode(this: &NumberFormatOptions, value: RoundingMode);
11092
11093 #[wasm_bindgen(method, getter = roundingPriority)]
11094 pub fn get_rounding_priority(this: &NumberFormatOptions) -> Option<RoundingPriority>;
11095 #[wasm_bindgen(method, setter = roundingPriority)]
11096 pub fn set_rounding_priority(this: &NumberFormatOptions, value: RoundingPriority);
11097
11098 #[wasm_bindgen(method, getter = roundingIncrement)]
11099 pub fn get_rounding_increment(this: &NumberFormatOptions) -> Option<u32>;
11100 #[wasm_bindgen(method, setter = roundingIncrement)]
11101 pub fn set_rounding_increment(this: &NumberFormatOptions, value: u32);
11102
11103 #[wasm_bindgen(method, getter = trailingZeroDisplay)]
11104 pub fn get_trailing_zero_display(this: &NumberFormatOptions)
11105 -> Option<TrailingZeroDisplay>;
11106 #[wasm_bindgen(method, setter = trailingZeroDisplay)]
11107 pub fn set_trailing_zero_display(this: &NumberFormatOptions, value: TrailingZeroDisplay);
11108 }
11109
11110 impl NumberFormatOptions {
11111 pub fn new() -> NumberFormatOptions {
11112 JsCast::unchecked_into(Object::new())
11113 }
11114 }
11115
11116 impl Default for NumberFormatOptions {
11117 fn default() -> Self {
11118 NumberFormatOptions::new()
11119 }
11120 }
11121
11122 // Intl.ResolvedNumberFormatOptions
11123 #[wasm_bindgen]
11124 extern "C" {
11125 /// Resolved options returned by `Intl.NumberFormat.prototype.resolvedOptions()`.
11126 ///
11127 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/resolvedOptions)
11128 #[wasm_bindgen(extends = NumberFormatOptions)]
11129 #[derive(Clone, Debug)]
11130 pub type ResolvedNumberFormatOptions;
11131
11132 /// The resolved locale string.
11133 #[wasm_bindgen(method, getter = locale)]
11134 pub fn get_locale(this: &ResolvedNumberFormatOptions) -> JsString;
11135 }
11136
11137 // Intl.NumberFormatPart
11138 #[wasm_bindgen]
11139 extern "C" {
11140 /// A part of the formatted number returned by `formatToParts()`.
11141 ///
11142 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatToParts)
11143 #[wasm_bindgen(extends = Object)]
11144 #[derive(Clone, Debug)]
11145 pub type NumberFormatPart;
11146
11147 /// The type of the part (e.g., "integer", "decimal", "fraction", "currency", etc.)
11148 #[wasm_bindgen(method, getter = type)]
11149 pub fn type_(this: &NumberFormatPart) -> NumberFormatPartType;
11150
11151 /// The value of the part.
11152 #[wasm_bindgen(method, getter)]
11153 pub fn value(this: &NumberFormatPart) -> JsString;
11154 }
11155
11156 // Intl.NumberRangeFormatPart
11157 #[wasm_bindgen]
11158 extern "C" {
11159 /// A part of the formatted number range returned by `formatRangeToParts()`.
11160 ///
11161 /// Extends `NumberFormatPart` with a `source` property indicating whether
11162 /// the part is from the start number, end number, or shared between them.
11163 ///
11164 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatRangeToParts)
11165 #[wasm_bindgen(extends = NumberFormatPart)]
11166 #[derive(Clone, Debug)]
11167 pub type NumberRangeFormatPart;
11168
11169 /// The source of the part: "startRange", "endRange", or "shared".
11170 #[wasm_bindgen(method, getter)]
11171 pub fn source(this: &NumberRangeFormatPart) -> RangeSource;
11172 }
11173
11174 // Intl.NumberFormat
11175 #[wasm_bindgen]
11176 extern "C" {
11177 /// The `Intl.NumberFormat` object is a constructor for objects
11178 /// that enable language sensitive number formatting.
11179 ///
11180 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat)
11181 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.NumberFormat")]
11182 #[derive(Clone, Debug)]
11183 pub type NumberFormat;
11184
11185 /// The `Intl.NumberFormat` object is a constructor for objects
11186 /// that enable language sensitive number formatting.
11187 ///
11188 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat)
11189 #[cfg(not(js_sys_unstable_apis))]
11190 #[wasm_bindgen(constructor, js_namespace = Intl)]
11191 pub fn new(locales: &Array, options: &Object) -> NumberFormat;
11192
11193 /// The `Intl.NumberFormat` object is a constructor for objects
11194 /// that enable language sensitive number formatting.
11195 ///
11196 /// Throws a `RangeError` if locales contain invalid values.
11197 ///
11198 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat)
11199 #[cfg(js_sys_unstable_apis)]
11200 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
11201 pub fn new(
11202 locales: &[JsString],
11203 options: &NumberFormatOptions,
11204 ) -> Result<NumberFormat, JsValue>;
11205
11206 /// The Intl.NumberFormat.prototype.format property returns a getter function that
11207 /// formats a number according to the locale and formatting options of this
11208 /// NumberFormat object.
11209 ///
11210 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/format)
11211 #[cfg(not(js_sys_unstable_apis))]
11212 #[wasm_bindgen(method, getter, js_class = "Intl.NumberFormat")]
11213 pub fn format(this: &NumberFormat) -> Function;
11214
11215 /// Formats a number according to the locale and formatting options of this
11216 /// `Intl.NumberFormat` object.
11217 ///
11218 /// Accepts numeric strings for BigInt/arbitrary precision (e.g., `"123n"` → `"123"`,
11219 /// or use E notation: `"1000000E-6"` → `"1"`).
11220 ///
11221 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/format)
11222 #[cfg(js_sys_unstable_apis)]
11223 #[wasm_bindgen(method, js_class = "Intl.NumberFormat")]
11224 pub fn format(this: &NumberFormat, value: &JsString) -> JsString;
11225
11226 /// The `Intl.Numberformat.prototype.formatToParts()` method allows locale-aware
11227 /// formatting of strings produced by NumberTimeFormat formatters.
11228 ///
11229 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/formatToParts)
11230 #[cfg(not(js_sys_unstable_apis))]
11231 #[wasm_bindgen(method, js_class = "Intl.NumberFormat", js_name = formatToParts)]
11232 pub fn format_to_parts(this: &NumberFormat, number: f64) -> Array;
11233
11234 /// The `Intl.NumberFormat.prototype.formatToParts()` method allows locale-aware
11235 /// formatting of strings produced by `Intl.NumberFormat` formatters.
11236 ///
11237 /// Accepts numeric strings for BigInt/arbitrary precision (e.g., `"123n"` → `"123"`,
11238 /// or use E notation: `"1000000E-6"` → `"1"`).
11239 ///
11240 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatToParts)
11241 #[cfg(js_sys_unstable_apis)]
11242 #[wasm_bindgen(method, js_class = "Intl.NumberFormat", js_name = formatToParts)]
11243 pub fn format_to_parts(this: &NumberFormat, value: &JsString) -> Array<NumberFormatPart>;
11244
11245 /// Formats a range of numbers according to the locale and formatting options
11246 /// of this `Intl.NumberFormat` object.
11247 ///
11248 /// Accepts numeric strings for BigInt/arbitrary precision (e.g., `"123n"` → `"123"`,
11249 /// or use E notation: `"1000000E-6"` → `"1"`).
11250 ///
11251 /// Throws a `TypeError` if the values are invalid.
11252 ///
11253 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatRange)
11254 #[wasm_bindgen(method, js_class = "Intl.NumberFormat", js_name = formatRange, catch)]
11255 pub fn format_range(
11256 this: &NumberFormat,
11257 start: &JsString,
11258 end: &JsString,
11259 ) -> Result<JsString, JsValue>;
11260
11261 /// Returns an array of locale-specific tokens representing each part of
11262 /// the formatted number range.
11263 ///
11264 /// Accepts numeric strings for BigInt/arbitrary precision (e.g., `"123n"` → `"123"`,
11265 /// or use E notation: `"1000000E-6"` → `"1"`).
11266 ///
11267 /// Throws a `TypeError` if the values are invalid.
11268 ///
11269 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatRangeToParts)
11270 #[wasm_bindgen(method, js_class = "Intl.NumberFormat", js_name = formatRangeToParts, catch)]
11271 pub fn format_range_to_parts(
11272 this: &NumberFormat,
11273 start: &JsString,
11274 end: &JsString,
11275 ) -> Result<Array<NumberRangeFormatPart>, JsValue>;
11276
11277 /// The `Intl.NumberFormat.prototype.resolvedOptions()` method returns a new
11278 /// object with properties reflecting the locale and number formatting
11279 /// options computed during initialization of this NumberFormat object.
11280 ///
11281 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/resolvedOptions)
11282 #[cfg(not(js_sys_unstable_apis))]
11283 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11284 pub fn resolved_options(this: &NumberFormat) -> Object;
11285
11286 /// The `Intl.NumberFormat.prototype.resolvedOptions()` method returns a new
11287 /// object with properties reflecting the locale and number formatting
11288 /// options computed during initialization of this NumberFormat object.
11289 ///
11290 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/resolvedOptions)
11291 #[cfg(js_sys_unstable_apis)]
11292 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11293 pub fn resolved_options(this: &NumberFormat) -> ResolvedNumberFormatOptions;
11294
11295 /// The `Intl.NumberFormat.supportedLocalesOf()` method returns an array
11296 /// containing those of the provided locales that are supported in number
11297 /// formatting without having to fall back to the runtime's default locale.
11298 ///
11299 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/supportedLocalesOf)
11300 #[cfg(not(js_sys_unstable_apis))]
11301 #[wasm_bindgen(static_method_of = NumberFormat, js_namespace = Intl, js_name = supportedLocalesOf)]
11302 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
11303
11304 /// The `Intl.NumberFormat.supportedLocalesOf()` method returns an array
11305 /// containing those of the provided locales that are supported in number
11306 /// formatting without having to fall back to the runtime's default locale.
11307 ///
11308 /// Throws a `RangeError` if locales contain invalid values.
11309 ///
11310 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/supportedLocalesOf)
11311 #[cfg(js_sys_unstable_apis)]
11312 #[wasm_bindgen(static_method_of = NumberFormat, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
11313 pub fn supported_locales_of(
11314 locales: &[JsString],
11315 options: &LocaleMatcherOptions,
11316 ) -> Result<Array<JsString>, JsValue>;
11317 }
11318
11319 #[cfg(not(js_sys_unstable_apis))]
11320 impl Default for NumberFormat {
11321 fn default() -> Self {
11322 Self::new(
11323 &JsValue::UNDEFINED.unchecked_into(),
11324 &JsValue::UNDEFINED.unchecked_into(),
11325 )
11326 }
11327 }
11328
11329 #[cfg(js_sys_unstable_apis)]
11330 impl Default for NumberFormat {
11331 fn default() -> Self {
11332 Self::new(&[], &Default::default()).unwrap()
11333 }
11334 }
11335
11336 // Intl.PluralRulesOptions
11337 #[wasm_bindgen]
11338 extern "C" {
11339 /// Options for `Intl.PluralRules` constructor.
11340 ///
11341 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules/PluralRules#options)
11342 #[wasm_bindgen(extends = Object)]
11343 #[derive(Clone, Debug)]
11344 pub type PluralRulesOptions;
11345
11346 #[wasm_bindgen(method, getter = localeMatcher)]
11347 pub fn get_locale_matcher(this: &PluralRulesOptions) -> Option<LocaleMatcher>;
11348 #[wasm_bindgen(method, setter = localeMatcher)]
11349 pub fn set_locale_matcher(this: &PluralRulesOptions, value: LocaleMatcher);
11350
11351 #[wasm_bindgen(method, getter = type)]
11352 pub fn get_type(this: &PluralRulesOptions) -> Option<PluralRulesType>;
11353 #[wasm_bindgen(method, setter = type)]
11354 pub fn set_type(this: &PluralRulesOptions, value: PluralRulesType);
11355
11356 #[wasm_bindgen(method, getter = minimumIntegerDigits)]
11357 pub fn get_minimum_integer_digits(this: &PluralRulesOptions) -> Option<u8>;
11358 #[wasm_bindgen(method, setter = minimumIntegerDigits)]
11359 pub fn set_minimum_integer_digits(this: &PluralRulesOptions, value: u8);
11360
11361 #[wasm_bindgen(method, getter = minimumFractionDigits)]
11362 pub fn get_minimum_fraction_digits(this: &PluralRulesOptions) -> Option<u8>;
11363 #[wasm_bindgen(method, setter = minimumFractionDigits)]
11364 pub fn set_minimum_fraction_digits(this: &PluralRulesOptions, value: u8);
11365
11366 #[wasm_bindgen(method, getter = maximumFractionDigits)]
11367 pub fn get_maximum_fraction_digits(this: &PluralRulesOptions) -> Option<u8>;
11368 #[wasm_bindgen(method, setter = maximumFractionDigits)]
11369 pub fn set_maximum_fraction_digits(this: &PluralRulesOptions, value: u8);
11370
11371 #[wasm_bindgen(method, getter = minimumSignificantDigits)]
11372 pub fn get_minimum_significant_digits(this: &PluralRulesOptions) -> Option<u8>;
11373 #[wasm_bindgen(method, setter = minimumSignificantDigits)]
11374 pub fn set_minimum_significant_digits(this: &PluralRulesOptions, value: u8);
11375
11376 #[wasm_bindgen(method, getter = maximumSignificantDigits)]
11377 pub fn get_maximum_significant_digits(this: &PluralRulesOptions) -> Option<u8>;
11378 #[wasm_bindgen(method, setter = maximumSignificantDigits)]
11379 pub fn set_maximum_significant_digits(this: &PluralRulesOptions, value: u8);
11380
11381 #[wasm_bindgen(method, getter = roundingPriority)]
11382 pub fn get_rounding_priority(this: &PluralRulesOptions) -> Option<RoundingPriority>;
11383 #[wasm_bindgen(method, setter = roundingPriority)]
11384 pub fn set_rounding_priority(this: &PluralRulesOptions, value: RoundingPriority);
11385
11386 #[wasm_bindgen(method, getter = roundingIncrement)]
11387 pub fn get_rounding_increment(this: &PluralRulesOptions) -> Option<u32>;
11388 #[wasm_bindgen(method, setter = roundingIncrement)]
11389 pub fn set_rounding_increment(this: &PluralRulesOptions, value: u32);
11390
11391 #[wasm_bindgen(method, getter = roundingMode)]
11392 pub fn get_rounding_mode(this: &PluralRulesOptions) -> Option<RoundingMode>;
11393 #[wasm_bindgen(method, setter = roundingMode)]
11394 pub fn set_rounding_mode(this: &PluralRulesOptions, value: RoundingMode);
11395
11396 #[wasm_bindgen(method, getter = trailingZeroDisplay)]
11397 pub fn get_trailing_zero_display(this: &PluralRulesOptions) -> Option<TrailingZeroDisplay>;
11398 #[wasm_bindgen(method, setter = trailingZeroDisplay)]
11399 pub fn set_trailing_zero_display(this: &PluralRulesOptions, value: TrailingZeroDisplay);
11400 }
11401
11402 impl PluralRulesOptions {
11403 pub fn new() -> PluralRulesOptions {
11404 JsCast::unchecked_into(Object::new())
11405 }
11406 }
11407
11408 impl Default for PluralRulesOptions {
11409 fn default() -> Self {
11410 PluralRulesOptions::new()
11411 }
11412 }
11413
11414 // Intl.ResolvedPluralRulesOptions
11415 #[wasm_bindgen]
11416 extern "C" {
11417 /// Resolved options returned by `Intl.PluralRules.prototype.resolvedOptions()`.
11418 ///
11419 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules/resolvedOptions)
11420 #[wasm_bindgen(extends = PluralRulesOptions)]
11421 #[derive(Clone, Debug)]
11422 pub type ResolvedPluralRulesOptions;
11423
11424 /// The resolved locale string.
11425 #[wasm_bindgen(method, getter = locale)]
11426 pub fn get_locale(this: &ResolvedPluralRulesOptions) -> JsString;
11427
11428 /// The plural categories used by the locale.
11429 #[wasm_bindgen(method, getter = pluralCategories)]
11430 pub fn get_plural_categories(this: &ResolvedPluralRulesOptions) -> Array<JsString>;
11431 }
11432
11433 // Intl.PluralRules
11434 #[wasm_bindgen]
11435 extern "C" {
11436 /// The `Intl.PluralRules` object is a constructor for objects
11437 /// that enable plural sensitive formatting and plural language rules.
11438 ///
11439 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules)
11440 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.PluralRules")]
11441 #[derive(Clone, Debug)]
11442 pub type PluralRules;
11443
11444 /// The `Intl.PluralRules` object is a constructor for objects
11445 /// that enable plural sensitive formatting and plural language rules.
11446 ///
11447 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules)
11448 #[cfg(not(js_sys_unstable_apis))]
11449 #[wasm_bindgen(constructor, js_namespace = Intl)]
11450 pub fn new(locales: &Array, options: &Object) -> PluralRules;
11451
11452 /// The `Intl.PluralRules` object is a constructor for objects
11453 /// that enable plural sensitive formatting and plural language rules.
11454 ///
11455 /// Throws a `RangeError` if locales contain invalid values.
11456 ///
11457 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules)
11458 #[cfg(js_sys_unstable_apis)]
11459 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
11460 pub fn new(
11461 locales: &[JsString],
11462 options: &PluralRulesOptions,
11463 ) -> Result<PluralRules, JsValue>;
11464
11465 /// The `Intl.PluralRules.prototype.resolvedOptions()` method returns a new
11466 /// object with properties reflecting the locale and plural formatting
11467 /// options computed during initialization of this PluralRules object.
11468 ///
11469 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/resolvedOptions)
11470 #[cfg(not(js_sys_unstable_apis))]
11471 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11472 pub fn resolved_options(this: &PluralRules) -> Object;
11473
11474 /// The `Intl.PluralRules.prototype.resolvedOptions()` method returns a new
11475 /// object with properties reflecting the locale and plural formatting
11476 /// options computed during initialization of this PluralRules object.
11477 ///
11478 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/resolvedOptions)
11479 #[cfg(js_sys_unstable_apis)]
11480 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11481 pub fn resolved_options(this: &PluralRules) -> ResolvedPluralRulesOptions;
11482
11483 /// The `Intl.PluralRules.prototype.select()` method returns a String indicating
11484 /// which plural rule to use for locale-aware formatting.
11485 ///
11486 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/select)
11487 #[cfg(not(js_sys_unstable_apis))]
11488 #[wasm_bindgen(method, js_namespace = Intl)]
11489 pub fn select(this: &PluralRules, number: f64) -> JsString;
11490
11491 /// The `Intl.PluralRules.prototype.select()` method returns a String indicating
11492 /// which plural rule to use for locale-aware formatting.
11493 ///
11494 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/select)
11495 #[cfg(js_sys_unstable_apis)]
11496 #[wasm_bindgen(method, js_namespace = Intl)]
11497 pub fn select(this: &PluralRules, number: f64) -> PluralCategory;
11498
11499 /// The `Intl.PluralRules.prototype.selectRange()` method returns a string indicating
11500 /// which plural rule to use for locale-aware formatting of a range of numbers.
11501 ///
11502 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules/selectRange)
11503 #[cfg(not(js_sys_unstable_apis))]
11504 #[wasm_bindgen(method, js_namespace = Intl, js_name = selectRange)]
11505 pub fn select_range(this: &PluralRules, start: f64, end: f64) -> JsString;
11506
11507 /// The `Intl.PluralRules.prototype.selectRange()` method returns a string indicating
11508 /// which plural rule to use for locale-aware formatting of a range of numbers.
11509 ///
11510 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules/selectRange)
11511 #[cfg(js_sys_unstable_apis)]
11512 #[wasm_bindgen(method, js_namespace = Intl, js_name = selectRange)]
11513 pub fn select_range(this: &PluralRules, start: f64, end: f64) -> PluralCategory;
11514
11515 /// The `Intl.PluralRules.supportedLocalesOf()` method returns an array
11516 /// containing those of the provided locales that are supported in plural
11517 /// formatting without having to fall back to the runtime's default locale.
11518 ///
11519 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/supportedLocalesOf)
11520 #[cfg(not(js_sys_unstable_apis))]
11521 #[wasm_bindgen(static_method_of = PluralRules, js_namespace = Intl, js_name = supportedLocalesOf)]
11522 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
11523
11524 /// The `Intl.PluralRules.supportedLocalesOf()` method returns an array
11525 /// containing those of the provided locales that are supported in plural
11526 /// formatting without having to fall back to the runtime's default locale.
11527 ///
11528 /// Throws a `RangeError` if locales contain invalid values.
11529 ///
11530 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/supportedLocalesOf)
11531 #[cfg(js_sys_unstable_apis)]
11532 #[wasm_bindgen(static_method_of = PluralRules, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
11533 pub fn supported_locales_of(
11534 locales: &[JsString],
11535 options: &LocaleMatcherOptions,
11536 ) -> Result<Array<JsString>, JsValue>;
11537 }
11538
11539 #[cfg(not(js_sys_unstable_apis))]
11540 impl Default for PluralRules {
11541 fn default() -> Self {
11542 Self::new(
11543 &JsValue::UNDEFINED.unchecked_into(),
11544 &JsValue::UNDEFINED.unchecked_into(),
11545 )
11546 }
11547 }
11548
11549 #[cfg(js_sys_unstable_apis)]
11550 impl Default for PluralRules {
11551 fn default() -> Self {
11552 Self::new(&[], &Default::default()).unwrap()
11553 }
11554 }
11555
11556 // Intl.RelativeTimeFormat
11557 #[wasm_bindgen]
11558 extern "C" {
11559 /// The `Intl.RelativeTimeFormat` object is a constructor for objects
11560 /// that enable language-sensitive relative time formatting.
11561 ///
11562 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat)
11563 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.RelativeTimeFormat")]
11564 #[derive(Clone, Debug)]
11565 pub type RelativeTimeFormat;
11566
11567 /// The `Intl.RelativeTimeFormat` object is a constructor for objects
11568 /// that enable language-sensitive relative time formatting.
11569 ///
11570 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat)
11571 #[cfg(not(js_sys_unstable_apis))]
11572 #[wasm_bindgen(constructor, js_namespace = Intl)]
11573 pub fn new(locales: &Array, options: &Object) -> RelativeTimeFormat;
11574
11575 /// The `Intl.RelativeTimeFormat` object is a constructor for objects
11576 /// that enable language-sensitive relative time formatting.
11577 ///
11578 /// Throws a `RangeError` if locales contain invalid values.
11579 ///
11580 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat)
11581 #[cfg(js_sys_unstable_apis)]
11582 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
11583 pub fn new(locales: &[JsString]) -> Result<RelativeTimeFormat, JsValue>;
11584
11585 /// The `Intl.RelativeTimeFormat` object is a constructor for objects
11586 /// that enable language-sensitive relative time formatting.
11587 ///
11588 /// Throws a `RangeError` if locales or options contain invalid values.
11589 ///
11590 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat)
11591 #[cfg(js_sys_unstable_apis)]
11592 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
11593 pub fn new_with_options(
11594 locales: &[JsString],
11595 options: &RelativeTimeFormatOptions,
11596 ) -> Result<RelativeTimeFormat, JsValue>;
11597
11598 /// The `Intl.RelativeTimeFormat.prototype.format` method formats a `value` and `unit`
11599 /// according to the locale and formatting options of this Intl.RelativeTimeFormat object.
11600 ///
11601 /// Throws a `RangeError` if unit is invalid.
11602 ///
11603 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/format)
11604 #[cfg(not(js_sys_unstable_apis))]
11605 #[wasm_bindgen(method, js_class = "Intl.RelativeTimeFormat")]
11606 pub fn format(this: &RelativeTimeFormat, value: f64, unit: &str) -> JsString;
11607
11608 /// The `Intl.RelativeTimeFormat.prototype.format` method formats a `value` and `unit`
11609 /// according to the locale and formatting options of this Intl.RelativeTimeFormat object.
11610 ///
11611 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/format)
11612 #[cfg(js_sys_unstable_apis)]
11613 #[wasm_bindgen(method, js_class = "Intl.RelativeTimeFormat")]
11614 pub fn format(
11615 this: &RelativeTimeFormat,
11616 value: f64,
11617 unit: RelativeTimeFormatUnit,
11618 ) -> JsString;
11619
11620 /// The `Intl.RelativeTimeFormat.prototype.formatToParts()` method returns an array of
11621 /// objects representing the relative time format in parts that can be used for custom locale-aware formatting.
11622 ///
11623 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/formatToParts)
11624 #[cfg(not(js_sys_unstable_apis))]
11625 #[wasm_bindgen(method, js_class = "Intl.RelativeTimeFormat", js_name = formatToParts)]
11626 pub fn format_to_parts(this: &RelativeTimeFormat, value: f64, unit: &str) -> Array;
11627
11628 /// The `Intl.RelativeTimeFormat.prototype.formatToParts()` method returns an array of
11629 /// objects representing the relative time format in parts that can be used for custom locale-aware formatting.
11630 ///
11631 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/formatToParts)
11632 #[cfg(js_sys_unstable_apis)]
11633 #[wasm_bindgen(method, js_class = "Intl.RelativeTimeFormat", js_name = formatToParts)]
11634 pub fn format_to_parts(
11635 this: &RelativeTimeFormat,
11636 value: f64,
11637 unit: RelativeTimeFormatUnit,
11638 ) -> Array<RelativeTimeFormatPart>;
11639
11640 /// The `Intl.RelativeTimeFormat.prototype.resolvedOptions()` method returns a new
11641 /// object with properties reflecting the locale and relative time formatting
11642 /// options computed during initialization of this RelativeTimeFormat object.
11643 ///
11644 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/resolvedOptions)
11645 #[cfg(not(js_sys_unstable_apis))]
11646 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11647 pub fn resolved_options(this: &RelativeTimeFormat) -> Object;
11648
11649 /// The `Intl.RelativeTimeFormat.prototype.resolvedOptions()` method returns a new
11650 /// object with properties reflecting the locale and relative time formatting
11651 /// options computed during initialization of this RelativeTimeFormat object.
11652 ///
11653 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/resolvedOptions)
11654 #[cfg(js_sys_unstable_apis)]
11655 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11656 pub fn resolved_options(this: &RelativeTimeFormat) -> ResolvedRelativeTimeFormatOptions;
11657
11658 /// The `Intl.RelativeTimeFormat.supportedLocalesOf()` method returns an array
11659 /// containing those of the provided locales that are supported in date and time
11660 /// formatting without having to fall back to the runtime's default locale.
11661 ///
11662 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RelativeTimeFormat/supportedLocalesOf)
11663 #[cfg(not(js_sys_unstable_apis))]
11664 #[wasm_bindgen(static_method_of = RelativeTimeFormat, js_namespace = Intl, js_name = supportedLocalesOf)]
11665 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
11666
11667 /// The `Intl.RelativeTimeFormat.supportedLocalesOf()` method returns an array
11668 /// containing those of the provided locales that are supported in date and time
11669 /// formatting without having to fall back to the runtime's default locale.
11670 ///
11671 /// Throws a `RangeError` if locales contain invalid values.
11672 ///
11673 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RelativeTimeFormat/supportedLocalesOf)
11674 #[cfg(js_sys_unstable_apis)]
11675 #[wasm_bindgen(static_method_of = RelativeTimeFormat, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
11676 pub fn supported_locales_of(
11677 locales: &[JsString],
11678 options: &LocaleMatcherOptions,
11679 ) -> Result<Array<JsString>, JsValue>;
11680 }
11681
11682 #[cfg(not(js_sys_unstable_apis))]
11683 impl Default for RelativeTimeFormat {
11684 fn default() -> Self {
11685 Self::new(
11686 &JsValue::UNDEFINED.unchecked_into(),
11687 &JsValue::UNDEFINED.unchecked_into(),
11688 )
11689 }
11690 }
11691
11692 #[cfg(js_sys_unstable_apis)]
11693 impl Default for RelativeTimeFormat {
11694 fn default() -> Self {
11695 Self::new(&[]).unwrap()
11696 }
11697 }
11698
11699 // Intl.ListFormatOptions
11700 #[wasm_bindgen]
11701 extern "C" {
11702 /// Options for `Intl.ListFormat` constructor.
11703 ///
11704 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/ListFormat#options)
11705 #[wasm_bindgen(extends = Object)]
11706 #[derive(Clone, Debug)]
11707 pub type ListFormatOptions;
11708
11709 #[wasm_bindgen(method, getter = localeMatcher)]
11710 pub fn get_locale_matcher(this: &ListFormatOptions) -> Option<LocaleMatcher>;
11711 #[wasm_bindgen(method, setter = localeMatcher)]
11712 pub fn set_locale_matcher(this: &ListFormatOptions, value: LocaleMatcher);
11713
11714 #[wasm_bindgen(method, getter = type)]
11715 pub fn get_type(this: &ListFormatOptions) -> Option<ListFormatType>;
11716 #[wasm_bindgen(method, setter = type)]
11717 pub fn set_type(this: &ListFormatOptions, value: ListFormatType);
11718
11719 #[wasm_bindgen(method, getter = style)]
11720 pub fn get_style(this: &ListFormatOptions) -> Option<ListFormatStyle>;
11721 #[wasm_bindgen(method, setter = style)]
11722 pub fn set_style(this: &ListFormatOptions, value: ListFormatStyle);
11723 }
11724
11725 impl ListFormatOptions {
11726 pub fn new() -> ListFormatOptions {
11727 JsCast::unchecked_into(Object::new())
11728 }
11729 }
11730
11731 impl Default for ListFormatOptions {
11732 fn default() -> Self {
11733 ListFormatOptions::new()
11734 }
11735 }
11736
11737 // Intl.ResolvedListFormatOptions
11738 #[wasm_bindgen]
11739 extern "C" {
11740 /// Resolved options returned by `Intl.ListFormat.prototype.resolvedOptions()`.
11741 ///
11742 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/resolvedOptions)
11743 #[wasm_bindgen(extends = ListFormatOptions)]
11744 #[derive(Clone, Debug)]
11745 pub type ResolvedListFormatOptions;
11746
11747 /// The resolved locale string.
11748 #[wasm_bindgen(method, getter = locale)]
11749 pub fn get_locale(this: &ResolvedListFormatOptions) -> JsString;
11750 }
11751
11752 // Intl.ListFormatPart
11753 #[wasm_bindgen]
11754 extern "C" {
11755 /// A part of the formatted list returned by `formatToParts()`.
11756 ///
11757 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/formatToParts)
11758 #[wasm_bindgen(extends = Object)]
11759 #[derive(Clone, Debug)]
11760 pub type ListFormatPart;
11761
11762 /// The type of the part ("element" or "literal").
11763 #[wasm_bindgen(method, getter = type)]
11764 pub fn type_(this: &ListFormatPart) -> ListFormatPartType;
11765
11766 /// The value of the part.
11767 #[wasm_bindgen(method, getter)]
11768 pub fn value(this: &ListFormatPart) -> JsString;
11769 }
11770
11771 // Intl.ListFormat
11772 #[wasm_bindgen]
11773 extern "C" {
11774 /// The `Intl.ListFormat` object enables language-sensitive list formatting.
11775 ///
11776 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat)
11777 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.ListFormat")]
11778 #[derive(Clone, Debug)]
11779 pub type ListFormat;
11780
11781 /// Creates a new `Intl.ListFormat` object.
11782 ///
11783 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/ListFormat)
11784 #[cfg(not(js_sys_unstable_apis))]
11785 #[wasm_bindgen(constructor, js_namespace = Intl)]
11786 pub fn new(locales: &Array, options: &Object) -> ListFormat;
11787
11788 /// Creates a new `Intl.ListFormat` object.
11789 ///
11790 /// Throws a `RangeError` if locales or options contain invalid values.
11791 ///
11792 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/ListFormat)
11793 #[cfg(js_sys_unstable_apis)]
11794 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
11795 pub fn new(
11796 locales: &[JsString],
11797 options: &ListFormatOptions,
11798 ) -> Result<ListFormat, JsValue>;
11799
11800 /// Formats a list of strings according to the locale and options.
11801 ///
11802 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/format)
11803 #[cfg(not(js_sys_unstable_apis))]
11804 #[wasm_bindgen(method, js_class = "Intl.ListFormat")]
11805 pub fn format(this: &ListFormat, list: &Array) -> JsString;
11806
11807 /// Formats a list of strings according to the locale and options.
11808 ///
11809 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/format)
11810 #[cfg(js_sys_unstable_apis)]
11811 #[wasm_bindgen(method, js_class = "Intl.ListFormat")]
11812 pub fn format(this: &ListFormat, list: &[JsString]) -> JsString;
11813
11814 /// Returns an array of objects representing the list in parts.
11815 ///
11816 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/formatToParts)
11817 #[cfg(not(js_sys_unstable_apis))]
11818 #[wasm_bindgen(method, js_class = "Intl.ListFormat", js_name = formatToParts)]
11819 pub fn format_to_parts(this: &ListFormat, list: &Array) -> Array;
11820
11821 /// Returns an array of objects representing the list in parts.
11822 ///
11823 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/formatToParts)
11824 #[cfg(js_sys_unstable_apis)]
11825 #[wasm_bindgen(method, js_class = "Intl.ListFormat", js_name = formatToParts)]
11826 pub fn format_to_parts(this: &ListFormat, list: &[JsString]) -> Array<ListFormatPart>;
11827
11828 /// Returns an object with properties reflecting the options used.
11829 ///
11830 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/resolvedOptions)
11831 #[cfg(not(js_sys_unstable_apis))]
11832 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11833 pub fn resolved_options(this: &ListFormat) -> Object;
11834
11835 /// Returns an object with properties reflecting the options used.
11836 ///
11837 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/resolvedOptions)
11838 #[cfg(js_sys_unstable_apis)]
11839 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11840 pub fn resolved_options(this: &ListFormat) -> ResolvedListFormatOptions;
11841
11842 /// Returns an array of supported locales.
11843 ///
11844 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/supportedLocalesOf)
11845 #[cfg(not(js_sys_unstable_apis))]
11846 #[wasm_bindgen(static_method_of = ListFormat, js_namespace = Intl, js_name = supportedLocalesOf)]
11847 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
11848
11849 /// Returns an array of supported locales.
11850 ///
11851 /// Throws a `RangeError` if locales contain invalid values.
11852 ///
11853 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/supportedLocalesOf)
11854 #[cfg(js_sys_unstable_apis)]
11855 #[wasm_bindgen(static_method_of = ListFormat, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
11856 pub fn supported_locales_of(
11857 locales: &[JsString],
11858 options: &LocaleMatcherOptions,
11859 ) -> Result<Array<JsString>, JsValue>;
11860 }
11861
11862 #[cfg(not(js_sys_unstable_apis))]
11863 impl Default for ListFormat {
11864 fn default() -> Self {
11865 Self::new(
11866 &JsValue::UNDEFINED.unchecked_into(),
11867 &JsValue::UNDEFINED.unchecked_into(),
11868 )
11869 }
11870 }
11871
11872 #[cfg(js_sys_unstable_apis)]
11873 impl Default for ListFormat {
11874 fn default() -> Self {
11875 Self::new(&[], &Default::default()).unwrap()
11876 }
11877 }
11878
11879 // Intl.SegmenterOptions
11880 #[wasm_bindgen]
11881 extern "C" {
11882 /// Options for `Intl.Segmenter` constructor.
11883 ///
11884 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/Segmenter#options)
11885 #[wasm_bindgen(extends = Object)]
11886 #[derive(Clone, Debug)]
11887 pub type SegmenterOptions;
11888
11889 #[wasm_bindgen(method, getter = localeMatcher)]
11890 pub fn get_locale_matcher(this: &SegmenterOptions) -> Option<LocaleMatcher>;
11891 #[wasm_bindgen(method, setter = localeMatcher)]
11892 pub fn set_locale_matcher(this: &SegmenterOptions, value: LocaleMatcher);
11893
11894 #[wasm_bindgen(method, getter = granularity)]
11895 pub fn get_granularity(this: &SegmenterOptions) -> Option<SegmenterGranularity>;
11896 #[wasm_bindgen(method, setter = granularity)]
11897 pub fn set_granularity(this: &SegmenterOptions, value: SegmenterGranularity);
11898 }
11899
11900 impl SegmenterOptions {
11901 pub fn new() -> SegmenterOptions {
11902 JsCast::unchecked_into(Object::new())
11903 }
11904 }
11905
11906 impl Default for SegmenterOptions {
11907 fn default() -> Self {
11908 SegmenterOptions::new()
11909 }
11910 }
11911
11912 // Intl.ResolvedSegmenterOptions
11913 #[wasm_bindgen]
11914 extern "C" {
11915 /// Resolved options returned by `Intl.Segmenter.prototype.resolvedOptions()`.
11916 ///
11917 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/resolvedOptions)
11918 #[wasm_bindgen(extends = SegmenterOptions)]
11919 #[derive(Clone, Debug)]
11920 pub type ResolvedSegmenterOptions;
11921
11922 /// The resolved locale string.
11923 #[wasm_bindgen(method, getter = locale)]
11924 pub fn get_locale(this: &ResolvedSegmenterOptions) -> JsString;
11925 }
11926
11927 // Intl.SegmentData
11928 #[wasm_bindgen]
11929 extern "C" {
11930 /// Data about a segment returned by the Segments iterator.
11931 ///
11932 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/segment/Segments#segment_data)
11933 #[wasm_bindgen(extends = Object)]
11934 #[derive(Clone, Debug)]
11935 pub type SegmentData;
11936
11937 /// The segment string.
11938 #[wasm_bindgen(method, getter)]
11939 pub fn segment(this: &SegmentData) -> JsString;
11940
11941 /// The index of the segment in the original string.
11942 #[wasm_bindgen(method, getter)]
11943 pub fn index(this: &SegmentData) -> u32;
11944
11945 /// The original input string.
11946 #[wasm_bindgen(method, getter)]
11947 pub fn input(this: &SegmentData) -> JsString;
11948
11949 /// Whether the segment is word-like (only for word granularity).
11950 #[wasm_bindgen(method, getter = isWordLike)]
11951 pub fn is_word_like(this: &SegmentData) -> Option<bool>;
11952 }
11953
11954 // Intl.Segments
11955 #[wasm_bindgen]
11956 extern "C" {
11957 /// The Segments object is an iterable collection of segments of a string.
11958 ///
11959 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/segment/Segments)
11960 #[wasm_bindgen(extends = Object)]
11961 #[derive(Clone, Debug)]
11962 pub type Segments;
11963
11964 /// Returns segment data for the segment containing the character at the given index.
11965 ///
11966 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/segment/Segments/containing)
11967 #[wasm_bindgen(method)]
11968 pub fn containing(this: &Segments, index: u32) -> Option<SegmentData>;
11969 }
11970
11971 // Intl.Segmenter
11972 #[wasm_bindgen]
11973 extern "C" {
11974 /// The `Intl.Segmenter` object enables locale-sensitive text segmentation.
11975 ///
11976 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter)
11977 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.Segmenter")]
11978 #[derive(Clone, Debug)]
11979 pub type Segmenter;
11980
11981 /// Creates a new `Intl.Segmenter` object.
11982 ///
11983 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/Segmenter)
11984 #[cfg(not(js_sys_unstable_apis))]
11985 #[wasm_bindgen(constructor, js_namespace = Intl)]
11986 pub fn new(locales: &Array, options: &Object) -> Segmenter;
11987
11988 /// Creates a new `Intl.Segmenter` object.
11989 ///
11990 /// Throws a `RangeError` if locales or options contain invalid values.
11991 ///
11992 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/Segmenter)
11993 #[cfg(js_sys_unstable_apis)]
11994 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
11995 pub fn new(locales: &[JsString], options: &SegmenterOptions) -> Result<Segmenter, JsValue>;
11996
11997 /// Returns a Segments object containing the segments of the input string.
11998 ///
11999 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/segment)
12000 #[wasm_bindgen(method, js_class = "Intl.Segmenter")]
12001 pub fn segment(this: &Segmenter, input: &str) -> Segments;
12002
12003 /// Returns an object with properties reflecting the options used.
12004 ///
12005 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/resolvedOptions)
12006 #[cfg(not(js_sys_unstable_apis))]
12007 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
12008 pub fn resolved_options(this: &Segmenter) -> Object;
12009
12010 /// Returns an object with properties reflecting the options used.
12011 ///
12012 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/resolvedOptions)
12013 #[cfg(js_sys_unstable_apis)]
12014 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
12015 pub fn resolved_options(this: &Segmenter) -> ResolvedSegmenterOptions;
12016
12017 /// Returns an array of supported locales.
12018 ///
12019 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/supportedLocalesOf)
12020 #[cfg(not(js_sys_unstable_apis))]
12021 #[wasm_bindgen(static_method_of = Segmenter, js_namespace = Intl, js_name = supportedLocalesOf)]
12022 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
12023
12024 /// Returns an array of supported locales.
12025 ///
12026 /// Throws a `RangeError` if locales contain invalid values.
12027 ///
12028 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/supportedLocalesOf)
12029 #[cfg(js_sys_unstable_apis)]
12030 #[wasm_bindgen(static_method_of = Segmenter, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
12031 pub fn supported_locales_of(
12032 locales: &[JsString],
12033 options: &LocaleMatcherOptions,
12034 ) -> Result<Array<JsString>, JsValue>;
12035 }
12036
12037 #[cfg(not(js_sys_unstable_apis))]
12038 impl Default for Segmenter {
12039 fn default() -> Self {
12040 Self::new(
12041 &JsValue::UNDEFINED.unchecked_into(),
12042 &JsValue::UNDEFINED.unchecked_into(),
12043 )
12044 }
12045 }
12046
12047 #[cfg(js_sys_unstable_apis)]
12048 impl Default for Segmenter {
12049 fn default() -> Self {
12050 Self::new(&[], &Default::default()).unwrap()
12051 }
12052 }
12053
12054 // Intl.DisplayNamesOptions
12055 #[wasm_bindgen]
12056 extern "C" {
12057 /// Options for `Intl.DisplayNames` constructor.
12058 ///
12059 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/DisplayNames#options)
12060 #[wasm_bindgen(extends = Object)]
12061 #[derive(Clone, Debug)]
12062 pub type DisplayNamesOptions;
12063
12064 #[wasm_bindgen(method, getter = localeMatcher)]
12065 pub fn get_locale_matcher(this: &DisplayNamesOptions) -> Option<LocaleMatcher>;
12066 #[wasm_bindgen(method, setter = localeMatcher)]
12067 pub fn set_locale_matcher(this: &DisplayNamesOptions, value: LocaleMatcher);
12068
12069 #[wasm_bindgen(method, getter = type)]
12070 pub fn get_type(this: &DisplayNamesOptions) -> Option<DisplayNamesType>;
12071 #[wasm_bindgen(method, setter = type)]
12072 pub fn set_type(this: &DisplayNamesOptions, value: DisplayNamesType);
12073
12074 #[wasm_bindgen(method, getter = style)]
12075 pub fn get_style(this: &DisplayNamesOptions) -> Option<DisplayNamesStyle>;
12076 #[wasm_bindgen(method, setter = style)]
12077 pub fn set_style(this: &DisplayNamesOptions, value: DisplayNamesStyle);
12078
12079 #[wasm_bindgen(method, getter = fallback)]
12080 pub fn get_fallback(this: &DisplayNamesOptions) -> Option<DisplayNamesFallback>;
12081 #[wasm_bindgen(method, setter = fallback)]
12082 pub fn set_fallback(this: &DisplayNamesOptions, value: DisplayNamesFallback);
12083
12084 #[wasm_bindgen(method, getter = languageDisplay)]
12085 pub fn get_language_display(
12086 this: &DisplayNamesOptions,
12087 ) -> Option<DisplayNamesLanguageDisplay>;
12088 #[wasm_bindgen(method, setter = languageDisplay)]
12089 pub fn set_language_display(this: &DisplayNamesOptions, value: DisplayNamesLanguageDisplay);
12090 }
12091
12092 impl DisplayNamesOptions {
12093 pub fn new() -> DisplayNamesOptions {
12094 JsCast::unchecked_into(Object::new())
12095 }
12096 }
12097
12098 impl Default for DisplayNamesOptions {
12099 fn default() -> Self {
12100 DisplayNamesOptions::new()
12101 }
12102 }
12103
12104 // Intl.ResolvedDisplayNamesOptions
12105 #[wasm_bindgen]
12106 extern "C" {
12107 /// Resolved options returned by `Intl.DisplayNames.prototype.resolvedOptions()`.
12108 ///
12109 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/resolvedOptions)
12110 #[wasm_bindgen(extends = DisplayNamesOptions)]
12111 #[derive(Clone, Debug)]
12112 pub type ResolvedDisplayNamesOptions;
12113
12114 /// The resolved locale string.
12115 #[wasm_bindgen(method, getter = locale)]
12116 pub fn get_locale(this: &ResolvedDisplayNamesOptions) -> JsString;
12117 }
12118
12119 // Intl.DisplayNames
12120 #[wasm_bindgen]
12121 extern "C" {
12122 /// The `Intl.DisplayNames` object enables the consistent translation of
12123 /// language, region, and script display names.
12124 ///
12125 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames)
12126 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.DisplayNames")]
12127 #[derive(Clone, Debug)]
12128 pub type DisplayNames;
12129
12130 /// Creates a new `Intl.DisplayNames` object.
12131 ///
12132 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/DisplayNames)
12133 #[cfg(not(js_sys_unstable_apis))]
12134 #[wasm_bindgen(constructor, js_namespace = Intl)]
12135 pub fn new(locales: &Array, options: &Object) -> DisplayNames;
12136
12137 /// Creates a new `Intl.DisplayNames` object.
12138 ///
12139 /// Throws a `RangeError` if locales or options contain invalid values.
12140 ///
12141 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/DisplayNames)
12142 #[cfg(js_sys_unstable_apis)]
12143 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
12144 pub fn new(
12145 locales: &[JsString],
12146 options: &DisplayNamesOptions,
12147 ) -> Result<DisplayNames, JsValue>;
12148
12149 /// Returns the display name for the given code.
12150 ///
12151 /// Returns `undefined` if fallback is "none" and no name is available.
12152 ///
12153 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/of)
12154 #[wasm_bindgen(method, js_class = "Intl.DisplayNames")]
12155 pub fn of(this: &DisplayNames, code: &str) -> Option<JsString>;
12156
12157 /// Returns an object with properties reflecting the options used.
12158 ///
12159 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/resolvedOptions)
12160 #[cfg(not(js_sys_unstable_apis))]
12161 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
12162 pub fn resolved_options(this: &DisplayNames) -> Object;
12163
12164 /// Returns an object with properties reflecting the options used.
12165 ///
12166 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/resolvedOptions)
12167 #[cfg(js_sys_unstable_apis)]
12168 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
12169 pub fn resolved_options(this: &DisplayNames) -> ResolvedDisplayNamesOptions;
12170
12171 /// Returns an array of supported locales.
12172 ///
12173 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/supportedLocalesOf)
12174 #[cfg(not(js_sys_unstable_apis))]
12175 #[wasm_bindgen(static_method_of = DisplayNames, js_namespace = Intl, js_name = supportedLocalesOf)]
12176 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
12177
12178 /// Returns an array of supported locales.
12179 ///
12180 /// Throws a `RangeError` if locales contain invalid values.
12181 ///
12182 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/supportedLocalesOf)
12183 #[cfg(js_sys_unstable_apis)]
12184 #[wasm_bindgen(static_method_of = DisplayNames, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
12185 pub fn supported_locales_of(
12186 locales: &[JsString],
12187 options: &LocaleMatcherOptions,
12188 ) -> Result<Array<JsString>, JsValue>;
12189 }
12190
12191 // Intl.Locale
12192 #[wasm_bindgen]
12193 extern "C" {
12194 /// The `Intl.Locale` object is a standard built-in property of the Intl object
12195 /// that represents a Unicode locale identifier.
12196 ///
12197 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale)
12198 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.Locale")]
12199 #[derive(Clone, Debug)]
12200 pub type Locale;
12201
12202 /// Creates a new `Intl.Locale` object.
12203 ///
12204 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/Locale)
12205 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
12206 pub fn new(tag: &str) -> Result<Locale, JsValue>;
12207
12208 /// Creates a new `Intl.Locale` object with options.
12209 ///
12210 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/Locale)
12211 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
12212 pub fn new_with_options(tag: &str, options: &Object) -> Result<Locale, JsValue>;
12213
12214 /// The base name of the locale (language + region + script).
12215 ///
12216 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/baseName)
12217 #[wasm_bindgen(method, getter = baseName)]
12218 pub fn base_name(this: &Locale) -> JsString;
12219
12220 /// The calendar type for the locale.
12221 ///
12222 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/calendar)
12223 #[wasm_bindgen(method, getter)]
12224 pub fn calendar(this: &Locale) -> Option<JsString>;
12225
12226 /// The case first sorting option.
12227 ///
12228 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/caseFirst)
12229 #[wasm_bindgen(method, getter = caseFirst)]
12230 pub fn case_first(this: &Locale) -> Option<JsString>;
12231
12232 /// The collation type for the locale.
12233 ///
12234 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/collation)
12235 #[wasm_bindgen(method, getter)]
12236 pub fn collation(this: &Locale) -> Option<JsString>;
12237
12238 /// The hour cycle for the locale.
12239 ///
12240 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/hourCycle)
12241 #[wasm_bindgen(method, getter = hourCycle)]
12242 pub fn hour_cycle(this: &Locale) -> Option<JsString>;
12243
12244 /// The language code for the locale.
12245 ///
12246 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/language)
12247 #[wasm_bindgen(method, getter)]
12248 pub fn language(this: &Locale) -> JsString;
12249
12250 /// The numbering system for the locale.
12251 ///
12252 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/numberingSystem)
12253 #[wasm_bindgen(method, getter = numberingSystem)]
12254 pub fn numbering_system(this: &Locale) -> Option<JsString>;
12255
12256 /// Whether the locale uses numeric collation.
12257 ///
12258 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/numeric)
12259 #[wasm_bindgen(method, getter)]
12260 pub fn numeric(this: &Locale) -> bool;
12261
12262 /// The region code for the locale.
12263 ///
12264 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/region)
12265 #[wasm_bindgen(method, getter)]
12266 pub fn region(this: &Locale) -> Option<JsString>;
12267
12268 /// The script code for the locale.
12269 ///
12270 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/script)
12271 #[wasm_bindgen(method, getter)]
12272 pub fn script(this: &Locale) -> Option<JsString>;
12273
12274 /// Returns an array of available calendars for the locale.
12275 ///
12276 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getCalendars)
12277 #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getCalendars)]
12278 pub fn get_calendars(this: &Locale) -> Array<JsString>;
12279
12280 /// Returns an array of available collations for the locale.
12281 ///
12282 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getCollations)
12283 #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getCollations)]
12284 pub fn get_collations(this: &Locale) -> Array<JsString>;
12285
12286 /// Returns an array of available hour cycles for the locale.
12287 ///
12288 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getHourCycles)
12289 #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getHourCycles)]
12290 pub fn get_hour_cycles(this: &Locale) -> Array<JsString>;
12291
12292 /// Returns an array of available numbering systems for the locale.
12293 ///
12294 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getNumberingSystems)
12295 #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getNumberingSystems)]
12296 pub fn get_numbering_systems(this: &Locale) -> Array<JsString>;
12297
12298 /// Returns an array of available time zones for the locale's region.
12299 ///
12300 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getTimeZones)
12301 #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getTimeZones)]
12302 pub fn get_time_zones(this: &Locale) -> Option<Array<JsString>>;
12303
12304 /// Returns week information for the locale.
12305 ///
12306 /// May not be available in all environments.
12307 ///
12308 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getWeekInfo)
12309 #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getWeekInfo, catch)]
12310 pub fn get_week_info(this: &Locale) -> Result<WeekInfo, JsValue>;
12311
12312 /// Returns text layout information for the locale.
12313 ///
12314 /// May not be available in all environments.
12315 ///
12316 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getTextInfo)
12317 #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getTextInfo, catch)]
12318 pub fn get_text_info(this: &Locale) -> Result<TextInfo, JsValue>;
12319
12320 /// Returns a new Locale with the specified calendar.
12321 ///
12322 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/maximize)
12323 #[wasm_bindgen(method, js_class = "Intl.Locale")]
12324 pub fn maximize(this: &Locale) -> Locale;
12325
12326 /// Returns a new Locale with the minimal subtags.
12327 ///
12328 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/minimize)
12329 #[wasm_bindgen(method, js_class = "Intl.Locale")]
12330 pub fn minimize(this: &Locale) -> Locale;
12331 }
12332
12333 // Intl.Locale WeekInfo
12334 #[wasm_bindgen]
12335 extern "C" {
12336 /// Week information for a locale.
12337 ///
12338 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getWeekInfo)
12339 #[wasm_bindgen(extends = Object)]
12340 #[derive(Clone, Debug)]
12341 pub type WeekInfo;
12342
12343 /// The first day of the week (1 = Monday, 7 = Sunday).
12344 #[wasm_bindgen(method, getter = firstDay)]
12345 pub fn first_day(this: &WeekInfo) -> u8;
12346
12347 /// Array of weekend days.
12348 #[wasm_bindgen(method, getter)]
12349 pub fn weekend(this: &WeekInfo) -> Array<Number>;
12350
12351 /// Minimal days in the first week of the year.
12352 #[wasm_bindgen(method, getter = minimalDays)]
12353 pub fn minimal_days(this: &WeekInfo) -> u8;
12354 }
12355
12356 // Intl.Locale TextInfo
12357 #[wasm_bindgen]
12358 extern "C" {
12359 /// Text layout information for a locale.
12360 ///
12361 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getTextInfo)
12362 #[wasm_bindgen(extends = Object)]
12363 #[derive(Clone, Debug)]
12364 pub type TextInfo;
12365
12366 /// The text direction ("ltr" or "rtl").
12367 #[wasm_bindgen(method, getter)]
12368 pub fn direction(this: &TextInfo) -> JsString;
12369 }
12370
12371 // Intl.DurationFormat enums
12372
12373 /// The style for duration formatting.
12374 ///
12375 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat#style)
12376 #[wasm_bindgen]
12377 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
12378 pub enum DurationFormatStyle {
12379 Long = "long",
12380 Short = "short",
12381 Narrow = "narrow",
12382 Digital = "digital",
12383 }
12384
12385 /// The display style for individual duration units.
12386 ///
12387 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat#years)
12388 #[wasm_bindgen]
12389 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
12390 pub enum DurationUnitStyle {
12391 Long = "long",
12392 Short = "short",
12393 Narrow = "narrow",
12394 }
12395
12396 /// The display style for time duration units (hours, minutes, seconds).
12397 ///
12398 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat#hours)
12399 #[wasm_bindgen]
12400 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
12401 pub enum DurationTimeUnitStyle {
12402 Long = "long",
12403 Short = "short",
12404 Narrow = "narrow",
12405 Numeric = "numeric",
12406 #[wasm_bindgen(js_name = "2-digit")]
12407 TwoDigit = "2-digit",
12408 }
12409
12410 /// The display option for duration units.
12411 ///
12412 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat#yearsdisplay)
12413 #[wasm_bindgen]
12414 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
12415 pub enum DurationUnitDisplay {
12416 Auto = "auto",
12417 Always = "always",
12418 }
12419
12420 /// The type of a duration format part.
12421 ///
12422 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/formatToParts#type)
12423 #[wasm_bindgen]
12424 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
12425 pub enum DurationFormatPartType {
12426 Years = "years",
12427 Months = "months",
12428 Weeks = "weeks",
12429 Days = "days",
12430 Hours = "hours",
12431 Minutes = "minutes",
12432 Seconds = "seconds",
12433 Milliseconds = "milliseconds",
12434 Microseconds = "microseconds",
12435 Nanoseconds = "nanoseconds",
12436 Literal = "literal",
12437 Integer = "integer",
12438 Decimal = "decimal",
12439 Fraction = "fraction",
12440 }
12441
12442 // Intl.DurationFormatOptions
12443 #[wasm_bindgen]
12444 extern "C" {
12445 /// Options for `Intl.DurationFormat` constructor.
12446 ///
12447 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat#options)
12448 #[wasm_bindgen(extends = Object)]
12449 #[derive(Clone, Debug)]
12450 pub type DurationFormatOptions;
12451
12452 #[wasm_bindgen(method, getter = localeMatcher)]
12453 pub fn get_locale_matcher(this: &DurationFormatOptions) -> Option<LocaleMatcher>;
12454 #[wasm_bindgen(method, setter = localeMatcher)]
12455 pub fn set_locale_matcher(this: &DurationFormatOptions, value: LocaleMatcher);
12456
12457 #[wasm_bindgen(method, getter = style)]
12458 pub fn get_style(this: &DurationFormatOptions) -> Option<DurationFormatStyle>;
12459 #[wasm_bindgen(method, setter = style)]
12460 pub fn set_style(this: &DurationFormatOptions, value: DurationFormatStyle);
12461
12462 #[wasm_bindgen(method, getter = years)]
12463 pub fn get_years(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
12464 #[wasm_bindgen(method, setter = years)]
12465 pub fn set_years(this: &DurationFormatOptions, value: DurationUnitStyle);
12466
12467 #[wasm_bindgen(method, getter = yearsDisplay)]
12468 pub fn get_years_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
12469 #[wasm_bindgen(method, setter = yearsDisplay)]
12470 pub fn set_years_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12471
12472 #[wasm_bindgen(method, getter = months)]
12473 pub fn get_months(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
12474 #[wasm_bindgen(method, setter = months)]
12475 pub fn set_months(this: &DurationFormatOptions, value: DurationUnitStyle);
12476
12477 #[wasm_bindgen(method, getter = monthsDisplay)]
12478 pub fn get_months_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
12479 #[wasm_bindgen(method, setter = monthsDisplay)]
12480 pub fn set_months_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12481
12482 #[wasm_bindgen(method, getter = weeks)]
12483 pub fn get_weeks(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
12484 #[wasm_bindgen(method, setter = weeks)]
12485 pub fn set_weeks(this: &DurationFormatOptions, value: DurationUnitStyle);
12486
12487 #[wasm_bindgen(method, getter = weeksDisplay)]
12488 pub fn get_weeks_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
12489 #[wasm_bindgen(method, setter = weeksDisplay)]
12490 pub fn set_weeks_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12491
12492 #[wasm_bindgen(method, getter = days)]
12493 pub fn get_days(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
12494 #[wasm_bindgen(method, setter = days)]
12495 pub fn set_days(this: &DurationFormatOptions, value: DurationUnitStyle);
12496
12497 #[wasm_bindgen(method, getter = daysDisplay)]
12498 pub fn get_days_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
12499 #[wasm_bindgen(method, setter = daysDisplay)]
12500 pub fn set_days_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12501
12502 #[wasm_bindgen(method, getter = hours)]
12503 pub fn get_hours(this: &DurationFormatOptions) -> Option<DurationTimeUnitStyle>;
12504 #[wasm_bindgen(method, setter = hours)]
12505 pub fn set_hours(this: &DurationFormatOptions, value: DurationTimeUnitStyle);
12506
12507 #[wasm_bindgen(method, getter = hoursDisplay)]
12508 pub fn get_hours_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
12509 #[wasm_bindgen(method, setter = hoursDisplay)]
12510 pub fn set_hours_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12511
12512 #[wasm_bindgen(method, getter = minutes)]
12513 pub fn get_minutes(this: &DurationFormatOptions) -> Option<DurationTimeUnitStyle>;
12514 #[wasm_bindgen(method, setter = minutes)]
12515 pub fn set_minutes(this: &DurationFormatOptions, value: DurationTimeUnitStyle);
12516
12517 #[wasm_bindgen(method, getter = minutesDisplay)]
12518 pub fn get_minutes_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
12519 #[wasm_bindgen(method, setter = minutesDisplay)]
12520 pub fn set_minutes_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12521
12522 #[wasm_bindgen(method, getter = seconds)]
12523 pub fn get_seconds(this: &DurationFormatOptions) -> Option<DurationTimeUnitStyle>;
12524 #[wasm_bindgen(method, setter = seconds)]
12525 pub fn set_seconds(this: &DurationFormatOptions, value: DurationTimeUnitStyle);
12526
12527 #[wasm_bindgen(method, getter = secondsDisplay)]
12528 pub fn get_seconds_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
12529 #[wasm_bindgen(method, setter = secondsDisplay)]
12530 pub fn set_seconds_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12531
12532 #[wasm_bindgen(method, getter = milliseconds)]
12533 pub fn get_milliseconds(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
12534 #[wasm_bindgen(method, setter = milliseconds)]
12535 pub fn set_milliseconds(this: &DurationFormatOptions, value: DurationUnitStyle);
12536
12537 #[wasm_bindgen(method, getter = millisecondsDisplay)]
12538 pub fn get_milliseconds_display(
12539 this: &DurationFormatOptions,
12540 ) -> Option<DurationUnitDisplay>;
12541 #[wasm_bindgen(method, setter = millisecondsDisplay)]
12542 pub fn set_milliseconds_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12543
12544 #[wasm_bindgen(method, getter = microseconds)]
12545 pub fn get_microseconds(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
12546 #[wasm_bindgen(method, setter = microseconds)]
12547 pub fn set_microseconds(this: &DurationFormatOptions, value: DurationUnitStyle);
12548
12549 #[wasm_bindgen(method, getter = microsecondsDisplay)]
12550 pub fn get_microseconds_display(
12551 this: &DurationFormatOptions,
12552 ) -> Option<DurationUnitDisplay>;
12553 #[wasm_bindgen(method, setter = microsecondsDisplay)]
12554 pub fn set_microseconds_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12555
12556 #[wasm_bindgen(method, getter = nanoseconds)]
12557 pub fn get_nanoseconds(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
12558 #[wasm_bindgen(method, setter = nanoseconds)]
12559 pub fn set_nanoseconds(this: &DurationFormatOptions, value: DurationUnitStyle);
12560
12561 #[wasm_bindgen(method, getter = nanosecondsDisplay)]
12562 pub fn get_nanoseconds_display(this: &DurationFormatOptions)
12563 -> Option<DurationUnitDisplay>;
12564 #[wasm_bindgen(method, setter = nanosecondsDisplay)]
12565 pub fn set_nanoseconds_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12566
12567 #[wasm_bindgen(method, getter = fractionalDigits)]
12568 pub fn get_fractional_digits(this: &DurationFormatOptions) -> Option<u8>;
12569 #[wasm_bindgen(method, setter = fractionalDigits)]
12570 pub fn set_fractional_digits(this: &DurationFormatOptions, value: u8);
12571 }
12572
12573 impl DurationFormatOptions {
12574 pub fn new() -> DurationFormatOptions {
12575 JsCast::unchecked_into(Object::new())
12576 }
12577 }
12578
12579 impl Default for DurationFormatOptions {
12580 fn default() -> Self {
12581 DurationFormatOptions::new()
12582 }
12583 }
12584
12585 // Intl.ResolvedDurationFormatOptions
12586 #[wasm_bindgen]
12587 extern "C" {
12588 /// Resolved options returned by `Intl.DurationFormat.prototype.resolvedOptions()`.
12589 ///
12590 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/resolvedOptions)
12591 #[wasm_bindgen(extends = DurationFormatOptions)]
12592 #[derive(Clone, Debug)]
12593 pub type ResolvedDurationFormatOptions;
12594
12595 /// The resolved locale string.
12596 #[wasm_bindgen(method, getter = locale)]
12597 pub fn get_locale(this: &ResolvedDurationFormatOptions) -> JsString;
12598
12599 /// The resolved numbering system.
12600 #[wasm_bindgen(method, getter = numberingSystem)]
12601 pub fn get_numbering_system(this: &ResolvedDurationFormatOptions) -> JsString;
12602 }
12603
12604 // Intl.Duration (input object for DurationFormat)
12605 #[wasm_bindgen]
12606 extern "C" {
12607 /// A duration object used as input to `Intl.DurationFormat.format()`.
12608 ///
12609 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/format#duration)
12610 #[wasm_bindgen(extends = Object)]
12611 #[derive(Clone, Debug)]
12612 pub type Duration;
12613
12614 #[wasm_bindgen(method, getter)]
12615 pub fn years(this: &Duration) -> Option<f64>;
12616 #[wasm_bindgen(method, setter)]
12617 pub fn set_years(this: &Duration, value: f64);
12618
12619 #[wasm_bindgen(method, getter)]
12620 pub fn months(this: &Duration) -> Option<f64>;
12621 #[wasm_bindgen(method, setter)]
12622 pub fn set_months(this: &Duration, value: f64);
12623
12624 #[wasm_bindgen(method, getter)]
12625 pub fn weeks(this: &Duration) -> Option<f64>;
12626 #[wasm_bindgen(method, setter)]
12627 pub fn set_weeks(this: &Duration, value: f64);
12628
12629 #[wasm_bindgen(method, getter)]
12630 pub fn days(this: &Duration) -> Option<f64>;
12631 #[wasm_bindgen(method, setter)]
12632 pub fn set_days(this: &Duration, value: f64);
12633
12634 #[wasm_bindgen(method, getter)]
12635 pub fn hours(this: &Duration) -> Option<f64>;
12636 #[wasm_bindgen(method, setter)]
12637 pub fn set_hours(this: &Duration, value: f64);
12638
12639 #[wasm_bindgen(method, getter)]
12640 pub fn minutes(this: &Duration) -> Option<f64>;
12641 #[wasm_bindgen(method, setter)]
12642 pub fn set_minutes(this: &Duration, value: f64);
12643
12644 #[wasm_bindgen(method, getter)]
12645 pub fn seconds(this: &Duration) -> Option<f64>;
12646 #[wasm_bindgen(method, setter)]
12647 pub fn set_seconds(this: &Duration, value: f64);
12648
12649 #[wasm_bindgen(method, getter)]
12650 pub fn milliseconds(this: &Duration) -> Option<f64>;
12651 #[wasm_bindgen(method, setter)]
12652 pub fn set_milliseconds(this: &Duration, value: f64);
12653
12654 #[wasm_bindgen(method, getter)]
12655 pub fn microseconds(this: &Duration) -> Option<f64>;
12656 #[wasm_bindgen(method, setter)]
12657 pub fn set_microseconds(this: &Duration, value: f64);
12658
12659 #[wasm_bindgen(method, getter)]
12660 pub fn nanoseconds(this: &Duration) -> Option<f64>;
12661 #[wasm_bindgen(method, setter)]
12662 pub fn set_nanoseconds(this: &Duration, value: f64);
12663 }
12664
12665 impl Duration {
12666 pub fn new() -> Duration {
12667 JsCast::unchecked_into(Object::new())
12668 }
12669 }
12670
12671 impl Default for Duration {
12672 fn default() -> Self {
12673 Duration::new()
12674 }
12675 }
12676
12677 // Intl.DurationFormatPart
12678 #[wasm_bindgen]
12679 extern "C" {
12680 /// A part of the formatted duration returned by `formatToParts()`.
12681 ///
12682 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/formatToParts)
12683 #[wasm_bindgen(extends = Object)]
12684 #[derive(Clone, Debug)]
12685 pub type DurationFormatPart;
12686
12687 /// The type of the part.
12688 #[wasm_bindgen(method, getter = type)]
12689 pub fn type_(this: &DurationFormatPart) -> DurationFormatPartType;
12690
12691 /// The value of the part.
12692 #[wasm_bindgen(method, getter)]
12693 pub fn value(this: &DurationFormatPart) -> JsString;
12694
12695 /// The unit this part represents (if applicable).
12696 #[wasm_bindgen(method, getter)]
12697 pub fn unit(this: &DurationFormatPart) -> Option<JsString>;
12698 }
12699
12700 // Intl.DurationFormat
12701 #[wasm_bindgen]
12702 extern "C" {
12703 /// The `Intl.DurationFormat` object enables language-sensitive duration formatting.
12704 ///
12705 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat)
12706 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.DurationFormat")]
12707 #[derive(Clone, Debug)]
12708 pub type DurationFormat;
12709
12710 /// Creates a new `Intl.DurationFormat` object.
12711 ///
12712 /// Throws a `RangeError` if locales or options contain invalid values.
12713 ///
12714 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat)
12715 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
12716 pub fn new(
12717 locales: &[JsString],
12718 options: &DurationFormatOptions,
12719 ) -> Result<DurationFormat, JsValue>;
12720
12721 /// Formats a duration according to the locale and formatting options.
12722 ///
12723 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/format)
12724 #[wasm_bindgen(method, js_class = "Intl.DurationFormat")]
12725 pub fn format(this: &DurationFormat, duration: &Duration) -> JsString;
12726
12727 /// Returns an array of objects representing the formatted duration in parts.
12728 ///
12729 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/formatToParts)
12730 #[wasm_bindgen(method, js_class = "Intl.DurationFormat", js_name = formatToParts)]
12731 pub fn format_to_parts(
12732 this: &DurationFormat,
12733 duration: &Duration,
12734 ) -> Array<DurationFormatPart>;
12735
12736 /// Returns an object with properties reflecting the options used.
12737 ///
12738 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/resolvedOptions)
12739 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
12740 pub fn resolved_options(this: &DurationFormat) -> ResolvedDurationFormatOptions;
12741
12742 /// Returns an array of supported locales.
12743 ///
12744 /// Throws a `RangeError` if locales contain invalid values.
12745 ///
12746 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/supportedLocalesOf)
12747 #[wasm_bindgen(static_method_of = DurationFormat, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
12748 pub fn supported_locales_of(
12749 locales: &[JsString],
12750 options: &LocaleMatcherOptions,
12751 ) -> Result<Array<JsString>, JsValue>;
12752 }
12753
12754 impl Default for DurationFormat {
12755 fn default() -> Self {
12756 Self::new(&[], &Default::default()).unwrap()
12757 }
12758 }
12759}
12760
12761#[wasm_bindgen]
12762extern "C" {
12763 /// The `PromiseState` object represents the the status of the promise,
12764 /// as used in `allSettled`.
12765 ///
12766 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled)
12767 #[must_use]
12768 #[wasm_bindgen(extends = Object, typescript_type = "any")]
12769 #[derive(Clone, Debug)]
12770 pub type PromiseState<T = JsValue>;
12771
12772 /// A string, either "fulfilled" or "rejected", indicating the eventual state of the promise.
12773 #[wasm_bindgen(method, getter = status)]
12774 pub fn get_status<T>(this: &PromiseState<T>) -> String;
12775
12776 /// Only present if status is "fulfilled". The value that the promise was fulfilled with.
12777 #[wasm_bindgen(method, getter = value)]
12778 pub fn get_value<T>(this: &PromiseState<T>) -> Option<T>;
12779
12780 /// Only present if status is "rejected". The reason that the promise was rejected with.
12781 #[wasm_bindgen(method, getter = reason)]
12782 pub fn get_reason<T>(this: &PromiseState<T>) -> Option<JsValue>;
12783}
12784
12785impl<T> PromiseState<T> {
12786 pub fn is_fulfilled(&self) -> bool {
12787 self.get_status() == "fulfilled"
12788 }
12789
12790 pub fn is_rejected(&self) -> bool {
12791 self.get_status() == "rejected"
12792 }
12793}
12794
12795// Promise
12796#[wasm_bindgen]
12797extern "C" {
12798 /// The `Promise` object represents the eventual completion (or failure) of
12799 /// an asynchronous operation, and its resulting value.
12800 ///
12801 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
12802 #[must_use]
12803 #[wasm_bindgen(extends = Object, typescript_type = "Promise<any>", no_promising)]
12804 #[derive(Clone, Debug)]
12805 pub type Promise<T = JsValue>;
12806
12807 /// Creates a new `Promise` with the provided executor `cb`
12808 ///
12809 /// The `cb` is a function that is passed with the arguments `resolve` and
12810 /// `reject`. The `cb` function is executed immediately by the `Promise`
12811 /// implementation, passing `resolve` and `reject` functions (the executor
12812 /// is called before the `Promise` constructor even returns the created
12813 /// object). The `resolve` and `reject` functions, when called, resolve or
12814 /// reject the promise, respectively. The executor normally initiates
12815 /// some asynchronous work, and then, once that completes, either calls
12816 /// the `resolve` function to resolve the promise or else rejects it if an
12817 /// error occurred.
12818 ///
12819 /// If an error is thrown in the executor function, the promise is rejected.
12820 /// The return value of the executor is ignored.
12821 ///
12822 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
12823 #[cfg(not(js_sys_unstable_apis))]
12824 #[wasm_bindgen(constructor)]
12825 pub fn new(cb: &mut dyn FnMut(Function, Function)) -> Promise;
12826
12827 /// Creates a new `Promise` with the provided executor `cb`
12828 ///
12829 /// The `cb` is a function that is passed with the arguments `resolve` and
12830 /// `reject`. The `cb` function is executed immediately by the `Promise`
12831 /// implementation, passing `resolve` and `reject` functions (the executor
12832 /// is called before the `Promise` constructor even returns the created
12833 /// object). The `resolve` and `reject` functions, when called, resolve or
12834 /// reject the promise, respectively. The executor normally initiates
12835 /// some asynchronous work, and then, once that completes, either calls
12836 /// the `resolve` function to resolve the promise or else rejects it if an
12837 /// error occurred.
12838 ///
12839 /// If an error is thrown in the executor function, the promise is rejected.
12840 /// The return value of the executor is ignored.
12841 ///
12842 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
12843 #[cfg(js_sys_unstable_apis)]
12844 #[wasm_bindgen(constructor)]
12845 pub fn new<T: JsGeneric>(
12846 cb: &mut dyn FnMut(Function<fn(T) -> Undefined>, Function<fn(JsValue) -> Undefined>),
12847 ) -> Promise<T>;
12848
12849 // Next major: deprecate
12850 /// Creates a new `Promise` with the provided executor `cb`
12851 ///
12852 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
12853 #[wasm_bindgen(constructor)]
12854 pub fn new_typed<T: JsGeneric>(
12855 cb: &mut dyn FnMut(Function<fn(T) -> Undefined>, Function<fn(JsValue) -> Undefined>),
12856 ) -> Promise<T>;
12857
12858 /// The `Promise.all(iterable)` method returns a single `Promise` that
12859 /// resolves when all of the promises in the iterable argument have resolved
12860 /// or when the iterable argument contains no promises. It rejects with the
12861 /// reason of the first promise that rejects.
12862 ///
12863 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all)
12864 #[cfg(not(js_sys_unstable_apis))]
12865 #[wasm_bindgen(static_method_of = Promise)]
12866 pub fn all(obj: &JsValue) -> Promise;
12867
12868 /// The `Promise.all(iterable)` method returns a single `Promise` that
12869 /// resolves when all of the promises in the iterable argument have resolved
12870 /// or when the iterable argument contains no promises. It rejects with the
12871 /// reason of the first promise that rejects.
12872 ///
12873 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all)
12874 #[cfg(js_sys_unstable_apis)]
12875 #[wasm_bindgen(static_method_of = Promise, js_name = all)]
12876 pub fn all<I: Iterable>(obj: &I) -> Promise<Array<<I::Item as Promising>::Resolution>>
12877 where
12878 I::Item: Promising;
12879
12880 // Next major: deprecate
12881 /// The `Promise.all(iterable)` method returns a single `Promise` that
12882 /// resolves when all of the promises in the iterable argument have resolved
12883 /// or when the iterable argument contains no promises. It rejects with the
12884 /// reason of the first promise that rejects.
12885 ///
12886 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all)
12887 #[wasm_bindgen(static_method_of = Promise, js_name = all)]
12888 pub fn all_iterable<I: Iterable>(obj: &I) -> Promise<Array<<I::Item as Promising>::Resolution>>
12889 where
12890 I::Item: Promising;
12891
12892 /// The `Promise.allSettled(iterable)` method returns a single `Promise` that
12893 /// resolves when all of the promises in the iterable argument have either
12894 /// fulfilled or rejected or when the iterable argument contains no promises.
12895 ///
12896 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled)
12897 #[cfg(not(js_sys_unstable_apis))]
12898 #[wasm_bindgen(static_method_of = Promise, js_name = allSettled)]
12899 pub fn all_settled(obj: &JsValue) -> Promise;
12900
12901 /// The `Promise.allSettled(iterable)` method returns a single `Promise` that
12902 /// resolves when all of the promises in the iterable argument have either
12903 /// fulfilled or rejected or when the iterable argument contains no promises.
12904 ///
12905 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled)
12906 #[cfg(js_sys_unstable_apis)]
12907 #[wasm_bindgen(static_method_of = Promise, js_name = allSettled)]
12908 pub fn all_settled<I: Iterable>(
12909 obj: &I,
12910 ) -> Promise<Array<PromiseState<<I::Item as Promising>::Resolution>>>
12911 where
12912 I::Item: Promising;
12913
12914 // Next major: deprecate
12915 /// The `Promise.allSettled(iterable)` method returns a single `Promise` that
12916 /// resolves when all of the promises in the iterable argument have either
12917 /// fulfilled or rejected or when the iterable argument contains no promises.
12918 ///
12919 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled)
12920 #[wasm_bindgen(static_method_of = Promise, js_name = allSettled)]
12921 pub fn all_settled_iterable<I: Iterable>(
12922 obj: &I,
12923 ) -> Promise<Array<PromiseState<<I::Item as Promising>::Resolution>>>
12924 where
12925 I::Item: Promising;
12926
12927 /// The `Promise.any(iterable)` method returns a single `Promise` that
12928 /// resolves when any of the promises in the iterable argument have resolved
12929 /// or when the iterable argument contains no promises. It rejects with an
12930 /// `AggregateError` if all promises in the iterable rejected.
12931 ///
12932 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/any)
12933 #[cfg(not(js_sys_unstable_apis))]
12934 #[wasm_bindgen(static_method_of = Promise)]
12935 pub fn any(obj: &JsValue) -> Promise;
12936
12937 /// The `Promise.any(iterable)` method returns a single `Promise` that
12938 /// resolves when any of the promises in the iterable argument have resolved
12939 /// or when the iterable argument contains no promises. It rejects with an
12940 /// `AggregateError` if all promises in the iterable rejected.
12941 ///
12942 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/any)
12943 #[cfg(js_sys_unstable_apis)]
12944 #[wasm_bindgen(static_method_of = Promise, js_name = any)]
12945 pub fn any<I: Iterable>(obj: &I) -> Promise<<I::Item as Promising>::Resolution>
12946 where
12947 I::Item: Promising;
12948
12949 // Next major: deprecate
12950 /// The `Promise.any(iterable)` method returns a single `Promise` that
12951 /// resolves when any of the promises in the iterable argument have resolved
12952 /// or when the iterable argument contains no promises. It rejects with an
12953 /// `AggregateError` if all promises in the iterable rejected.
12954 ///
12955 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/any)
12956 #[cfg(not(js_sys_unstable_apis))]
12957 #[wasm_bindgen(static_method_of = Promise, js_name = any)]
12958 pub fn any_iterable<I: Iterable>(obj: &I) -> Promise<<I::Item as Promising>::Resolution>
12959 where
12960 I::Item: Promising;
12961
12962 /// The `Promise.race(iterable)` method returns a promise that resolves or
12963 /// rejects as soon as one of the promises in the iterable resolves or
12964 /// rejects, with the value or reason from that promise.
12965 ///
12966 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/race)
12967 #[cfg(not(js_sys_unstable_apis))]
12968 #[wasm_bindgen(static_method_of = Promise)]
12969 pub fn race(obj: &JsValue) -> Promise;
12970
12971 /// The `Promise.race(iterable)` method returns a promise that resolves or
12972 /// rejects as soon as one of the promises in the iterable resolves or
12973 /// rejects, with the value or reason from that promise.
12974 ///
12975 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/race)
12976 #[cfg(js_sys_unstable_apis)]
12977 #[wasm_bindgen(static_method_of = Promise, js_name = race)]
12978 pub fn race<I: Iterable>(obj: &I) -> Promise<<I::Item as Promising>::Resolution>
12979 where
12980 I::Item: Promising;
12981
12982 // Next major: deprecate
12983 /// The `Promise.race(iterable)` method returns a promise that resolves or
12984 /// rejects as soon as one of the promises in the iterable resolves or
12985 /// rejects, with the value or reason from that promise.
12986 ///
12987 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/race)
12988 #[wasm_bindgen(static_method_of = Promise, js_name = race)]
12989 pub fn race_iterable<I: Iterable>(obj: &I) -> Promise<<I::Item as Promising>::Resolution>
12990 where
12991 I::Item: Promising;
12992
12993 /// The `Promise.reject(reason)` method returns a `Promise` object that is
12994 /// rejected with the given reason.
12995 ///
12996 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/reject)
12997 #[cfg(not(js_sys_unstable_apis))]
12998 #[wasm_bindgen(static_method_of = Promise)]
12999 pub fn reject(obj: &JsValue) -> Promise;
13000
13001 /// The `Promise.reject(reason)` method returns a `Promise` object that is
13002 /// rejected with the given reason.
13003 ///
13004 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/reject)
13005 #[cfg(js_sys_unstable_apis)]
13006 #[wasm_bindgen(static_method_of = Promise, js_name = reject)]
13007 pub fn reject<T>(obj: &JsValue) -> Promise<T>;
13008
13009 // Next major: deprecate
13010 /// The `Promise.reject(reason)` method returns a `Promise` object that is
13011 /// rejected with the given reason.
13012 ///
13013 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/reject)
13014 #[wasm_bindgen(static_method_of = Promise, js_name = reject)]
13015 pub fn reject_typed<T>(obj: &JsValue) -> Promise<T>;
13016
13017 /// The `Promise.resolve(value)` method returns a `Promise` object that is
13018 /// resolved with the given value. If the value is a promise, that promise
13019 /// is returned; if the value is a thenable (i.e. has a "then" method), the
13020 /// returned promise will "follow" that thenable, adopting its eventual
13021 /// state; otherwise the returned promise will be fulfilled with the value.
13022 ///
13023 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/resolve)
13024 #[wasm_bindgen(static_method_of = Promise, js_name = resolve)]
13025 pub fn resolve<U: Promising>(obj: &U) -> Promise<U::Resolution>;
13026
13027 /// The `catch()` method returns a `Promise` and deals with rejected cases
13028 /// only. It behaves the same as calling `Promise.prototype.then(undefined,
13029 /// onRejected)` (in fact, calling `obj.catch(onRejected)` internally calls
13030 /// `obj.then(undefined, onRejected)`).
13031 ///
13032 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch)
13033 #[cfg(not(js_sys_unstable_apis))]
13034 #[wasm_bindgen(method)]
13035 pub fn catch<T>(this: &Promise<T>, cb: &ScopedClosure<dyn FnMut(JsValue)>) -> Promise<JsValue>;
13036
13037 /// The `catch()` method returns a `Promise` and deals with rejected cases
13038 /// only. It behaves the same as calling `Promise.prototype.then(undefined,
13039 /// onRejected)` (in fact, calling `obj.catch(onRejected)` internally calls
13040 /// `obj.then(undefined, onRejected)`).
13041 ///
13042 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch)
13043 #[cfg(js_sys_unstable_apis)]
13044 #[wasm_bindgen(method, js_name = catch)]
13045 pub fn catch<'a, T, R: Promising>(
13046 this: &Promise<T>,
13047 cb: &ScopedClosure<'a, dyn FnMut(T) -> Result<R, JsError>>,
13048 ) -> Promise<R::Resolution>;
13049
13050 // Next major: deprecate
13051 /// Same as `catch`, but returning a result to become the new Promise value.
13052 #[wasm_bindgen(method, js_name = catch)]
13053 pub fn catch_map<'a, T, R: Promising>(
13054 this: &Promise<T>,
13055 cb: &ScopedClosure<'a, dyn FnMut(T) -> Result<R, JsError>>,
13056 ) -> Promise<R::Resolution>;
13057
13058 /// The `then()` method returns a `Promise`. It takes up to two arguments:
13059 /// callback functions for the success and failure cases of the `Promise`.
13060 ///
13061 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then)
13062 #[cfg(not(js_sys_unstable_apis))]
13063 #[wasm_bindgen(method)]
13064 pub fn then<'a, T>(this: &Promise<T>, cb: &ScopedClosure<'a, dyn FnMut(T)>)
13065 -> Promise<JsValue>;
13066
13067 /// The `then()` method returns a `Promise`. It takes up to two arguments:
13068 /// callback functions for the success and failure cases of the `Promise`.
13069 ///
13070 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then)
13071 #[cfg(js_sys_unstable_apis)]
13072 #[wasm_bindgen(method, js_name = then)]
13073 pub fn then<'a, T, R: Promising>(
13074 this: &Promise<T>,
13075 cb: &ScopedClosure<'a, dyn FnMut(T) -> Result<R, JsError>>,
13076 ) -> Promise<R::Resolution>;
13077
13078 /// The `then()` method returns a `Promise`. It takes up to two arguments:
13079 /// callback functions for the success and failure cases of the `Promise`.
13080 ///
13081 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then)
13082 #[wasm_bindgen(method, js_name = then)]
13083 pub fn then_with_reject<'a, T, R: Promising>(
13084 this: &Promise<T>,
13085 resolve: &ScopedClosure<'a, dyn FnMut(T) -> Result<R, JsError>>,
13086 reject: &ScopedClosure<'a, dyn FnMut(JsValue) -> Result<R, JsError>>,
13087 ) -> Promise<R::Resolution>;
13088
13089 // Next major: deprecate
13090 /// Alias for `then()` with a return value.
13091 /// The `then()` method returns a `Promise`. It takes up to two arguments:
13092 /// callback functions for the success and failure cases of the `Promise`.
13093 ///
13094 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then)
13095 #[wasm_bindgen(method, js_name = then)]
13096 pub fn then_map<'a, T, R: Promising>(
13097 this: &Promise<T>,
13098 cb: &ScopedClosure<'a, dyn FnMut(T) -> Result<R, JsError>>,
13099 ) -> Promise<R::Resolution>;
13100
13101 /// Same as `then`, only with both arguments provided.
13102 ///
13103 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then)
13104 #[wasm_bindgen(method, js_name = then)]
13105 pub fn then2(
13106 this: &Promise,
13107 resolve: &ScopedClosure<dyn FnMut(JsValue)>,
13108 reject: &ScopedClosure<dyn FnMut(JsValue)>,
13109 ) -> Promise;
13110
13111 /// The `finally()` method returns a `Promise`. When the promise is settled,
13112 /// whether fulfilled or rejected, the specified callback function is
13113 /// executed. This provides a way for code that must be executed once the
13114 /// `Promise` has been dealt with to be run whether the promise was
13115 /// fulfilled successfully or rejected.
13116 ///
13117 /// This lets you avoid duplicating code in both the promise's `then()` and
13118 /// `catch()` handlers.
13119 ///
13120 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/finally)
13121 #[wasm_bindgen(method)]
13122 pub fn finally<T>(this: &Promise<T>, cb: &ScopedClosure<dyn FnMut()>) -> Promise<JsValue>;
13123}
13124
13125impl<T: JsGeneric> Promising for Promise<T> {
13126 type Resolution = T;
13127}
13128
13129/// Returns a handle to the global scope object.
13130///
13131/// This allows access to the global properties and global names by accessing
13132/// the `Object` returned.
13133pub fn global() -> Object {
13134 use once_cell::unsync::Lazy;
13135
13136 struct Wrapper<T>(Lazy<T>);
13137
13138 #[cfg(not(target_feature = "atomics"))]
13139 unsafe impl<T> Sync for Wrapper<T> {}
13140
13141 #[cfg(not(target_feature = "atomics"))]
13142 unsafe impl<T> Send for Wrapper<T> {}
13143
13144 #[cfg_attr(target_feature = "atomics", thread_local)]
13145 static GLOBAL: Wrapper<Object> = Wrapper(Lazy::new(get_global_object));
13146
13147 return GLOBAL.0.clone();
13148
13149 fn get_global_object() -> Object {
13150 // Accessing the global object is not an easy thing to do, and what we
13151 // basically want is `globalThis` but we can't rely on that existing
13152 // everywhere. In the meantime we've got the fallbacks mentioned in:
13153 //
13154 // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis
13155 //
13156 // Note that this is pretty heavy code-size wise but it at least gets
13157 // the job largely done for now and avoids the `Function` constructor at
13158 // the end which triggers CSP errors.
13159 #[wasm_bindgen]
13160 extern "C" {
13161 type Global;
13162
13163 #[wasm_bindgen(thread_local_v2, js_name = globalThis)]
13164 static GLOBAL_THIS: Option<Object>;
13165
13166 #[wasm_bindgen(thread_local_v2, js_name = self)]
13167 static SELF: Option<Object>;
13168
13169 #[wasm_bindgen(thread_local_v2, js_name = window)]
13170 static WINDOW: Option<Object>;
13171
13172 #[wasm_bindgen(thread_local_v2, js_name = global)]
13173 static GLOBAL: Option<Object>;
13174 }
13175
13176 // The order is important: in Firefox Extension Content Scripts `globalThis`
13177 // is a Sandbox (not Window), so `globalThis` must be checked after `window`.
13178 let static_object = SELF
13179 .with(Option::clone)
13180 .or_else(|| WINDOW.with(Option::clone))
13181 .or_else(|| GLOBAL_THIS.with(Option::clone))
13182 .or_else(|| GLOBAL.with(Option::clone));
13183 if let Some(obj) = static_object {
13184 if !obj.is_undefined() {
13185 return obj;
13186 }
13187 }
13188
13189 // Global object not found
13190 JsValue::undefined().unchecked_into()
13191 }
13192}
13193
13194// Float16Array
13195//
13196// Rust does not yet have a stable builtin `f16`, so the raw JS bindings live
13197// here and any Rust-side helper APIs use explicit `u16` / `f32` naming. The
13198// unsuffixed float APIs are reserved for a future native `f16` binding.
13199#[wasm_bindgen]
13200extern "C" {
13201 #[wasm_bindgen(extends = Object, typescript_type = "Float16Array")]
13202 #[derive(Clone, Debug)]
13203 pub type Float16Array;
13204
13205 /// The `Float16Array()` constructor creates a new array.
13206 ///
13207 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float16Array)
13208 #[wasm_bindgen(constructor)]
13209 pub fn new(constructor_arg: &JsValue) -> Float16Array;
13210
13211 /// The `Float16Array()` constructor creates an array with an internal
13212 /// buffer large enough for `length` elements.
13213 ///
13214 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float16Array)
13215 #[wasm_bindgen(constructor)]
13216 pub fn new_with_length(length: u32) -> Float16Array;
13217
13218 /// The `Float16Array()` constructor creates an array with the given
13219 /// buffer but is a view starting at `byte_offset`.
13220 ///
13221 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float16Array)
13222 #[wasm_bindgen(constructor)]
13223 pub fn new_with_byte_offset(buffer: &JsValue, byte_offset: u32) -> Float16Array;
13224
13225 /// The `Float16Array()` constructor creates an array with the given
13226 /// buffer but is a view starting at `byte_offset` for `length` elements.
13227 ///
13228 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float16Array)
13229 #[wasm_bindgen(constructor)]
13230 pub fn new_with_byte_offset_and_length(
13231 buffer: &JsValue,
13232 byte_offset: u32,
13233 length: u32,
13234 ) -> Float16Array;
13235
13236 /// The `fill()` method fills all elements from a start index to an end
13237 /// index with a static `f32` value.
13238 ///
13239 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/fill)
13240 #[wasm_bindgen(method, js_name = fill)]
13241 pub fn fill_with_f32(this: &Float16Array, value: f32, start: u32, end: u32) -> Float16Array;
13242
13243 /// The buffer accessor property represents the `ArrayBuffer` referenced
13244 /// by a `TypedArray` at construction time.
13245 #[wasm_bindgen(getter, method)]
13246 pub fn buffer(this: &Float16Array) -> ArrayBuffer;
13247
13248 /// The `subarray()` method returns a new `TypedArray` on the same
13249 /// `ArrayBuffer` store and with the same element types as this array.
13250 #[wasm_bindgen(method)]
13251 pub fn subarray(this: &Float16Array, begin: u32, end: u32) -> Float16Array;
13252
13253 /// The `slice()` method returns a shallow copy of a portion of a typed
13254 /// array into a new typed array object.
13255 #[wasm_bindgen(method)]
13256 pub fn slice(this: &Float16Array, begin: u32, end: u32) -> Float16Array;
13257
13258 /// The `forEach()` method executes a provided function once per array
13259 /// element, passing values as `f32`.
13260 #[wasm_bindgen(method, js_name = forEach)]
13261 pub fn for_each_as_f32(this: &Float16Array, callback: &mut dyn FnMut(f32, u32, Float16Array));
13262
13263 /// The `forEach()` method executes a provided function once per array
13264 /// element, passing values as `f32`.
13265 #[wasm_bindgen(method, js_name = forEach, catch)]
13266 pub fn try_for_each_as_f32(
13267 this: &Float16Array,
13268 callback: &mut dyn FnMut(f32, u32, Float16Array) -> Result<(), JsError>,
13269 ) -> Result<(), JsValue>;
13270
13271 /// The length accessor property represents the length (in elements) of a
13272 /// typed array.
13273 #[wasm_bindgen(method, getter)]
13274 pub fn length(this: &Float16Array) -> u32;
13275
13276 /// The byteLength accessor property represents the length (in bytes) of a
13277 /// typed array.
13278 #[wasm_bindgen(method, getter, js_name = byteLength)]
13279 pub fn byte_length(this: &Float16Array) -> u32;
13280
13281 /// The byteOffset accessor property represents the offset (in bytes) of a
13282 /// typed array from the start of its `ArrayBuffer`.
13283 #[wasm_bindgen(method, getter, js_name = byteOffset)]
13284 pub fn byte_offset(this: &Float16Array) -> u32;
13285
13286 /// The `set()` method stores multiple values in the typed array, reading
13287 /// input values from a specified array.
13288 #[wasm_bindgen(method)]
13289 pub fn set(this: &Float16Array, src: &JsValue, offset: u32);
13290
13291 /// Gets the value at `idx` as an `f32`, counting from the end if negative.
13292 #[wasm_bindgen(method, js_name = at)]
13293 pub fn at_as_f32(this: &Float16Array, idx: i32) -> Option<f32>;
13294
13295 /// The `copyWithin()` method shallow copies part of a typed array to another
13296 /// location in the same typed array and returns it, without modifying its size.
13297 ///
13298 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin)
13299 #[wasm_bindgen(method, js_name = copyWithin)]
13300 pub fn copy_within(this: &Float16Array, target: i32, start: i32, end: i32) -> Float16Array;
13301
13302 /// Gets the value at `idx` as an `f32`, equivalent to JavaScript
13303 /// `arr[idx]`.
13304 #[wasm_bindgen(method, indexing_getter)]
13305 pub fn get_index_as_f32(this: &Float16Array, idx: u32) -> f32;
13306
13307 /// Sets the value at `idx` from an `f32`, equivalent to JavaScript
13308 /// `arr[idx] = value`.
13309 #[wasm_bindgen(method, indexing_setter)]
13310 pub fn set_index_from_f32(this: &Float16Array, idx: u32, value: f32);
13311}
13312
13313impl Default for Float16Array {
13314 fn default() -> Self {
13315 Self::new(&JsValue::UNDEFINED.unchecked_into())
13316 }
13317}
13318
13319impl TypedArray for Float16Array {}
13320
13321impl Float16Array {
13322 fn as_uint16_view(&self) -> Uint16Array {
13323 let buffer = self.buffer();
13324 Uint16Array::new_with_byte_offset_and_length(
13325 buffer.as_ref(),
13326 self.byte_offset(),
13327 self.length(),
13328 )
13329 }
13330
13331 /// Creates an array from raw IEEE 754 binary16 bit patterns.
13332 ///
13333 /// This pairs naturally with the optional `half` crate:
13334 ///
13335 /// ```rust
13336 /// use half::f16;
13337 /// use js_sys::Float16Array;
13338 ///
13339 /// let values = [f16::from_f32(1.0), f16::from_f32(-2.0)];
13340 /// let bits = values.map(f16::to_bits);
13341 /// let array = Float16Array::new_from_u16_slice(&bits);
13342 /// ```
13343 pub fn new_from_u16_slice(slice: &[u16]) -> Float16Array {
13344 let array = Float16Array::new_with_length(slice.len() as u32);
13345 array.copy_from_u16_slice(slice);
13346 array
13347 }
13348
13349 /// Copy the raw IEEE 754 binary16 bit patterns from this JS typed array
13350 /// into the destination Rust slice.
13351 ///
13352 /// # Panics
13353 ///
13354 /// This function will panic if this typed array's length is different than
13355 /// the length of the provided `dst` array.
13356 ///
13357 /// Values copied into `dst` can be converted back into `half::f16` with
13358 /// `half::f16::from_bits`.
13359 pub fn copy_to_u16_slice(&self, dst: &mut [u16]) {
13360 self.as_uint16_view().copy_to(dst);
13361 }
13362
13363 /// Copy raw IEEE 754 binary16 bit patterns from the source Rust slice into
13364 /// this JS typed array.
13365 ///
13366 /// # Panics
13367 ///
13368 /// This function will panic if this typed array's length is different than
13369 /// the length of the provided `src` array.
13370 ///
13371 /// When using the optional `half` crate, populate `src` with
13372 /// `half::f16::to_bits()`.
13373 pub fn copy_from_u16_slice(&self, src: &[u16]) {
13374 self.as_uint16_view().copy_from(src);
13375 }
13376
13377 /// Efficiently copies the contents of this JS typed array into a new Vec of
13378 /// raw IEEE 754 binary16 bit patterns.
13379 ///
13380 /// This makes it easy to round-trip through the optional `half` crate:
13381 ///
13382 /// ```rust
13383 /// use half::f16;
13384 ///
13385 /// let bits = array.to_u16_vec();
13386 /// let values: Vec<f16> = bits.into_iter().map(f16::from_bits).collect();
13387 /// ```
13388 pub fn to_u16_vec(&self) -> Vec<u16> {
13389 self.as_uint16_view().to_vec()
13390 }
13391}
13392
13393macro_rules! arrays {
13394 ($(#[doc = $ctor:literal] #[doc = $mdn:literal] $name:ident: $ty:ident,)*) => ($(
13395 #[wasm_bindgen]
13396 extern "C" {
13397 #[wasm_bindgen(extends = Object, typescript_type = $name)]
13398 #[derive(Clone, Debug)]
13399 pub type $name;
13400
13401 /// The
13402 #[doc = $ctor]
13403 /// constructor creates a new array.
13404 ///
13405 /// [MDN documentation](
13406 #[doc = $mdn]
13407 /// )
13408 #[wasm_bindgen(constructor)]
13409 pub fn new(constructor_arg: &JsValue) -> $name;
13410
13411 /// An
13412 #[doc = $ctor]
13413 /// which creates an array with an internal buffer large
13414 /// enough for `length` elements.
13415 ///
13416 /// [MDN documentation](
13417 #[doc = $mdn]
13418 /// )
13419 #[wasm_bindgen(constructor)]
13420 pub fn new_with_length(length: u32) -> $name;
13421
13422 /// An
13423 #[doc = $ctor]
13424 /// which creates an array from a Rust slice.
13425 ///
13426 /// [MDN documentation](
13427 #[doc = $mdn]
13428 /// )
13429 #[wasm_bindgen(constructor)]
13430 pub fn new_from_slice(slice: &[$ty]) -> $name;
13431
13432 /// An
13433 #[doc = $ctor]
13434 /// which creates an array with the given buffer but is a
13435 /// view starting at `byte_offset`.
13436 ///
13437 /// [MDN documentation](
13438 #[doc = $mdn]
13439 /// )
13440 #[wasm_bindgen(constructor)]
13441 pub fn new_with_byte_offset(buffer: &JsValue, byte_offset: u32) -> $name;
13442
13443 /// An
13444 #[doc = $ctor]
13445 /// which creates an array with the given buffer but is a
13446 /// view starting at `byte_offset` for `length` elements.
13447 ///
13448 /// [MDN documentation](
13449 #[doc = $mdn]
13450 /// )
13451 #[wasm_bindgen(constructor)]
13452 pub fn new_with_byte_offset_and_length(
13453 buffer: &JsValue,
13454 byte_offset: u32,
13455 length: u32,
13456 ) -> $name;
13457
13458 /// The `fill()` method fills all the elements of an array from a start index
13459 /// to an end index with a static value. The end index is not included.
13460 ///
13461 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/fill)
13462 #[wasm_bindgen(method)]
13463 pub fn fill(this: &$name, value: $ty, start: u32, end: u32) -> $name;
13464
13465 /// The buffer accessor property represents the `ArrayBuffer` referenced
13466 /// by a `TypedArray` at construction time.
13467 #[wasm_bindgen(getter, method)]
13468 pub fn buffer(this: &$name) -> ArrayBuffer;
13469
13470 /// The `subarray()` method returns a new `TypedArray` on the same
13471 /// `ArrayBuffer` store and with the same element types as for this
13472 /// `TypedArray` object.
13473 #[wasm_bindgen(method)]
13474 pub fn subarray(this: &$name, begin: u32, end: u32) -> $name;
13475
13476 /// The `slice()` method returns a shallow copy of a portion of a typed
13477 /// array into a new typed array object. This method has the same algorithm
13478 /// as `Array.prototype.slice()`.
13479 #[wasm_bindgen(method)]
13480 pub fn slice(this: &$name, begin: u32, end: u32) -> $name;
13481
13482 /// The `forEach()` method executes a provided function once per array
13483 /// element. This method has the same algorithm as
13484 /// `Array.prototype.forEach()`. `TypedArray` is one of the typed array
13485 /// types here.
13486 #[wasm_bindgen(method, js_name = forEach)]
13487 pub fn for_each(this: &$name, callback: &mut dyn FnMut($ty, u32, $name));
13488
13489 /// The `forEach()` method executes a provided function once per array
13490 /// element. This method has the same algorithm as
13491 /// `Array.prototype.forEach()`. `TypedArray` is one of the typed array
13492 /// types here.
13493 #[wasm_bindgen(method, js_name = forEach, catch)]
13494 pub fn try_for_each(this: &$name, callback: &mut dyn FnMut($ty, u32, $name) -> Result<(), JsError>) -> Result<(), JsValue>;
13495
13496 /// The length accessor property represents the length (in elements) of a
13497 /// typed array.
13498 #[wasm_bindgen(method, getter)]
13499 pub fn length(this: &$name) -> u32;
13500
13501 /// The byteLength accessor property represents the length (in bytes) of a
13502 /// typed array.
13503 #[wasm_bindgen(method, getter, js_name = byteLength)]
13504 pub fn byte_length(this: &$name) -> u32;
13505
13506 /// The byteOffset accessor property represents the offset (in bytes) of a
13507 /// typed array from the start of its `ArrayBuffer`.
13508 #[wasm_bindgen(method, getter, js_name = byteOffset)]
13509 pub fn byte_offset(this: &$name) -> u32;
13510
13511 /// The `set()` method stores multiple values in the typed array, reading
13512 /// input values from a specified array.
13513 #[wasm_bindgen(method)]
13514 pub fn set(this: &$name, src: &JsValue, offset: u32);
13515
13516 /// Gets the value at `idx`, counting from the end if negative.
13517 #[wasm_bindgen(method)]
13518 pub fn at(this: &$name, idx: i32) -> Option<$ty>;
13519
13520 /// The `copyWithin()` method shallow copies part of a typed array to another
13521 /// location in the same typed array and returns it, without modifying its size.
13522 ///
13523 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin)
13524 #[wasm_bindgen(method, js_name = copyWithin)]
13525 pub fn copy_within(this: &$name, target: i32, start: i32, end: i32) -> $name;
13526
13527 /// Gets the value at `idx`, equivalent to the javascript `my_var = arr[idx]`.
13528 #[wasm_bindgen(method, indexing_getter)]
13529 pub fn get_index(this: &$name, idx: u32) -> $ty;
13530
13531 /// Sets the value at `idx`, equivalent to the javascript `arr[idx] = value`.
13532 #[wasm_bindgen(method, indexing_setter)]
13533 pub fn set_index(this: &$name, idx: u32, value: $ty);
13534
13535 /// Copies the Rust slice's data to self.
13536 ///
13537 /// This method is not expected to be public. It requires the length of the
13538 /// TypedArray to be the same as the slice, use `self.copy_from(slice)` instead.
13539 #[wasm_bindgen(method, js_name = set)]
13540 fn copy_from_slice(this: &$name, slice: &[$ty]);
13541
13542 /// Copies this TypedArray's data to Rust slice;
13543 ///
13544 /// This method is not expected to be public. It requires the length of the
13545 /// TypedArray to be the same as the slice, use `self.copy_to(slice)` instead.
13546 ///
13547 /// # Workaround
13548 ///
13549 /// We actually need `slice.set(typed_array)` here, but since slice cannot be treated as
13550 /// `Uint8Array` on the Rust side, we use `Uint8Array.prototype.set.call`, which allows
13551 /// us to specify the `this` value inside the function.
13552 ///
13553 /// Therefore, `Uint8Array.prototype.set.call(slice, typed_array)` is equivalent to
13554 /// `slice.set(typed_array)`.
13555 #[wasm_bindgen(js_namespace = $name, js_name = "prototype.set.call")]
13556 fn copy_to_slice(slice: &mut [$ty], this: &$name);
13557 }
13558
13559 impl $name {
13560 /// Creates a JS typed array which is a view into wasm's linear
13561 /// memory at the slice specified.
13562 ///
13563 /// This function returns a new typed array which is a view into
13564 /// wasm's memory. This view does not copy the underlying data.
13565 ///
13566 /// # Safety
13567 ///
13568 /// Views into WebAssembly memory are only valid so long as the
13569 /// backing buffer isn't resized in JS. Once this function is called
13570 /// any future calls to `Box::new` (or malloc of any form) may cause
13571 /// the returned value here to be invalidated. Use with caution!
13572 ///
13573 /// Additionally the returned object can be safely mutated but the
13574 /// input slice isn't guaranteed to be mutable.
13575 ///
13576 /// Finally, the returned object is disconnected from the input
13577 /// slice's lifetime, so there's no guarantee that the data is read
13578 /// at the right time.
13579 pub unsafe fn view(rust: &[$ty]) -> $name {
13580 wasm_bindgen::__rt::wbg_cast(rust)
13581 }
13582
13583 /// Creates a JS typed array which is a view into wasm's linear
13584 /// memory at the specified pointer with specified length.
13585 ///
13586 /// This function returns a new typed array which is a view into
13587 /// wasm's memory. This view does not copy the underlying data.
13588 ///
13589 /// # Safety
13590 ///
13591 /// Views into WebAssembly memory are only valid so long as the
13592 /// backing buffer isn't resized in JS. Once this function is called
13593 /// any future calls to `Box::new` (or malloc of any form) may cause
13594 /// the returned value here to be invalidated. Use with caution!
13595 ///
13596 /// Additionally the returned object can be safely mutated,
13597 /// the changes are guaranteed to be reflected in the input array.
13598 pub unsafe fn view_mut_raw(ptr: *mut $ty, length: usize) -> $name {
13599 let slice = core::slice::from_raw_parts_mut(ptr, length);
13600 Self::view(slice)
13601 }
13602
13603 /// Copy the contents of this JS typed array into the destination
13604 /// Rust pointer.
13605 ///
13606 /// This function will efficiently copy the memory from a typed
13607 /// array into this Wasm module's own linear memory, initializing
13608 /// the memory destination provided.
13609 ///
13610 /// # Safety
13611 ///
13612 /// This function requires `dst` to point to a buffer
13613 /// large enough to fit this array's contents.
13614 pub unsafe fn raw_copy_to_ptr(&self, dst: *mut $ty) {
13615 let slice = core::slice::from_raw_parts_mut(dst, self.length() as usize);
13616 self.copy_to(slice);
13617 }
13618
13619 /// Copy the contents of this JS typed array into the destination
13620 /// Rust slice.
13621 ///
13622 /// This function will efficiently copy the memory from a typed
13623 /// array into this Wasm module's own linear memory, initializing
13624 /// the memory destination provided.
13625 ///
13626 /// # Panics
13627 ///
13628 /// This function will panic if this typed array's length is
13629 /// different than the length of the provided `dst` array.
13630 pub fn copy_to(&self, dst: &mut [$ty]) {
13631 core::assert_eq!(self.length() as usize, dst.len());
13632 $name::copy_to_slice(dst, self);
13633 }
13634
13635 /// Copy the contents of this JS typed array into the destination
13636 /// Rust slice.
13637 ///
13638 /// This function will efficiently copy the memory from a typed
13639 /// array into this Wasm module's own linear memory, initializing
13640 /// the memory destination provided.
13641 ///
13642 /// # Panics
13643 ///
13644 /// This function will panic if this typed array's length is
13645 /// different than the length of the provided `dst` array.
13646 pub fn copy_to_uninit<'dst>(&self, dst: &'dst mut [MaybeUninit<$ty>]) -> &'dst mut [$ty] {
13647 core::assert_eq!(self.length() as usize, dst.len());
13648 let dst = unsafe { &mut *(dst as *mut [MaybeUninit<$ty>] as *mut [$ty]) };
13649 self.copy_to(dst);
13650 dst
13651 }
13652
13653 /// Copy the contents of the source Rust slice into this
13654 /// JS typed array.
13655 ///
13656 /// This function will efficiently copy the memory from within
13657 /// the Wasm module's own linear memory to this typed array.
13658 ///
13659 /// # Panics
13660 ///
13661 /// This function will panic if this typed array's length is
13662 /// different than the length of the provided `src` array.
13663 pub fn copy_from(&self, src: &[$ty]) {
13664 core::assert_eq!(self.length() as usize, src.len());
13665 self.copy_from_slice(src);
13666 }
13667
13668 /// Efficiently copies the contents of this JS typed array into a new Vec.
13669 pub fn to_vec(&self) -> Vec<$ty> {
13670 let len = self.length() as usize;
13671 let mut output = Vec::with_capacity(len);
13672 // Safety: the capacity has been set
13673 unsafe {
13674 self.raw_copy_to_ptr(output.as_mut_ptr());
13675 output.set_len(len);
13676 }
13677 output
13678 }
13679 }
13680
13681 impl<'a> From<&'a [$ty]> for $name {
13682 #[inline]
13683 fn from(slice: &'a [$ty]) -> $name {
13684 // This is safe because the `new` function makes a copy if its argument is a TypedArray
13685 $name::new_from_slice(slice)
13686 }
13687 }
13688
13689 impl Default for $name {
13690 fn default() -> Self {
13691 Self::new(&JsValue::UNDEFINED.unchecked_into())
13692 }
13693 }
13694
13695 impl TypedArray for $name {}
13696
13697
13698 )*);
13699}
13700
13701arrays! {
13702 /// `Int8Array()`
13703 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int8Array
13704 Int8Array: i8,
13705
13706 /// `Int16Array()`
13707 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int16Array
13708 Int16Array: i16,
13709
13710 /// `Int32Array()`
13711 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int32Array
13712 Int32Array: i32,
13713
13714 /// `Uint8Array()`
13715 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array
13716 Uint8Array: u8,
13717
13718 /// `Uint8ClampedArray()`
13719 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8ClampedArray
13720 Uint8ClampedArray: u8,
13721
13722 /// `Uint16Array()`
13723 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint16Array
13724 Uint16Array: u16,
13725
13726 /// `Uint32Array()`
13727 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint32Array
13728 Uint32Array: u32,
13729
13730 /// `Float32Array()`
13731 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array
13732 Float32Array: f32,
13733
13734 /// `Float64Array()`
13735 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float64Array
13736 Float64Array: f64,
13737
13738 /// `BigInt64Array()`
13739 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt64Array
13740 BigInt64Array: i64,
13741
13742 /// `BigUint64Array()`
13743 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigUint64Array
13744 BigUint64Array: u64,
13745}
13746
13747/// Bridging between JavaScript `Promise`s and Rust `Future`s.
13748///
13749/// Enables `promise.await` directly on any [`Promise`] when this feature is active.
13750/// This module is automatically available when depending on `wasm-bindgen-futures`.
13751#[cfg(feature = "futures")]
13752pub mod futures;