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 `getFloat64()` method gets a signed 64-bit float (double) at the specified
3373 /// byte offset from the start of the DataView.
3374 ///
3375 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat64)
3376 #[wasm_bindgen(method, js_name = getFloat64)]
3377 pub fn get_float64(this: &DataView, byte_offset: usize) -> f64;
3378
3379 /// The `getFloat64()` method gets a signed 64-bit float (double) at the specified
3380 /// byte offset from the start of the DataView.
3381 ///
3382 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat64)
3383 #[wasm_bindgen(method, js_name = getFloat64)]
3384 pub fn get_float64_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> f64;
3385
3386 /// The `setInt8()` method stores a signed 8-bit integer (byte) value at the
3387 /// specified byte offset from the start of the DataView.
3388 ///
3389 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt8)
3390 #[wasm_bindgen(method, js_name = setInt8)]
3391 pub fn set_int8(this: &DataView, byte_offset: usize, value: i8);
3392
3393 /// The `setUint8()` method stores an unsigned 8-bit integer (byte) value at the
3394 /// specified byte offset from the start of the DataView.
3395 ///
3396 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint8)
3397 #[wasm_bindgen(method, js_name = setUint8)]
3398 pub fn set_uint8(this: &DataView, byte_offset: usize, value: u8);
3399
3400 /// The `setInt16()` method stores a signed 16-bit integer (short) value at the
3401 /// specified byte offset from the start of the DataView.
3402 ///
3403 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt16)
3404 #[wasm_bindgen(method, js_name = setInt16)]
3405 pub fn set_int16(this: &DataView, byte_offset: usize, value: i16);
3406
3407 /// The `setInt16()` method stores a signed 16-bit integer (short) value at the
3408 /// specified byte offset from the start of the DataView.
3409 ///
3410 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt16)
3411 #[wasm_bindgen(method, js_name = setInt16)]
3412 pub fn set_int16_endian(this: &DataView, byte_offset: usize, value: i16, little_endian: bool);
3413
3414 /// The `setUint16()` method stores an unsigned 16-bit integer (unsigned short) value at the
3415 /// specified byte offset from the start of the DataView.
3416 ///
3417 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint16)
3418 #[wasm_bindgen(method, js_name = setUint16)]
3419 pub fn set_uint16(this: &DataView, byte_offset: usize, value: u16);
3420
3421 /// The `setUint16()` method stores an unsigned 16-bit integer (unsigned short) value at the
3422 /// specified byte offset from the start of the DataView.
3423 ///
3424 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint16)
3425 #[wasm_bindgen(method, js_name = setUint16)]
3426 pub fn set_uint16_endian(this: &DataView, byte_offset: usize, value: u16, little_endian: bool);
3427
3428 /// The `setInt32()` method stores a signed 32-bit integer (long) value at the
3429 /// specified byte offset from the start of the DataView.
3430 ///
3431 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt32)
3432 #[wasm_bindgen(method, js_name = setInt32)]
3433 pub fn set_int32(this: &DataView, byte_offset: usize, value: i32);
3434
3435 /// The `setInt32()` method stores a signed 32-bit integer (long) value at the
3436 /// specified byte offset from the start of the DataView.
3437 ///
3438 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt32)
3439 #[wasm_bindgen(method, js_name = setInt32)]
3440 pub fn set_int32_endian(this: &DataView, byte_offset: usize, value: i32, little_endian: bool);
3441
3442 /// The `setUint32()` method stores an unsigned 32-bit integer (unsigned long) value at the
3443 /// specified byte offset from the start of the DataView.
3444 ///
3445 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint32)
3446 #[wasm_bindgen(method, js_name = setUint32)]
3447 pub fn set_uint32(this: &DataView, byte_offset: usize, value: u32);
3448
3449 /// The `setUint32()` method stores an unsigned 32-bit integer (unsigned long) value at the
3450 /// specified byte offset from the start of the DataView.
3451 ///
3452 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint32)
3453 #[wasm_bindgen(method, js_name = setUint32)]
3454 pub fn set_uint32_endian(this: &DataView, byte_offset: usize, value: u32, little_endian: bool);
3455
3456 /// The `setFloat32()` method stores a signed 32-bit float (float) value at the
3457 /// specified byte offset from the start of the DataView.
3458 ///
3459 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat32)
3460 #[wasm_bindgen(method, js_name = setFloat32)]
3461 pub fn set_float32(this: &DataView, byte_offset: usize, value: f32);
3462
3463 /// The `setFloat32()` method stores a signed 32-bit float (float) value at the
3464 /// specified byte offset from the start of the DataView.
3465 ///
3466 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat32)
3467 #[wasm_bindgen(method, js_name = setFloat32)]
3468 pub fn set_float32_endian(this: &DataView, byte_offset: usize, value: f32, little_endian: bool);
3469
3470 /// The `setFloat64()` method stores a signed 64-bit float (double) value at the
3471 /// specified byte offset from the start of the DataView.
3472 ///
3473 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat64)
3474 #[wasm_bindgen(method, js_name = setFloat64)]
3475 pub fn set_float64(this: &DataView, byte_offset: usize, value: f64);
3476
3477 /// The `setFloat64()` method stores a signed 64-bit float (double) value at the
3478 /// specified byte offset from the start of the DataView.
3479 ///
3480 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat64)
3481 #[wasm_bindgen(method, js_name = setFloat64)]
3482 pub fn set_float64_endian(this: &DataView, byte_offset: usize, value: f64, little_endian: bool);
3483}
3484
3485// Error
3486#[wasm_bindgen]
3487extern "C" {
3488 #[wasm_bindgen(extends = Object, typescript_type = "Error")]
3489 #[derive(Clone, Debug, PartialEq, Eq)]
3490 pub type Error;
3491
3492 /// The Error constructor creates an error object.
3493 /// Instances of Error objects are thrown when runtime errors occur.
3494 /// The Error object can also be used as a base object for user-defined exceptions.
3495 /// See below for standard built-in error types.
3496 ///
3497 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)
3498 #[wasm_bindgen(constructor)]
3499 pub fn new(message: &str) -> Error;
3500 #[wasm_bindgen(constructor)]
3501 pub fn new_with_options(message: &str, options: &Object) -> Error;
3502
3503 /// The cause property is the underlying cause of the error.
3504 /// Usually this is used to add context to re-thrown errors.
3505 ///
3506 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error#differentiate_between_similar_errors)
3507 #[wasm_bindgen(method, getter)]
3508 pub fn cause(this: &Error) -> JsValue;
3509 #[wasm_bindgen(method, setter)]
3510 pub fn set_cause(this: &Error, cause: &JsValue);
3511
3512 /// The message property is a human-readable description of the error.
3513 ///
3514 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/message)
3515 #[wasm_bindgen(method, getter)]
3516 pub fn message(this: &Error) -> JsString;
3517 #[wasm_bindgen(method, setter)]
3518 pub fn set_message(this: &Error, message: &str);
3519
3520 /// The name property represents a name for the type of error. The initial value is "Error".
3521 ///
3522 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/name)
3523 #[wasm_bindgen(method, getter)]
3524 pub fn name(this: &Error) -> JsString;
3525 #[wasm_bindgen(method, setter)]
3526 pub fn set_name(this: &Error, name: &str);
3527
3528 /// The `toString()` method returns a string representing the specified Error object
3529 ///
3530 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/toString)
3531 #[cfg(not(js_sys_unstable_apis))]
3532 #[wasm_bindgen(method, js_name = toString)]
3533 pub fn to_string(this: &Error) -> JsString;
3534}
3535
3536partialord_ord!(JsString);
3537
3538// EvalError
3539#[wasm_bindgen]
3540extern "C" {
3541 #[wasm_bindgen(extends = Object, extends = Error, typescript_type = "EvalError")]
3542 #[derive(Clone, Debug, PartialEq, Eq)]
3543 pub type EvalError;
3544
3545 /// The `EvalError` object indicates an error regarding the global eval() function. This
3546 /// exception is not thrown by JavaScript anymore, however the EvalError object remains for
3547 /// compatibility.
3548 ///
3549 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/EvalError)
3550 #[wasm_bindgen(constructor)]
3551 pub fn new(message: &str) -> EvalError;
3552}
3553
3554#[wasm_bindgen]
3555extern "C" {
3556 #[wasm_bindgen(extends = Object, is_type_of = JsValue::is_function, no_upcast, typescript_type = "Function")]
3557 #[derive(Clone, Debug, PartialEq, Eq)]
3558 /// `Function` represents any generic Function in JS, by treating all arguments as `JsValue`.
3559 ///
3560 /// It takes a generic parameter of phantom type `fn (Arg1, ..., Argn) -> Ret` which
3561 /// is used to type the JS function. For example, `Function<fn () -> Number>` represents
3562 /// a function taking no arguments that returns a number.
3563 ///
3564 /// The 8 generic argument parameters (`Arg1` through `Arg8`) are the argument
3565 /// types. Arguments not provided enable strict arity checking at compile time.
3566 ///
3567 /// A void function is represented by `fn (Arg) -> Undefined`, and **not** the `()` unit
3568 /// type. This is because generics must be based on JS values in the JS generic type system.
3569 ///
3570 /// _The default without any parameters is as a void function - no arguments, `Undefined` return._
3571 ///
3572 /// _The default generic for `Function` is `fn (JsValue, JsValue, ...) -> JsValue`,
3573 /// representing any function, since all functions safely upcast into this function._
3574 ///
3575 /// ### Arity Enforcement
3576 ///
3577 /// It is not possible to use `call4` or `bind4` on a function that does not have
3578 /// at least 4 arguments — the compiler will reject this because only arguments that
3579 /// are not `None` support the trait bound for `ErasableGeneric`.
3580 ///
3581 /// ### Examples
3582 ///
3583 /// ```ignore
3584 /// // A function taking no args, returning Number
3585 /// let f: Function<Number> = get_some_fn();
3586 ///
3587 /// // A function taking (String, Number) and returning Boolean
3588 /// let f: Function<Boolean, String, Number> = get_some_fn();
3589 ///
3590 /// ### Upcasting
3591 ///
3592 /// To pass a typed `Function` where a different generic Function is expected, `upcast()` may be used
3593 /// to convert into any generic `Function` at zero cost with type-safety.
3594 ///
3595 /// MDN documentation (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
3596 pub type Function<
3597 T: JsFunction = fn(
3598 JsValue,
3599 JsValue,
3600 JsValue,
3601 JsValue,
3602 JsValue,
3603 JsValue,
3604 JsValue,
3605 JsValue,
3606 ) -> JsValue,
3607 >;
3608}
3609
3610#[wasm_bindgen]
3611extern "C" {
3612 /// The `Function` constructor creates a new `Function` object. Calling the
3613 /// constructor directly can create functions dynamically, but suffers from
3614 /// security and similar (but far less significant) performance issues
3615 /// similar to `eval`. However, unlike `eval`, the `Function` constructor
3616 /// allows executing code in the global scope, prompting better programming
3617 /// habits and allowing for more efficient code minification.
3618 ///
3619 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
3620 #[cfg(all(feature = "unsafe-eval", not(js_sys_unstable_apis)))]
3621 #[wasm_bindgen(constructor)]
3622 pub fn new_with_args(args: &str, body: &str) -> Function;
3623
3624 /// The `Function` constructor creates a new `Function` object. Calling the
3625 /// constructor directly can create functions dynamically, but suffers from
3626 /// security and similar (but far less significant) performance issues
3627 /// similar to `eval`. However, unlike `eval`, the `Function` constructor
3628 /// allows executing code in the global scope, prompting better programming
3629 /// habits and allowing for more efficient code minification.
3630 ///
3631 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
3632 #[cfg(all(feature = "unsafe-eval", js_sys_unstable_apis))]
3633 #[wasm_bindgen(constructor)]
3634 pub fn new_with_args<T: JsFunction = fn() -> JsValue>(args: &str, body: &str) -> Function<T>;
3635
3636 // Next major: deprecate
3637 /// The `Function` constructor creates a new `Function` object. Calling the
3638 /// constructor directly can create functions dynamically, but suffers from
3639 /// security and similar (but far less significant) performance issues
3640 /// similar to `eval`. However, unlike `eval`, the `Function` constructor
3641 /// allows executing code in the global scope, prompting better programming
3642 /// habits and allowing for more efficient code minification.
3643 ///
3644 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
3645 #[cfg(feature = "unsafe-eval")]
3646 #[wasm_bindgen(constructor)]
3647 pub fn new_with_args_typed<T: JsFunction = fn() -> JsValue>(
3648 args: &str,
3649 body: &str,
3650 ) -> Function<T>;
3651
3652 /// The `Function` constructor creates a new `Function` object. Calling the
3653 /// constructor directly can create functions dynamically, but suffers from
3654 /// security and similar (but far less significant) performance issues
3655 /// similar to `eval`. However, unlike `eval`, the `Function` constructor
3656 /// allows executing code in the global scope, prompting better programming
3657 /// habits and allowing for more efficient code minification.
3658 ///
3659 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
3660 #[cfg(all(feature = "unsafe-eval", not(js_sys_unstable_apis)))]
3661 #[wasm_bindgen(constructor)]
3662 pub fn new_no_args(body: &str) -> Function;
3663
3664 /// The `Function` constructor creates a new `Function` object. Calling the
3665 /// constructor directly can create functions dynamically, but suffers from
3666 /// security and similar (but far less significant) performance issues
3667 /// similar to `eval`. However, unlike `eval`, the `Function` constructor
3668 /// allows executing code in the global scope, prompting better programming
3669 /// habits and allowing for more efficient code minification.
3670 ///
3671 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
3672 #[cfg(all(feature = "unsafe-eval", js_sys_unstable_apis))]
3673 #[wasm_bindgen(constructor)]
3674 pub fn new_no_args<T: JsFunction = fn() -> JsValue>(body: &str) -> Function<T>;
3675
3676 // Next major: deprecate
3677 /// The `Function` constructor creates a new `Function` object.
3678 ///
3679 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
3680 #[cfg(feature = "unsafe-eval")]
3681 #[wasm_bindgen(constructor)]
3682 pub fn new_no_args_typed<T: JsFunction = fn() -> JsValue>(body: &str) -> Function<T>;
3683
3684 /// The `apply()` method calls a function with a given this value, and arguments provided as an array
3685 /// (or an array-like object).
3686 ///
3687 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply)
3688 #[wasm_bindgen(method, catch)]
3689 pub fn apply<T: JsFunction = fn() -> JsValue>(
3690 this: &Function<T>,
3691 context: &JsValue,
3692 args: &Array,
3693 ) -> Result<<T as JsFunction>::Ret, JsValue>;
3694
3695 // Next major: Deprecate, and separately provide provide impl
3696 /// The `call()` method calls a function with a given this value and
3697 /// arguments provided individually.
3698 ///
3699 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3700 ///
3701 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3702 #[wasm_bindgen(method, catch, js_name = call)]
3703 pub fn call0<Ret: JsGeneric, F: JsFunction<Ret = Ret> = fn() -> JsValue>(
3704 this: &Function<F>,
3705 context: &JsValue,
3706 ) -> Result<Ret, JsValue>;
3707
3708 // Next major: Deprecate, and separately provide provide impl
3709 /// The `call()` method calls a function with a given this value and
3710 /// arguments provided individually.
3711 ///
3712 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3713 ///
3714 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3715 #[wasm_bindgen(method, catch, js_name = call)]
3716 pub fn call1<
3717 Ret: JsGeneric,
3718 Arg1: JsGeneric,
3719 F: JsFunction<Ret = Ret> + JsFunction1<Arg1 = Arg1> = fn(JsValue) -> JsValue,
3720 >(
3721 this: &Function<F>,
3722 context: &JsValue,
3723 arg1: &Arg1,
3724 ) -> Result<Ret, JsValue>;
3725
3726 // Next major: Deprecate, and separately provide provide impl
3727 /// The `call()` method calls a function with a given this value and
3728 /// arguments provided individually.
3729 ///
3730 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3731 ///
3732 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3733 #[wasm_bindgen(method, catch, js_name = call)]
3734 pub fn call2<
3735 Ret: JsGeneric,
3736 Arg1: JsGeneric,
3737 Arg2: JsGeneric,
3738 F: JsFunction<Ret = Ret> + JsFunction1<Arg1 = Arg1> + JsFunction2<Arg2 = Arg2> = fn(
3739 JsValue,
3740 JsValue,
3741 ) -> JsValue,
3742 >(
3743 this: &Function<F>,
3744 context: &JsValue,
3745 arg1: &Arg1,
3746 arg2: &Arg2,
3747 ) -> Result<Ret, JsValue>;
3748
3749 // Next major: Deprecate, and separately provide provide impl
3750 /// The `call()` method calls a function with a given this value and
3751 /// arguments provided individually.
3752 ///
3753 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3754 ///
3755 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3756 #[wasm_bindgen(method, catch, js_name = call)]
3757 pub fn call3<
3758 Ret: JsGeneric,
3759 Arg1: JsGeneric,
3760 Arg2: JsGeneric,
3761 Arg3: JsGeneric,
3762 F: JsFunction<Ret = Ret> + JsFunction3<Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3> = fn(
3763 JsValue,
3764 JsValue,
3765 JsValue,
3766 ) -> JsValue,
3767 >(
3768 this: &Function<F>,
3769 context: &JsValue,
3770 arg1: &Arg1,
3771 arg2: &Arg2,
3772 arg3: &Arg3,
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 call4<
3784 Ret: JsGeneric,
3785 Arg1: JsGeneric,
3786 Arg2: JsGeneric,
3787 Arg3: JsGeneric,
3788 Arg4: JsGeneric,
3789 F: JsFunction<Ret = Ret> + JsFunction4<Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3, Arg4 = Arg4> = fn(
3790 JsValue,
3791 JsValue,
3792 JsValue,
3793 JsValue,
3794 ) -> JsValue,
3795 >(
3796 this: &Function<F>,
3797 context: &JsValue,
3798 arg1: &Arg1,
3799 arg2: &Arg2,
3800 arg3: &Arg3,
3801 arg4: &Arg4,
3802 ) -> Result<Ret, JsValue>;
3803
3804 // Next major: Deprecate, and separately provide provide impl
3805 /// The `call()` method calls a function with a given this value and
3806 /// arguments provided individually.
3807 ///
3808 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3809 ///
3810 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3811 #[wasm_bindgen(method, catch, js_name = call)]
3812 pub fn call5<
3813 Ret: JsGeneric,
3814 Arg1: JsGeneric,
3815 Arg2: JsGeneric,
3816 Arg3: JsGeneric,
3817 Arg4: JsGeneric,
3818 Arg5: JsGeneric,
3819 F: JsFunction<Ret = Ret>
3820 + JsFunction5<Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3, Arg4 = Arg4, Arg5 = Arg5> = fn(
3821 JsValue,
3822 JsValue,
3823 JsValue,
3824 JsValue,
3825 JsValue,
3826 ) -> JsValue,
3827 >(
3828 this: &Function<F>,
3829 context: &JsValue,
3830 arg1: &Arg1,
3831 arg2: &Arg2,
3832 arg3: &Arg3,
3833 arg4: &Arg4,
3834 arg5: &Arg5,
3835 ) -> Result<Ret, JsValue>;
3836
3837 // Next major: Deprecate, and separately provide provide impl
3838 /// The `call()` method calls a function with a given this value and
3839 /// arguments provided individually.
3840 ///
3841 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3842 ///
3843 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3844 #[wasm_bindgen(method, catch, js_name = call)]
3845 pub fn call6<
3846 Ret: JsGeneric,
3847 Arg1: JsGeneric,
3848 Arg2: JsGeneric,
3849 Arg3: JsGeneric,
3850 Arg4: JsGeneric,
3851 Arg5: JsGeneric,
3852 Arg6: JsGeneric,
3853 F: JsFunction<Ret = Ret>
3854 + JsFunction6<
3855 Arg1 = Arg1,
3856 Arg2 = Arg2,
3857 Arg3 = Arg3,
3858 Arg4 = Arg4,
3859 Arg5 = Arg5,
3860 Arg6 = Arg6,
3861 > = fn(JsValue, JsValue, JsValue, JsValue, JsValue, JsValue) -> JsValue,
3862 >(
3863 this: &Function<F>,
3864 context: &JsValue,
3865 arg1: &Arg1,
3866 arg2: &Arg2,
3867 arg3: &Arg3,
3868 arg4: &Arg4,
3869 arg5: &Arg5,
3870 arg6: &Arg6,
3871 ) -> Result<Ret, JsValue>;
3872
3873 // Next major: Deprecate, and separately provide provide impl
3874 /// The `call()` method calls a function with a given this value and
3875 /// arguments provided individually.
3876 ///
3877 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3878 ///
3879 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3880 #[wasm_bindgen(method, catch, js_name = call)]
3881 pub fn call7<
3882 Ret: JsGeneric,
3883 Arg1: JsGeneric,
3884 Arg2: JsGeneric,
3885 Arg3: JsGeneric,
3886 Arg4: JsGeneric,
3887 Arg5: JsGeneric,
3888 Arg6: JsGeneric,
3889 Arg7: JsGeneric,
3890 F: JsFunction<Ret = Ret>
3891 + JsFunction7<
3892 Arg1 = Arg1,
3893 Arg2 = Arg2,
3894 Arg3 = Arg3,
3895 Arg4 = Arg4,
3896 Arg5 = Arg5,
3897 Arg6 = Arg6,
3898 Arg7 = Arg7,
3899 > = fn(
3900 JsValue,
3901 JsValue,
3902 JsValue,
3903 JsValue,
3904 JsValue,
3905 JsValue,
3906 JsValue,
3907 ) -> JsValue,
3908 >(
3909 this: &Function<F>,
3910 context: &JsValue,
3911 arg1: &Arg1,
3912 arg2: &Arg2,
3913 arg3: &Arg3,
3914 arg4: &Arg4,
3915 arg5: &Arg5,
3916 arg6: &Arg6,
3917 arg7: &Arg7,
3918 ) -> Result<Ret, JsValue>;
3919
3920 // Next major: Deprecate, and separately provide provide impl
3921 /// The `call()` method calls a function with a given this value and
3922 /// arguments provided individually.
3923 ///
3924 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3925 ///
3926 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3927 #[wasm_bindgen(method, catch, js_name = call)]
3928 pub fn call8<
3929 Ret: JsGeneric,
3930 Arg1: JsGeneric,
3931 Arg2: JsGeneric,
3932 Arg3: JsGeneric,
3933 Arg4: JsGeneric,
3934 Arg5: JsGeneric,
3935 Arg6: JsGeneric,
3936 Arg7: JsGeneric,
3937 Arg8: JsGeneric,
3938 F: JsFunction8<
3939 Ret = Ret,
3940 Arg1 = Arg1,
3941 Arg2 = Arg2,
3942 Arg3 = Arg3,
3943 Arg4 = Arg4,
3944 Arg5 = Arg5,
3945 Arg6 = Arg6,
3946 Arg7 = Arg7,
3947 Arg8 = Arg8,
3948 > = fn(
3949 JsValue,
3950 JsValue,
3951 JsValue,
3952 JsValue,
3953 JsValue,
3954 JsValue,
3955 JsValue,
3956 JsValue,
3957 ) -> JsValue,
3958 >(
3959 this: &Function<F>,
3960 context: &JsValue,
3961 arg1: &Arg1,
3962 arg2: &Arg2,
3963 arg3: &Arg3,
3964 arg4: &Arg4,
3965 arg5: &Arg5,
3966 arg6: &Arg6,
3967 arg7: &Arg7,
3968 arg8: &Arg8,
3969 ) -> Result<Ret, JsValue>;
3970
3971 /// The `call()` method calls a function with a given this value and
3972 /// arguments provided individually.
3973 ///
3974 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3975 ///
3976 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3977 #[deprecated]
3978 #[allow(deprecated)]
3979 #[wasm_bindgen(method, catch, js_name = call)]
3980 pub fn call9<
3981 Ret: JsGeneric,
3982 Arg1: JsGeneric,
3983 Arg2: JsGeneric,
3984 Arg3: JsGeneric,
3985 Arg4: JsGeneric,
3986 Arg5: JsGeneric,
3987 Arg6: JsGeneric,
3988 Arg7: JsGeneric,
3989 Arg8: JsGeneric,
3990 F: JsFunction8<
3991 Ret = Ret,
3992 Arg1 = Arg1,
3993 Arg2 = Arg2,
3994 Arg3 = Arg3,
3995 Arg4 = Arg4,
3996 Arg5 = Arg5,
3997 Arg6 = Arg6,
3998 Arg7 = Arg7,
3999 Arg8 = Arg8,
4000 > = fn(
4001 JsValue,
4002 JsValue,
4003 JsValue,
4004 JsValue,
4005 JsValue,
4006 JsValue,
4007 JsValue,
4008 JsValue,
4009 ) -> JsValue,
4010 >(
4011 this: &Function<F>,
4012 context: &JsValue,
4013 arg1: &Arg1,
4014 arg2: &Arg2,
4015 arg3: &Arg3,
4016 arg4: &Arg4,
4017 arg5: &Arg5,
4018 arg6: &Arg6,
4019 arg7: &Arg7,
4020 arg8: &Arg8,
4021 arg9: &JsValue,
4022 ) -> Result<Ret, JsValue>;
4023
4024 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4025 /// with a given sequence of arguments preceding any provided when the new function is called.
4026 ///
4027 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4028 #[cfg(not(js_sys_unstable_apis))]
4029 #[deprecated(note = "Use `Function::bind0` instead.")]
4030 #[allow(deprecated)]
4031 #[wasm_bindgen(method, js_name = bind)]
4032 pub fn bind<T: JsFunction = fn() -> JsValue>(
4033 this: &Function<T>,
4034 context: &JsValue,
4035 ) -> Function<T>;
4036
4037 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4038 /// with a given sequence of arguments preceding any provided when the new function is called.
4039 ///
4040 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4041 ///
4042 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4043 #[wasm_bindgen(method, js_name = bind)]
4044 pub fn bind0<T: JsFunction = fn() -> JsValue>(
4045 this: &Function<T>,
4046 context: &JsValue,
4047 ) -> Function<T>;
4048
4049 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4050 /// with a given sequence of arguments preceding any provided when the new function is called.
4051 ///
4052 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4053 ///
4054 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4055 #[wasm_bindgen(method, js_name = bind)]
4056 pub fn bind1<
4057 Ret: JsGeneric,
4058 Arg1: JsGeneric,
4059 F: JsFunction1<Ret = Ret, Arg1 = Arg1> = fn(JsValue) -> JsValue,
4060 >(
4061 this: &Function<F>,
4062 context: &JsValue,
4063 arg1: &Arg1,
4064 ) -> Function<<F as JsFunction1>::Bind1>;
4065
4066 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4067 /// with a given sequence of arguments preceding any provided when the new function is called.
4068 ///
4069 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4070 ///
4071 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4072 #[wasm_bindgen(method, js_name = bind)]
4073 pub fn bind2<
4074 Ret: JsGeneric,
4075 Arg1: JsGeneric,
4076 Arg2: JsGeneric,
4077 F: JsFunction2<Ret = Ret, Arg1 = Arg1, Arg2 = Arg2> = fn(JsValue, JsValue) -> JsValue,
4078 >(
4079 this: &Function<F>,
4080 context: &JsValue,
4081 arg1: &Arg1,
4082 arg2: &Arg2,
4083 ) -> Function<<F as JsFunction2>::Bind2>;
4084
4085 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4086 /// with a given sequence of arguments preceding any provided when the new function is called.
4087 ///
4088 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4089 ///
4090 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4091 #[wasm_bindgen(method, js_name = bind)]
4092 pub fn bind3<
4093 Ret: JsGeneric,
4094 Arg1: JsGeneric,
4095 Arg2: JsGeneric,
4096 Arg3: JsGeneric,
4097 F: JsFunction3<Ret = Ret, Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3> = fn(
4098 JsValue,
4099 JsValue,
4100 JsValue,
4101 ) -> JsValue,
4102 >(
4103 this: &Function<F>,
4104 context: &JsValue,
4105 arg1: &Arg1,
4106 arg2: &Arg2,
4107 arg3: &Arg3,
4108 ) -> Function<<F as JsFunction3>::Bind3>;
4109
4110 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4111 /// with a given sequence of arguments preceding any provided when the new function is called.
4112 ///
4113 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4114 ///
4115 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4116 #[wasm_bindgen(method, js_name = bind)]
4117 pub fn bind4<
4118 Ret: JsGeneric,
4119 Arg1: JsGeneric,
4120 Arg2: JsGeneric,
4121 Arg3: JsGeneric,
4122 Arg4: JsGeneric,
4123 F: JsFunction4<Ret = Ret, Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3, Arg4 = Arg4> = fn(
4124 JsValue,
4125 JsValue,
4126 JsValue,
4127 JsValue,
4128 ) -> JsValue,
4129 >(
4130 this: &Function<F>,
4131 context: &JsValue,
4132 arg1: &Arg1,
4133 arg2: &Arg2,
4134 arg3: &Arg3,
4135 arg4: &Arg4,
4136 ) -> Function<<F as JsFunction4>::Bind4>;
4137
4138 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4139 /// with a given sequence of arguments preceding any provided when the new function is called.
4140 ///
4141 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4142 ///
4143 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4144 #[wasm_bindgen(method, js_name = bind)]
4145 pub fn bind5<
4146 Ret: JsGeneric,
4147 Arg1: JsGeneric,
4148 Arg2: JsGeneric,
4149 Arg3: JsGeneric,
4150 Arg4: JsGeneric,
4151 Arg5: JsGeneric,
4152 F: JsFunction5<Ret = Ret, Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3, Arg4 = Arg4, Arg5 = Arg5> = fn(
4153 JsValue,
4154 JsValue,
4155 JsValue,
4156 JsValue,
4157 JsValue,
4158 ) -> JsValue,
4159 >(
4160 this: &Function<F>,
4161 context: &JsValue,
4162 arg1: &Arg1,
4163 arg2: &Arg2,
4164 arg3: &Arg3,
4165 arg4: &Arg4,
4166 arg5: &Arg5,
4167 ) -> Function<<F as JsFunction5>::Bind5>;
4168
4169 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4170 /// with a given sequence of arguments preceding any provided when the new function is called.
4171 ///
4172 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4173 ///
4174 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4175 #[wasm_bindgen(method, js_name = bind)]
4176 pub fn bind6<
4177 Ret: JsGeneric,
4178 Arg1: JsGeneric,
4179 Arg2: JsGeneric,
4180 Arg3: JsGeneric,
4181 Arg4: JsGeneric,
4182 Arg5: JsGeneric,
4183 Arg6: JsGeneric,
4184 F: JsFunction6<
4185 Ret = Ret,
4186 Arg1 = Arg1,
4187 Arg2 = Arg2,
4188 Arg3 = Arg3,
4189 Arg4 = Arg4,
4190 Arg5 = Arg5,
4191 Arg6 = Arg6,
4192 > = fn(JsValue, JsValue, JsValue, JsValue, JsValue, JsValue) -> JsValue,
4193 >(
4194 this: &Function<F>,
4195 context: &JsValue,
4196 arg1: &Arg1,
4197 arg2: &Arg2,
4198 arg3: &Arg3,
4199 arg4: &Arg4,
4200 arg5: &Arg5,
4201 arg6: &Arg6,
4202 ) -> Function<<F as JsFunction6>::Bind6>;
4203
4204 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4205 /// with a given sequence of arguments preceding any provided when the new function is called.
4206 ///
4207 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4208 ///
4209 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4210 #[wasm_bindgen(method, js_name = bind)]
4211 pub fn bind7<
4212 Ret: JsGeneric,
4213 Arg1: JsGeneric,
4214 Arg2: JsGeneric,
4215 Arg3: JsGeneric,
4216 Arg4: JsGeneric,
4217 Arg5: JsGeneric,
4218 Arg6: JsGeneric,
4219 Arg7: JsGeneric,
4220 F: JsFunction7<
4221 Ret = Ret,
4222 Arg1 = Arg1,
4223 Arg2 = Arg2,
4224 Arg3 = Arg3,
4225 Arg4 = Arg4,
4226 Arg5 = Arg5,
4227 Arg6 = Arg6,
4228 Arg7 = Arg7,
4229 > = fn(
4230 JsValue,
4231 JsValue,
4232 JsValue,
4233 JsValue,
4234 JsValue,
4235 JsValue,
4236 JsValue,
4237 ) -> JsValue,
4238 >(
4239 this: &Function<F>,
4240 context: &JsValue,
4241 arg1: &Arg1,
4242 arg2: &Arg2,
4243 arg3: &Arg3,
4244 arg4: &Arg4,
4245 arg5: &Arg5,
4246 arg6: &Arg6,
4247 arg7: &Arg7,
4248 ) -> Function<<F as JsFunction7>::Bind7>;
4249
4250 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4251 /// with a given sequence of arguments preceding any provided when the new function is called.
4252 ///
4253 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4254 ///
4255 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4256 #[wasm_bindgen(method, js_name = bind)]
4257 pub fn bind8<
4258 Ret: JsGeneric,
4259 Arg1: JsGeneric,
4260 Arg2: JsGeneric,
4261 Arg3: JsGeneric,
4262 Arg4: JsGeneric,
4263 Arg5: JsGeneric,
4264 Arg6: JsGeneric,
4265 Arg7: JsGeneric,
4266 Arg8: JsGeneric,
4267 F: JsFunction8<
4268 Ret = Ret,
4269 Arg1 = Arg1,
4270 Arg2 = Arg2,
4271 Arg3 = Arg3,
4272 Arg4 = Arg4,
4273 Arg5 = Arg5,
4274 Arg6 = Arg6,
4275 Arg7 = Arg7,
4276 Arg8 = Arg8,
4277 > = fn(
4278 JsValue,
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 arg8: &Arg8,
4298 ) -> Function<<F as JsFunction8>::Bind8>;
4299
4300 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4301 /// with a given sequence of arguments preceding any provided when the new function is called.
4302 ///
4303 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4304 ///
4305 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4306 #[deprecated]
4307 #[allow(deprecated)]
4308 #[wasm_bindgen(method, js_name = bind)]
4309 pub fn bind9<
4310 Ret: JsGeneric,
4311 Arg1: JsGeneric,
4312 Arg2: JsGeneric,
4313 Arg3: JsGeneric,
4314 Arg4: JsGeneric,
4315 Arg5: JsGeneric,
4316 Arg6: JsGeneric,
4317 Arg7: JsGeneric,
4318 Arg8: JsGeneric,
4319 F: JsFunction8<
4320 Ret = Ret,
4321 Arg1 = Arg1,
4322 Arg2 = Arg2,
4323 Arg3 = Arg3,
4324 Arg4 = Arg4,
4325 Arg5 = Arg5,
4326 Arg6 = Arg6,
4327 Arg7 = Arg7,
4328 Arg8 = Arg8,
4329 > = fn(
4330 JsValue,
4331 JsValue,
4332 JsValue,
4333 JsValue,
4334 JsValue,
4335 JsValue,
4336 JsValue,
4337 JsValue,
4338 ) -> JsValue,
4339 >(
4340 this: &Function<F>,
4341 context: &JsValue,
4342 arg1: &Arg1,
4343 arg2: &Arg2,
4344 arg3: &Arg3,
4345 arg4: &Arg4,
4346 arg5: &Arg5,
4347 arg6: &Arg6,
4348 arg7: &Arg7,
4349 arg8: &Arg8,
4350 arg9: &JsValue,
4351 ) -> Function<fn() -> Ret>;
4352
4353 /// The length property indicates the number of arguments expected by the function.
4354 ///
4355 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/length)
4356 #[wasm_bindgen(method, getter)]
4357 pub fn length<T: JsFunction = fn() -> JsValue>(this: &Function<T>) -> u32;
4358
4359 /// A Function object's read-only name property indicates the function's
4360 /// name as specified when it was created or "anonymous" for functions
4361 /// created anonymously.
4362 ///
4363 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name)
4364 #[wasm_bindgen(method, getter)]
4365 pub fn name<T: JsFunction = fn() -> JsValue>(this: &Function<T>) -> JsString;
4366
4367 /// The `toString()` method returns a string representing the source code of the function.
4368 ///
4369 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/toString)
4370 #[cfg(not(js_sys_unstable_apis))]
4371 #[wasm_bindgen(method, js_name = toString)]
4372 pub fn to_string<T: JsFunction = fn() -> JsValue>(this: &Function<T>) -> JsString;
4373}
4374
4375// Basic UpcastFrom impls for Function<T>
4376impl<T: JsFunction> UpcastFrom<Function<T>> for JsValue {}
4377impl<T: JsFunction> UpcastFrom<Function<T>> for JsOption<JsValue> {}
4378impl<T: JsFunction> UpcastFrom<Function<T>> for Object {}
4379impl<T: JsFunction> UpcastFrom<Function<T>> for JsOption<Object> {}
4380
4381// Blanket trait for Function upcast
4382// Function<T> upcasts to Function<U> when the underlying fn type T upcasts to U.
4383// The fn signature UpcastFrom impls already encode correct variance (covariant return, contravariant args).
4384impl<T: JsFunction, U: JsFunction> UpcastFrom<Function<T>> for Function<U> where U: UpcastFrom<T> {}
4385
4386// len() method for Function<T> using JsFunction::ARITY
4387impl<T: JsFunction> Function<T> {
4388 /// Get the static arity of this function type.
4389 #[allow(clippy::len_without_is_empty)]
4390 pub fn len(&self) -> usize {
4391 T::ARITY
4392 }
4393
4394 /// Returns true if this is a zero-argument function.
4395 pub fn is_empty(&self) -> bool {
4396 T::ARITY == 0
4397 }
4398}
4399
4400// Base traits for function signature types.
4401pub trait JsFunction {
4402 type Ret: JsGeneric;
4403 const ARITY: usize;
4404}
4405
4406pub trait JsFunction1: JsFunction {
4407 type Arg1: JsGeneric;
4408 type Bind1: JsFunction;
4409}
4410pub trait JsFunction2: JsFunction1 {
4411 type Arg2: JsGeneric;
4412 type Bind2: JsFunction;
4413}
4414pub trait JsFunction3: JsFunction2 {
4415 type Arg3: JsGeneric;
4416 type Bind3: JsFunction;
4417}
4418pub trait JsFunction4: JsFunction3 {
4419 type Arg4: JsGeneric;
4420 type Bind4: JsFunction;
4421}
4422pub trait JsFunction5: JsFunction4 {
4423 type Arg5: JsGeneric;
4424 type Bind5: JsFunction;
4425}
4426pub trait JsFunction6: JsFunction5 {
4427 type Arg6: JsGeneric;
4428 type Bind6: JsFunction;
4429}
4430pub trait JsFunction7: JsFunction6 {
4431 type Arg7: JsGeneric;
4432 type Bind7: JsFunction;
4433}
4434pub trait JsFunction8: JsFunction7 {
4435 type Arg8: JsGeneric;
4436 type Bind8: JsFunction;
4437}
4438
4439// Manual impl for fn() -> R
4440impl<Ret: JsGeneric> JsFunction for fn() -> Ret {
4441 type Ret = Ret;
4442 const ARITY: usize = 0;
4443}
4444
4445macro_rules! impl_fn {
4446 () => {
4447 impl_fn!(@impl 1 [Arg1] [
4448 JsFunction1 Arg1 Bind1 {fn() -> Ret}
4449 ]);
4450 impl_fn!(@impl 2 [Arg1 Arg2] [
4451 JsFunction1 Arg1 Bind1 {fn(Arg2) -> Ret}
4452 JsFunction2 Arg2 Bind2 {fn() -> Ret}
4453 ]);
4454 impl_fn!(@impl 3 [Arg1 Arg2 Arg3] [
4455 JsFunction1 Arg1 Bind1 {fn(Arg2, Arg3) -> Ret}
4456 JsFunction2 Arg2 Bind2 {fn(Arg3) -> Ret}
4457 JsFunction3 Arg3 Bind3 {fn() -> Ret}
4458 ]);
4459 impl_fn!(@impl 4 [Arg1 Arg2 Arg3 Arg4] [
4460 JsFunction1 Arg1 Bind1 {fn(Arg2, Arg3, Arg4) -> Ret}
4461 JsFunction2 Arg2 Bind2 {fn(Arg3, Arg4) -> Ret}
4462 JsFunction3 Arg3 Bind3 {fn(Arg4) -> Ret}
4463 JsFunction4 Arg4 Bind4 {fn() -> Ret}
4464 ]);
4465 impl_fn!(@impl 5 [Arg1 Arg2 Arg3 Arg4 Arg5] [
4466 JsFunction1 Arg1 Bind1 {fn(Arg2, Arg3, Arg4, Arg5) -> Ret}
4467 JsFunction2 Arg2 Bind2 {fn(Arg3, Arg4, Arg5) -> Ret}
4468 JsFunction3 Arg3 Bind3 {fn(Arg4, Arg5) -> Ret}
4469 JsFunction4 Arg4 Bind4 {fn(Arg5) -> Ret}
4470 JsFunction5 Arg5 Bind5 {fn() -> Ret}
4471 ]);
4472 impl_fn!(@impl 6 [Arg1 Arg2 Arg3 Arg4 Arg5 Arg6] [
4473 JsFunction1 Arg1 Bind1 {fn(Arg2, Arg3, Arg4, Arg5, Arg6) -> Ret}
4474 JsFunction2 Arg2 Bind2 {fn(Arg3, Arg4, Arg5, Arg6) -> Ret}
4475 JsFunction3 Arg3 Bind3 {fn(Arg4, Arg5, Arg6) -> Ret}
4476 JsFunction4 Arg4 Bind4 {fn(Arg5, Arg6) -> Ret}
4477 JsFunction5 Arg5 Bind5 {fn(Arg6) -> Ret}
4478 JsFunction6 Arg6 Bind6 {fn() -> Ret}
4479 ]);
4480 impl_fn!(@impl 7 [Arg1 Arg2 Arg3 Arg4 Arg5 Arg6 Arg7] [
4481 JsFunction1 Arg1 Bind1 {fn(Arg2, Arg3, Arg4, Arg5, Arg6, Arg7) -> Ret}
4482 JsFunction2 Arg2 Bind2 {fn(Arg3, Arg4, Arg5, Arg6, Arg7) -> Ret}
4483 JsFunction3 Arg3 Bind3 {fn(Arg4, Arg5, Arg6, Arg7) -> Ret}
4484 JsFunction4 Arg4 Bind4 {fn(Arg5, Arg6, Arg7) -> Ret}
4485 JsFunction5 Arg5 Bind5 {fn(Arg6, Arg7) -> Ret}
4486 JsFunction6 Arg6 Bind6 {fn(Arg7) -> Ret}
4487 JsFunction7 Arg7 Bind7 {fn() -> Ret}
4488 ]);
4489 impl_fn!(@impl 8 [Arg1 Arg2 Arg3 Arg4 Arg5 Arg6 Arg7 Arg8] [
4490 JsFunction1 Arg1 Bind1 {fn(Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8) -> Ret}
4491 JsFunction2 Arg2 Bind2 {fn(Arg3, Arg4, Arg5, Arg6, Arg7, Arg8) -> Ret}
4492 JsFunction3 Arg3 Bind3 {fn(Arg4, Arg5, Arg6, Arg7, Arg8) -> Ret}
4493 JsFunction4 Arg4 Bind4 {fn(Arg5, Arg6, Arg7, Arg8) -> Ret}
4494 JsFunction5 Arg5 Bind5 {fn(Arg6, Arg7, Arg8) -> Ret}
4495 JsFunction6 Arg6 Bind6 {fn(Arg7, Arg8) -> Ret}
4496 JsFunction7 Arg7 Bind7 {fn(Arg8) -> Ret}
4497 JsFunction8 Arg8 Bind8 {fn() -> Ret}
4498 ]);
4499 };
4500
4501 (@impl $arity:literal [$($A:ident)+] [$($trait:ident $arg:ident $bind:ident {$bind_ty:ty})+]) => {
4502 impl<Ret: JsGeneric $(, $A: JsGeneric)+> JsFunction for fn($($A),+) -> Ret {
4503 type Ret = Ret;
4504 const ARITY: usize = $arity;
4505 }
4506
4507 impl_fn!(@traits [$($A)+] [$($trait $arg $bind {$bind_ty})+]);
4508 };
4509
4510 (@traits [$($A:ident)+] []) => {};
4511
4512 (@traits [$($A:ident)+] [$trait:ident $arg:ident $bind:ident {$bind_ty:ty} $($rest:tt)*]) => {
4513 impl<Ret: JsGeneric $(, $A: JsGeneric)+> $trait for fn($($A),+) -> Ret {
4514 type $arg = $arg;
4515 type $bind = $bind_ty;
4516 }
4517
4518 impl_fn!(@traits [$($A)+] [$($rest)*]);
4519 };
4520}
4521
4522impl_fn!();
4523
4524/// Trait for argument tuples that can call or bind a `Function<T>`.
4525pub trait JsArgs<T: JsFunction> {
4526 type BindOutput;
4527 fn apply_call(self, func: &Function<T>, context: &JsValue) -> Result<T::Ret, JsValue>;
4528 fn apply_bind(self, func: &Function<T>, context: &JsValue) -> Self::BindOutput;
4529}
4530
4531// Manual impl for 0-arg
4532impl<Ret: JsGeneric, F: JsFunction<Ret = Ret>> JsArgs<F> for () {
4533 type BindOutput = Function<F>;
4534
4535 #[inline]
4536 fn apply_call(self, func: &Function<F>, context: &JsValue) -> Result<Ret, JsValue> {
4537 func.call0(context)
4538 }
4539
4540 #[inline]
4541 fn apply_bind(self, func: &Function<F>, context: &JsValue) -> Self::BindOutput {
4542 func.bind0(context)
4543 }
4544}
4545
4546macro_rules! impl_js_args {
4547 ($arity:literal $trait:ident $bind_output:ident [$($A:ident)+] [$($idx:tt)+] $call:ident $bind:ident) => {
4548 impl<Ret: JsGeneric, $($A: JsGeneric,)+ F: $trait<Ret = Ret, $($A = $A,)*>> JsArgs<F> for ($(&$A,)+)
4549 {
4550 type BindOutput = Function<<F as $trait>::$bind_output>;
4551
4552 #[inline]
4553 fn apply_call(self, func: &Function<F>, context: &JsValue) -> Result<Ret, JsValue> {
4554 func.$call(context, $(self.$idx),+)
4555 }
4556
4557 #[inline]
4558 fn apply_bind(self, func: &Function<F>, context: &JsValue) -> Self::BindOutput {
4559 func.$bind(context, $(self.$idx),+)
4560 }
4561 }
4562 };
4563}
4564
4565impl_js_args!(1 JsFunction1 Bind1 [Arg1] [0] call1 bind1);
4566impl_js_args!(2 JsFunction2 Bind2 [Arg1 Arg2] [0 1] call2 bind2);
4567impl_js_args!(3 JsFunction3 Bind3 [Arg1 Arg2 Arg3] [0 1 2] call3 bind3);
4568impl_js_args!(4 JsFunction4 Bind4 [Arg1 Arg2 Arg3 Arg4] [0 1 2 3] call4 bind4);
4569impl_js_args!(5 JsFunction5 Bind5 [Arg1 Arg2 Arg3 Arg4 Arg5] [0 1 2 3 4] call5 bind5);
4570impl_js_args!(6 JsFunction6 Bind6 [Arg1 Arg2 Arg3 Arg4 Arg5 Arg6] [0 1 2 3 4 5] call6 bind6);
4571impl_js_args!(7 JsFunction7 Bind7 [Arg1 Arg2 Arg3 Arg4 Arg5 Arg6 Arg7] [0 1 2 3 4 5 6] call7 bind7);
4572impl_js_args!(8 JsFunction8 Bind8 [Arg1 Arg2 Arg3 Arg4 Arg5 Arg6 Arg7 Arg8] [0 1 2 3 4 5 6 7] call8 bind8);
4573
4574impl<T: JsFunction> Function<T> {
4575 /// The `call()` method calls a function with a given `this` value and
4576 /// arguments provided as a tuple.
4577 ///
4578 /// This method accepts a tuple of references matching the function's
4579 /// argument types.
4580 ///
4581 /// # Example
4582 ///
4583 /// ```ignore
4584 /// // 0-arg function
4585 /// let f: Function<fn() -> Number> = get_fn();
4586 /// let result = f.call(&JsValue::NULL, ())?;
4587 ///
4588 /// // 1-arg function (note trailing comma for 1-tuple)
4589 /// let f: Function<fn(JsString) -> Number> = get_fn();
4590 /// let result = f.call(&JsValue::NULL, (&name,))?;
4591 ///
4592 /// // 2-arg function
4593 /// let f: Function<fn(JsString, Boolean) -> Number> = get_fn();
4594 /// let result = f.call(&JsValue::NULL, (&name, &flag))?;
4595 /// ```
4596 ///
4597 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
4598 #[inline]
4599 pub fn call<Args: JsArgs<T>>(&self, context: &JsValue, args: Args) -> Result<T::Ret, JsValue> {
4600 args.apply_call(self, context)
4601 }
4602
4603 /// The `bind()` method creates a new function that, when called, has its
4604 /// `this` keyword set to the provided value, with a given sequence of
4605 /// arguments preceding any provided when the new function is called.
4606 ///
4607 /// This method accepts a tuple of references to bind.
4608 ///
4609 /// # Example
4610 ///
4611 /// ```ignore
4612 /// let f: Function<fn(JsString, Boolean) -> Number> = get_fn();
4613 ///
4614 /// // Bind no args - same signature
4615 /// let bound: Function<fn(JsString, Boolean) -> Number> = f.bind(&ctx, ());
4616 ///
4617 /// // Bind one arg (use 1-tuple of references)
4618 /// let bound: Function<fn(Boolean) -> Number> = f.bind(&ctx, (&my_string,));
4619 ///
4620 /// // Bind two args - becomes 0-arg function
4621 /// let bound: Function<fn() -> Number> = f.bind(&ctx, (&my_string, &my_bool));
4622 /// ```
4623 ///
4624 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4625 #[inline]
4626 pub fn bindn<Args: JsArgs<T>>(&self, context: &JsValue, args: Args) -> Args::BindOutput {
4627 args.apply_bind(self, context)
4628 }
4629
4630 /// The `bind()` method creates a new function that, when called, has its
4631 /// `this` keyword set to the provided value, with a given sequence of
4632 /// arguments preceding any provided when the new function is called.
4633 ///
4634 /// This method accepts a tuple of references to bind.
4635 ///
4636 /// # Example
4637 ///
4638 /// ```ignore
4639 /// let f: Function<fn(JsString, Boolean) -> Number> = get_fn();
4640 ///
4641 /// // Bind no args - same signature
4642 /// let bound: Function<fn(JsString, Boolean) -> Number> = f.bind(&ctx, ());
4643 ///
4644 /// // Bind one arg (use 1-tuple of references)
4645 /// let bound: Function<fn(Boolean) -> Number> = f.bind(&ctx, (&my_string,));
4646 ///
4647 /// // Bind two args - becomes 0-arg function
4648 /// let bound: Function<fn() -> Number> = f.bind(&ctx, (&my_string, &my_bool));
4649 /// ```
4650 ///
4651 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4652 #[cfg(js_sys_unstable_apis)]
4653 #[inline]
4654 pub fn bind<Args: JsArgs<T>>(&self, context: &JsValue, args: Args) -> Args::BindOutput {
4655 args.apply_bind(self, context)
4656 }
4657}
4658
4659pub trait FunctionIntoClosure: JsFunction {
4660 type ClosureTypeMut: WasmClosure + ?Sized;
4661}
4662
4663macro_rules! impl_function_into_closure {
4664 ( $(($($var:ident)*))* ) => {$(
4665 impl<$($var: FromWasmAbi + JsGeneric,)* R: IntoWasmAbi + JsGeneric> FunctionIntoClosure for fn($($var),*) -> R {
4666 type ClosureTypeMut = dyn FnMut($($var),*) -> R;
4667 }
4668 )*};
4669}
4670
4671impl_function_into_closure! {
4672 ()
4673 (A)
4674 (A B)
4675 (A B C)
4676 (A B C D)
4677 (A B C D E)
4678 (A B C D E F)
4679 (A B C D E F G)
4680 (A B C D E F G H)
4681}
4682
4683impl<F: JsFunction> Function<F> {
4684 /// Convert a borrowed `ScopedClosure` into a typed JavaScript Function reference.
4685 ///
4686 /// The conversion is a direct type-safe conversion and upcast of a
4687 /// closure into its corresponding typed JavaScript Function,
4688 /// based on covariance and contravariance [`Upcast`] trait hierarchy.
4689 ///
4690 /// For transferring ownership to JS, use [`Function::from_closure`].
4691 #[inline]
4692 pub fn closure_ref<'a, C>(closure: &'a ScopedClosure<'_, C>) -> &'a Self
4693 where
4694 F: FunctionIntoClosure,
4695 C: WasmClosure + ?Sized,
4696 <F as FunctionIntoClosure>::ClosureTypeMut: UpcastFrom<<C as WasmClosure>::AsMut>,
4697 {
4698 closure.as_js_value().unchecked_ref()
4699 }
4700
4701 /// Convert a Rust closure into a typed JavaScript Function.
4702 ///
4703 /// This function releases ownership of the closure to JS, and provides
4704 /// an owned function handle for the same closure.
4705 ///
4706 /// The conversion is a direct type-safe conversion and upcast of a
4707 /// closure into its corresponding typed JavaScript Function,
4708 /// based on covariance and contravariance [`Upcast`] trait hierarchy.
4709 ///
4710 /// This method is only supported for static closures which do not have
4711 /// borrowed lifetime data, and thus can be released into JS.
4712 ///
4713 /// For borrowed closures, which cannot cede ownership to JS,
4714 /// instead use [`Function::closure_ref`].
4715 #[inline]
4716 pub fn from_closure<C>(closure: ScopedClosure<'static, C>) -> Self
4717 where
4718 F: FunctionIntoClosure,
4719 C: WasmClosure + ?Sized,
4720 <F as FunctionIntoClosure>::ClosureTypeMut: UpcastFrom<<C as WasmClosure>::AsMut>,
4721 {
4722 closure.into_js_value().unchecked_into()
4723 }
4724}
4725
4726#[cfg(not(js_sys_unstable_apis))]
4727impl Function {
4728 /// Returns the `Function` value of this JS value if it's an instance of a
4729 /// function.
4730 ///
4731 /// If this JS value is not an instance of a function then this returns
4732 /// `None`.
4733 #[deprecated(note = "recommended to use dyn_ref instead which is now equivalent")]
4734 pub fn try_from(val: &JsValue) -> Option<&Function> {
4735 val.dyn_ref()
4736 }
4737}
4738
4739#[cfg(feature = "unsafe-eval")]
4740impl Default for Function {
4741 fn default() -> Self {
4742 Self::new_no_args("")
4743 }
4744}
4745
4746// Generator
4747#[wasm_bindgen]
4748extern "C" {
4749 #[wasm_bindgen(extends = Object, typescript_type = "Generator<any, any, any>")]
4750 #[derive(Clone, Debug, PartialEq, Eq)]
4751 pub type Generator<T = JsValue>;
4752
4753 /// The `next()` method returns an object with two properties done and value.
4754 /// You can also provide a parameter to the next method to send a value to the generator.
4755 ///
4756 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/next)
4757 #[cfg(not(js_sys_unstable_apis))]
4758 #[wasm_bindgen(method, catch)]
4759 pub fn next<T>(this: &Generator<T>, value: &T) -> Result<JsValue, JsValue>;
4760
4761 /// The `next()` method returns an object with two properties done and value.
4762 /// You can also provide a parameter to the next method to send a value to the generator.
4763 ///
4764 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/next)
4765 #[cfg(js_sys_unstable_apis)]
4766 #[wasm_bindgen(method, catch, js_name = next)]
4767 pub fn next<T: FromWasmAbi>(this: &Generator<T>, value: &T)
4768 -> Result<IteratorNext<T>, JsValue>;
4769
4770 // Next major: deprecate
4771 /// The `next()` method returns an object with two properties done and value.
4772 /// You can also provide a parameter to the next method to send a value to the generator.
4773 ///
4774 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/next)
4775 #[wasm_bindgen(method, catch)]
4776 pub fn next_iterator<T: FromWasmAbi>(
4777 this: &Generator<T>,
4778 value: &T,
4779 ) -> Result<IteratorNext<T>, JsValue>;
4780
4781 /// The `return()` method returns the given value and finishes the generator.
4782 ///
4783 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/return)
4784 #[cfg(not(js_sys_unstable_apis))]
4785 #[wasm_bindgen(method, js_name = "return")]
4786 pub fn return_<T>(this: &Generator<T>, value: &T) -> JsValue;
4787
4788 /// The `return()` method returns the given value and finishes the generator.
4789 ///
4790 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/return)
4791 #[cfg(js_sys_unstable_apis)]
4792 #[wasm_bindgen(method, catch, js_name = "return")]
4793 pub fn return_<T: FromWasmAbi>(
4794 this: &Generator<T>,
4795 value: &T,
4796 ) -> Result<IteratorNext<T>, JsValue>;
4797
4798 // Next major: deprecate
4799 /// The `return()` method returns the given value and finishes the generator.
4800 ///
4801 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/return)
4802 #[wasm_bindgen(method, catch, js_name = "return")]
4803 pub fn try_return<T: FromWasmAbi>(
4804 this: &Generator<T>,
4805 value: &T,
4806 ) -> Result<IteratorNext<T>, JsValue>;
4807
4808 /// The `throw()` method resumes the execution of a generator by throwing an error into it
4809 /// and returns an object with two properties done and value.
4810 ///
4811 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/throw)
4812 #[cfg(not(js_sys_unstable_apis))]
4813 #[wasm_bindgen(method, catch)]
4814 pub fn throw<T>(this: &Generator<T>, error: &Error) -> Result<JsValue, JsValue>;
4815
4816 /// The `throw()` method resumes the execution of a generator by throwing an error into it
4817 /// and returns an object with two properties done and value.
4818 ///
4819 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/throw)
4820 #[cfg(js_sys_unstable_apis)]
4821 #[wasm_bindgen(method, catch, js_name = throw)]
4822 pub fn throw<T: FromWasmAbi>(
4823 this: &Generator<T>,
4824 error: &JsValue,
4825 ) -> Result<IteratorNext<T>, JsValue>;
4826
4827 // Next major: deprecate
4828 /// The `throw()` method resumes the execution of a generator by throwing an error into it
4829 /// and returns an object with two properties done and value.
4830 ///
4831 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/throw)
4832 #[wasm_bindgen(method, catch, js_name = throw)]
4833 pub fn throw_value<T: FromWasmAbi>(
4834 this: &Generator<T>,
4835 error: &JsValue,
4836 ) -> Result<IteratorNext<T>, JsValue>;
4837}
4838
4839impl<T: FromWasmAbi> Iterable for Generator<T> {
4840 type Item = T;
4841}
4842
4843// AsyncGenerator
4844#[wasm_bindgen]
4845extern "C" {
4846 #[wasm_bindgen(extends = Object, typescript_type = "AsyncGenerator<any, any, any>")]
4847 #[derive(Clone, Debug, PartialEq, Eq)]
4848 pub type AsyncGenerator<T = JsValue>;
4849
4850 /// The `next()` method returns an object with two properties done and value.
4851 /// You can also provide a parameter to the next method to send a value to the generator.
4852 ///
4853 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncGenerator/next)
4854 #[wasm_bindgen(method, catch)]
4855 pub fn next<T>(
4856 this: &AsyncGenerator<T>,
4857 value: &T,
4858 ) -> Result<Promise<IteratorNext<T>>, JsValue>;
4859
4860 /// The `return()` method returns the given value and finishes the generator.
4861 ///
4862 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncGenerator/return)
4863 #[wasm_bindgen(method, js_name = "return", catch)]
4864 pub fn return_<T>(
4865 this: &AsyncGenerator<T>,
4866 value: &T,
4867 ) -> Result<Promise<IteratorNext<T>>, JsValue>;
4868
4869 /// The `throw()` method resumes the execution of a generator by throwing an error into it
4870 /// and returns an object with two properties done and value.
4871 ///
4872 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncGenerator/throw)
4873 #[wasm_bindgen(method, catch)]
4874 pub fn throw<T>(
4875 this: &AsyncGenerator<T>,
4876 error: &JsValue,
4877 ) -> Result<Promise<IteratorNext<T>>, JsValue>;
4878}
4879
4880impl<T: FromWasmAbi> AsyncIterable for AsyncGenerator<T> {
4881 type Item = T;
4882}
4883
4884// Map
4885#[wasm_bindgen]
4886extern "C" {
4887 #[wasm_bindgen(extends = Object, typescript_type = "Map<any, any>")]
4888 #[derive(Clone, Debug, PartialEq, Eq)]
4889 pub type Map<K = JsValue, V = JsValue>;
4890
4891 /// The Map object holds key-value pairs. Any value (both objects and
4892 /// primitive values) maybe used as either a key or a value.
4893 ///
4894 /// **Note:** Consider using [`Map::new_typed`] for typing support.
4895 ///
4896 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)
4897 #[cfg(not(js_sys_unstable_apis))]
4898 #[wasm_bindgen(constructor)]
4899 pub fn new() -> Map;
4900
4901 /// The Map object holds key-value pairs. Any value (both objects and
4902 /// primitive values) maybe used as either a key or a value.
4903 ///
4904 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)
4905 #[cfg(js_sys_unstable_apis)]
4906 #[wasm_bindgen(constructor)]
4907 pub fn new<K, V>() -> Map<K, V>;
4908
4909 // Next major: deprecate
4910 /// The Map object holds key-value pairs. Any value (both objects and
4911 /// primitive values) maybe used as either a key or a value.
4912 ///
4913 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)
4914 #[wasm_bindgen(constructor)]
4915 pub fn new_typed<K, V>() -> Map<K, V>;
4916
4917 /// The Map object holds key-value pairs. Any value (both objects and
4918 /// primitive values) maybe used as either a key or a value.
4919 ///
4920 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)
4921 #[wasm_bindgen(constructor, js_name = new)]
4922 pub fn new_from_entries<K, V, I: Iterable<Item = ArrayTuple<(K, V)>>>(entries: &I)
4923 -> Map<K, V>;
4924
4925 /// The `clear()` method removes all elements from a Map object.
4926 ///
4927 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/clear)
4928 #[wasm_bindgen(method)]
4929 pub fn clear<K, V>(this: &Map<K, V>);
4930
4931 /// The `delete()` method removes the specified element from a Map object.
4932 ///
4933 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/delete)
4934 #[wasm_bindgen(method)]
4935 pub fn delete<K, V>(this: &Map<K, V>, key: &K) -> bool;
4936
4937 /// The `forEach()` method executes a provided function once per each
4938 /// key/value pair in the Map object, in insertion order.
4939 /// Note that in Javascript land the `Key` and `Value` are reversed compared to normal expectations:
4940 /// # Examples
4941 /// ```
4942 /// let js_map = Map::new();
4943 /// js_map.for_each(&mut |value, key| {
4944 /// // Do something here...
4945 /// })
4946 /// ```
4947 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/forEach)
4948 #[wasm_bindgen(method, js_name = forEach)]
4949 pub fn for_each<K, V>(this: &Map<K, V>, callback: &mut dyn FnMut(V, K));
4950
4951 /// The `forEach()` method executes a provided function once per each
4952 /// key/value pair in the Map object, in insertion order. _(Fallible variation)_
4953 /// Note that in Javascript land the `Key` and `Value` are reversed compared to normal expectations:
4954 /// # Examples
4955 /// ```
4956 /// let js_map = Map::new();
4957 /// js_map.for_each(&mut |value, key| {
4958 /// // Do something here...
4959 /// })
4960 /// ```
4961 ///
4962 /// **Note:** Consider using [`Map::try_for_each`] if the callback might throw an error.
4963 ///
4964 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/forEach)
4965 #[wasm_bindgen(method, js_name = forEach, catch)]
4966 pub fn try_for_each<K, V>(
4967 this: &Map<K, V>,
4968 callback: &mut dyn FnMut(V, K) -> Result<(), JsError>,
4969 ) -> Result<(), JsValue>;
4970
4971 /// The `get()` method returns a specified element from a Map object.
4972 /// Returns `undefined` if the key is not found.
4973 ///
4974 /// **Note:** Consider using [`Map::get_checked`] to get an `Option<V>` instead.
4975 ///
4976 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get)
4977 #[cfg(not(js_sys_unstable_apis))]
4978 #[wasm_bindgen(method)]
4979 pub fn get<K, V>(this: &Map<K, V>, key: &K) -> V;
4980
4981 /// The `get()` method returns a specified element from a Map object.
4982 /// Returns `None` if the key is not found.
4983 ///
4984 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get)
4985 #[cfg(js_sys_unstable_apis)]
4986 #[wasm_bindgen(method)]
4987 pub fn get<K, V>(this: &Map<K, V>, key: &K) -> Option<V>;
4988
4989 /// The `get()` method returns a specified element from a Map object.
4990 /// Returns `None` if the key is not found.
4991 ///
4992 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get)
4993 #[wasm_bindgen(method, js_name = get)]
4994 pub fn get_checked<K, V>(this: &Map<K, V>, key: &K) -> Option<V>;
4995
4996 /// The `has()` method returns a boolean indicating whether an element with
4997 /// the specified key exists or not.
4998 ///
4999 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/has)
5000 #[wasm_bindgen(method)]
5001 pub fn has<K, V>(this: &Map<K, V>, key: &K) -> bool;
5002
5003 /// The `set()` method adds or updates an element with a specified key
5004 /// and value to a Map object.
5005 ///
5006 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/set)
5007 #[wasm_bindgen(method)]
5008 pub fn set<K, V>(this: &Map<K, V>, key: &K, value: &V) -> Map<K, V>;
5009
5010 /// The value of size is an integer representing how many entries
5011 /// the Map object has. A set accessor function for size is undefined;
5012 /// you can not change this property.
5013 ///
5014 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/size)
5015 #[wasm_bindgen(method, getter)]
5016 pub fn size<K, V>(this: &Map<K, V>) -> u32;
5017}
5018
5019impl Default for Map<JsValue, JsValue> {
5020 fn default() -> Self {
5021 Self::new()
5022 }
5023}
5024
5025// Map Iterator
5026#[wasm_bindgen]
5027extern "C" {
5028 /// The `entries()` method returns a new Iterator object that contains
5029 /// the [key, value] pairs for each element in the Map object in
5030 /// insertion order.
5031 ///
5032 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries)
5033 #[cfg(not(js_sys_unstable_apis))]
5034 #[wasm_bindgen(method)]
5035 pub fn entries<K, V: FromWasmAbi>(this: &Map<K, V>) -> Iterator;
5036
5037 /// The `entries()` method returns a new Iterator object that contains
5038 /// the [key, value] pairs for each element in the Map object in
5039 /// insertion order.
5040 ///
5041 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries)
5042 #[cfg(js_sys_unstable_apis)]
5043 #[wasm_bindgen(method, js_name = entries)]
5044 pub fn entries<K: JsGeneric, V: FromWasmAbi + JsGeneric>(
5045 this: &Map<K, V>,
5046 ) -> Iterator<ArrayTuple<(K, V)>>;
5047
5048 // Next major: deprecate
5049 /// The `entries()` method returns a new Iterator object that contains
5050 /// the [key, value] pairs for each element in the Map object in
5051 /// insertion order.
5052 ///
5053 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries)
5054 #[wasm_bindgen(method, js_name = entries)]
5055 pub fn entries_typed<K: JsGeneric, V: FromWasmAbi + JsGeneric>(
5056 this: &Map<K, V>,
5057 ) -> Iterator<ArrayTuple<(K, V)>>;
5058
5059 /// The `keys()` method returns a new Iterator object that contains the
5060 /// keys for each element in the Map object in insertion order.
5061 ///
5062 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/keys)
5063 #[wasm_bindgen(method)]
5064 pub fn keys<K: FromWasmAbi, V: FromWasmAbi>(this: &Map<K, V>) -> Iterator<K>;
5065
5066 /// The `values()` method returns a new Iterator object that contains the
5067 /// values for each element in the Map object in insertion order.
5068 ///
5069 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/values)
5070 #[wasm_bindgen(method)]
5071 pub fn values<K, V: FromWasmAbi>(this: &Map<K, V>) -> Iterator<V>;
5072}
5073
5074impl<K, V> Iterable for Map<K, V> {
5075 type Item = ArrayTuple<(K, V)>;
5076}
5077
5078// Iterator
5079#[wasm_bindgen]
5080extern "C" {
5081 /// Any object that conforms to the JS iterator protocol. For example,
5082 /// something returned by `myArray[Symbol.iterator]()`.
5083 ///
5084 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols)
5085 #[derive(Clone, Debug)]
5086 #[wasm_bindgen(is_type_of = Iterator::looks_like_iterator, typescript_type = "Iterator<any>")]
5087 pub type Iterator<T = JsValue>;
5088
5089 /// The `next()` method always has to return an object with appropriate
5090 /// properties including done and value. If a non-object value gets returned
5091 /// (such as false or undefined), a TypeError ("iterator.next() returned a
5092 /// non-object value") will be thrown.
5093 #[wasm_bindgen(catch, method)]
5094 pub fn next<T: FromWasmAbi>(this: &Iterator<T>) -> Result<IteratorNext<T>, JsValue>;
5095}
5096
5097impl<T> UpcastFrom<Iterator<T>> for Object {}
5098
5099impl Iterator {
5100 fn looks_like_iterator(it: &JsValue) -> bool {
5101 #[wasm_bindgen]
5102 extern "C" {
5103 type MaybeIterator;
5104
5105 #[wasm_bindgen(method, getter)]
5106 fn next(this: &MaybeIterator) -> JsValue;
5107 }
5108
5109 if !it.is_object() {
5110 return false;
5111 }
5112
5113 let it = it.unchecked_ref::<MaybeIterator>();
5114
5115 it.next().is_function()
5116 }
5117}
5118
5119// iterators in JS are themselves iterable
5120impl<T> Iterable for Iterator<T> {
5121 type Item = T;
5122}
5123
5124// Async Iterator
5125#[wasm_bindgen]
5126extern "C" {
5127 /// Any object that conforms to the JS async iterator protocol. For example,
5128 /// something returned by `myObject[Symbol.asyncIterator]()`.
5129 ///
5130 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of)
5131 #[derive(Clone, Debug)]
5132 #[wasm_bindgen(is_type_of = Iterator::looks_like_iterator, typescript_type = "AsyncIterator<any>")]
5133 pub type AsyncIterator<T = JsValue>;
5134
5135 /// The `next()` method always has to return a Promise which resolves to an object
5136 /// with appropriate properties including done and value. If a non-object value
5137 /// gets returned (such as false or undefined), a TypeError ("iterator.next()
5138 /// returned a non-object value") will be thrown.
5139 #[cfg(not(js_sys_unstable_apis))]
5140 #[wasm_bindgen(catch, method)]
5141 pub fn next<T>(this: &AsyncIterator<T>) -> Result<Promise, JsValue>;
5142
5143 /// The `next()` method always has to return a Promise which resolves to an object
5144 /// with appropriate properties including done and value. If a non-object value
5145 /// gets returned (such as false or undefined), a TypeError ("iterator.next()
5146 /// returned a non-object value") will be thrown.
5147 #[cfg(js_sys_unstable_apis)]
5148 #[wasm_bindgen(catch, method, js_name = next)]
5149 pub fn next<T: FromWasmAbi>(
5150 this: &AsyncIterator<T>,
5151 ) -> Result<Promise<IteratorNext<T>>, JsValue>;
5152
5153 // Next major: deprecate
5154 /// The `next()` method always has to return a Promise which resolves to an object
5155 /// with appropriate properties including done and value. If a non-object value
5156 /// gets returned (such as false or undefined), a TypeError ("iterator.next()
5157 /// returned a non-object value") will be thrown.
5158 #[wasm_bindgen(catch, method, js_name = next)]
5159 pub fn next_iterator<T: FromWasmAbi>(
5160 this: &AsyncIterator<T>,
5161 ) -> Result<Promise<IteratorNext<T>>, JsValue>;
5162}
5163
5164impl<T> UpcastFrom<AsyncIterator<T>> for Object {}
5165
5166// iterators in JS are themselves iterable
5167impl<T> AsyncIterable for AsyncIterator<T> {
5168 type Item = T;
5169}
5170
5171/// An iterator over the JS `Symbol.iterator` iteration protocol.
5172///
5173/// Use the `IntoIterator for &js_sys::Iterator` implementation to create this.
5174pub struct Iter<'a, T = JsValue> {
5175 js: &'a Iterator<T>,
5176 state: IterState,
5177}
5178
5179/// An iterator over the JS `Symbol.iterator` iteration protocol.
5180///
5181/// Use the `IntoIterator for js_sys::Iterator` implementation to create this.
5182pub struct IntoIter<T = JsValue> {
5183 js: Iterator<T>,
5184 state: IterState,
5185}
5186
5187struct IterState {
5188 done: bool,
5189}
5190
5191impl<'a, T: FromWasmAbi + JsGeneric> IntoIterator for &'a Iterator<T> {
5192 type Item = Result<T, JsValue>;
5193 type IntoIter = Iter<'a, T>;
5194
5195 fn into_iter(self) -> Iter<'a, T> {
5196 Iter {
5197 js: self,
5198 state: IterState::new(),
5199 }
5200 }
5201}
5202
5203impl<T: FromWasmAbi + JsGeneric> core::iter::Iterator for Iter<'_, T> {
5204 type Item = Result<T, JsValue>;
5205
5206 fn next(&mut self) -> Option<Self::Item> {
5207 self.state.next(self.js)
5208 }
5209}
5210
5211impl<T: FromWasmAbi + JsGeneric> IntoIterator for Iterator<T> {
5212 type Item = Result<T, JsValue>;
5213 type IntoIter = IntoIter<T>;
5214
5215 fn into_iter(self) -> IntoIter<T> {
5216 IntoIter {
5217 js: self,
5218 state: IterState::new(),
5219 }
5220 }
5221}
5222
5223impl<T: FromWasmAbi + JsGeneric> core::iter::Iterator for IntoIter<T> {
5224 type Item = Result<T, JsValue>;
5225
5226 fn next(&mut self) -> Option<Self::Item> {
5227 self.state.next(&self.js)
5228 }
5229}
5230
5231impl IterState {
5232 fn new() -> IterState {
5233 IterState { done: false }
5234 }
5235
5236 fn next<T: FromWasmAbi + JsGeneric>(&mut self, js: &Iterator<T>) -> Option<Result<T, JsValue>> {
5237 if self.done {
5238 return None;
5239 }
5240 let next = match js.next() {
5241 Ok(val) => val,
5242 Err(e) => {
5243 self.done = true;
5244 return Some(Err(e));
5245 }
5246 };
5247 if next.done() {
5248 self.done = true;
5249 None
5250 } else {
5251 Some(Ok(next.value()))
5252 }
5253 }
5254}
5255
5256/// Create an iterator over `val` using the JS iteration protocol and
5257/// `Symbol.iterator`.
5258// #[cfg(not(js_sys_unstable_apis))]
5259pub fn try_iter(val: &JsValue) -> Result<Option<IntoIter<JsValue>>, JsValue> {
5260 let iter_sym = Symbol::iterator();
5261
5262 let iter_fn = Reflect::get_symbol::<Object>(val.unchecked_ref(), iter_sym.as_ref())?;
5263 let iter_fn: Function = match iter_fn.dyn_into() {
5264 Ok(iter_fn) => iter_fn,
5265 Err(_) => return Ok(None),
5266 };
5267
5268 let it: Iterator = match iter_fn.call0(val)?.dyn_into() {
5269 Ok(it) => it,
5270 Err(_) => return Ok(None),
5271 };
5272
5273 Ok(Some(it.into_iter()))
5274}
5275
5276/// Trait for JavaScript types that implement the iterable protocol via `Symbol.iterator`.
5277///
5278/// Types implementing this trait can be iterated over using JavaScript's iteration
5279/// protocol. The `Item` associated type specifies the type of values yielded.
5280///
5281/// ## Built-in Iterables
5282///
5283/// Many `js-sys` collection types implement `Iterable` out of the box:
5284///
5285/// ```ignore
5286/// use js_sys::{Array, Map, Set};
5287///
5288/// // Array<T> yields T
5289/// let arr: Array<Number> = get_numbers();
5290/// for value in arr.iter() {
5291/// let num: Number = value?;
5292/// }
5293///
5294/// // Map<K, V> yields Array (key-value pairs)
5295/// let map: Map<JsString, Number> = get_map();
5296/// for entry in map.iter() {
5297/// let pair: Array = entry?;
5298/// }
5299///
5300/// // Set<T> yields T
5301/// let set: Set<JsString> = get_set();
5302/// for value in set.iter() {
5303/// let s: JsString = value?;
5304/// }
5305/// ```
5306///
5307/// ## Typing Foreign Iterators
5308///
5309/// If you have a JavaScript value that implements the iterator protocol (has a `next()`
5310/// method) but isn't a built-in type, you can use [`JsCast`] to cast it to [`Iterator<T>`]:
5311///
5312/// ```ignore
5313/// use js_sys::Iterator;
5314/// use wasm_bindgen::JsCast;
5315///
5316/// // For a value you know implements the iterator protocol
5317/// fn process_iterator(js_iter: JsValue) {
5318/// // Checked cast - returns None if not an iterator
5319/// if let Some(iter) = js_iter.dyn_ref::<Iterator<Number>>() {
5320/// for value in iter.into_iter() {
5321/// let num: Number = value.unwrap();
5322/// // ...
5323/// }
5324/// }
5325/// }
5326///
5327/// // Or with unchecked cast when you're certain of the type
5328/// fn process_known_iterator(js_iter: JsValue) {
5329/// let iter: &Iterator<JsString> = js_iter.unchecked_ref();
5330/// for value in iter.into_iter() {
5331/// let s: JsString = value.unwrap();
5332/// // ...
5333/// }
5334/// }
5335/// ```
5336///
5337/// ## Using with `JsValue`
5338///
5339/// For dynamic or unknown iterables, use [`try_iter`] which returns an untyped iterator:
5340///
5341/// ```ignore
5342/// fn iterate_unknown(val: &JsValue) -> Result<(), JsValue> {
5343/// if let Some(iter) = js_sys::try_iter(val)? {
5344/// for item in iter {
5345/// let value: JsValue = item?;
5346/// // Handle dynamically...
5347/// }
5348/// }
5349/// Ok(())
5350/// }
5351/// ```
5352///
5353/// [`JsCast`]: wasm_bindgen::JsCast
5354/// [`Iterator<T>`]: Iterator
5355/// [`try_iter`]: crate::try_iter
5356pub trait Iterable {
5357 /// The type of values yielded by this iterable.
5358 type Item;
5359}
5360
5361impl<T: Iterable> Iterable for &T {
5362 type Item = T::Item;
5363}
5364
5365/// Trait for types known to implement the iterator protocol on Symbol.asyncIterator
5366pub trait AsyncIterable {
5367 type Item;
5368}
5369
5370impl<T: AsyncIterable> AsyncIterable for &T {
5371 type Item = T::Item;
5372}
5373
5374impl AsyncIterable for JsValue {
5375 type Item = JsValue;
5376}
5377
5378// IteratorNext
5379#[wasm_bindgen]
5380extern "C" {
5381 /// The result of calling `next()` on a JS iterator.
5382 ///
5383 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols)
5384 #[wasm_bindgen(extends = Object, typescript_type = "IteratorResult<any>")]
5385 #[derive(Clone, Debug, PartialEq, Eq)]
5386 pub type IteratorNext<T = JsValue>;
5387
5388 /// Has the value `true` if the iterator is past the end of the iterated
5389 /// sequence. In this case value optionally specifies the return value of
5390 /// the iterator.
5391 ///
5392 /// Has the value `false` if the iterator was able to produce the next value
5393 /// in the sequence. This is equivalent of not specifying the done property
5394 /// altogether.
5395 #[wasm_bindgen(method, getter)]
5396 pub fn done<T>(this: &IteratorNext<T>) -> bool;
5397
5398 /// Any JavaScript value returned by the iterator. Can be omitted when done
5399 /// is true.
5400 #[wasm_bindgen(method, getter)]
5401 pub fn value<T>(this: &IteratorNext<T>) -> T;
5402}
5403
5404#[allow(non_snake_case)]
5405pub mod Math {
5406 use super::*;
5407
5408 // Math
5409 #[wasm_bindgen]
5410 extern "C" {
5411 /// The `Math.abs()` function returns the absolute value of a number, that is
5412 /// Math.abs(x) = |x|
5413 ///
5414 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/abs)
5415 #[wasm_bindgen(js_namespace = Math)]
5416 pub fn abs(x: f64) -> f64;
5417
5418 /// The `Math.acos()` function returns the arccosine (in radians) of a
5419 /// number, that is ∀x∊[-1;1]
5420 /// Math.acos(x) = arccos(x) = the unique y∊[0;π] such that cos(y)=x
5421 ///
5422 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/acos)
5423 #[wasm_bindgen(js_namespace = Math)]
5424 pub fn acos(x: f64) -> f64;
5425
5426 /// The `Math.acosh()` function returns the hyperbolic arc-cosine of a
5427 /// number, that is ∀x ≥ 1
5428 /// Math.acosh(x) = arcosh(x) = the unique y ≥ 0 such that cosh(y) = x
5429 ///
5430 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/acosh)
5431 #[wasm_bindgen(js_namespace = Math)]
5432 pub fn acosh(x: f64) -> f64;
5433
5434 /// The `Math.asin()` function returns the arcsine (in radians) of a
5435 /// number, that is ∀x ∊ [-1;1]
5436 /// Math.asin(x) = arcsin(x) = the unique y∊[-π2;π2] such that sin(y) = x
5437 ///
5438 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/asin)
5439 #[wasm_bindgen(js_namespace = Math)]
5440 pub fn asin(x: f64) -> f64;
5441
5442 /// The `Math.asinh()` function returns the hyperbolic arcsine of a
5443 /// number, that is Math.asinh(x) = arsinh(x) = the unique y such that sinh(y) = x
5444 ///
5445 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/asinh)
5446 #[wasm_bindgen(js_namespace = Math)]
5447 pub fn asinh(x: f64) -> f64;
5448
5449 /// The `Math.atan()` function returns the arctangent (in radians) of a
5450 /// number, that is Math.atan(x) = arctan(x) = the unique y ∊ [-π2;π2]such that
5451 /// tan(y) = x
5452 #[wasm_bindgen(js_namespace = Math)]
5453 pub fn atan(x: f64) -> f64;
5454
5455 /// The `Math.atan2()` function returns the arctangent of the quotient of
5456 /// its arguments.
5457 ///
5458 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/atan2)
5459 #[wasm_bindgen(js_namespace = Math)]
5460 pub fn atan2(y: f64, x: f64) -> f64;
5461
5462 /// The `Math.atanh()` function returns the hyperbolic arctangent of a number,
5463 /// that is ∀x ∊ (-1,1), Math.atanh(x) = arctanh(x) = the unique y such that
5464 /// tanh(y) = x
5465 ///
5466 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/atanh)
5467 #[wasm_bindgen(js_namespace = Math)]
5468 pub fn atanh(x: f64) -> f64;
5469
5470 /// The `Math.cbrt() `function returns the cube root of a number, that is
5471 /// Math.cbrt(x) = ∛x = the unique y such that y^3 = x
5472 ///
5473 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/cbrt)
5474 #[wasm_bindgen(js_namespace = Math)]
5475 pub fn cbrt(x: f64) -> f64;
5476
5477 /// The `Math.ceil()` function returns the smallest integer greater than
5478 /// or equal to a given number.
5479 ///
5480 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/ceil)
5481 #[wasm_bindgen(js_namespace = Math)]
5482 pub fn ceil(x: f64) -> f64;
5483
5484 /// The `Math.clz32()` function returns the number of leading zero bits in
5485 /// the 32-bit binary representation of a number.
5486 ///
5487 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/clz32)
5488 #[wasm_bindgen(js_namespace = Math)]
5489 pub fn clz32(x: i32) -> u32;
5490
5491 /// The `Math.cos()` static function returns the cosine of the specified angle,
5492 /// which must be specified in radians. This value is length(adjacent)/length(hypotenuse).
5493 ///
5494 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/cos)
5495 #[wasm_bindgen(js_namespace = Math)]
5496 pub fn cos(x: f64) -> f64;
5497
5498 /// The `Math.cosh()` function returns the hyperbolic cosine of a number,
5499 /// that can be expressed using the constant e.
5500 ///
5501 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/cosh)
5502 #[wasm_bindgen(js_namespace = Math)]
5503 pub fn cosh(x: f64) -> f64;
5504
5505 /// The `Math.exp()` function returns e^x, where x is the argument, and e is Euler's number
5506 /// (also known as Napier's constant), the base of the natural logarithms.
5507 ///
5508 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/exp)
5509 #[wasm_bindgen(js_namespace = Math)]
5510 pub fn exp(x: f64) -> f64;
5511
5512 /// The `Math.expm1()` function returns e^x - 1, where x is the argument, and e the base of the
5513 /// natural logarithms.
5514 ///
5515 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/expm1)
5516 #[wasm_bindgen(js_namespace = Math)]
5517 pub fn expm1(x: f64) -> f64;
5518
5519 /// The `Math.floor()` function returns the largest integer less than or
5520 /// equal to a given number.
5521 ///
5522 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/floor)
5523 #[wasm_bindgen(js_namespace = Math)]
5524 pub fn floor(x: f64) -> f64;
5525
5526 /// The `Math.fround()` function returns the nearest 32-bit single precision float representation
5527 /// of a Number.
5528 ///
5529 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/fround)
5530 #[wasm_bindgen(js_namespace = Math)]
5531 pub fn fround(x: f64) -> f32;
5532
5533 /// The `Math.hypot()` function returns the square root of the sum of squares of its arguments.
5534 ///
5535 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/hypot)
5536 #[wasm_bindgen(js_namespace = Math)]
5537 pub fn hypot(x: f64, y: f64) -> f64;
5538
5539 /// The `Math.imul()` function returns the result of the C-like 32-bit multiplication of the
5540 /// two parameters.
5541 ///
5542 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/imul)
5543 #[wasm_bindgen(js_namespace = Math)]
5544 pub fn imul(x: i32, y: i32) -> i32;
5545
5546 /// The `Math.log()` function returns the natural logarithm (base e) of a number.
5547 /// The JavaScript `Math.log()` function is equivalent to ln(x) in mathematics.
5548 ///
5549 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log)
5550 #[wasm_bindgen(js_namespace = Math)]
5551 pub fn log(x: f64) -> f64;
5552
5553 /// The `Math.log10()` function returns the base 10 logarithm of a number.
5554 ///
5555 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log10)
5556 #[wasm_bindgen(js_namespace = Math)]
5557 pub fn log10(x: f64) -> f64;
5558
5559 /// The `Math.log1p()` function returns the natural logarithm (base e) of 1 + a number.
5560 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log1p)
5561 #[wasm_bindgen(js_namespace = Math)]
5562 pub fn log1p(x: f64) -> f64;
5563
5564 /// The `Math.log2()` function returns the base 2 logarithm of a number.
5565 ///
5566 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log2)
5567 #[wasm_bindgen(js_namespace = Math)]
5568 pub fn log2(x: f64) -> f64;
5569
5570 /// The `Math.max()` function returns the largest of two numbers.
5571 ///
5572 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/max)
5573 #[wasm_bindgen(js_namespace = Math)]
5574 pub fn max(x: f64, y: f64) -> f64;
5575
5576 /// The static function `Math.min()` returns the lowest-valued number passed into it.
5577 ///
5578 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/min)
5579 #[wasm_bindgen(js_namespace = Math)]
5580 pub fn min(x: f64, y: f64) -> f64;
5581
5582 /// The `Math.pow()` function returns the base to the exponent power, that is, base^exponent.
5583 ///
5584 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/pow)
5585 #[wasm_bindgen(js_namespace = Math)]
5586 pub fn pow(base: f64, exponent: f64) -> f64;
5587
5588 /// The `Math.random()` function returns a floating-point, pseudo-random number
5589 /// in the range 0–1 (inclusive of 0, but not 1) with approximately uniform distribution
5590 /// over that range — which you can then scale to your desired range.
5591 /// The implementation selects the initial seed to the random number generation algorithm;
5592 /// it cannot be chosen or reset by the user.
5593 ///
5594 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random)
5595 #[wasm_bindgen(js_namespace = Math)]
5596 pub fn random() -> f64;
5597
5598 /// The `Math.round()` function returns the value of a number rounded to the nearest integer.
5599 ///
5600 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round)
5601 #[wasm_bindgen(js_namespace = Math)]
5602 pub fn round(x: f64) -> f64;
5603
5604 /// The `Math.sign()` function returns the sign of a number, indicating whether the number is
5605 /// positive, negative or zero.
5606 ///
5607 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign)
5608 #[wasm_bindgen(js_namespace = Math)]
5609 pub fn sign(x: f64) -> f64;
5610
5611 /// The `Math.sin()` function returns the sine of a number.
5612 ///
5613 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sin)
5614 #[wasm_bindgen(js_namespace = Math)]
5615 pub fn sin(x: f64) -> f64;
5616
5617 /// The `Math.sinh()` function returns the hyperbolic sine of a number, that can be expressed
5618 /// using the constant e: Math.sinh(x) = (e^x - e^-x)/2
5619 ///
5620 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sinh)
5621 #[wasm_bindgen(js_namespace = Math)]
5622 pub fn sinh(x: f64) -> f64;
5623
5624 /// The `Math.sqrt()` function returns the square root of a number, that is
5625 /// ∀x ≥ 0, Math.sqrt(x) = √x = the unique y ≥ 0 such that y^2 = x
5626 ///
5627 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sqrt)
5628 #[wasm_bindgen(js_namespace = Math)]
5629 pub fn sqrt(x: f64) -> f64;
5630
5631 /// The `Math.tan()` function returns the tangent of a number.
5632 ///
5633 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/tan)
5634 #[wasm_bindgen(js_namespace = Math)]
5635 pub fn tan(x: f64) -> f64;
5636
5637 /// The `Math.tanh()` function returns the hyperbolic tangent of a number, that is
5638 /// tanh x = sinh x / cosh x = (e^x - e^-x)/(e^x + e^-x) = (e^2x - 1)/(e^2x + 1)
5639 ///
5640 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/tanh)
5641 #[wasm_bindgen(js_namespace = Math)]
5642 pub fn tanh(x: f64) -> f64;
5643
5644 /// The `Math.trunc()` function returns the integer part of a number by removing any fractional
5645 /// digits.
5646 ///
5647 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/trunc)
5648 #[wasm_bindgen(js_namespace = Math)]
5649 pub fn trunc(x: f64) -> f64;
5650
5651 /// The `Math.PI` property represents the ratio of the circumference of a circle to its diameter,
5652 /// approximately 3.14159.
5653 ///
5654 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/PI)
5655 #[wasm_bindgen(thread_local_v2, js_namespace = Math)]
5656 pub static PI: f64;
5657 }
5658}
5659
5660// Number.
5661#[wasm_bindgen]
5662extern "C" {
5663 #[wasm_bindgen(extends = Object, is_type_of = |v| v.as_f64().is_some(), typescript_type = "number")]
5664 #[derive(Clone, PartialEq)]
5665 pub type Number;
5666
5667 /// The `Number.isFinite()` method determines whether the passed value is a finite number.
5668 ///
5669 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isFinite)
5670 #[wasm_bindgen(static_method_of = Number, js_name = isFinite)]
5671 pub fn is_finite(value: &JsValue) -> bool;
5672
5673 /// The `Number.isInteger()` method determines whether the passed value is an integer.
5674 ///
5675 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isInteger)
5676 #[wasm_bindgen(static_method_of = Number, js_name = isInteger)]
5677 pub fn is_integer(value: &JsValue) -> bool;
5678
5679 /// The `Number.isNaN()` method determines whether the passed value is `NaN` and its type is Number.
5680 /// It is a more robust version of the original, global isNaN().
5681 ///
5682 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isNaN)
5683 #[wasm_bindgen(static_method_of = Number, js_name = isNaN)]
5684 pub fn is_nan(value: &JsValue) -> bool;
5685
5686 /// The `Number.isSafeInteger()` method determines whether the provided value is a number
5687 /// that is a safe integer.
5688 ///
5689 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isSafeInteger)
5690 #[wasm_bindgen(static_method_of = Number, js_name = isSafeInteger)]
5691 pub fn is_safe_integer(value: &JsValue) -> bool;
5692
5693 /// The `Number` JavaScript object is a wrapper object allowing
5694 /// you to work with numerical values. A `Number` object is
5695 /// created using the `Number()` constructor.
5696 ///
5697 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
5698 #[cfg(not(js_sys_unstable_apis))]
5699 #[wasm_bindgen(constructor)]
5700 #[deprecated(note = "recommended to use `Number::from` instead")]
5701 #[allow(deprecated)]
5702 pub fn new(value: &JsValue) -> Number;
5703
5704 #[wasm_bindgen(constructor)]
5705 fn new_from_str(value: &str) -> Number;
5706
5707 /// The `Number.parseInt()` method parses a string argument and returns an
5708 /// integer of the specified radix or base.
5709 ///
5710 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/parseInt)
5711 #[wasm_bindgen(static_method_of = Number, js_name = parseInt)]
5712 pub fn parse_int(text: &str, radix: u8) -> f64;
5713
5714 /// The `Number.parseFloat()` method parses a string argument and returns a
5715 /// floating point number.
5716 ///
5717 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/parseFloat)
5718 #[wasm_bindgen(static_method_of = Number, js_name = parseFloat)]
5719 pub fn parse_float(text: &str) -> f64;
5720
5721 /// The `toLocaleString()` method returns a string with a language sensitive
5722 /// representation of this number.
5723 ///
5724 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString)
5725 #[cfg(not(js_sys_unstable_apis))]
5726 #[wasm_bindgen(method, js_name = toLocaleString)]
5727 pub fn to_locale_string(this: &Number, locale: &str) -> JsString;
5728
5729 /// The `toLocaleString()` method returns a string with a language sensitive
5730 /// representation of this number.
5731 ///
5732 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString)
5733 #[cfg(js_sys_unstable_apis)]
5734 #[wasm_bindgen(method, js_name = toLocaleString)]
5735 pub fn to_locale_string(
5736 this: &Number,
5737 locales: &[JsString],
5738 options: &Intl::NumberFormatOptions,
5739 ) -> JsString;
5740
5741 /// The `toPrecision()` method returns a string representing the Number
5742 /// object to the specified precision.
5743 ///
5744 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision)
5745 #[wasm_bindgen(catch, method, js_name = toPrecision)]
5746 pub fn to_precision(this: &Number, precision: u8) -> Result<JsString, JsValue>;
5747
5748 /// The `toFixed()` method returns a string representing the Number
5749 /// object using fixed-point notation.
5750 ///
5751 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed)
5752 #[wasm_bindgen(catch, method, js_name = toFixed)]
5753 pub fn to_fixed(this: &Number, digits: u8) -> Result<JsString, JsValue>;
5754
5755 /// The `toExponential()` method returns a string representing the Number
5756 /// object in exponential notation.
5757 ///
5758 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toExponential)
5759 #[wasm_bindgen(catch, method, js_name = toExponential)]
5760 pub fn to_exponential(this: &Number, fraction_digits: u8) -> Result<JsString, JsValue>;
5761
5762 /// The `toString()` method returns a string representing the
5763 /// specified Number object.
5764 ///
5765 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString)
5766 #[cfg(not(js_sys_unstable_apis))]
5767 #[deprecated(note = "Use `Number::to_string_with_radix` instead.")]
5768 #[allow(deprecated)]
5769 #[wasm_bindgen(catch, method, js_name = toString)]
5770 pub fn to_string(this: &Number, radix: u8) -> Result<JsString, JsValue>;
5771
5772 /// The `toString()` method returns a string representing the
5773 /// specified Number object.
5774 ///
5775 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString)
5776 #[wasm_bindgen(catch, method, js_name = toString)]
5777 pub fn to_string_with_radix(this: &Number, radix: u8) -> Result<JsString, JsValue>;
5778
5779 /// The `valueOf()` method returns the wrapped primitive value of
5780 /// a Number object.
5781 ///
5782 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/valueOf)
5783 #[wasm_bindgen(method, js_name = valueOf)]
5784 pub fn value_of(this: &Number) -> f64;
5785}
5786
5787impl Number {
5788 /// The smallest interval between two representable numbers.
5789 ///
5790 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/EPSILON)
5791 pub const EPSILON: f64 = f64::EPSILON;
5792 /// The maximum safe integer in JavaScript (2^53 - 1).
5793 ///
5794 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER)
5795 pub const MAX_SAFE_INTEGER: f64 = 9007199254740991.0;
5796 /// The largest positive representable number.
5797 ///
5798 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_VALUE)
5799 pub const MAX_VALUE: f64 = f64::MAX;
5800 /// The minimum safe integer in JavaScript (-(2^53 - 1)).
5801 ///
5802 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MIN_SAFE_INTEGER)
5803 pub const MIN_SAFE_INTEGER: f64 = -9007199254740991.0;
5804 /// The smallest positive representable number—that is, the positive number closest to zero
5805 /// (without actually being zero).
5806 ///
5807 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MIN_VALUE)
5808 // Cannot use f64::MIN_POSITIVE since that is the smallest **normal** positive number.
5809 pub const MIN_VALUE: f64 = 5E-324;
5810 /// Special "Not a Number" value.
5811 ///
5812 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/NaN)
5813 pub const NAN: f64 = f64::NAN;
5814 /// Special value representing negative infinity. Returned on overflow.
5815 ///
5816 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/NEGATIVE_INFINITY)
5817 pub const NEGATIVE_INFINITY: f64 = f64::NEG_INFINITY;
5818 /// Special value representing infinity. Returned on overflow.
5819 ///
5820 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/POSITIVE_INFINITY)
5821 pub const POSITIVE_INFINITY: f64 = f64::INFINITY;
5822
5823 /// Applies the binary `**` JS operator on the two `Number`s.
5824 ///
5825 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Exponentiation)
5826 #[inline]
5827 pub fn pow(&self, rhs: &Self) -> Self {
5828 JsValue::as_ref(self)
5829 .pow(JsValue::as_ref(rhs))
5830 .unchecked_into()
5831 }
5832
5833 /// Applies the binary `>>>` JS operator on the two `Number`s.
5834 ///
5835 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Unsigned_right_shift)
5836 #[inline]
5837 pub fn unsigned_shr(&self, rhs: &Self) -> Self {
5838 Number::from(JsValue::as_ref(self).unsigned_shr(JsValue::as_ref(rhs)))
5839 }
5840}
5841
5842macro_rules! number_from {
5843 ($($x:ident)*) => ($(
5844 impl From<$x> for Number {
5845 #[inline]
5846 fn from(x: $x) -> Number {
5847 Number::unchecked_from_js(JsValue::from(x))
5848 }
5849 }
5850
5851 impl PartialEq<$x> for Number {
5852 #[inline]
5853 fn eq(&self, other: &$x) -> bool {
5854 self.value_of() == f64::from(*other)
5855 }
5856 }
5857
5858 impl UpcastFrom<$x> for Number {}
5859 )*)
5860}
5861number_from!(i8 u8 i16 u16 i32 u32 f32 f64);
5862
5863// The only guarantee for a JS number
5864impl UpcastFrom<Number> for f64 {}
5865
5866/// The error type returned when a checked integral type conversion fails.
5867#[derive(Debug, Copy, Clone, PartialEq, Eq)]
5868pub struct TryFromIntError(());
5869
5870impl fmt::Display for TryFromIntError {
5871 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
5872 fmt.write_str("out of range integral type conversion attempted")
5873 }
5874}
5875
5876#[cfg(feature = "std")]
5877impl std::error::Error for TryFromIntError {}
5878
5879macro_rules! number_try_from {
5880 ($($x:ident)*) => ($(
5881 impl TryFrom<$x> for Number {
5882 type Error = TryFromIntError;
5883
5884 #[inline]
5885 fn try_from(x: $x) -> Result<Number, Self::Error> {
5886 let x_f64 = x as f64;
5887 if (Number::MIN_SAFE_INTEGER..=Number::MAX_SAFE_INTEGER).contains(&x_f64) {
5888 Ok(Number::from(x_f64))
5889 } else {
5890 Err(TryFromIntError(()))
5891 }
5892 }
5893 }
5894 )*)
5895}
5896number_try_from!(i64 u64 i128 u128);
5897
5898impl From<&Number> for f64 {
5899 #[inline]
5900 fn from(n: &Number) -> f64 {
5901 n.value_of()
5902 }
5903}
5904
5905impl From<Number> for f64 {
5906 #[inline]
5907 fn from(n: Number) -> f64 {
5908 <f64 as From<&'_ Number>>::from(&n)
5909 }
5910}
5911
5912impl fmt::Debug for Number {
5913 #[inline]
5914 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5915 fmt::Debug::fmt(&self.value_of(), f)
5916 }
5917}
5918
5919impl fmt::Display for Number {
5920 #[inline]
5921 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5922 fmt::Display::fmt(&self.value_of(), f)
5923 }
5924}
5925
5926impl Default for Number {
5927 fn default() -> Self {
5928 Self::from(f64::default())
5929 }
5930}
5931
5932impl PartialEq<BigInt> for Number {
5933 #[inline]
5934 fn eq(&self, other: &BigInt) -> bool {
5935 JsValue::as_ref(self).loose_eq(JsValue::as_ref(other))
5936 }
5937}
5938
5939impl Not for &Number {
5940 type Output = BigInt;
5941
5942 #[inline]
5943 fn not(self) -> Self::Output {
5944 JsValue::as_ref(self).bit_not().unchecked_into()
5945 }
5946}
5947
5948forward_deref_unop!(impl Not, not for Number);
5949forward_js_unop!(impl Neg, neg for Number);
5950forward_js_binop!(impl BitAnd, bitand for Number);
5951forward_js_binop!(impl BitOr, bitor for Number);
5952forward_js_binop!(impl BitXor, bitxor for Number);
5953forward_js_binop!(impl Shl, shl for Number);
5954forward_js_binop!(impl Shr, shr for Number);
5955forward_js_binop!(impl Add, add for Number);
5956forward_js_binop!(impl Sub, sub for Number);
5957forward_js_binop!(impl Div, div for Number);
5958forward_js_binop!(impl Mul, mul for Number);
5959forward_js_binop!(impl Rem, rem for Number);
5960
5961sum_product!(Number);
5962
5963impl PartialOrd for Number {
5964 #[inline]
5965 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
5966 if Number::is_nan(self) || Number::is_nan(other) {
5967 None
5968 } else if self == other {
5969 Some(Ordering::Equal)
5970 } else if self.lt(other) {
5971 Some(Ordering::Less)
5972 } else {
5973 Some(Ordering::Greater)
5974 }
5975 }
5976
5977 #[inline]
5978 fn lt(&self, other: &Self) -> bool {
5979 JsValue::as_ref(self).lt(JsValue::as_ref(other))
5980 }
5981
5982 #[inline]
5983 fn le(&self, other: &Self) -> bool {
5984 JsValue::as_ref(self).le(JsValue::as_ref(other))
5985 }
5986
5987 #[inline]
5988 fn ge(&self, other: &Self) -> bool {
5989 JsValue::as_ref(self).ge(JsValue::as_ref(other))
5990 }
5991
5992 #[inline]
5993 fn gt(&self, other: &Self) -> bool {
5994 JsValue::as_ref(self).gt(JsValue::as_ref(other))
5995 }
5996}
5997
5998#[cfg(not(js_sys_unstable_apis))]
5999impl FromStr for Number {
6000 type Err = Infallible;
6001
6002 #[allow(deprecated)]
6003 #[inline]
6004 fn from_str(s: &str) -> Result<Self, Self::Err> {
6005 Ok(Number::new_from_str(s))
6006 }
6007}
6008
6009// Date.
6010#[wasm_bindgen]
6011extern "C" {
6012 #[wasm_bindgen(extends = Object, typescript_type = "Date")]
6013 #[derive(Clone, Debug, PartialEq, Eq)]
6014 pub type Date;
6015
6016 /// The `getDate()` method returns the day of the month for the
6017 /// specified date according to local time.
6018 ///
6019 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getDate)
6020 #[wasm_bindgen(method, js_name = getDate)]
6021 pub fn get_date(this: &Date) -> u32;
6022
6023 /// The `getDay()` method returns the day of the week for the specified date according to local time,
6024 /// where 0 represents Sunday. For the day of the month see getDate().
6025 ///
6026 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getDay)
6027 #[wasm_bindgen(method, js_name = getDay)]
6028 pub fn get_day(this: &Date) -> u32;
6029
6030 /// The `getFullYear()` method returns the year of the specified date according to local time.
6031 ///
6032 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getFullYear)
6033 #[wasm_bindgen(method, js_name = getFullYear)]
6034 pub fn get_full_year(this: &Date) -> u32;
6035
6036 /// The `getHours()` method returns the hour for the specified date, according to local time.
6037 ///
6038 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getHours)
6039 #[wasm_bindgen(method, js_name = getHours)]
6040 pub fn get_hours(this: &Date) -> u32;
6041
6042 /// The `getMilliseconds()` method returns the milliseconds in the specified date according to local time.
6043 ///
6044 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMilliseconds)
6045 #[wasm_bindgen(method, js_name = getMilliseconds)]
6046 pub fn get_milliseconds(this: &Date) -> u32;
6047
6048 /// The `getMinutes()` method returns the minutes in the specified date according to local time.
6049 ///
6050 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMinutes)
6051 #[wasm_bindgen(method, js_name = getMinutes)]
6052 pub fn get_minutes(this: &Date) -> u32;
6053
6054 /// The `getMonth()` method returns the month in the specified date according to local time,
6055 /// as a zero-based value (where zero indicates the first month of the year).
6056 ///
6057 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMonth)
6058 #[wasm_bindgen(method, js_name = getMonth)]
6059 pub fn get_month(this: &Date) -> u32;
6060
6061 /// The `getSeconds()` method returns the seconds in the specified date according to local time.
6062 ///
6063 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getSeconds)
6064 #[wasm_bindgen(method, js_name = getSeconds)]
6065 pub fn get_seconds(this: &Date) -> u32;
6066
6067 /// The `getTime()` method returns the numeric value corresponding to the time for the specified date
6068 /// according to universal time.
6069 ///
6070 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTime)
6071 #[wasm_bindgen(method, js_name = getTime)]
6072 pub fn get_time(this: &Date) -> f64;
6073
6074 /// The `getTimezoneOffset()` method returns the time zone difference, in minutes,
6075 /// from current locale (host system settings) to UTC.
6076 ///
6077 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTimezoneOffset)
6078 #[wasm_bindgen(method, js_name = getTimezoneOffset)]
6079 pub fn get_timezone_offset(this: &Date) -> f64;
6080
6081 /// The `getUTCDate()` method returns the day (date) of the month in the specified date
6082 /// according to universal time.
6083 ///
6084 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCDate)
6085 #[wasm_bindgen(method, js_name = getUTCDate)]
6086 pub fn get_utc_date(this: &Date) -> u32;
6087
6088 /// The `getUTCDay()` method returns the day of the week in the specified date according to universal time,
6089 /// where 0 represents Sunday.
6090 ///
6091 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCDay)
6092 #[wasm_bindgen(method, js_name = getUTCDay)]
6093 pub fn get_utc_day(this: &Date) -> u32;
6094
6095 /// The `getUTCFullYear()` method returns the year in the specified date according to universal time.
6096 ///
6097 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCFullYear)
6098 #[wasm_bindgen(method, js_name = getUTCFullYear)]
6099 pub fn get_utc_full_year(this: &Date) -> u32;
6100
6101 /// The `getUTCHours()` method returns the hours in the specified date according to universal time.
6102 ///
6103 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCHours)
6104 #[wasm_bindgen(method, js_name = getUTCHours)]
6105 pub fn get_utc_hours(this: &Date) -> u32;
6106
6107 /// The `getUTCMilliseconds()` method returns the milliseconds in the specified date
6108 /// according to universal time.
6109 ///
6110 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCMilliseconds)
6111 #[wasm_bindgen(method, js_name = getUTCMilliseconds)]
6112 pub fn get_utc_milliseconds(this: &Date) -> u32;
6113
6114 /// The `getUTCMinutes()` method returns the minutes in the specified date according to universal time.
6115 ///
6116 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCMinutes)
6117 #[wasm_bindgen(method, js_name = getUTCMinutes)]
6118 pub fn get_utc_minutes(this: &Date) -> u32;
6119
6120 /// The `getUTCMonth()` returns the month of the specified date according to universal time,
6121 /// as a zero-based value (where zero indicates the first month of the year).
6122 ///
6123 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCMonth)
6124 #[wasm_bindgen(method, js_name = getUTCMonth)]
6125 pub fn get_utc_month(this: &Date) -> u32;
6126
6127 /// The `getUTCSeconds()` method returns the seconds in the specified date according to universal time.
6128 ///
6129 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCSeconds)
6130 #[wasm_bindgen(method, js_name = getUTCSeconds)]
6131 pub fn get_utc_seconds(this: &Date) -> u32;
6132
6133 /// Creates a JavaScript `Date` instance that represents
6134 /// a single moment in time. `Date` objects are based on a time value that is
6135 /// the number of milliseconds since 1 January 1970 UTC.
6136 ///
6137 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6138 #[wasm_bindgen(constructor)]
6139 pub fn new(init: &JsValue) -> Date;
6140
6141 /// Creates a JavaScript `Date` instance that represents the current moment in
6142 /// time.
6143 ///
6144 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6145 #[wasm_bindgen(constructor)]
6146 pub fn new_0() -> Date;
6147
6148 /// Creates a JavaScript `Date` instance that represents
6149 /// a single moment in time. `Date` objects are based on a time value that is
6150 /// the number of milliseconds since 1 January 1970 UTC.
6151 ///
6152 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6153 #[wasm_bindgen(constructor)]
6154 pub fn new_with_year_month(year: u32, month: i32) -> Date;
6155
6156 /// Creates a JavaScript `Date` instance that represents
6157 /// a single moment in time. `Date` objects are based on a time value that is
6158 /// the number of milliseconds since 1 January 1970 UTC.
6159 ///
6160 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6161 #[wasm_bindgen(constructor)]
6162 pub fn new_with_year_month_day(year: u32, month: i32, day: i32) -> Date;
6163
6164 /// Creates a JavaScript `Date` instance that represents
6165 /// a single moment in time. `Date` objects are based on a time value that is
6166 /// the number of milliseconds since 1 January 1970 UTC.
6167 ///
6168 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6169 #[wasm_bindgen(constructor)]
6170 pub fn new_with_year_month_day_hr(year: u32, month: i32, day: i32, hr: i32) -> Date;
6171
6172 /// Creates a JavaScript `Date` instance that represents
6173 /// a single moment in time. `Date` objects are based on a time value that is
6174 /// the number of milliseconds since 1 January 1970 UTC.
6175 ///
6176 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6177 #[wasm_bindgen(constructor)]
6178 pub fn new_with_year_month_day_hr_min(
6179 year: u32,
6180 month: i32,
6181 day: i32,
6182 hr: i32,
6183 min: i32,
6184 ) -> Date;
6185
6186 /// Creates a JavaScript `Date` instance that represents
6187 /// a single moment in time. `Date` objects are based on a time value that is
6188 /// the number of milliseconds since 1 January 1970 UTC.
6189 ///
6190 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6191 #[wasm_bindgen(constructor)]
6192 pub fn new_with_year_month_day_hr_min_sec(
6193 year: u32,
6194 month: i32,
6195 day: i32,
6196 hr: i32,
6197 min: i32,
6198 sec: i32,
6199 ) -> Date;
6200
6201 /// Creates a JavaScript `Date` instance that represents
6202 /// a single moment in time. `Date` objects are based on a time value that is
6203 /// the number of milliseconds since 1 January 1970 UTC.
6204 ///
6205 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6206 #[wasm_bindgen(constructor)]
6207 pub fn new_with_year_month_day_hr_min_sec_milli(
6208 year: u32,
6209 month: i32,
6210 day: i32,
6211 hr: i32,
6212 min: i32,
6213 sec: i32,
6214 milli: i32,
6215 ) -> Date;
6216
6217 /// The `Date.now()` method returns the number of milliseconds
6218 /// elapsed since January 1, 1970 00:00:00 UTC.
6219 ///
6220 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/now)
6221 #[wasm_bindgen(static_method_of = Date)]
6222 pub fn now() -> f64;
6223
6224 /// The `Date.parse()` method parses a string representation of a date, and returns the number of milliseconds
6225 /// since January 1, 1970, 00:00:00 UTC or `NaN` if the string is unrecognized or, in some cases,
6226 /// contains illegal date values (e.g. 2015-02-31).
6227 ///
6228 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse)
6229 #[wasm_bindgen(static_method_of = Date)]
6230 pub fn parse(date: &str) -> f64;
6231
6232 /// The `setDate()` method sets the day of the Date object relative to the beginning of the currently set month.
6233 ///
6234 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setDate)
6235 #[wasm_bindgen(method, js_name = setDate)]
6236 pub fn set_date(this: &Date, day: u32) -> f64;
6237
6238 /// The `setFullYear()` method sets the full year for a specified date according to local time.
6239 /// Returns new timestamp.
6240 ///
6241 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setFullYear)
6242 #[wasm_bindgen(method, js_name = setFullYear)]
6243 pub fn set_full_year(this: &Date, year: u32) -> f64;
6244
6245 /// The `setFullYear()` method sets the full year for a specified date according to local time.
6246 /// Returns new timestamp.
6247 ///
6248 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setFullYear)
6249 #[wasm_bindgen(method, js_name = setFullYear)]
6250 pub fn set_full_year_with_month(this: &Date, year: u32, month: i32) -> f64;
6251
6252 /// The `setFullYear()` method sets the full year for a specified date according to local time.
6253 /// Returns new timestamp.
6254 ///
6255 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setFullYear)
6256 #[wasm_bindgen(method, js_name = setFullYear)]
6257 pub fn set_full_year_with_month_date(this: &Date, year: u32, month: i32, date: i32) -> f64;
6258
6259 /// The `setHours()` method sets the hours for a specified date according to local time,
6260 /// and returns the number of milliseconds since January 1, 1970 00:00:00 UTC until the time represented
6261 /// by the updated Date instance.
6262 ///
6263 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setHours)
6264 #[wasm_bindgen(method, js_name = setHours)]
6265 pub fn set_hours(this: &Date, hours: u32) -> f64;
6266
6267 /// The `setMilliseconds()` method sets the milliseconds for a specified date according to local time.
6268 ///
6269 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setMilliseconds)
6270 #[wasm_bindgen(method, js_name = setMilliseconds)]
6271 pub fn set_milliseconds(this: &Date, milliseconds: u32) -> f64;
6272
6273 /// The `setMinutes()` method sets the minutes for a specified date according to local time.
6274 ///
6275 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setMinutes)
6276 #[wasm_bindgen(method, js_name = setMinutes)]
6277 pub fn set_minutes(this: &Date, minutes: u32) -> f64;
6278
6279 /// The `setMonth()` method sets the month for a specified date according to the currently set year.
6280 ///
6281 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setMonth)
6282 #[wasm_bindgen(method, js_name = setMonth)]
6283 pub fn set_month(this: &Date, month: u32) -> f64;
6284
6285 /// The `setSeconds()` method sets the seconds for a specified date according to local time.
6286 ///
6287 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setSeconds)
6288 #[wasm_bindgen(method, js_name = setSeconds)]
6289 pub fn set_seconds(this: &Date, seconds: u32) -> f64;
6290
6291 /// The `setTime()` method sets the Date object to the time represented by a number of milliseconds
6292 /// since January 1, 1970, 00:00:00 UTC.
6293 ///
6294 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setTime)
6295 #[wasm_bindgen(method, js_name = setTime)]
6296 pub fn set_time(this: &Date, time: f64) -> f64;
6297
6298 /// The `setUTCDate()` method sets the day of the month for a specified date
6299 /// according to universal time.
6300 ///
6301 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCDate)
6302 #[wasm_bindgen(method, js_name = setUTCDate)]
6303 pub fn set_utc_date(this: &Date, day: u32) -> f64;
6304
6305 /// The `setUTCFullYear()` method sets the full year for a specified date according to universal time.
6306 ///
6307 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCFullYear)
6308 #[wasm_bindgen(method, js_name = setUTCFullYear)]
6309 pub fn set_utc_full_year(this: &Date, year: u32) -> f64;
6310
6311 /// The `setUTCFullYear()` method sets the full year for a specified date according to universal time.
6312 ///
6313 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCFullYear)
6314 #[wasm_bindgen(method, js_name = setUTCFullYear)]
6315 pub fn set_utc_full_year_with_month(this: &Date, year: u32, month: i32) -> f64;
6316
6317 /// The `setUTCFullYear()` method sets the full year for a specified date according to universal time.
6318 ///
6319 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCFullYear)
6320 #[wasm_bindgen(method, js_name = setUTCFullYear)]
6321 pub fn set_utc_full_year_with_month_date(this: &Date, year: u32, month: i32, date: i32) -> f64;
6322
6323 /// The `setUTCHours()` method sets the hour for a specified date according to universal time,
6324 /// and returns the number of milliseconds since January 1, 1970 00:00:00 UTC until the time
6325 /// represented by the updated Date instance.
6326 ///
6327 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCHours)
6328 #[wasm_bindgen(method, js_name = setUTCHours)]
6329 pub fn set_utc_hours(this: &Date, hours: u32) -> f64;
6330
6331 /// The `setUTCMilliseconds()` method sets the milliseconds for a specified date
6332 /// according to universal time.
6333 ///
6334 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCMilliseconds)
6335 #[wasm_bindgen(method, js_name = setUTCMilliseconds)]
6336 pub fn set_utc_milliseconds(this: &Date, milliseconds: u32) -> f64;
6337
6338 /// The `setUTCMinutes()` method sets the minutes for a specified date according to universal time.
6339 ///
6340 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCMinutes)
6341 #[wasm_bindgen(method, js_name = setUTCMinutes)]
6342 pub fn set_utc_minutes(this: &Date, minutes: u32) -> f64;
6343
6344 /// The `setUTCMonth()` method sets the month for a specified date according to universal time.
6345 ///
6346 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCMonth)
6347 #[wasm_bindgen(method, js_name = setUTCMonth)]
6348 pub fn set_utc_month(this: &Date, month: u32) -> f64;
6349
6350 /// The `setUTCSeconds()` method sets the seconds for a specified date according to universal time.
6351 ///
6352 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCSeconds)
6353 #[wasm_bindgen(method, js_name = setUTCSeconds)]
6354 pub fn set_utc_seconds(this: &Date, seconds: u32) -> f64;
6355
6356 /// The `toDateString()` method returns the date portion of a Date object
6357 /// in human readable form in American English.
6358 ///
6359 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toDateString)
6360 #[wasm_bindgen(method, js_name = toDateString)]
6361 pub fn to_date_string(this: &Date) -> JsString;
6362
6363 /// The `toISOString()` method returns a string in simplified extended ISO format (ISO
6364 /// 8601), which is always 24 or 27 characters long (YYYY-MM-DDTHH:mm:ss.sssZ or
6365 /// ±YYYYYY-MM-DDTHH:mm:ss.sssZ, respectively). The timezone is always zero UTC offset,
6366 /// as denoted by the suffix "Z"
6367 ///
6368 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString)
6369 #[wasm_bindgen(method, js_name = toISOString)]
6370 pub fn to_iso_string(this: &Date) -> JsString;
6371
6372 /// The `toJSON()` method returns a string representation of the Date object.
6373 ///
6374 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toJSON)
6375 #[wasm_bindgen(method, js_name = toJSON)]
6376 pub fn to_json(this: &Date) -> JsString;
6377
6378 /// The `toLocaleDateString()` method returns a string with a language sensitive
6379 /// representation of the date portion of this date. The new locales and options
6380 /// arguments let applications specify the language whose formatting conventions
6381 /// should be used and allow to customize the behavior of the function.
6382 /// In older implementations, which ignore the locales and options arguments,
6383 /// the locale used and the form of the string
6384 /// returned are entirely implementation dependent.
6385 ///
6386 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString)
6387 #[cfg(not(js_sys_unstable_apis))]
6388 #[wasm_bindgen(method, js_name = toLocaleDateString)]
6389 pub fn to_locale_date_string(this: &Date, locale: &str, options: &JsValue) -> JsString;
6390
6391 /// The `toLocaleDateString()` method returns a string with a language sensitive
6392 /// representation of the date portion of this date.
6393 ///
6394 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString)
6395 #[cfg(js_sys_unstable_apis)]
6396 #[wasm_bindgen(method, js_name = toLocaleDateString)]
6397 pub fn to_locale_date_string(
6398 this: &Date,
6399 locales: &[JsString],
6400 options: &Intl::DateTimeFormatOptions,
6401 ) -> JsString;
6402
6403 /// The `toLocaleString()` method returns a string with a language sensitive
6404 /// representation of this date. The new locales and options arguments
6405 /// let applications specify the language whose formatting conventions
6406 /// should be used and customize the behavior of the function.
6407 /// In older implementations, which ignore the locales
6408 /// and options arguments, the locale used and the form of the string
6409 /// returned are entirely implementation dependent.
6410 ///
6411 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString)
6412 #[cfg(not(js_sys_unstable_apis))]
6413 #[wasm_bindgen(method, js_name = toLocaleString)]
6414 pub fn to_locale_string(this: &Date, locale: &str, options: &JsValue) -> JsString;
6415
6416 /// The `toLocaleString()` method returns a string with a language sensitive
6417 /// representation of this date.
6418 ///
6419 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString)
6420 #[cfg(js_sys_unstable_apis)]
6421 #[wasm_bindgen(method, js_name = toLocaleString)]
6422 pub fn to_locale_string(
6423 this: &Date,
6424 locales: &[JsString],
6425 options: &Intl::DateTimeFormatOptions,
6426 ) -> JsString;
6427
6428 /// The `toLocaleTimeString()` method returns a string with a language sensitive
6429 /// representation of the time portion of this date. The new locales and options
6430 /// arguments let applications specify the language whose formatting conventions should be
6431 /// used and customize the behavior of the function. In older implementations, which ignore
6432 /// the locales and options arguments, 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/toLocaleTimeString)
6436 #[cfg(not(js_sys_unstable_apis))]
6437 #[wasm_bindgen(method, js_name = toLocaleTimeString)]
6438 pub fn to_locale_time_string(this: &Date, locale: &str) -> JsString;
6439
6440 /// The `toLocaleTimeString()` method returns a string with a language sensitive
6441 /// representation of the time portion of this date.
6442 ///
6443 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleTimeString)
6444 #[cfg(js_sys_unstable_apis)]
6445 #[wasm_bindgen(method, js_name = toLocaleTimeString)]
6446 pub fn to_locale_time_string(
6447 this: &Date,
6448 locales: &[JsString],
6449 options: &Intl::DateTimeFormatOptions,
6450 ) -> JsString;
6451
6452 #[cfg(not(js_sys_unstable_apis))]
6453 #[wasm_bindgen(method, js_name = toLocaleTimeString)]
6454 pub fn to_locale_time_string_with_options(
6455 this: &Date,
6456 locale: &str,
6457 options: &JsValue,
6458 ) -> JsString;
6459
6460 /// The `toString()` method returns a string representing
6461 /// the specified Date object.
6462 ///
6463 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toString)
6464 #[cfg(not(js_sys_unstable_apis))]
6465 #[wasm_bindgen(method, js_name = toString)]
6466 pub fn to_string(this: &Date) -> JsString;
6467
6468 /// The `toTimeString()` method returns the time portion of a Date object in human
6469 /// readable form in American English.
6470 ///
6471 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toTimeString)
6472 #[wasm_bindgen(method, js_name = toTimeString)]
6473 pub fn to_time_string(this: &Date) -> JsString;
6474
6475 /// The `toUTCString()` method converts a date to a string,
6476 /// using the UTC time zone.
6477 ///
6478 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toUTCString)
6479 #[wasm_bindgen(method, js_name = toUTCString)]
6480 pub fn to_utc_string(this: &Date) -> JsString;
6481
6482 /// The `Date.UTC()` method accepts the same parameters as the
6483 /// longest form of the constructor, and returns the number of
6484 /// milliseconds in a `Date` object since January 1, 1970,
6485 /// 00:00:00, universal time.
6486 ///
6487 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/UTC)
6488 #[wasm_bindgen(static_method_of = Date, js_name = UTC)]
6489 pub fn utc(year: f64, month: f64) -> f64;
6490
6491 /// The `valueOf()` method returns the primitive value of
6492 /// a Date object.
6493 ///
6494 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/valueOf)
6495 #[wasm_bindgen(method, js_name = valueOf)]
6496 pub fn value_of(this: &Date) -> f64;
6497
6498 /// The `toTemporalInstant()` method converts a legacy `Date` object to a
6499 /// `Temporal.Instant` object representing the same moment in time.
6500 ///
6501 /// This method is added by the Temporal proposal to facilitate migration
6502 /// from legacy `Date` to the new Temporal API.
6503 ///
6504 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toTemporalInstant)
6505 #[cfg(js_sys_unstable_apis)]
6506 #[wasm_bindgen(method, js_name = toTemporalInstant)]
6507 pub fn to_temporal_instant(this: &Date) -> Temporal::Instant;
6508}
6509
6510// Property Descriptor.
6511#[wasm_bindgen]
6512extern "C" {
6513 #[wasm_bindgen(extends = Object)]
6514 #[derive(Clone, Debug)]
6515 pub type PropertyDescriptor<T = JsValue>;
6516
6517 #[wasm_bindgen(method, getter = writable)]
6518 pub fn get_writable<T>(this: &PropertyDescriptor<T>) -> Option<bool>;
6519
6520 #[wasm_bindgen(method, setter = writable)]
6521 pub fn set_writable<T>(this: &PropertyDescriptor<T>, writable: bool);
6522
6523 #[wasm_bindgen(method, getter = enumerable)]
6524 pub fn get_enumerable<T>(this: &PropertyDescriptor<T>) -> Option<bool>;
6525
6526 #[wasm_bindgen(method, setter = enumerable)]
6527 pub fn set_enumerable<T>(this: &PropertyDescriptor<T>, enumerable: bool);
6528
6529 #[wasm_bindgen(method, getter = configurable)]
6530 pub fn get_configurable<T>(this: &PropertyDescriptor<T>) -> Option<bool>;
6531
6532 #[wasm_bindgen(method, setter = configurable)]
6533 pub fn set_configurable<T>(this: &PropertyDescriptor<T>, configurable: bool);
6534
6535 #[wasm_bindgen(method, getter = get)]
6536 pub fn get_get<T: JsGeneric>(this: &PropertyDescriptor<T>) -> Option<Function<fn() -> T>>;
6537
6538 #[wasm_bindgen(method, setter = get)]
6539 pub fn set_get<T: JsGeneric>(this: &PropertyDescriptor<T>, get: Function<fn() -> T>);
6540
6541 #[wasm_bindgen(method, getter = set)]
6542 pub fn get_set<T: JsGeneric>(
6543 this: &PropertyDescriptor<T>,
6544 ) -> Option<Function<fn(T) -> JsValue>>;
6545
6546 #[wasm_bindgen(method, setter = set)]
6547 pub fn set_set<T: JsGeneric>(this: &PropertyDescriptor<T>, set: Function<fn(T) -> JsValue>);
6548
6549 #[wasm_bindgen(method, getter = value)]
6550 pub fn get_value<T>(this: &PropertyDescriptor<T>) -> Option<T>;
6551
6552 #[wasm_bindgen(method, setter = value)]
6553 pub fn set_value<T>(this: &PropertyDescriptor<T>, value: &T);
6554}
6555
6556impl PropertyDescriptor {
6557 #[cfg(not(js_sys_unstable_apis))]
6558 pub fn new<T>() -> PropertyDescriptor<T> {
6559 JsCast::unchecked_into(Object::new())
6560 }
6561
6562 #[cfg(js_sys_unstable_apis)]
6563 pub fn new<T>() -> PropertyDescriptor<T> {
6564 JsCast::unchecked_into(Object::<JsValue>::new())
6565 }
6566
6567 #[cfg(not(js_sys_unstable_apis))]
6568 pub fn new_value<T: JsGeneric>(value: &T) -> PropertyDescriptor<T> {
6569 let desc: PropertyDescriptor<T> = JsCast::unchecked_into(Object::new());
6570 desc.set_value(value);
6571 desc
6572 }
6573
6574 #[cfg(js_sys_unstable_apis)]
6575 pub fn new_value<T: JsGeneric>(value: &T) -> PropertyDescriptor<T> {
6576 let desc: PropertyDescriptor<T> = JsCast::unchecked_into(Object::<JsValue>::new());
6577 desc.set_value(value);
6578 desc
6579 }
6580}
6581
6582impl Default for PropertyDescriptor {
6583 fn default() -> Self {
6584 PropertyDescriptor::new()
6585 }
6586}
6587
6588// Object.
6589#[wasm_bindgen]
6590extern "C" {
6591 #[wasm_bindgen(typescript_type = "object")]
6592 #[derive(Clone, Debug)]
6593 pub type Object<T = JsValue>;
6594
6595 // Next major: deprecate
6596 /// The `Object.assign()` method is used to copy the values of all enumerable
6597 /// own properties from one or more source objects to a target object. It
6598 /// will return the target object.
6599 ///
6600 /// **Note:** Consider using [`Object::try_assign`] to support error handling.
6601 ///
6602 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
6603 #[wasm_bindgen(static_method_of = Object)]
6604 pub fn assign<T>(target: &Object<T>, source: &Object<T>) -> Object<T>;
6605
6606 // Next major: deprecate
6607 /// The `Object.assign()` method is used to copy the values of all enumerable
6608 /// own properties from one or more source objects to a target object. It
6609 /// will return the target object.
6610 ///
6611 /// **Note:** Consider using [`Object::try_assign`] to support error handling.
6612 ///
6613 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
6614 #[wasm_bindgen(static_method_of = Object, js_name = assign, catch)]
6615 pub fn try_assign<T>(target: &Object<T>, source: &Object<T>) -> Result<Object<T>, JsValue>;
6616
6617 /// The `Object.assign()` method is used to copy the values of all enumerable
6618 /// own properties from one or more source objects to a target object. It
6619 /// will return the target object.
6620 ///
6621 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
6622 #[cfg(not(js_sys_unstable_apis))]
6623 #[wasm_bindgen(static_method_of = Object, js_name = assign)]
6624 #[deprecated(note = "use `assign_many` for arbitrary assign arguments instead")]
6625 #[allow(deprecated)]
6626 pub fn assign2<T>(target: &Object<T>, source1: &Object<T>, source2: &Object<T>) -> Object<T>;
6627
6628 /// The `Object.assign()` method is used to copy the values of all enumerable
6629 /// own properties from one or more source objects to a target object. It
6630 /// will return the target object.
6631 ///
6632 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
6633 #[cfg(not(js_sys_unstable_apis))]
6634 #[wasm_bindgen(static_method_of = Object, js_name = assign)]
6635 #[deprecated(note = "use `assign_many` for arbitrary assign arguments instead")]
6636 #[allow(deprecated)]
6637 pub fn assign3<T>(
6638 target: &Object<T>,
6639 source1: &Object<T>,
6640 source2: &Object<T>,
6641 source3: &Object<T>,
6642 ) -> Object<T>;
6643
6644 /// The `Object.assign()` method is used to copy the values of all enumerable
6645 /// own properties from one or more source objects to a target object. It
6646 /// will return the target object.
6647 ///
6648 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
6649 #[wasm_bindgen(static_method_of = Object, js_name = assign, catch, variadic)]
6650 pub fn assign_many<T>(target: &Object<T>, sources: &[Object<T>]) -> Result<Object<T>, JsValue>;
6651
6652 /// The constructor property returns a reference to the `Object` constructor
6653 /// function that created the instance object.
6654 ///
6655 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/constructor)
6656 #[wasm_bindgen(method, getter)]
6657 pub fn constructor<T>(this: &Object<T>) -> Function;
6658
6659 /// The `Object.create()` method creates a new object, using an existing
6660 /// object to provide the newly created object's prototype.
6661 ///
6662 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/create)
6663 #[wasm_bindgen(static_method_of = Object)]
6664 pub fn create<T>(prototype: &Object<T>) -> Object<T>;
6665
6666 /// The static method `Object.defineProperty()` defines a new
6667 /// property directly on an object, or modifies an existing
6668 /// property on an object, and returns the object.
6669 ///
6670 /// **Note:** Consider using [`Object::define_property_str`] to support typing and error handling.
6671 ///
6672 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty)
6673 #[cfg(not(js_sys_unstable_apis))]
6674 #[wasm_bindgen(static_method_of = Object, js_name = defineProperty)]
6675 pub fn define_property<T>(obj: &Object<T>, prop: &JsValue, descriptor: &Object) -> Object<T>;
6676
6677 /// The static method `Object.defineProperty()` defines a new
6678 /// property directly on an object, or modifies an existing
6679 /// property on an object, and returns the object.
6680 ///
6681 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty)
6682 #[cfg(js_sys_unstable_apis)]
6683 #[wasm_bindgen(static_method_of = Object, js_name = defineProperty, catch)]
6684 pub fn define_property<T>(
6685 obj: &Object<T>,
6686 prop: &JsString,
6687 descriptor: &PropertyDescriptor<T>,
6688 ) -> Result<Object<T>, JsValue>;
6689
6690 // Next major: deprecate
6691 /// The static method `Object.defineProperty()` defines a new
6692 /// property directly on an object, or modifies an existing
6693 /// property on an object, and returns the object.
6694 ///
6695 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty)
6696 #[wasm_bindgen(static_method_of = Object, js_name = defineProperty, catch)]
6697 pub fn define_property_str<T>(
6698 obj: &Object<T>,
6699 prop: &JsString,
6700 descriptor: &PropertyDescriptor<T>,
6701 ) -> Result<Object<T>, JsValue>;
6702
6703 /// The static method `Object.defineProperty()` defines a new
6704 /// property directly on an object, or modifies an existing
6705 /// property on an object, and returns the object.
6706 ///
6707 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty)
6708 #[wasm_bindgen(static_method_of = Object, js_name = defineProperty, catch)]
6709 pub fn define_property_symbol<T>(
6710 obj: &Object<T>,
6711 prop: &Symbol,
6712 descriptor: &PropertyDescriptor<JsValue>,
6713 ) -> Result<Object<T>, JsValue>;
6714
6715 /// The `Object.defineProperties()` method defines new or modifies
6716 /// existing properties directly on an object, returning the
6717 /// object.
6718 ///
6719 /// **Note:** Consider using [`Object::try_define_properties`] to support typing and error handling.
6720 ///
6721 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperties)
6722 #[wasm_bindgen(static_method_of = Object, js_name = defineProperties)]
6723 pub fn define_properties<T>(obj: &Object<T>, props: &Object) -> Object<T>;
6724
6725 /// The `Object.defineProperties()` method defines new or modifies
6726 /// existing properties directly on an object, returning the
6727 /// object.
6728 ///
6729 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperties)
6730 #[cfg(js_sys_unstable_apis)]
6731 #[wasm_bindgen(static_method_of = Object, js_name = defineProperties, catch)]
6732 pub fn try_define_properties<T>(
6733 obj: &Object<T>,
6734 props: &Object<PropertyDescriptor<T>>,
6735 ) -> Result<Object<T>, JsValue>;
6736
6737 /// The `Object.entries()` method returns an array of a given
6738 /// object's own enumerable property [key, value] pairs, in the
6739 /// same order as that provided by a for...in loop (the difference
6740 /// being that a for-in loop enumerates properties in the
6741 /// prototype chain as well).
6742 ///
6743 /// **Note:** Consider using [`Object::entries_typed`] to support typing and error handling.
6744 ///
6745 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries)
6746 #[cfg(not(js_sys_unstable_apis))]
6747 #[wasm_bindgen(static_method_of = Object)]
6748 pub fn entries(object: &Object) -> Array;
6749
6750 /// The `Object.entries()` method returns an array of a given
6751 /// object's own enumerable property [key, value] pairs, in the
6752 /// same order as that provided by a for...in loop (the difference
6753 /// being that a for-in loop enumerates properties in the
6754 /// prototype chain as well).
6755 ///
6756 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries)
6757 #[cfg(js_sys_unstable_apis)]
6758 #[wasm_bindgen(static_method_of = Object, js_name = entries, catch)]
6759 pub fn entries<T: JsGeneric>(
6760 object: &Object<T>,
6761 ) -> Result<Array<ArrayTuple<(JsString, T)>>, JsValue>;
6762
6763 // Next major: deprecate
6764 /// The `Object.entries()` method returns an array of a given
6765 /// object's own enumerable property [key, value] pairs, in the
6766 /// same order as that provided by a for...in loop (the difference
6767 /// being that a for-in loop enumerates properties in the
6768 /// prototype chain as well).
6769 ///
6770 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries)
6771 #[wasm_bindgen(static_method_of = Object, js_name = entries, catch)]
6772 pub fn entries_typed<T: JsGeneric>(
6773 object: &Object<T>,
6774 ) -> Result<Array<ArrayTuple<(JsString, T)>>, JsValue>;
6775
6776 /// The `Object.freeze()` method freezes an object: that is, prevents new
6777 /// properties from being added to it; prevents existing properties from
6778 /// being removed; and prevents existing properties, or their enumerability,
6779 /// configurability, or writability, from being changed, it also prevents
6780 /// the prototype from being changed. The method returns the passed object.
6781 ///
6782 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze)
6783 #[wasm_bindgen(static_method_of = Object)]
6784 pub fn freeze<T>(value: &Object<T>) -> Object<T>;
6785
6786 /// The `Object.fromEntries()` method transforms a list of key-value pairs
6787 /// into an object.
6788 ///
6789 /// **Note:** Consider using [`Object::from_entries_typed`] to support typing and error handling.
6790 ///
6791 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/fromEntries)
6792 #[cfg(not(js_sys_unstable_apis))]
6793 #[wasm_bindgen(static_method_of = Object, catch, js_name = fromEntries)]
6794 pub fn from_entries(entries: &JsValue) -> Result<Object, JsValue>;
6795
6796 /// The `Object.fromEntries()` method transforms a list of key-value pairs
6797 /// into an object.
6798 ///
6799 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/fromEntries)
6800 #[cfg(js_sys_unstable_apis)]
6801 #[wasm_bindgen(static_method_of = Object, catch, js_name = fromEntries)]
6802 pub fn from_entries<T: JsGeneric, I: Iterable<Item = ArrayTuple<(JsString, T)>>>(
6803 entries: &I,
6804 ) -> Result<Object<T>, JsValue>;
6805
6806 // Next major: deprecate
6807 /// The `Object.fromEntries()` method transforms a list of key-value pairs
6808 /// into an object.
6809 ///
6810 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/fromEntries)
6811 #[wasm_bindgen(static_method_of = Object, catch, js_name = fromEntries)]
6812 pub fn from_entries_typed<T: JsGeneric, I: Iterable<Item = ArrayTuple<(JsString, T)>>>(
6813 entries: &I,
6814 ) -> Result<Object<T>, JsValue>;
6815
6816 /// The `Object.getOwnPropertyDescriptor()` method returns a
6817 /// property descriptor for an own property (that is, one directly
6818 /// present on an object and not in the object's prototype chain)
6819 /// of a given object.
6820 ///
6821 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor)
6822 #[cfg(not(js_sys_unstable_apis))]
6823 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptor)]
6824 pub fn get_own_property_descriptor<T>(obj: &Object<T>, prop: &JsValue) -> JsValue;
6825
6826 /// The `Object.getOwnPropertyDescriptor()` method returns a
6827 /// property descriptor for an own property (that is, one directly
6828 /// present on an object and not in the object's prototype chain)
6829 /// of a given object.
6830 ///
6831 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor)
6832 #[cfg(js_sys_unstable_apis)]
6833 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptor, catch)]
6834 pub fn get_own_property_descriptor<T>(
6835 obj: &Object<T>,
6836 prop: &JsString,
6837 ) -> Result<PropertyDescriptor<T>, JsValue>;
6838
6839 // Next major: deprecate
6840 /// The `Object.getOwnPropertyDescriptor()` method returns a
6841 /// property descriptor for an own property (that is, one directly
6842 /// present on an object and not in the object's prototype chain)
6843 /// of a given object.
6844 ///
6845 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor)
6846 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptor, catch)]
6847 pub fn get_own_property_descriptor_str<T>(
6848 obj: &Object<T>,
6849 prop: &JsString,
6850 ) -> Result<PropertyDescriptor<T>, JsValue>;
6851
6852 /// The `Object.getOwnPropertyDescriptor()` method returns a
6853 /// property descriptor for an own property (that is, one directly
6854 /// present on an object and not in the object's prototype chain)
6855 /// of a given object.
6856 ///
6857 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor)
6858 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptor, catch)]
6859 pub fn get_own_property_descriptor_symbol<T>(
6860 obj: &Object<T>,
6861 prop: &Symbol,
6862 ) -> Result<PropertyDescriptor<JsValue>, JsValue>;
6863
6864 /// The `Object.getOwnPropertyDescriptors()` method returns all own
6865 /// property descriptors of a given object.
6866 ///
6867 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptors)
6868 #[cfg(not(js_sys_unstable_apis))]
6869 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptors)]
6870 pub fn get_own_property_descriptors<T>(obj: &Object<T>) -> JsValue;
6871
6872 /// The `Object.getOwnPropertyDescriptors()` method returns all own
6873 /// property descriptors of a given object.
6874 ///
6875 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptors)
6876 #[cfg(js_sys_unstable_apis)]
6877 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptors, catch)]
6878 pub fn get_own_property_descriptors<T>(
6879 obj: &Object<T>,
6880 ) -> Result<Object<PropertyDescriptor<T>>, JsValue>;
6881
6882 /// The `Object.getOwnPropertyNames()` method returns an array of
6883 /// all properties (including non-enumerable properties except for
6884 /// those which use Symbol) found directly upon a given object.
6885 ///
6886 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyNames)
6887 #[cfg(not(js_sys_unstable_apis))]
6888 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyNames)]
6889 pub fn get_own_property_names<T>(obj: &Object<T>) -> Array;
6890
6891 /// The `Object.getOwnPropertyNames()` method returns an array of
6892 /// all properties (including non-enumerable properties except for
6893 /// those which use Symbol) found directly upon a given object.
6894 ///
6895 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyNames)
6896 #[cfg(js_sys_unstable_apis)]
6897 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyNames, catch)]
6898 pub fn get_own_property_names<T>(obj: &Object<T>) -> Result<Array<JsString>, JsValue>;
6899
6900 /// The `Object.getOwnPropertySymbols()` method returns an array of
6901 /// all symbol properties found directly upon a given object.
6902 ///
6903 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertySymbols)
6904 #[cfg(not(js_sys_unstable_apis))]
6905 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertySymbols)]
6906 pub fn get_own_property_symbols<T>(obj: &Object<T>) -> Array;
6907
6908 /// The `Object.getOwnPropertySymbols()` method returns an array of
6909 /// all symbol properties found directly upon a given object.
6910 ///
6911 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertySymbols)
6912 #[cfg(js_sys_unstable_apis)]
6913 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertySymbols, catch)]
6914 pub fn get_own_property_symbols<T>(obj: &Object<T>) -> Result<Array<Symbol>, JsValue>;
6915
6916 /// The `Object.getPrototypeOf()` method returns the prototype
6917 /// (i.e. the value of the internal [[Prototype]] property) of the
6918 /// specified object.
6919 ///
6920 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getPrototypeOf)
6921 #[wasm_bindgen(static_method_of = Object, js_name = getPrototypeOf)]
6922 pub fn get_prototype_of(obj: &JsValue) -> Object;
6923
6924 /// The `hasOwnProperty()` method returns a boolean indicating whether the
6925 /// object has the specified property as its own property (as opposed to
6926 /// inheriting it).
6927 ///
6928 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty)
6929 #[deprecated(note = "Use `Object::hasOwn` instead.")]
6930 #[allow(deprecated)]
6931 #[wasm_bindgen(method, js_name = hasOwnProperty)]
6932 pub fn has_own_property<T>(this: &Object<T>, property: &JsValue) -> bool;
6933
6934 /// The `Object.hasOwn()` method returns a boolean indicating whether the
6935 /// object passed in has the specified property as its own property (as
6936 /// opposed to inheriting it).
6937 ///
6938 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn)
6939 #[cfg(not(js_sys_unstable_apis))]
6940 #[wasm_bindgen(static_method_of = Object, js_name = hasOwn)]
6941 pub fn has_own<T>(instance: &Object<T>, property: &JsValue) -> bool;
6942
6943 /// The `Object.hasOwn()` method returns a boolean indicating whether the
6944 /// object passed in has the specified property as its own property (as
6945 /// opposed to inheriting it).
6946 ///
6947 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn)
6948 #[cfg(js_sys_unstable_apis)]
6949 #[wasm_bindgen(static_method_of = Object, js_name = hasOwn, catch)]
6950 pub fn has_own<T>(instance: &Object<T>, property: &JsString) -> Result<bool, JsValue>;
6951
6952 // Next major: deprecate
6953 /// The `Object.hasOwn()` method returns a boolean indicating whether the
6954 /// object passed in has the specified property as its own property (as
6955 /// opposed to inheriting it).
6956 ///
6957 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn)
6958 #[wasm_bindgen(static_method_of = Object, js_name = hasOwn, catch)]
6959 pub fn has_own_str<T>(instance: &Object<T>, property: &JsString) -> Result<bool, JsValue>;
6960
6961 /// The `Object.hasOwn()` method returns a boolean indicating whether the
6962 /// object passed in has the specified property as its own property (as
6963 /// opposed to inheriting it).
6964 ///
6965 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn)
6966 #[wasm_bindgen(static_method_of = Object, js_name = hasOwn, catch)]
6967 pub fn has_own_symbol<T>(instance: &Object<T>, property: &Symbol) -> Result<bool, JsValue>;
6968
6969 /// The `Object.is()` method determines whether two values are the same value.
6970 ///
6971 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is)
6972 #[wasm_bindgen(static_method_of = Object)]
6973 pub fn is(value1: &JsValue, value_2: &JsValue) -> bool;
6974
6975 /// The `Object.isExtensible()` method determines if an object is extensible
6976 /// (whether it can have new properties added to it).
6977 ///
6978 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isExtensible)
6979 #[wasm_bindgen(static_method_of = Object, js_name = isExtensible)]
6980 pub fn is_extensible<T>(object: &Object<T>) -> bool;
6981
6982 /// The `Object.isFrozen()` determines if an object is frozen.
6983 ///
6984 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isFrozen)
6985 #[wasm_bindgen(static_method_of = Object, js_name = isFrozen)]
6986 pub fn is_frozen<T>(object: &Object<T>) -> bool;
6987
6988 /// The `Object.isSealed()` method determines if an object is sealed.
6989 ///
6990 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isSealed)
6991 #[wasm_bindgen(static_method_of = Object, js_name = isSealed)]
6992 pub fn is_sealed<T>(object: &Object<T>) -> bool;
6993
6994 /// The `isPrototypeOf()` method checks if an object exists in another
6995 /// object's prototype chain.
6996 ///
6997 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isPrototypeOf)
6998 #[wasm_bindgen(method, js_name = isPrototypeOf)]
6999 pub fn is_prototype_of<T>(this: &Object<T>, value: &JsValue) -> bool;
7000
7001 /// The `Object.keys()` method returns an array of a given object's property
7002 /// names, in the same order as we get with a normal loop.
7003 ///
7004 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys)
7005 #[cfg(not(js_sys_unstable_apis))]
7006 #[wasm_bindgen(static_method_of = Object)]
7007 pub fn keys<T>(object: &Object<T>) -> Array;
7008
7009 /// The `Object.keys()` method returns an array of a given object's property
7010 /// names, in the same order as we get with a normal loop.
7011 ///
7012 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys)
7013 #[cfg(js_sys_unstable_apis)]
7014 #[wasm_bindgen(static_method_of = Object)]
7015 pub fn keys<T>(object: &Object<T>) -> Array<JsString>;
7016
7017 /// The [`Object`] constructor creates an object wrapper.
7018 ///
7019 /// **Note:** Consider using [`Object::new_typed`] for typed object records.
7020 ///
7021 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)
7022 #[wasm_bindgen(constructor)]
7023 pub fn new() -> Object;
7024
7025 // Next major: deprecate
7026 /// The [`Object`] constructor creates an object wrapper.
7027 ///
7028 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)
7029 #[wasm_bindgen(constructor)]
7030 pub fn new_typed<T>() -> Object<T>;
7031
7032 /// The `Object.preventExtensions()` method prevents new properties from
7033 /// ever being added to an object (i.e. prevents future extensions to the
7034 /// object).
7035 ///
7036 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/preventExtensions)
7037 #[wasm_bindgen(static_method_of = Object, js_name = preventExtensions)]
7038 pub fn prevent_extensions<T>(object: &Object<T>);
7039
7040 /// The `propertyIsEnumerable()` method returns a Boolean indicating
7041 /// whether the specified property is enumerable.
7042 ///
7043 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/propertyIsEnumerable)
7044 #[wasm_bindgen(method, js_name = propertyIsEnumerable)]
7045 pub fn property_is_enumerable<T>(this: &Object<T>, property: &JsValue) -> bool;
7046
7047 /// The `Object.seal()` method seals an object, preventing new properties
7048 /// from being added to it and marking all existing properties as
7049 /// non-configurable. Values of present properties can still be changed as
7050 /// long as they are writable.
7051 ///
7052 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/seal)
7053 #[wasm_bindgen(static_method_of = Object)]
7054 pub fn seal<T>(value: &Object<T>) -> Object<T>;
7055
7056 /// The `Object.setPrototypeOf()` method sets the prototype (i.e., the
7057 /// internal `[[Prototype]]` property) of a specified object to another
7058 /// object or `null`.
7059 ///
7060 /// **Note:** Consider using [`Object::try_set_prototype_of`] to support errors.
7061 ///
7062 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/setPrototypeOf)
7063 #[wasm_bindgen(static_method_of = Object, js_name = setPrototypeOf)]
7064 pub fn set_prototype_of<T>(object: &Object<T>, prototype: &Object) -> Object<T>;
7065
7066 /// The `Object.setPrototypeOf()` method sets the prototype (i.e., the
7067 /// internal `[[Prototype]]` property) of a specified object to another
7068 /// object or `null`.
7069 ///
7070 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/setPrototypeOf)
7071 #[wasm_bindgen(static_method_of = Object, js_name = setPrototypeOf, catch)]
7072 pub fn try_set_prototype_of<T>(
7073 object: &Object<T>,
7074 prototype: &Object,
7075 ) -> Result<Object<T>, JsValue>;
7076
7077 /// The `toLocaleString()` method returns a string representing the object.
7078 /// This method is meant to be overridden by derived objects for
7079 /// locale-specific purposes.
7080 ///
7081 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toLocaleString)
7082 #[wasm_bindgen(method, js_name = toLocaleString)]
7083 pub fn to_locale_string<T>(this: &Object<T>) -> JsString;
7084
7085 // Next major: deprecate
7086 /// The `toString()` method returns a string representing the object.
7087 ///
7088 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString)
7089 #[wasm_bindgen(method, js_name = toString)]
7090 pub fn to_string<T>(this: &Object<T>) -> JsString;
7091
7092 /// The `toString()` method returns a string representing the object.
7093 ///
7094 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString)
7095 #[wasm_bindgen(method, js_name = toString)]
7096 pub fn to_js_string<T>(this: &Object<T>) -> JsString;
7097
7098 /// The `valueOf()` method returns the primitive value of the
7099 /// specified object.
7100 ///
7101 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf)
7102 #[wasm_bindgen(method, js_name = valueOf)]
7103 pub fn value_of<T>(this: &Object<T>) -> Object;
7104
7105 /// The `Object.values()` method returns an array of a given object's own
7106 /// enumerable property values, in the same order as that provided by a
7107 /// `for...in` loop (the difference being that a for-in loop enumerates
7108 /// properties in the prototype chain as well).
7109 ///
7110 /// **Note:** Consider using [`Object::try_values`] to support errors.
7111 ///
7112 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values)
7113 #[cfg(not(js_sys_unstable_apis))]
7114 #[wasm_bindgen(static_method_of = Object)]
7115 pub fn values<T>(object: &Object<T>) -> Array<T>;
7116
7117 /// The `Object.values()` method returns an array of a given object's own
7118 /// enumerable property values, in the same order as that provided by a
7119 /// `for...in` loop (the difference being that a for-in loop enumerates
7120 /// properties in the prototype chain as well).
7121 ///
7122 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values)
7123 #[cfg(js_sys_unstable_apis)]
7124 #[wasm_bindgen(static_method_of = Object, catch, js_name = values)]
7125 pub fn values<T>(object: &Object<T>) -> Result<Array<T>, JsValue>;
7126
7127 // Next major: deprecate
7128 /// The `Object.values()` method returns an array of a given object's own
7129 /// enumerable property values, in the same order as that provided by a
7130 /// `for...in` loop (the difference being that a for-in loop enumerates
7131 /// properties in the prototype chain as well).
7132 ///
7133 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values)
7134 #[cfg(not(js_sys_unstable_apis))]
7135 #[wasm_bindgen(static_method_of = Object, catch, js_name = values)]
7136 pub fn try_values<T>(object: &Object<T>) -> Result<Array<T>, JsValue>;
7137}
7138
7139impl Object {
7140 /// Returns the `Object` value of this JS value if it's an instance of an
7141 /// object.
7142 ///
7143 /// If this JS value is not an instance of an object then this returns
7144 /// `None`.
7145 pub fn try_from(val: &JsValue) -> Option<&Object> {
7146 if val.is_object() {
7147 Some(val.unchecked_ref())
7148 } else {
7149 None
7150 }
7151 }
7152}
7153
7154impl PartialEq for Object {
7155 #[inline]
7156 fn eq(&self, other: &Object) -> bool {
7157 Object::is(self.as_ref(), other.as_ref())
7158 }
7159}
7160
7161impl Eq for Object {}
7162
7163impl Default for Object<JsValue> {
7164 fn default() -> Self {
7165 Self::new()
7166 }
7167}
7168
7169// Proxy
7170#[wasm_bindgen]
7171extern "C" {
7172 #[wasm_bindgen(typescript_type = "ProxyConstructor")]
7173 #[derive(Clone, Debug)]
7174 pub type Proxy;
7175
7176 /// The [`Proxy`] object is used to define custom behavior for fundamental
7177 /// operations (e.g. property lookup, assignment, enumeration, function
7178 /// invocation, etc).
7179 ///
7180 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy)
7181 #[wasm_bindgen(constructor)]
7182 pub fn new(target: &JsValue, handler: &Object) -> Proxy;
7183
7184 /// The `Proxy.revocable()` method is used to create a revocable [`Proxy`]
7185 /// object.
7186 ///
7187 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy/revocable)
7188 #[wasm_bindgen(static_method_of = Proxy)]
7189 pub fn revocable(target: &JsValue, handler: &Object) -> Object;
7190}
7191
7192// RangeError
7193#[wasm_bindgen]
7194extern "C" {
7195 /// The `RangeError` object indicates an error when a value is not in the set
7196 /// or range of allowed values.
7197 ///
7198 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError)
7199 #[wasm_bindgen(extends = Error, extends = Object, typescript_type = "RangeError")]
7200 #[derive(Clone, Debug, PartialEq, Eq)]
7201 pub type RangeError;
7202
7203 /// The `RangeError` object indicates an error when a value is not in the set
7204 /// or range of allowed values.
7205 ///
7206 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError)
7207 #[wasm_bindgen(constructor)]
7208 pub fn new(message: &str) -> RangeError;
7209}
7210
7211// ReferenceError
7212#[wasm_bindgen]
7213extern "C" {
7214 /// The `ReferenceError` object represents an error when a non-existent
7215 /// variable is referenced.
7216 ///
7217 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError)
7218 #[wasm_bindgen(extends = Error, extends = Object, typescript_type = "ReferenceError")]
7219 #[derive(Clone, Debug, PartialEq, Eq)]
7220 pub type ReferenceError;
7221
7222 /// The `ReferenceError` object represents an error when a non-existent
7223 /// variable is referenced.
7224 ///
7225 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError)
7226 #[wasm_bindgen(constructor)]
7227 pub fn new(message: &str) -> ReferenceError;
7228}
7229
7230#[allow(non_snake_case)]
7231pub mod Reflect {
7232 use super::*;
7233
7234 // Reflect
7235 #[wasm_bindgen]
7236 extern "C" {
7237 /// The static `Reflect.apply()` method calls a target function with
7238 /// arguments as specified.
7239 ///
7240 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/apply)
7241 #[wasm_bindgen(js_namespace = Reflect, catch)]
7242 pub fn apply<T: JsFunction = fn() -> JsValue>(
7243 target: &Function<T>,
7244 this_argument: &JsValue,
7245 arguments_list: &Array,
7246 ) -> Result<<T as JsFunction>::Ret, JsValue>;
7247
7248 /// The static `Reflect.construct()` method acts like the new operator, but
7249 /// as a function. It is equivalent to calling `new target(...args)`. It
7250 /// gives also the added option to specify a different prototype.
7251 ///
7252 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/construct)
7253 #[cfg(not(js_sys_unstable_apis))]
7254 #[wasm_bindgen(js_namespace = Reflect, catch)]
7255 pub fn construct<T: JsFunction = fn() -> JsValue>(
7256 target: &Function<T>,
7257 arguments_list: &Array,
7258 ) -> Result<JsValue, JsValue>;
7259
7260 /// The static `Reflect.construct()` method acts like the new operator, but
7261 /// as a function. It is equivalent to calling `new target(...args)`. It
7262 /// gives also the added option to specify a different prototype.
7263 ///
7264 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/construct)
7265 #[cfg(js_sys_unstable_apis)]
7266 #[wasm_bindgen(js_namespace = Reflect, catch)]
7267 pub fn construct<T: JsFunction = fn() -> JsValue>(
7268 target: &Function<T>,
7269 arguments_list: &ArrayTuple, // DOTO: <A1, A2, A3, A4, A5, A6, A7, A8>,
7270 ) -> Result<JsValue, JsValue>;
7271
7272 /// The static `Reflect.construct()` method acts like the new operator, but
7273 /// as a function. It is equivalent to calling `new target(...args)`. It
7274 /// gives also the added option to specify a different prototype.
7275 ///
7276 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/construct)
7277 #[wasm_bindgen(js_namespace = Reflect, js_name = construct, catch)]
7278 pub fn construct_with_new_target(
7279 target: &Function,
7280 arguments_list: &Array,
7281 new_target: &Function,
7282 ) -> Result<JsValue, JsValue>;
7283
7284 /// The static `Reflect.defineProperty()` method is like
7285 /// `Object.defineProperty()` but returns a `Boolean`.
7286 ///
7287 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/defineProperty)
7288 #[cfg(not(js_sys_unstable_apis))]
7289 #[wasm_bindgen(js_namespace = Reflect, js_name = defineProperty, catch)]
7290 pub fn define_property<T>(
7291 target: &Object<T>,
7292 property_key: &JsValue,
7293 attributes: &Object,
7294 ) -> Result<bool, JsValue>;
7295
7296 /// The static `Reflect.defineProperty()` method is like
7297 /// `Object.defineProperty()` but returns a `Boolean`.
7298 ///
7299 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/defineProperty)
7300 #[cfg(js_sys_unstable_apis)]
7301 #[wasm_bindgen(js_namespace = Reflect, js_name = defineProperty, catch)]
7302 pub fn define_property<T>(
7303 target: &Object<T>,
7304 property_key: &JsValue,
7305 attributes: &PropertyDescriptor<T>,
7306 ) -> Result<bool, JsValue>;
7307
7308 /// The static `Reflect.defineProperty()` method is like
7309 /// `Object.defineProperty()` but returns a `Boolean`.
7310 ///
7311 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/defineProperty)
7312 #[wasm_bindgen(js_namespace = Reflect, js_name = defineProperty, catch)]
7313 pub fn define_property_str<T>(
7314 target: &Object<T>,
7315 property_key: &JsString,
7316 attributes: &PropertyDescriptor<T>,
7317 ) -> Result<bool, JsValue>;
7318
7319 /// The static `Reflect.deleteProperty()` method allows to delete
7320 /// properties. It is like the `delete` operator as a function.
7321 ///
7322 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/deleteProperty)
7323 #[wasm_bindgen(js_namespace = Reflect, js_name = deleteProperty, catch)]
7324 pub fn delete_property<T>(target: &Object<T>, key: &JsValue) -> Result<bool, JsValue>;
7325
7326 /// The static `Reflect.deleteProperty()` method allows to delete
7327 /// properties. It is like the `delete` operator as a function.
7328 ///
7329 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/deleteProperty)
7330 #[wasm_bindgen(js_namespace = Reflect, js_name = deleteProperty, catch)]
7331 pub fn delete_property_str<T>(target: &Object<T>, key: &JsString) -> Result<bool, JsValue>;
7332
7333 /// The static `Reflect.get()` method works like getting a property from
7334 /// an object (`target[propertyKey]`) as a function.
7335 ///
7336 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/get)
7337 #[cfg(not(js_sys_unstable_apis))]
7338 #[wasm_bindgen(js_namespace = Reflect, catch)]
7339 pub fn get(target: &JsValue, key: &JsValue) -> Result<JsValue, JsValue>;
7340
7341 /// The static `Reflect.get()` method works like getting a property from
7342 /// an object (`target[propertyKey]`) as a function.
7343 ///
7344 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/get)
7345 #[cfg(js_sys_unstable_apis)]
7346 #[wasm_bindgen(js_namespace = Reflect, catch)]
7347 pub fn get<T>(target: &Object<T>, key: &JsString) -> Result<Option<T>, JsValue>;
7348
7349 /// The static `Reflect.get()` method works like getting a property from
7350 /// an object (`target[propertyKey]`) as a function.
7351 ///
7352 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/get)
7353 #[wasm_bindgen(js_namespace = Reflect, js_name = get, catch)]
7354 pub fn get_str<T>(target: &Object<T>, key: &JsString) -> Result<Option<T>, JsValue>;
7355
7356 /// The static `Reflect.get()` method works like getting a property from
7357 /// an object (`target[propertyKey]`) as a function.
7358 ///
7359 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/get)
7360 #[wasm_bindgen(js_namespace = Reflect, js_name = get, catch)]
7361 pub fn get_symbol<T>(target: &Object<T>, key: &Symbol) -> Result<JsValue, JsValue>;
7362
7363 /// The same as [`get`](fn.get.html)
7364 /// except the key is an `f64`, which is slightly faster.
7365 #[wasm_bindgen(js_namespace = Reflect, js_name = get, catch)]
7366 pub fn get_f64(target: &JsValue, key: f64) -> Result<JsValue, JsValue>;
7367
7368 /// The same as [`get`](fn.get.html)
7369 /// except the key is a `u32`, which is slightly faster.
7370 #[wasm_bindgen(js_namespace = Reflect, js_name = get, catch)]
7371 pub fn get_u32(target: &JsValue, key: u32) -> Result<JsValue, JsValue>;
7372
7373 /// The static `Reflect.getOwnPropertyDescriptor()` method is similar to
7374 /// `Object.getOwnPropertyDescriptor()`. It returns a property descriptor
7375 /// of the given property if it exists on the object, `undefined` otherwise.
7376 ///
7377 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getOwnPropertyDescriptor)
7378 #[wasm_bindgen(js_namespace = Reflect, js_name = getOwnPropertyDescriptor, catch)]
7379 pub fn get_own_property_descriptor<T>(
7380 target: &Object<T>,
7381 property_key: &JsValue,
7382 ) -> Result<JsValue, JsValue>;
7383
7384 /// The static `Reflect.getOwnPropertyDescriptor()` method is similar to
7385 /// `Object.getOwnPropertyDescriptor()`. It returns a property descriptor
7386 /// of the given property if it exists on the object, `undefined` otherwise.
7387 ///
7388 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getOwnPropertyDescriptor)
7389 #[wasm_bindgen(js_namespace = Reflect, js_name = getOwnPropertyDescriptor, catch)]
7390 pub fn get_own_property_descriptor_str<T>(
7391 target: &Object<T>,
7392 property_key: &JsString,
7393 ) -> Result<PropertyDescriptor<T>, JsValue>;
7394
7395 /// The static `Reflect.getPrototypeOf()` method is almost the same
7396 /// method as `Object.getPrototypeOf()`. It returns the prototype
7397 /// (i.e. the value of the internal `[[Prototype]]` property) of
7398 /// the specified object.
7399 ///
7400 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getPrototypeOf)
7401 #[cfg(not(js_sys_unstable_apis))]
7402 #[wasm_bindgen(js_namespace = Reflect, js_name = getPrototypeOf, catch)]
7403 pub fn get_prototype_of(target: &JsValue) -> Result<Object, JsValue>;
7404
7405 /// The static `Reflect.getPrototypeOf()` method is almost the same
7406 /// method as `Object.getPrototypeOf()`. It returns the prototype
7407 /// (i.e. the value of the internal `[[Prototype]]` property) of
7408 /// the specified object.
7409 ///
7410 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getPrototypeOf)
7411 #[cfg(js_sys_unstable_apis)]
7412 #[wasm_bindgen(js_namespace = Reflect, js_name = getPrototypeOf, catch)]
7413 pub fn get_prototype_of(target: &Object) -> Result<Object, JsValue>;
7414
7415 /// The static `Reflect.has()` method works like the in operator as a
7416 /// function.
7417 ///
7418 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/has)
7419 #[cfg(not(js_sys_unstable_apis))]
7420 #[wasm_bindgen(js_namespace = Reflect, catch)]
7421 pub fn has(target: &JsValue, property_key: &JsValue) -> Result<bool, JsValue>;
7422
7423 /// The static `Reflect.has()` method works like the in operator as a
7424 /// function.
7425 ///
7426 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/has)
7427 #[cfg(js_sys_unstable_apis)]
7428 #[wasm_bindgen(js_namespace = Reflect, catch)]
7429 pub fn has(target: &JsValue, property_key: &Symbol) -> Result<bool, JsValue>;
7430
7431 // Next major: deprecate
7432 /// The static `Reflect.has()` method works like the in operator as a
7433 /// function.
7434 ///
7435 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/has)
7436 #[wasm_bindgen(js_namespace = Reflect, js_name = has, catch)]
7437 pub fn has_str<T>(target: &Object<T>, property_key: &JsString) -> Result<bool, JsValue>;
7438
7439 /// The static `Reflect.has()` method works like the in operator as a
7440 /// function.
7441 ///
7442 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/has)
7443 #[wasm_bindgen(js_namespace = Reflect, js_name = has, catch)]
7444 pub fn has_symbol<T>(target: &Object<T>, property_key: &Symbol) -> Result<bool, JsValue>;
7445
7446 /// The static `Reflect.isExtensible()` method determines if an object is
7447 /// extensible (whether it can have new properties added to it). It is
7448 /// similar to `Object.isExtensible()`, but with some differences.
7449 ///
7450 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/isExtensible)
7451 #[wasm_bindgen(js_namespace = Reflect, js_name = isExtensible, catch)]
7452 pub fn is_extensible<T>(target: &Object<T>) -> Result<bool, JsValue>;
7453
7454 /// The static `Reflect.ownKeys()` method returns an array of the
7455 /// target object's own property keys.
7456 ///
7457 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/ownKeys)
7458 #[wasm_bindgen(js_namespace = Reflect, js_name = ownKeys, catch)]
7459 pub fn own_keys(target: &JsValue) -> Result<Array, JsValue>;
7460
7461 /// The static `Reflect.preventExtensions()` method prevents new
7462 /// properties from ever being added to an object (i.e. prevents
7463 /// future extensions to the object). It is similar to
7464 /// `Object.preventExtensions()`, but with some differences.
7465 ///
7466 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/preventExtensions)
7467 #[wasm_bindgen(js_namespace = Reflect, js_name = preventExtensions, catch)]
7468 pub fn prevent_extensions<T>(target: &Object<T>) -> Result<bool, JsValue>;
7469
7470 /// The static `Reflect.set()` method works like setting a
7471 /// property on an object.
7472 ///
7473 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
7474 #[cfg(not(js_sys_unstable_apis))]
7475 #[wasm_bindgen(js_namespace = Reflect, catch)]
7476 pub fn set(
7477 target: &JsValue,
7478 property_key: &JsValue,
7479 value: &JsValue,
7480 ) -> Result<bool, JsValue>;
7481
7482 /// The static `Reflect.set()` method works like setting a
7483 /// property on an object.
7484 ///
7485 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
7486 #[cfg(js_sys_unstable_apis)]
7487 #[wasm_bindgen(js_namespace = Reflect, catch)]
7488 pub fn set<T>(
7489 target: &Object<T>,
7490 property_key: &JsString,
7491 value: &T,
7492 ) -> Result<bool, JsValue>;
7493
7494 /// The static `Reflect.set()` method works like setting a
7495 /// property on an object.
7496 ///
7497 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
7498 #[cfg(js_sys_unstable_apis)]
7499 #[wasm_bindgen(js_namespace = Reflect, catch)]
7500 pub fn set_symbol<T>(
7501 target: &Object<T>,
7502 property_key: &Symbol,
7503 value: &JsValue,
7504 ) -> Result<bool, JsValue>;
7505
7506 // Next major: deprecate
7507 /// The static `Reflect.set()` method works like setting a
7508 /// property on an object.
7509 ///
7510 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
7511 #[wasm_bindgen(js_namespace = Reflect, js_name = set, catch)]
7512 pub fn set_str<T>(
7513 target: &Object<T>,
7514 property_key: &JsString,
7515 value: &T,
7516 ) -> Result<bool, JsValue>;
7517
7518 /// The same as [`set`](fn.set.html)
7519 /// except the key is an `f64`, which is slightly faster.
7520 #[wasm_bindgen(js_namespace = Reflect, js_name = set, catch)]
7521 pub fn set_f64(
7522 target: &JsValue,
7523 property_key: f64,
7524 value: &JsValue,
7525 ) -> Result<bool, JsValue>;
7526
7527 /// The same as [`set`](fn.set.html)
7528 /// except the key is a `u32`, which is slightly faster.
7529 #[wasm_bindgen(js_namespace = Reflect, js_name = set, catch)]
7530 pub fn set_u32(
7531 target: &JsValue,
7532 property_key: u32,
7533 value: &JsValue,
7534 ) -> Result<bool, JsValue>;
7535
7536 /// The static `Reflect.set()` method works like setting a
7537 /// property on an object.
7538 ///
7539 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
7540 #[wasm_bindgen(js_namespace = Reflect, js_name = set, catch)]
7541 pub fn set_with_receiver(
7542 target: &JsValue,
7543 property_key: &JsValue,
7544 value: &JsValue,
7545 receiver: &JsValue,
7546 ) -> Result<bool, JsValue>;
7547
7548 /// The static `Reflect.setPrototypeOf()` method is the same
7549 /// method as `Object.setPrototypeOf()`. It sets the prototype
7550 /// (i.e., the internal `[[Prototype]]` property) of a specified
7551 /// object to another object or to null.
7552 ///
7553 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/setPrototypeOf)
7554 #[wasm_bindgen(js_namespace = Reflect, js_name = setPrototypeOf, catch)]
7555 pub fn set_prototype_of<T>(
7556 target: &Object<T>,
7557 prototype: &JsValue,
7558 ) -> Result<bool, JsValue>;
7559 }
7560}
7561
7562// RegExp
7563#[wasm_bindgen]
7564extern "C" {
7565 #[wasm_bindgen(extends = Object, typescript_type = "RegExp")]
7566 #[derive(Clone, Debug, PartialEq, Eq)]
7567 pub type RegExp;
7568
7569 /// The `exec()` method executes a search for a match in a specified
7570 /// string. Returns a result array, or null.
7571 ///
7572 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec)
7573 #[cfg(not(js_sys_unstable_apis))]
7574 #[wasm_bindgen(method)]
7575 pub fn exec(this: &RegExp, text: &str) -> Option<Array<JsString>>;
7576
7577 /// The `exec()` method executes a search for a match in a specified
7578 /// string. Returns a result array, or null.
7579 ///
7580 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec)
7581 #[cfg(js_sys_unstable_apis)]
7582 #[wasm_bindgen(method)]
7583 pub fn exec(this: &RegExp, text: &str) -> Option<RegExpMatchArray>;
7584
7585 /// The flags property returns a string consisting of the flags of
7586 /// the current regular expression object.
7587 ///
7588 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/flags)
7589 #[wasm_bindgen(method, getter)]
7590 pub fn flags(this: &RegExp) -> JsString;
7591
7592 /// The global property indicates whether or not the "g" flag is
7593 /// used with the regular expression. global is a read-only
7594 /// property of an individual regular expression instance.
7595 ///
7596 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/global)
7597 #[wasm_bindgen(method, getter)]
7598 pub fn global(this: &RegExp) -> bool;
7599
7600 /// The ignoreCase property indicates whether or not the "i" flag
7601 /// is used with the regular expression. ignoreCase is a read-only
7602 /// property of an individual regular expression instance.
7603 ///
7604 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/ignoreCase)
7605 #[wasm_bindgen(method, getter, js_name = ignoreCase)]
7606 pub fn ignore_case(this: &RegExp) -> bool;
7607
7608 /// The non-standard input property is a static property of
7609 /// regular expressions that contains the string against which a
7610 /// regular expression is matched. RegExp.$_ is an alias for this
7611 /// property.
7612 ///
7613 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/input)
7614 #[wasm_bindgen(static_method_of = RegExp, getter)]
7615 pub fn input() -> JsString;
7616
7617 /// The lastIndex is a read/write integer property of regular expression
7618 /// instances that specifies the index at which to start the next match.
7619 ///
7620 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex)
7621 #[wasm_bindgen(structural, getter = lastIndex, method)]
7622 pub fn last_index(this: &RegExp) -> u32;
7623
7624 /// The lastIndex is a read/write integer property of regular expression
7625 /// instances that specifies the index at which to start the next match.
7626 ///
7627 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex)
7628 #[wasm_bindgen(structural, setter = lastIndex, method)]
7629 pub fn set_last_index(this: &RegExp, index: u32);
7630
7631 /// The non-standard lastMatch property is a static and read-only
7632 /// property of regular expressions that contains the last matched
7633 /// characters. `RegExp.$&` is an alias for this property.
7634 ///
7635 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastMatch)
7636 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = lastMatch)]
7637 pub fn last_match() -> JsString;
7638
7639 /// The non-standard lastParen property is a static and read-only
7640 /// property of regular expressions that contains the last
7641 /// parenthesized substring match, if any. `RegExp.$+` is an alias
7642 /// for this property.
7643 ///
7644 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastParen)
7645 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = lastParen)]
7646 pub fn last_paren() -> JsString;
7647
7648 /// The non-standard leftContext property is a static and
7649 /// read-only property of regular expressions that contains the
7650 /// substring preceding the most recent match. `RegExp.$`` is an
7651 /// alias for this property.
7652 ///
7653 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/leftContext)
7654 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = leftContext)]
7655 pub fn left_context() -> JsString;
7656
7657 /// The multiline property indicates whether or not the "m" flag
7658 /// is used with the regular expression. multiline is a read-only
7659 /// property of an individual regular expression instance.
7660 ///
7661 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/multiline)
7662 #[wasm_bindgen(method, getter)]
7663 pub fn multiline(this: &RegExp) -> bool;
7664
7665 /// The non-standard $1, $2, $3, $4, $5, $6, $7, $8, $9 properties
7666 /// are static and read-only properties of regular expressions
7667 /// that contain parenthesized substring matches.
7668 ///
7669 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/n)
7670 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$1")]
7671 pub fn n1() -> JsString;
7672 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$2")]
7673 pub fn n2() -> JsString;
7674 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$3")]
7675 pub fn n3() -> JsString;
7676 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$4")]
7677 pub fn n4() -> JsString;
7678 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$5")]
7679 pub fn n5() -> JsString;
7680 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$6")]
7681 pub fn n6() -> JsString;
7682 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$7")]
7683 pub fn n7() -> JsString;
7684 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$8")]
7685 pub fn n8() -> JsString;
7686 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$9")]
7687 pub fn n9() -> JsString;
7688
7689 /// The `RegExp` constructor creates a regular expression object for matching text with a pattern.
7690 ///
7691 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp)
7692 #[wasm_bindgen(constructor)]
7693 pub fn new(pattern: &str, flags: &str) -> RegExp;
7694 #[wasm_bindgen(constructor)]
7695 pub fn new_regexp(pattern: &RegExp, flags: &str) -> RegExp;
7696
7697 /// The non-standard rightContext property is a static and
7698 /// read-only property of regular expressions that contains the
7699 /// substring following 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/rightContext)
7703 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = rightContext)]
7704 pub fn right_context() -> JsString;
7705
7706 /// The source property returns a String containing the source
7707 /// text of the regexp object, and it doesn't contain the two
7708 /// forward slashes on both sides and any flags.
7709 ///
7710 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/source)
7711 #[wasm_bindgen(method, getter)]
7712 pub fn source(this: &RegExp) -> JsString;
7713
7714 /// The sticky property reflects whether or not the search is
7715 /// sticky (searches in strings only from the index indicated by
7716 /// the lastIndex property of this regular expression). sticky is
7717 /// a read-only property of an individual regular expression
7718 /// object.
7719 ///
7720 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/sticky)
7721 #[wasm_bindgen(method, getter)]
7722 pub fn sticky(this: &RegExp) -> bool;
7723
7724 /// The `test()` method executes a search for a match between a
7725 /// regular expression and a specified string. Returns true or
7726 /// false.
7727 ///
7728 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/test)
7729 #[wasm_bindgen(method)]
7730 pub fn test(this: &RegExp, text: &str) -> bool;
7731
7732 /// The `toString()` method returns a string representing the
7733 /// regular expression.
7734 ///
7735 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/toString)
7736 #[cfg(not(js_sys_unstable_apis))]
7737 #[wasm_bindgen(method, js_name = toString)]
7738 pub fn to_string(this: &RegExp) -> JsString;
7739
7740 /// The unicode property indicates whether or not the "u" flag is
7741 /// used with a regular expression. unicode is a read-only
7742 /// property of an individual regular expression instance.
7743 ///
7744 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/unicode)
7745 #[wasm_bindgen(method, getter)]
7746 pub fn unicode(this: &RegExp) -> bool;
7747}
7748
7749// RegExpMatchArray
7750#[wasm_bindgen]
7751extern "C" {
7752 /// The result array from `RegExp.exec()` or `String.matchAll()`.
7753 ///
7754 /// This is an array of strings with additional properties `index`, `input`, and `groups`.
7755 ///
7756 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec#return_value)
7757 #[wasm_bindgen(extends = Object, extends = Array, typescript_type = "RegExpMatchArray")]
7758 #[derive(Clone, Debug, PartialEq, Eq)]
7759 pub type RegExpMatchArray;
7760
7761 /// The 0-based index of the match in the string.
7762 #[wasm_bindgen(method, getter)]
7763 pub fn index(this: &RegExpMatchArray) -> u32;
7764
7765 /// The original string that was matched against.
7766 #[wasm_bindgen(method, getter)]
7767 pub fn input(this: &RegExpMatchArray) -> JsString;
7768
7769 /// An object of named capturing groups whose keys are the names and valuestype Array
7770 /// are the capturing groups, or `undefined` if no named capturing groups were defined.
7771 #[wasm_bindgen(method, getter)]
7772 pub fn groups(this: &RegExpMatchArray) -> Option<Object>;
7773
7774 /// The number of elements in the match array (full match + capture groups).
7775 #[wasm_bindgen(method, getter)]
7776 pub fn length(this: &RegExpMatchArray) -> u32;
7777
7778 /// Gets the matched string or capture group at the given index.
7779 /// Index 0 is the full match, indices 1+ are capture groups.
7780 #[wasm_bindgen(method, indexing_getter)]
7781 pub fn get(this: &RegExpMatchArray, index: u32) -> Option<JsString>;
7782}
7783
7784// Set
7785#[wasm_bindgen]
7786extern "C" {
7787 #[wasm_bindgen(extends = Object, typescript_type = "Set<any>")]
7788 #[derive(Clone, Debug, PartialEq, Eq)]
7789 pub type Set<T = JsValue>;
7790
7791 /// The [`Set`] object lets you store unique values of any type, whether
7792 /// primitive values or object references.
7793 ///
7794 /// **Note:** Consider using [`Set::new_typed`] to support typing.
7795 ///
7796 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
7797 #[cfg(not(js_sys_unstable_apis))]
7798 #[wasm_bindgen(constructor)]
7799 pub fn new(init: &JsValue) -> Set;
7800
7801 /// The [`Set`] object lets you store unique values of any type, whether
7802 /// primitive values or object references.
7803 ///
7804 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
7805 #[cfg(js_sys_unstable_apis)]
7806 #[wasm_bindgen(constructor)]
7807 pub fn new<T>() -> Set<T>;
7808
7809 // Next major: deprecate
7810 /// The [`Set`] object lets you store unique values of any type, whether
7811 /// primitive values or object references.
7812 ///
7813 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
7814 #[wasm_bindgen(constructor)]
7815 pub fn new_typed<T>() -> Set<T>;
7816
7817 /// The [`Set`] object lets you store unique values of any type, whether
7818 /// primitive values or object references.
7819 ///
7820 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
7821 #[wasm_bindgen(constructor, js_name = new)]
7822 pub fn new_empty<T>() -> Set<T>;
7823
7824 /// The [`Set`] object lets you store unique values of any type, whether
7825 /// primitive values or object references.
7826 ///
7827 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
7828 #[wasm_bindgen(constructor, js_name = new)]
7829 pub fn new_from_items<T>(items: &[T]) -> Set<T>;
7830
7831 /// The [`Set`] object lets you store unique values of any type, whether
7832 /// primitive values or object references.
7833 ///
7834 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
7835 #[wasm_bindgen(constructor, js_name = new, catch)]
7836 pub fn new_from_iterable<T, I: Iterable<Item = T>>(iterable: I) -> Result<Set<T>, JsValue>;
7837
7838 /// The `add()` method appends a new element with a specified value to the
7839 /// end of a [`Set`] object.
7840 ///
7841 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/add)
7842 #[wasm_bindgen(method)]
7843 pub fn add<T>(this: &Set<T>, value: &T) -> Set<T>;
7844
7845 /// The `clear()` method removes all elements from a [`Set`] object.
7846 ///
7847 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/clear)
7848 #[wasm_bindgen(method)]
7849 pub fn clear<T>(this: &Set<T>);
7850
7851 /// The `delete()` method removes the specified element from a [`Set`]
7852 /// object.
7853 ///
7854 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/delete)
7855 #[wasm_bindgen(method)]
7856 pub fn delete<T>(this: &Set<T>, value: &T) -> bool;
7857
7858 /// The `forEach()` method executes a provided function once for each value
7859 /// in the Set object, in insertion order.
7860 ///
7861 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/forEach)
7862 #[cfg(not(js_sys_unstable_apis))]
7863 #[wasm_bindgen(method, js_name = forEach)]
7864 pub fn for_each<T>(this: &Set<T>, callback: &mut dyn FnMut(T, T, Set<T>));
7865
7866 /// The `forEach()` method executes a provided function once for each value
7867 /// in the Set object, in insertion order.
7868 ///
7869 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/forEach)
7870 #[cfg(js_sys_unstable_apis)]
7871 #[wasm_bindgen(method, js_name = forEach)]
7872 pub fn for_each<T>(this: &Set<T>, callback: &mut dyn FnMut(T));
7873
7874 /// The `forEach()` method executes a provided function once for each value
7875 /// in the Set object, in insertion order.
7876 ///
7877 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/forEach)
7878 #[wasm_bindgen(method, js_name = forEach, catch)]
7879 pub fn try_for_each<T>(
7880 this: &Set<T>,
7881 callback: &mut dyn FnMut(T) -> Result<(), JsError>,
7882 ) -> Result<(), JsValue>;
7883
7884 /// The `has()` method returns a boolean indicating whether an element with
7885 /// the specified value exists in a [`Set`] object or not.
7886 ///
7887 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/has)
7888 #[wasm_bindgen(method)]
7889 pub fn has<T>(this: &Set<T>, value: &T) -> bool;
7890
7891 /// The size accessor property returns the number of elements in a [`Set`]
7892 /// object.
7893 ///
7894 /// [MDN documentation](https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Set/size)
7895 #[wasm_bindgen(method, getter)]
7896 pub fn size<T>(this: &Set<T>) -> u32;
7897
7898 /// The `union()` method returns a new set containing elements which are in
7899 /// either or both of this set and the given set.
7900 ///
7901 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/union)
7902 #[wasm_bindgen(method)]
7903 pub fn union<T>(this: &Set<T>, other: &Set<T>) -> Set<T>;
7904
7905 /// The `intersection()` method returns a new set containing elements which are
7906 /// in both this set and the given set.
7907 ///
7908 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/intersection)
7909 #[wasm_bindgen(method)]
7910 pub fn intersection<T>(this: &Set<T>, other: &Set<T>) -> Set<T>;
7911
7912 /// The `difference()` method returns a new set containing elements which are
7913 /// in this set but not in the given set.
7914 ///
7915 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/difference)
7916 #[wasm_bindgen(method)]
7917 pub fn difference<T>(this: &Set<T>, other: &Set<T>) -> Set<T>;
7918
7919 /// The `symmetricDifference()` method returns a new set containing elements
7920 /// which are in either this set or the given set, but not in both.
7921 ///
7922 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/symmetricDifference)
7923 #[wasm_bindgen(method, js_name = symmetricDifference)]
7924 pub fn symmetric_difference<T>(this: &Set<T>, other: &Set<T>) -> Set<T>;
7925
7926 /// The `isSubsetOf()` method returns a boolean indicating whether all elements
7927 /// of this set are in the given set.
7928 ///
7929 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/isSubsetOf)
7930 #[wasm_bindgen(method, js_name = isSubsetOf)]
7931 pub fn is_subset_of<T>(this: &Set<T>, other: &Set<T>) -> bool;
7932
7933 /// The `isSupersetOf()` method returns a boolean indicating whether all elements
7934 /// of the given set are in this set.
7935 ///
7936 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/isSupersetOf)
7937 #[wasm_bindgen(method, js_name = isSupersetOf)]
7938 pub fn is_superset_of<T>(this: &Set<T>, other: &Set<T>) -> bool;
7939
7940 /// The `isDisjointFrom()` method returns a boolean indicating whether this set
7941 /// has no elements in common with the given set.
7942 ///
7943 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/isDisjointFrom)
7944 #[wasm_bindgen(method, js_name = isDisjointFrom)]
7945 pub fn is_disjoint_from<T>(this: &Set<T>, other: &Set<T>) -> bool;
7946}
7947
7948impl Default for Set<JsValue> {
7949 fn default() -> Self {
7950 Self::new_typed()
7951 }
7952}
7953
7954impl<T> Iterable for Set<T> {
7955 type Item = T;
7956}
7957
7958// SetIterator
7959#[wasm_bindgen]
7960extern "C" {
7961 /// The `entries()` method returns a new Iterator object that contains an
7962 /// array of [value, value] for each element in the Set object, in insertion
7963 /// order. For Set objects there is no key like in Map objects. However, to
7964 /// keep the API similar to the Map object, each entry has the same value
7965 /// for its key and value here, so that an array [value, value] is returned.
7966 ///
7967 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/entries)
7968 #[cfg(not(js_sys_unstable_apis))]
7969 #[wasm_bindgen(method)]
7970 pub fn entries<T>(set: &Set<T>) -> Iterator;
7971
7972 /// The `entries()` method returns a new Iterator object that contains an
7973 /// array of [value, value] for each element in the Set object, in insertion
7974 /// order. For Set objects there is no key like in Map objects. However, to
7975 /// keep the API similar to the Map object, each entry has the same value
7976 /// for its key and value here, so that an array [value, value] is returned.
7977 ///
7978 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/entries)
7979 #[cfg(js_sys_unstable_apis)]
7980 #[wasm_bindgen(method, js_name = entries)]
7981 pub fn entries<T: JsGeneric>(set: &Set<T>) -> Iterator<ArrayTuple<(T, T)>>;
7982
7983 // Next major: deprecate
7984 /// The `entries()` method returns a new Iterator object that contains an
7985 /// array of [value, value] for each element in the Set object, in insertion
7986 /// order. For Set objects there is no key like in Map objects. However, to
7987 /// keep the API similar to the Map object, each entry has the same value
7988 /// for its key and value here, so that an array [value, value] is returned.
7989 ///
7990 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/entries)
7991 #[wasm_bindgen(method, js_name = entries)]
7992 pub fn entries_typed<T: JsGeneric>(set: &Set<T>) -> Iterator<ArrayTuple<(T, T)>>;
7993
7994 /// The `keys()` method is an alias for this method (for similarity with
7995 /// Map objects); it behaves exactly the same and returns values
7996 /// of Set elements.
7997 ///
7998 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/values)
7999 #[wasm_bindgen(method)]
8000 pub fn keys<T>(set: &Set<T>) -> Iterator<T>;
8001
8002 /// The `values()` method returns a new Iterator object that contains the
8003 /// values for each element in the Set object in insertion order.
8004 ///
8005 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/values)
8006 #[wasm_bindgen(method)]
8007 pub fn values<T>(set: &Set<T>) -> Iterator<T>;
8008}
8009
8010// SyntaxError
8011#[wasm_bindgen]
8012extern "C" {
8013 /// A `SyntaxError` is thrown when the JavaScript engine encounters tokens or
8014 /// token order that does not conform to the syntax of the language when
8015 /// parsing code.
8016 ///
8017 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError)
8018 #[wasm_bindgen(extends = Error, extends = Object, typescript_type = "SyntaxError")]
8019 #[derive(Clone, Debug, PartialEq, Eq)]
8020 pub type SyntaxError;
8021
8022 /// A `SyntaxError` is thrown when the JavaScript engine encounters tokens or
8023 /// token order that does not conform to the syntax of the language when
8024 /// parsing code.
8025 ///
8026 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError)
8027 #[wasm_bindgen(constructor)]
8028 pub fn new(message: &str) -> SyntaxError;
8029}
8030
8031// TypeError
8032#[wasm_bindgen]
8033extern "C" {
8034 /// The `TypeError` object represents an error when a value is not of the
8035 /// expected type.
8036 ///
8037 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError)
8038 #[wasm_bindgen(extends = Error, extends = Object, typescript_type = "TypeError")]
8039 #[derive(Clone, Debug, PartialEq, Eq)]
8040 pub type TypeError;
8041
8042 /// The `TypeError` object represents an error when a value is not of the
8043 /// expected type.
8044 ///
8045 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError)
8046 #[wasm_bindgen(constructor)]
8047 pub fn new(message: &str) -> TypeError;
8048}
8049
8050// URIError
8051#[wasm_bindgen]
8052extern "C" {
8053 /// The `URIError` object represents an error when a global URI handling
8054 /// function was used in a wrong way.
8055 ///
8056 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError)
8057 #[wasm_bindgen(extends = Error, extends = Object, js_name = URIError, typescript_type = "URIError")]
8058 #[derive(Clone, Debug, PartialEq, Eq)]
8059 pub type UriError;
8060
8061 /// The `URIError` object represents an error when a global URI handling
8062 /// function was used in a wrong way.
8063 ///
8064 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError)
8065 #[wasm_bindgen(constructor, js_class = "URIError")]
8066 pub fn new(message: &str) -> UriError;
8067}
8068
8069// WeakMap
8070#[wasm_bindgen]
8071extern "C" {
8072 #[wasm_bindgen(extends = Object, typescript_type = "WeakMap<object, any>")]
8073 #[derive(Clone, Debug, PartialEq, Eq)]
8074 pub type WeakMap<K = Object, V = JsValue>;
8075
8076 /// The [`WeakMap`] object is a collection of key/value pairs in which the
8077 /// keys are weakly referenced. The keys must be objects and the values can
8078 /// be arbitrary values.
8079 ///
8080 /// **Note:** Consider using [`WeakMap::new_typed`] to support typing.
8081 ///
8082 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap)
8083 #[cfg(not(js_sys_unstable_apis))]
8084 #[wasm_bindgen(constructor)]
8085 pub fn new() -> WeakMap;
8086
8087 /// The [`WeakMap`] object is a collection of key/value pairs in which the
8088 /// keys are weakly referenced. The keys must be objects and the values can
8089 /// be arbitrary values.
8090 ///
8091 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap)
8092 #[cfg(js_sys_unstable_apis)]
8093 #[wasm_bindgen(constructor)]
8094 pub fn new<K: JsGeneric = Object, V: JsGeneric = Object>() -> WeakMap<K, V>;
8095
8096 // Next major: deprecate
8097 /// The [`WeakMap`] object is a collection of key/value pairs in which the
8098 /// keys are weakly referenced. The keys must be objects and the values can
8099 /// be arbitrary values.
8100 ///
8101 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap)
8102 #[wasm_bindgen(constructor)]
8103 pub fn new_typed<K: JsGeneric = Object, V: JsGeneric = Object>() -> WeakMap<K, V>;
8104
8105 /// The `set()` method sets the value for the key in the [`WeakMap`] object.
8106 /// Returns the [`WeakMap`] object.
8107 ///
8108 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/set)
8109 #[wasm_bindgen(method, js_class = "WeakMap")]
8110 pub fn set<K, V>(this: &WeakMap<K, V>, key: &K, value: &V) -> WeakMap<K, V>;
8111
8112 /// The `get()` method returns a specified by key element
8113 /// from a [`WeakMap`] object. Returns `undefined` if the key is not found.
8114 ///
8115 /// **Note:** Consider using [`WeakMap::get_checked`] to get an `Option<V>` instead.
8116 ///
8117 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/get)
8118 #[cfg(not(js_sys_unstable_apis))]
8119 #[wasm_bindgen(method)]
8120 pub fn get<K, V>(this: &WeakMap<K, V>, key: &K) -> V;
8121
8122 /// The `get()` method returns a specified by key element
8123 /// from a [`WeakMap`] object. Returns `None` if the key is not found.
8124 ///
8125 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/get)
8126 #[cfg(js_sys_unstable_apis)]
8127 #[wasm_bindgen(method)]
8128 pub fn get<K, V>(this: &WeakMap<K, V>, key: &K) -> Option<V>;
8129
8130 /// The `get()` method returns a specified by key element
8131 /// from a [`WeakMap`] object. Returns `None` if the key is not found.
8132 ///
8133 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/get)
8134 #[wasm_bindgen(method, js_name = get)]
8135 pub fn get_checked<K, V>(this: &WeakMap<K, V>, key: &K) -> Option<V>;
8136
8137 /// The `has()` method returns a boolean indicating whether an element with
8138 /// the specified key exists in the [`WeakMap`] object or not.
8139 ///
8140 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/has)
8141 #[wasm_bindgen(method)]
8142 pub fn has<K, V>(this: &WeakMap<K, V>, key: &K) -> bool;
8143
8144 /// The `delete()` method removes the specified element from a [`WeakMap`]
8145 /// object.
8146 ///
8147 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/delete)
8148 #[wasm_bindgen(method)]
8149 pub fn delete<K, V>(this: &WeakMap<K, V>, key: &K) -> bool;
8150}
8151
8152impl Default for WeakMap {
8153 fn default() -> Self {
8154 Self::new()
8155 }
8156}
8157
8158// WeakSet
8159#[wasm_bindgen]
8160extern "C" {
8161 #[wasm_bindgen(extends = Object, typescript_type = "WeakSet<object>")]
8162 #[derive(Clone, Debug, PartialEq, Eq)]
8163 pub type WeakSet<T = Object>;
8164
8165 /// The `WeakSet` object lets you store weakly held objects in a collection.
8166 ///
8167 /// **Note:** Consider using [`WeakSet::new_typed`] for typed sets.
8168 ///
8169 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet)
8170 #[cfg(not(js_sys_unstable_apis))]
8171 #[wasm_bindgen(constructor)]
8172 pub fn new() -> WeakSet;
8173
8174 /// The `WeakSet` object lets you store weakly held objects in a collection.
8175 ///
8176 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet)
8177 #[cfg(js_sys_unstable_apis)]
8178 #[wasm_bindgen(constructor)]
8179 pub fn new<T = Object>() -> WeakSet<T>;
8180
8181 // Next major: deprecate
8182 /// The `WeakSet` object lets you store weakly held objects in a collection.
8183 ///
8184 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet)
8185 #[wasm_bindgen(constructor)]
8186 pub fn new_typed<T = Object>() -> WeakSet<T>;
8187
8188 /// The `has()` method returns a boolean indicating whether an object exists
8189 /// in a WeakSet or not.
8190 ///
8191 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet/has)
8192 #[wasm_bindgen(method)]
8193 pub fn has<T>(this: &WeakSet<T>, value: &T) -> bool;
8194
8195 /// The `add()` method appends a new object to the end of a WeakSet object.
8196 ///
8197 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet/add)
8198 #[wasm_bindgen(method)]
8199 pub fn add<T>(this: &WeakSet<T>, value: &T) -> WeakSet<T>;
8200
8201 /// The `delete()` method removes the specified element from a WeakSet
8202 /// object.
8203 ///
8204 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet/delete)
8205 #[wasm_bindgen(method)]
8206 pub fn delete<T>(this: &WeakSet<T>, value: &T) -> bool;
8207}
8208
8209impl Default for WeakSet {
8210 fn default() -> Self {
8211 Self::new()
8212 }
8213}
8214
8215// WeakRef
8216#[wasm_bindgen]
8217extern "C" {
8218 #[wasm_bindgen(extends = Object, typescript_type = "WeakRef<object>")]
8219 #[derive(Clone, Debug, PartialEq, Eq)]
8220 pub type WeakRef<T = Object>;
8221
8222 /// The `WeakRef` object contains a weak reference to an object. A weak
8223 /// reference to an object is a reference that does not prevent the object
8224 /// from being reclaimed by the garbage collector.
8225 ///
8226 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef)
8227 #[wasm_bindgen(constructor)]
8228 pub fn new<T = Object>(target: &T) -> WeakRef<T>;
8229
8230 /// Returns the `Object` this `WeakRef` points to, or `None` if the
8231 /// object has been garbage collected.
8232 ///
8233 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef/deref)
8234 #[wasm_bindgen(method)]
8235 pub fn deref<T>(this: &WeakRef<T>) -> Option<T>;
8236}
8237
8238#[cfg(js_sys_unstable_apis)]
8239#[allow(non_snake_case)]
8240pub mod Temporal;
8241
8242#[allow(non_snake_case)]
8243pub mod WebAssembly {
8244 use super::*;
8245
8246 // WebAssembly
8247 #[wasm_bindgen]
8248 extern "C" {
8249 /// The `WebAssembly.compile()` function compiles a `WebAssembly.Module`
8250 /// from WebAssembly binary code. This function is useful if it is
8251 /// necessary to a compile a module before it can be instantiated
8252 /// (otherwise, the `WebAssembly.instantiate()` function should be used).
8253 ///
8254 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compile)
8255 #[cfg(not(js_sys_unstable_apis))]
8256 #[wasm_bindgen(js_namespace = WebAssembly)]
8257 pub fn compile(buffer_source: &JsValue) -> Promise<JsValue>;
8258
8259 /// The `WebAssembly.compile()` function compiles a `WebAssembly.Module`
8260 /// from WebAssembly binary code. This function is useful if it is
8261 /// necessary to a compile a module before it can be instantiated
8262 /// (otherwise, the `WebAssembly.instantiate()` function should be used).
8263 ///
8264 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compile)
8265 #[cfg(js_sys_unstable_apis)]
8266 #[wasm_bindgen(js_namespace = WebAssembly)]
8267 pub fn compile(buffer_source: &JsValue) -> Promise<Module>;
8268
8269 /// The `WebAssembly.compileStreaming()` function compiles a
8270 /// `WebAssembly.Module` module directly from a streamed underlying
8271 /// source. This function is useful if it is necessary to a compile a
8272 /// module before it can be instantiated (otherwise, the
8273 /// `WebAssembly.instantiateStreaming()` function should be used).
8274 ///
8275 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compileStreaming)
8276 #[cfg(not(js_sys_unstable_apis))]
8277 #[wasm_bindgen(js_namespace = WebAssembly, js_name = compileStreaming)]
8278 pub fn compile_streaming(response: &Promise) -> Promise<JsValue>;
8279
8280 /// The `WebAssembly.compileStreaming()` function compiles a
8281 /// `WebAssembly.Module` module directly from a streamed underlying
8282 /// source. This function is useful if it is necessary to a compile a
8283 /// module before it can be instantiated (otherwise, the
8284 /// `WebAssembly.instantiateStreaming()` function should be used).
8285 ///
8286 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compileStreaming)
8287 #[cfg(js_sys_unstable_apis)]
8288 #[wasm_bindgen(js_namespace = WebAssembly, js_name = compileStreaming)]
8289 pub fn compile_streaming(response: &Promise) -> Promise<Module>;
8290
8291 /// The `WebAssembly.instantiate()` function allows you to compile and
8292 /// instantiate WebAssembly code.
8293 ///
8294 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate)
8295 #[cfg(not(js_sys_unstable_apis))]
8296 #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiate)]
8297 pub fn instantiate_buffer(buffer: &[u8], imports: &Object) -> Promise<JsValue>;
8298
8299 /// The `WebAssembly.instantiate()` function allows you to compile and
8300 /// instantiate WebAssembly code.
8301 ///
8302 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate)
8303 #[cfg(js_sys_unstable_apis)]
8304 #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiate)]
8305 pub fn instantiate_buffer(buffer: &[u8], imports: &Object) -> Promise<Instance>;
8306
8307 /// The `WebAssembly.instantiate()` function allows you to compile and
8308 /// instantiate WebAssembly code.
8309 ///
8310 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate)
8311 #[cfg(not(js_sys_unstable_apis))]
8312 #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiate)]
8313 pub fn instantiate_module(module: &Module, imports: &Object) -> Promise<JsValue>;
8314
8315 /// The `WebAssembly.instantiate()` function allows you to compile and
8316 /// instantiate WebAssembly code.
8317 ///
8318 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate)
8319 #[cfg(js_sys_unstable_apis)]
8320 #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiate)]
8321 pub fn instantiate_module(module: &Module, imports: &Object) -> Promise<Instance>;
8322
8323 /// The `WebAssembly.instantiateStreaming()` function compiles and
8324 /// instantiates a WebAssembly module directly from a streamed
8325 /// underlying source. This is the most efficient, optimized way to load
8326 /// Wasm code.
8327 ///
8328 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiateStreaming)
8329 #[cfg(not(js_sys_unstable_apis))]
8330 #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiateStreaming)]
8331 pub fn instantiate_streaming(response: &JsValue, imports: &Object) -> Promise<JsValue>;
8332
8333 /// The `WebAssembly.instantiateStreaming()` function compiles and
8334 /// instantiates a WebAssembly module directly from a streamed
8335 /// underlying source. This is the most efficient, optimized way to load
8336 /// Wasm code.
8337 ///
8338 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiateStreaming)
8339 #[cfg(js_sys_unstable_apis)]
8340 #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiateStreaming)]
8341 pub fn instantiate_streaming(response: &JsValue, imports: &Object) -> Promise<Instance>;
8342
8343 /// The `WebAssembly.validate()` function validates a given typed
8344 /// array of WebAssembly binary code, returning whether the bytes
8345 /// form a valid Wasm module (`true`) or not (`false`).
8346 ///
8347 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/validate)
8348 #[wasm_bindgen(js_namespace = WebAssembly, catch)]
8349 pub fn validate(buffer_source: &JsValue) -> Result<bool, JsValue>;
8350 }
8351
8352 // WebAssembly.CompileError
8353 #[wasm_bindgen]
8354 extern "C" {
8355 /// The `WebAssembly.CompileError()` constructor creates a new
8356 /// WebAssembly `CompileError` object, which indicates an error during
8357 /// WebAssembly decoding or validation.
8358 ///
8359 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/CompileError)
8360 #[wasm_bindgen(extends = Error, js_namespace = WebAssembly, typescript_type = "WebAssembly.CompileError")]
8361 #[derive(Clone, Debug, PartialEq, Eq)]
8362 pub type CompileError;
8363
8364 /// The `WebAssembly.CompileError()` constructor creates a new
8365 /// WebAssembly `CompileError` object, which indicates an error during
8366 /// WebAssembly decoding or validation.
8367 ///
8368 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/CompileError)
8369 #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
8370 pub fn new(message: &str) -> CompileError;
8371 }
8372
8373 // WebAssembly.Instance
8374 #[wasm_bindgen]
8375 extern "C" {
8376 /// A `WebAssembly.Instance` object is a stateful, executable instance
8377 /// of a `WebAssembly.Module`. Instance objects contain all the exported
8378 /// WebAssembly functions that allow calling into WebAssembly code from
8379 /// JavaScript.
8380 ///
8381 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance)
8382 #[wasm_bindgen(extends = Object, js_namespace = WebAssembly, typescript_type = "WebAssembly.Instance")]
8383 #[derive(Clone, Debug, PartialEq, Eq)]
8384 pub type Instance;
8385
8386 /// The `WebAssembly.Instance()` constructor function can be called to
8387 /// synchronously instantiate a given `WebAssembly.Module`
8388 /// object. However, the primary way to get an `Instance` is through the
8389 /// asynchronous `WebAssembly.instantiateStreaming()` function.
8390 ///
8391 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance)
8392 #[wasm_bindgen(catch, constructor, js_namespace = WebAssembly)]
8393 pub fn new(module: &Module, imports: &Object) -> Result<Instance, JsValue>;
8394
8395 /// The `exports` readonly property of the `WebAssembly.Instance` object
8396 /// prototype returns an object containing as its members all the
8397 /// functions exported from the WebAssembly module instance, to allow
8398 /// them to be accessed and used by JavaScript.
8399 ///
8400 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance/exports)
8401 #[wasm_bindgen(getter, method, js_namespace = WebAssembly)]
8402 pub fn exports(this: &Instance) -> Object;
8403 }
8404
8405 // WebAssembly.LinkError
8406 #[wasm_bindgen]
8407 extern "C" {
8408 /// The `WebAssembly.LinkError()` constructor creates a new WebAssembly
8409 /// LinkError object, which indicates an error during module
8410 /// instantiation (besides traps from the start function).
8411 ///
8412 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/LinkError)
8413 #[wasm_bindgen(extends = Error, js_namespace = WebAssembly, typescript_type = "WebAssembly.LinkError")]
8414 #[derive(Clone, Debug, PartialEq, Eq)]
8415 pub type LinkError;
8416
8417 /// The `WebAssembly.LinkError()` constructor creates a new WebAssembly
8418 /// LinkError object, which indicates an error during module
8419 /// instantiation (besides traps from the start function).
8420 ///
8421 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/LinkError)
8422 #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
8423 pub fn new(message: &str) -> LinkError;
8424 }
8425
8426 // WebAssembly.RuntimeError
8427 #[wasm_bindgen]
8428 extern "C" {
8429 /// The `WebAssembly.RuntimeError()` constructor creates a new WebAssembly
8430 /// `RuntimeError` object — the type that is thrown whenever WebAssembly
8431 /// specifies a trap.
8432 ///
8433 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/RuntimeError)
8434 #[wasm_bindgen(extends = Error, js_namespace = WebAssembly, typescript_type = "WebAssembly.RuntimeError")]
8435 #[derive(Clone, Debug, PartialEq, Eq)]
8436 pub type RuntimeError;
8437
8438 /// The `WebAssembly.RuntimeError()` constructor creates a new WebAssembly
8439 /// `RuntimeError` object — the type that is thrown whenever WebAssembly
8440 /// specifies a trap.
8441 ///
8442 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/RuntimeError)
8443 #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
8444 pub fn new(message: &str) -> RuntimeError;
8445 }
8446
8447 // WebAssembly.Module
8448 #[wasm_bindgen]
8449 extern "C" {
8450 /// A `WebAssembly.Module` object contains stateless WebAssembly code
8451 /// that has already been compiled by the browser and can be
8452 /// efficiently shared with Workers, and instantiated multiple times.
8453 ///
8454 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module)
8455 #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Module")]
8456 #[derive(Clone, Debug, PartialEq, Eq)]
8457 pub type Module;
8458
8459 /// A `WebAssembly.Module` object contains stateless WebAssembly code
8460 /// that has already been compiled by the browser and can be
8461 /// efficiently shared with Workers, and instantiated multiple times.
8462 ///
8463 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module)
8464 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
8465 pub fn new(buffer_source: &JsValue) -> Result<Module, JsValue>;
8466
8467 /// The `WebAssembly.customSections()` function returns a copy of the
8468 /// contents of all custom sections in the given module with the given
8469 /// string name.
8470 ///
8471 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/customSections)
8472 #[wasm_bindgen(static_method_of = Module, js_namespace = WebAssembly, js_name = customSections)]
8473 pub fn custom_sections(module: &Module, sectionName: &str) -> Array;
8474
8475 /// The `WebAssembly.exports()` function returns an array containing
8476 /// descriptions of all the declared exports of the given `Module`.
8477 ///
8478 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/exports)
8479 #[wasm_bindgen(static_method_of = Module, js_namespace = WebAssembly)]
8480 pub fn exports(module: &Module) -> Array;
8481
8482 /// The `WebAssembly.imports()` function returns an array containing
8483 /// descriptions of all the declared imports of the given `Module`.
8484 ///
8485 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/imports)
8486 #[wasm_bindgen(static_method_of = Module, js_namespace = WebAssembly)]
8487 pub fn imports(module: &Module) -> Array;
8488 }
8489
8490 // WebAssembly.Table
8491 #[wasm_bindgen]
8492 extern "C" {
8493 /// The `WebAssembly.Table()` constructor creates a new `Table` object
8494 /// of the given size and element type.
8495 ///
8496 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table)
8497 #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Table")]
8498 #[derive(Clone, Debug, PartialEq, Eq)]
8499 pub type Table;
8500
8501 /// The `WebAssembly.Table()` constructor creates a new `Table` object
8502 /// of the given size and element type.
8503 ///
8504 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table)
8505 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
8506 pub fn new(table_descriptor: &Object) -> Result<Table, JsValue>;
8507
8508 /// The `WebAssembly.Table()` constructor creates a new `Table` object
8509 /// of the given size and element type.
8510 ///
8511 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table)
8512 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
8513 pub fn new_with_value(table_descriptor: &Object, value: JsValue) -> Result<Table, JsValue>;
8514
8515 /// The length prototype property of the `WebAssembly.Table` object
8516 /// returns the length of the table, i.e. the number of elements in the
8517 /// table.
8518 ///
8519 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/length)
8520 #[wasm_bindgen(method, getter, js_namespace = WebAssembly)]
8521 pub fn length(this: &Table) -> u32;
8522
8523 /// The `get()` prototype method of the `WebAssembly.Table()` object
8524 /// retrieves a function reference stored at a given index.
8525 ///
8526 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/get)
8527 #[wasm_bindgen(method, catch, js_namespace = WebAssembly)]
8528 pub fn get(this: &Table, index: u32) -> Result<Function, JsValue>;
8529
8530 /// The `get()` prototype method of the `WebAssembly.Table()` object
8531 /// retrieves a function reference stored at a given index.
8532 ///
8533 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/get)
8534 #[wasm_bindgen(method, catch, js_namespace = WebAssembly, js_name = get)]
8535 pub fn get_raw(this: &Table, index: u32) -> Result<JsValue, JsValue>;
8536
8537 /// The `grow()` prototype method of the `WebAssembly.Table` object
8538 /// increases the size of the `Table` instance by a specified number of
8539 /// elements.
8540 ///
8541 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/grow)
8542 #[wasm_bindgen(method, catch, js_namespace = WebAssembly)]
8543 pub fn grow(this: &Table, additional_capacity: u32) -> Result<u32, JsValue>;
8544
8545 /// The `grow()` prototype method of the `WebAssembly.Table` object
8546 /// increases the size of the `Table` instance by a specified number of
8547 /// elements.
8548 ///
8549 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/grow)
8550 #[wasm_bindgen(method, catch, js_namespace = WebAssembly, js_name = grow)]
8551 pub fn grow_with_value(
8552 this: &Table,
8553 additional_capacity: u32,
8554 value: JsValue,
8555 ) -> Result<u32, JsValue>;
8556
8557 /// The `set()` prototype method of the `WebAssembly.Table` object mutates a
8558 /// reference stored at a given index to a different value.
8559 ///
8560 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/set)
8561 #[wasm_bindgen(method, catch, js_namespace = WebAssembly)]
8562 pub fn set(this: &Table, index: u32, function: &Function) -> Result<(), JsValue>;
8563
8564 /// The `set()` prototype method of the `WebAssembly.Table` object mutates a
8565 /// reference stored at a given index to a different value.
8566 ///
8567 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/set)
8568 #[wasm_bindgen(method, catch, js_namespace = WebAssembly, js_name = set)]
8569 pub fn set_raw(this: &Table, index: u32, value: &JsValue) -> Result<(), JsValue>;
8570 }
8571
8572 // WebAssembly.Tag
8573 #[wasm_bindgen]
8574 extern "C" {
8575 /// The `WebAssembly.Tag()` constructor creates a new `Tag` object
8576 ///
8577 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Tag)
8578 #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Tag")]
8579 #[derive(Clone, Debug, PartialEq, Eq)]
8580 pub type Tag;
8581
8582 /// The `WebAssembly.Tag()` constructor creates a new `Tag` object
8583 ///
8584 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Tag)
8585 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
8586 pub fn new(tag_descriptor: &Object) -> Result<Tag, JsValue>;
8587 }
8588
8589 // WebAssembly.Exception
8590 #[wasm_bindgen]
8591 extern "C" {
8592 /// The `WebAssembly.Exception()` constructor creates a new `Exception` object
8593 ///
8594 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception)
8595 #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Exception")]
8596 #[derive(Clone, Debug, PartialEq, Eq)]
8597 pub type Exception;
8598
8599 /// The `WebAssembly.Exception()` constructor creates a new `Exception` object
8600 ///
8601 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception)
8602 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
8603 pub fn new(tag: &Tag, payload: &Array) -> Result<Exception, JsValue>;
8604
8605 /// The `WebAssembly.Exception()` constructor creates a new `Exception` object
8606 ///
8607 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception)
8608 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
8609 pub fn new_with_options(
8610 tag: &Tag,
8611 payload: &Array,
8612 options: &Object,
8613 ) -> Result<Exception, JsValue>;
8614
8615 /// The `is()` prototype method of the `WebAssembly.Exception` can be used to
8616 /// test if the Exception matches a given tag.
8617 ///
8618 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception/is)
8619 #[wasm_bindgen(method, js_namespace = WebAssembly)]
8620 pub fn is(this: &Exception, tag: &Tag) -> bool;
8621
8622 /// The `getArg()` prototype method of the `WebAssembly.Exception` can be used
8623 /// to get the value of a specified item in the exception's data arguments
8624 ///
8625 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception/getArg)
8626 #[wasm_bindgen(method, js_namespace = WebAssembly, js_name = getArg, catch)]
8627 pub fn get_arg(this: &Exception, tag: &Tag, index: u32) -> Result<JsValue, JsValue>;
8628 }
8629
8630 // WebAssembly.Global
8631 #[wasm_bindgen]
8632 extern "C" {
8633 /// The `WebAssembly.Global()` constructor creates a new `Global` object
8634 /// of the given type and value.
8635 ///
8636 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global)
8637 #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Global")]
8638 #[derive(Clone, Debug, PartialEq, Eq)]
8639 pub type Global;
8640
8641 /// The `WebAssembly.Global()` constructor creates a new `Global` object
8642 /// of the given type and value.
8643 ///
8644 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global)
8645 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
8646 pub fn new(global_descriptor: &Object, value: &JsValue) -> Result<Global, JsValue>;
8647
8648 /// The value prototype property of the `WebAssembly.Global` object
8649 /// returns the value of the global.
8650 ///
8651 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global)
8652 #[wasm_bindgen(method, getter, js_namespace = WebAssembly)]
8653 pub fn value(this: &Global) -> JsValue;
8654 #[wasm_bindgen(method, setter = value, js_namespace = WebAssembly)]
8655 pub fn set_value(this: &Global, value: &JsValue);
8656 }
8657
8658 // WebAssembly.Memory
8659 #[wasm_bindgen]
8660 extern "C" {
8661 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory)
8662 #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Memory")]
8663 #[derive(Clone, Debug, PartialEq, Eq)]
8664 pub type Memory;
8665
8666 /// The `WebAssembly.Memory()` constructor creates a new `Memory` object
8667 /// which is a resizable `ArrayBuffer` that holds the raw bytes of
8668 /// memory accessed by a WebAssembly `Instance`.
8669 ///
8670 /// A memory created by JavaScript or in WebAssembly code will be
8671 /// accessible and mutable from both JavaScript and WebAssembly.
8672 ///
8673 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory)
8674 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
8675 pub fn new(descriptor: &Object) -> Result<Memory, JsValue>;
8676
8677 /// An accessor property that returns the buffer contained in the
8678 /// memory.
8679 ///
8680 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory/buffer)
8681 #[wasm_bindgen(method, getter, js_namespace = WebAssembly)]
8682 pub fn buffer(this: &Memory) -> JsValue;
8683
8684 /// The `grow()` prototype method of the `Memory` object increases the
8685 /// size of the memory instance by a specified number of WebAssembly
8686 /// pages.
8687 ///
8688 /// Takes the number of pages to grow (64KiB in size) and returns the
8689 /// previous size of memory, in pages.
8690 ///
8691 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory/grow)
8692 #[wasm_bindgen(method, js_namespace = WebAssembly)]
8693 pub fn grow(this: &Memory, pages: u32) -> u32;
8694 }
8695}
8696
8697/// The `JSON` object contains methods for parsing [JavaScript Object
8698/// Notation (JSON)](https://json.org/) and converting values to JSON. It
8699/// can't be called or constructed, and aside from its two method
8700/// properties, it has no interesting functionality of its own.
8701#[allow(non_snake_case)]
8702pub mod JSON {
8703 use super::*;
8704
8705 // JSON
8706 #[wasm_bindgen]
8707 extern "C" {
8708 /// The `JSON.parse()` method parses a JSON string, constructing the
8709 /// JavaScript value or object described by the string.
8710 ///
8711 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse)
8712 #[wasm_bindgen(catch, js_namespace = JSON)]
8713 pub fn parse(text: &str) -> Result<JsValue, JsValue>;
8714
8715 /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
8716 ///
8717 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
8718 #[wasm_bindgen(catch, js_namespace = JSON)]
8719 pub fn stringify(obj: &JsValue) -> Result<JsString, JsValue>;
8720
8721 /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
8722 ///
8723 /// The `replacer` argument is a function that alters the behavior of the stringification
8724 /// process, or an array of String and Number objects that serve as a whitelist
8725 /// for selecting/filtering the properties of the value object to be included
8726 /// in the JSON string. If this value is null or not provided, all properties
8727 /// of the object are included in the resulting JSON string.
8728 ///
8729 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
8730 #[cfg(not(js_sys_unstable_apis))]
8731 #[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
8732 pub fn stringify_with_replacer(
8733 obj: &JsValue,
8734 replacer: &JsValue,
8735 ) -> Result<JsString, JsValue>;
8736
8737 /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
8738 ///
8739 /// The `replacer` argument is a function that alters the behavior of the stringification
8740 /// process, or an array of String and Number objects that serve as a whitelist
8741 /// for selecting/filtering the properties of the value object to be included
8742 /// in the JSON string. If this value is null or not provided, all properties
8743 /// of the object are included in the resulting JSON string.
8744 ///
8745 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
8746 #[cfg(js_sys_unstable_apis)]
8747 #[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
8748 pub fn stringify_with_replacer<'a>(
8749 obj: &JsValue,
8750 replacer: &mut dyn FnMut(JsString, JsValue) -> Result<Option<JsValue>, JsError>,
8751 space: Option<u32>,
8752 ) -> Result<JsString, JsValue>;
8753
8754 // Next major: deprecate
8755 /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
8756 ///
8757 /// The `replacer` argument is a function that alters the behavior of the stringification
8758 /// process, or an array of String and Number objects that serve as a whitelist
8759 /// for selecting/filtering the properties of the value object to be included
8760 /// in the JSON string. If this value is null or not provided, all properties
8761 /// of the object are included in the resulting JSON string.
8762 ///
8763 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
8764 #[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
8765 pub fn stringify_with_replacer_func<'a>(
8766 obj: &JsValue,
8767 replacer: &mut dyn FnMut(JsString, JsValue) -> Result<Option<JsValue>, JsError>,
8768 space: Option<u32>,
8769 ) -> Result<JsString, JsValue>;
8770
8771 /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
8772 ///
8773 /// The `replacer` argument is a function that alters the behavior of the stringification
8774 /// process, or an array of String and Number objects that serve as a whitelist
8775 /// for selecting/filtering the properties of the value object to be included
8776 /// in the JSON string. If this value is null or not provided, all properties
8777 /// of the object are included in the resulting JSON string.
8778 ///
8779 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
8780 #[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
8781 pub fn stringify_with_replacer_list(
8782 obj: &JsValue,
8783 replacer: Vec<String>,
8784 space: Option<u32>,
8785 ) -> Result<JsString, JsValue>;
8786
8787 // Next major: deprecate
8788 /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
8789 ///
8790 /// The `replacer` argument is a function that alters the behavior of the stringification
8791 /// process, or an array of String and Number objects that serve as a whitelist
8792 /// for selecting/filtering the properties of the value object to be included
8793 /// in the JSON string. If this value is null or not provided, all properties
8794 /// of the object are included in the resulting JSON string.
8795 ///
8796 /// The `space` argument is a String or Number object that's used to insert white space into
8797 /// the output JSON string for readability purposes. If this is a Number, it
8798 /// indicates the number of space characters to use as white space; this number
8799 /// is capped at 10 (if it is greater, the value is just 10). Values less than
8800 /// 1 indicate that no space should be used. If this is a String, the string
8801 /// (or the first 10 characters of the string, if it's longer than that) is
8802 /// used as white space. If this parameter is not provided (or is null), no
8803 /// white space is used.
8804 ///
8805 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
8806 #[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
8807 pub fn stringify_with_replacer_and_space(
8808 obj: &JsValue,
8809 replacer: &JsValue,
8810 space: &JsValue,
8811 ) -> Result<JsString, JsValue>;
8812 }
8813}
8814// JsString
8815#[wasm_bindgen]
8816extern "C" {
8817 #[wasm_bindgen(js_name = String, extends = Object, is_type_of = JsValue::is_string, typescript_type = "string")]
8818 #[derive(Clone, PartialEq, Eq)]
8819 pub type JsString;
8820
8821 /// The length property of a String object indicates the length of a string,
8822 /// in UTF-16 code units.
8823 ///
8824 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/length)
8825 #[wasm_bindgen(method, getter)]
8826 pub fn length(this: &JsString) -> u32;
8827
8828 /// The 'at()' method returns a new string consisting of the single UTF-16
8829 /// code unit located at the specified offset into the string, counting from
8830 /// the end if it's negative.
8831 ///
8832 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/at)
8833 #[wasm_bindgen(method, js_class = "String")]
8834 pub fn at(this: &JsString, index: i32) -> Option<JsString>;
8835
8836 /// The String object's `charAt()` method returns a new string consisting of
8837 /// the single UTF-16 code unit located at the specified offset into the
8838 /// string.
8839 ///
8840 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charAt)
8841 #[wasm_bindgen(method, js_class = "String", js_name = charAt)]
8842 pub fn char_at(this: &JsString, index: u32) -> JsString;
8843
8844 /// The `charCodeAt()` method returns an integer between 0 and 65535
8845 /// representing the UTF-16 code unit at the given index (the UTF-16 code
8846 /// unit matches the Unicode code point for code points representable in a
8847 /// single UTF-16 code unit, but might also be the first code unit of a
8848 /// surrogate pair for code points not representable in a single UTF-16 code
8849 /// unit, e.g. Unicode code points > 0x10000). If you want the entire code
8850 /// point value, use `codePointAt()`.
8851 ///
8852 /// Returns `NaN` if index is out of range.
8853 ///
8854 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charCodeAt)
8855 #[wasm_bindgen(method, js_class = "String", js_name = charCodeAt)]
8856 pub fn char_code_at(this: &JsString, index: u32) -> f64;
8857
8858 /// The `codePointAt()` method returns a non-negative integer that is the
8859 /// Unicode code point value.
8860 ///
8861 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/codePointAt)
8862 #[cfg(not(js_sys_unstable_apis))]
8863 #[wasm_bindgen(method, js_class = "String", js_name = codePointAt)]
8864 pub fn code_point_at(this: &JsString, pos: u32) -> JsValue;
8865
8866 /// The `codePointAt()` method returns a non-negative integer that is the
8867 /// Unicode code point value.
8868 ///
8869 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/codePointAt)
8870 #[cfg(js_sys_unstable_apis)]
8871 #[wasm_bindgen(method, js_class = "String", js_name = codePointAt)]
8872 pub fn code_point_at(this: &JsString, pos: u32) -> Option<u32>;
8873
8874 // Next major: deprecate
8875 /// The `codePointAt()` method returns a non-negative integer that is the
8876 /// Unicode code point value.
8877 ///
8878 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/codePointAt)
8879 #[wasm_bindgen(method, js_class = "String", js_name = codePointAt)]
8880 pub fn try_code_point_at(this: &JsString, pos: u32) -> Option<u16>;
8881
8882 /// The `concat()` method concatenates the string arguments to the calling
8883 /// string and returns a new string.
8884 ///
8885 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/concat)
8886 #[cfg(not(js_sys_unstable_apis))]
8887 #[wasm_bindgen(method, js_class = "String")]
8888 pub fn concat(this: &JsString, string_2: &JsValue) -> JsString;
8889
8890 /// The `concat()` method concatenates the string arguments to the calling
8891 /// string and returns a new string.
8892 ///
8893 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/concat)
8894 #[cfg(js_sys_unstable_apis)]
8895 #[wasm_bindgen(method, js_class = "String")]
8896 pub fn concat(this: &JsString, string: &JsString) -> JsString;
8897
8898 /// The `concat()` method concatenates the string arguments to the calling
8899 /// string and returns a new string.
8900 ///
8901 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/concat)
8902 #[wasm_bindgen(method, js_class = "String")]
8903 pub fn concat_many(this: &JsString, strings: &[JsString]) -> JsString;
8904
8905 /// The `endsWith()` method determines whether a string ends with the characters of a
8906 /// specified string, returning true or false as appropriate.
8907 ///
8908 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith)
8909 #[cfg(not(js_sys_unstable_apis))]
8910 #[wasm_bindgen(method, js_class = "String", js_name = endsWith)]
8911 pub fn ends_with(this: &JsString, search_string: &str, length: i32) -> bool;
8912
8913 /// The `endsWith()` method determines whether a string ends with the characters of a
8914 /// specified string, returning true or false as appropriate.
8915 ///
8916 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith)
8917 #[cfg(js_sys_unstable_apis)]
8918 #[wasm_bindgen(method, js_class = "String", js_name = endsWith)]
8919 pub fn ends_with(this: &JsString, search_string: &str) -> bool;
8920
8921 /// The static `String.fromCharCode()` method returns a string created from
8922 /// the specified sequence of UTF-16 code units.
8923 ///
8924 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
8925 ///
8926 /// # Notes
8927 ///
8928 /// There are a few bindings to `from_char_code` in `js-sys`: `from_char_code1`, `from_char_code2`, etc...
8929 /// with different arities.
8930 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode, variadic)]
8931 pub fn from_char_code(char_codes: &[u16]) -> JsString;
8932
8933 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
8934 #[cfg(not(js_sys_unstable_apis))]
8935 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
8936 pub fn from_char_code1(a: u32) -> JsString;
8937
8938 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
8939 #[cfg(js_sys_unstable_apis)]
8940 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
8941 pub fn from_char_code1(a: u16) -> JsString;
8942
8943 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
8944 #[cfg(not(js_sys_unstable_apis))]
8945 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
8946 pub fn from_char_code2(a: u32, b: u32) -> JsString;
8947
8948 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
8949 #[cfg(js_sys_unstable_apis)]
8950 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
8951 pub fn from_char_code2(a: u16, b: u16) -> JsString;
8952
8953 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
8954 #[cfg(not(js_sys_unstable_apis))]
8955 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
8956 pub fn from_char_code3(a: u32, b: u32, c: u32) -> JsString;
8957
8958 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
8959 #[cfg(js_sys_unstable_apis)]
8960 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
8961 pub fn from_char_code3(a: u16, b: u16, c: u16) -> JsString;
8962
8963 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
8964 #[cfg(not(js_sys_unstable_apis))]
8965 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
8966 pub fn from_char_code4(a: u32, b: u32, c: u32, d: u32) -> JsString;
8967
8968 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
8969 #[cfg(js_sys_unstable_apis)]
8970 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
8971 pub fn from_char_code4(a: u16, b: u16, c: u16, d: u16) -> JsString;
8972
8973 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
8974 #[cfg(not(js_sys_unstable_apis))]
8975 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
8976 pub fn from_char_code5(a: u32, b: u32, c: u32, d: u32, e: u32) -> JsString;
8977
8978 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
8979 #[cfg(js_sys_unstable_apis)]
8980 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
8981 pub fn from_char_code5(a: u16, b: u16, c: u16, d: u16, e: u16) -> JsString;
8982
8983 /// The static `String.fromCodePoint()` method returns a string created by
8984 /// using the specified sequence of code points.
8985 ///
8986 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
8987 ///
8988 /// # Exceptions
8989 ///
8990 /// A RangeError is thrown if an invalid Unicode code point is given
8991 ///
8992 /// # Notes
8993 ///
8994 /// There are a few bindings to `from_code_point` in `js-sys`: `from_code_point1`, `from_code_point2`, etc...
8995 /// with different arities.
8996 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint, variadic)]
8997 pub fn from_code_point(code_points: &[u32]) -> Result<JsString, JsValue>;
8998
8999 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
9000 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
9001 pub fn from_code_point1(a: u32) -> Result<JsString, JsValue>;
9002
9003 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
9004 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
9005 pub fn from_code_point2(a: u32, b: u32) -> Result<JsString, JsValue>;
9006
9007 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
9008 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
9009 pub fn from_code_point3(a: u32, b: u32, c: u32) -> Result<JsString, JsValue>;
9010
9011 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
9012 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
9013 pub fn from_code_point4(a: u32, b: u32, c: u32, d: u32) -> Result<JsString, JsValue>;
9014
9015 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
9016 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
9017 pub fn from_code_point5(a: u32, b: u32, c: u32, d: u32, e: u32) -> Result<JsString, JsValue>;
9018
9019 /// The `includes()` method determines whether one string may be found
9020 /// within another string, returning true or false as appropriate.
9021 ///
9022 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes)
9023 #[wasm_bindgen(method, js_class = "String")]
9024 pub fn includes(this: &JsString, search_string: &str, position: i32) -> bool;
9025
9026 /// The `indexOf()` method returns the index within the calling String
9027 /// object of the first occurrence of the specified value, starting the
9028 /// search at fromIndex. Returns -1 if the value is not found.
9029 ///
9030 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf)
9031 #[wasm_bindgen(method, js_class = "String", js_name = indexOf)]
9032 pub fn index_of(this: &JsString, search_value: &str, from_index: i32) -> i32;
9033
9034 /// The `lastIndexOf()` method returns the index within the calling String
9035 /// object of the last occurrence of the specified value, searching
9036 /// backwards from fromIndex. Returns -1 if the value is not found.
9037 ///
9038 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/lastIndexOf)
9039 #[wasm_bindgen(method, js_class = "String", js_name = lastIndexOf)]
9040 pub fn last_index_of(this: &JsString, search_value: &str, from_index: i32) -> i32;
9041
9042 /// The `localeCompare()` method returns a number indicating whether
9043 /// a reference string comes before or after or is the same as
9044 /// the given string in sort order.
9045 ///
9046 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare)
9047 #[cfg(not(js_sys_unstable_apis))]
9048 #[wasm_bindgen(method, js_class = "String", js_name = localeCompare)]
9049 pub fn locale_compare(
9050 this: &JsString,
9051 compare_string: &str,
9052 locales: &Array,
9053 options: &Object,
9054 ) -> i32;
9055
9056 /// The `localeCompare()` method returns a number indicating whether
9057 /// a reference string comes before or after or is the same as
9058 /// the given string in sort order.
9059 ///
9060 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare)
9061 #[cfg(js_sys_unstable_apis)]
9062 #[wasm_bindgen(method, js_class = "String", js_name = localeCompare)]
9063 pub fn locale_compare(
9064 this: &JsString,
9065 compare_string: &str,
9066 locales: &[JsString],
9067 options: &Intl::CollatorOptions,
9068 ) -> i32;
9069
9070 /// The `match()` method retrieves the matches when matching a string against a regular expression.
9071 ///
9072 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match)
9073 #[wasm_bindgen(method, js_class = "String", js_name = match)]
9074 pub fn match_(this: &JsString, pattern: &RegExp) -> Option<Object>;
9075
9076 /// The `match_all()` method is similar to `match()`, but gives an iterator of `exec()` arrays, which preserve capture groups.
9077 ///
9078 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/matchAll)
9079 #[cfg(not(js_sys_unstable_apis))]
9080 #[wasm_bindgen(method, js_class = "String", js_name = matchAll)]
9081 pub fn match_all(this: &JsString, pattern: &RegExp) -> Iterator;
9082
9083 /// The `match_all()` method is similar to `match()`, but gives an iterator of `exec()` arrays, which preserve capture groups.
9084 ///
9085 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/matchAll)
9086 #[cfg(js_sys_unstable_apis)]
9087 #[wasm_bindgen(method, js_class = "String", js_name = matchAll)]
9088 pub fn match_all(this: &JsString, pattern: &RegExp) -> Iterator<RegExpMatchArray>;
9089
9090 /// The `normalize()` method returns the Unicode Normalization Form
9091 /// of a given string (if the value isn't a string, it will be converted to one first).
9092 ///
9093 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize)
9094 #[wasm_bindgen(method, js_class = "String")]
9095 pub fn normalize(this: &JsString, form: &str) -> JsString;
9096
9097 /// The `padEnd()` method pads the current string with a given string
9098 /// (repeated, if needed) so that the resulting string reaches a given
9099 /// length. The padding is applied from the end (right) of the current
9100 /// string.
9101 ///
9102 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padEnd)
9103 #[wasm_bindgen(method, js_class = "String", js_name = padEnd)]
9104 pub fn pad_end(this: &JsString, target_length: u32, pad_string: &str) -> JsString;
9105
9106 /// The `padStart()` method pads the current string with another string
9107 /// (repeated, if needed) so that the resulting string reaches the given
9108 /// length. The padding is applied from the start (left) of the current
9109 /// string.
9110 ///
9111 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padStart)
9112 #[wasm_bindgen(method, js_class = "String", js_name = padStart)]
9113 pub fn pad_start(this: &JsString, target_length: u32, pad_string: &str) -> JsString;
9114
9115 /// The `repeat()` method constructs and returns a new string which contains the specified
9116 /// number of copies of the string on which it was called, concatenated together.
9117 ///
9118 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat)
9119 #[wasm_bindgen(method, js_class = "String")]
9120 pub fn repeat(this: &JsString, count: i32) -> JsString;
9121
9122 /// The `replace()` method returns a new string with some or all matches of a pattern
9123 /// replaced by a replacement. The pattern can be a string or a RegExp, and
9124 /// the replacement can be a string or a function to be called for each match.
9125 ///
9126 /// Note: The original string will remain unchanged.
9127 ///
9128 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
9129 #[wasm_bindgen(method, js_class = "String")]
9130 pub fn replace(this: &JsString, pattern: &str, replacement: &str) -> JsString;
9131
9132 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
9133 #[cfg(not(js_sys_unstable_apis))]
9134 #[wasm_bindgen(method, js_class = "String", js_name = replace)]
9135 pub fn replace_with_function(
9136 this: &JsString,
9137 pattern: &str,
9138 replacement: &Function,
9139 ) -> JsString;
9140
9141 /// The replacer function signature is `(match, offset, string) -> replacement`
9142 /// for patterns without capture groups, or `(match, p1, p2, ..., pN, offset, string, groups) -> replacement`
9143 /// when capture groups are present.
9144 ///
9145 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
9146 #[cfg(js_sys_unstable_apis)]
9147 #[wasm_bindgen(method, js_class = "String", js_name = replace)]
9148 pub fn replace_with_function(
9149 this: &JsString,
9150 pattern: &str,
9151 replacement: &Function<fn(JsString) -> JsString>,
9152 ) -> JsString;
9153
9154 #[wasm_bindgen(method, js_class = "String", js_name = replace)]
9155 pub fn replace_by_pattern(this: &JsString, pattern: &RegExp, replacement: &str) -> JsString;
9156
9157 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
9158 #[cfg(not(js_sys_unstable_apis))]
9159 #[wasm_bindgen(method, js_class = "String", js_name = replace)]
9160 pub fn replace_by_pattern_with_function(
9161 this: &JsString,
9162 pattern: &RegExp,
9163 replacement: &Function,
9164 ) -> JsString;
9165
9166 /// The replacer function signature is `(match, offset, string) -> replacement`
9167 /// for patterns without capture groups, or `(match, p1, p2, ..., pN, offset, string, groups) -> replacement`
9168 /// when capture groups are present.
9169 ///
9170 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
9171 #[cfg(js_sys_unstable_apis)]
9172 #[wasm_bindgen(method, js_class = "String", js_name = replace)]
9173 pub fn replace_by_pattern_with_function(
9174 this: &JsString,
9175 pattern: &RegExp,
9176 replacement: &Function<fn(JsString) -> JsString>,
9177 ) -> JsString;
9178
9179 /// The `replace_all()` method returns a new string with all matches of a pattern
9180 /// replaced by a replacement. The pattern can be a string or a global RegExp, and
9181 /// the replacement can be a string or a function to be called for each match.
9182 ///
9183 /// Note: The original string will remain unchanged.
9184 ///
9185 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)
9186 #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
9187 pub fn replace_all(this: &JsString, pattern: &str, replacement: &str) -> JsString;
9188
9189 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)
9190 #[cfg(not(js_sys_unstable_apis))]
9191 #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
9192 pub fn replace_all_with_function(
9193 this: &JsString,
9194 pattern: &str,
9195 replacement: &Function,
9196 ) -> JsString;
9197
9198 /// The replacer function signature is `(match, offset, string) -> replacement`
9199 /// for patterns without capture groups, or `(match, p1, p2, ..., pN, offset, string, groups) -> replacement`
9200 /// when capture groups are present.
9201 ///
9202 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)
9203 #[cfg(js_sys_unstable_apis)]
9204 #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
9205 pub fn replace_all_with_function(
9206 this: &JsString,
9207 pattern: &str,
9208 replacement: &Function<fn(JsString) -> JsString>,
9209 ) -> JsString;
9210
9211 #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
9212 pub fn replace_all_by_pattern(this: &JsString, pattern: &RegExp, replacement: &str)
9213 -> JsString;
9214
9215 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)
9216 #[cfg(not(js_sys_unstable_apis))]
9217 #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
9218 pub fn replace_all_by_pattern_with_function(
9219 this: &JsString,
9220 pattern: &RegExp,
9221 replacement: &Function,
9222 ) -> JsString;
9223
9224 /// The replacer function signature is `(match, offset, string) -> replacement`
9225 /// for patterns without capture groups, or `(match, p1, p2, ..., pN, offset, string, groups) -> replacement`
9226 /// when capture groups are present.
9227 ///
9228 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)
9229 #[cfg(js_sys_unstable_apis)]
9230 #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
9231 pub fn replace_all_by_pattern_with_function(
9232 this: &JsString,
9233 pattern: &RegExp,
9234 replacement: &Function<fn(JsString) -> JsString>,
9235 ) -> JsString;
9236
9237 /// The `search()` method executes a search for a match between
9238 /// a regular expression and this String object.
9239 ///
9240 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/search)
9241 #[wasm_bindgen(method, js_class = "String")]
9242 pub fn search(this: &JsString, pattern: &RegExp) -> i32;
9243
9244 /// The `slice()` method extracts a section of a string and returns it as a
9245 /// new string, without modifying the original string.
9246 ///
9247 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice)
9248 #[wasm_bindgen(method, js_class = "String")]
9249 pub fn slice(this: &JsString, start: u32, end: u32) -> JsString;
9250
9251 /// The `split()` method splits a String object into an array of strings by separating the string
9252 /// into substrings, using a specified separator string to determine where to make each split.
9253 ///
9254 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)
9255 #[wasm_bindgen(method, js_class = "String")]
9256 pub fn split(this: &JsString, separator: &str) -> Array;
9257
9258 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)
9259 #[wasm_bindgen(method, js_class = "String", js_name = split)]
9260 pub fn split_limit(this: &JsString, separator: &str, limit: u32) -> Array;
9261
9262 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)
9263 #[wasm_bindgen(method, js_class = "String", js_name = split)]
9264 pub fn split_by_pattern(this: &JsString, pattern: &RegExp) -> Array;
9265
9266 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)
9267 #[wasm_bindgen(method, js_class = "String", js_name = split)]
9268 pub fn split_by_pattern_limit(this: &JsString, pattern: &RegExp, limit: u32) -> Array;
9269
9270 /// The `startsWith()` method determines whether a string begins with the
9271 /// characters of a specified string, returning true or false as
9272 /// appropriate.
9273 ///
9274 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith)
9275 #[wasm_bindgen(method, js_class = "String", js_name = startsWith)]
9276 pub fn starts_with(this: &JsString, search_string: &str, position: u32) -> bool;
9277
9278 /// The `substring()` method returns the part of the string between the
9279 /// start and end indexes, or to the end of the string.
9280 ///
9281 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring)
9282 #[wasm_bindgen(method, js_class = "String")]
9283 pub fn substring(this: &JsString, index_start: u32, index_end: u32) -> JsString;
9284
9285 /// The `substr()` method returns the part of a string between
9286 /// the start index and a number of characters after it.
9287 ///
9288 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr)
9289 #[wasm_bindgen(method, js_class = "String")]
9290 pub fn substr(this: &JsString, start: i32, length: i32) -> JsString;
9291
9292 /// The `toLocaleLowerCase()` method returns the calling string value converted to lower case,
9293 /// according to any locale-specific case mappings.
9294 ///
9295 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLocaleLowerCase)
9296 #[wasm_bindgen(method, js_class = "String", js_name = toLocaleLowerCase)]
9297 pub fn to_locale_lower_case(this: &JsString, locale: Option<&str>) -> JsString;
9298
9299 /// The `toLocaleUpperCase()` method returns the calling string value converted to upper case,
9300 /// according to any locale-specific case mappings.
9301 ///
9302 /// [MDN documentation](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/String/toLocaleUpperCase)
9303 #[wasm_bindgen(method, js_class = "String", js_name = toLocaleUpperCase)]
9304 pub fn to_locale_upper_case(this: &JsString, locale: Option<&str>) -> JsString;
9305
9306 /// The `toLowerCase()` method returns the calling string value
9307 /// converted to lower case.
9308 ///
9309 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLowerCase)
9310 #[wasm_bindgen(method, js_class = "String", js_name = toLowerCase)]
9311 pub fn to_lower_case(this: &JsString) -> JsString;
9312
9313 /// The `toString()` method returns a string representing the specified
9314 /// object.
9315 ///
9316 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toString)
9317 #[cfg(not(js_sys_unstable_apis))]
9318 #[wasm_bindgen(method, js_class = "String", js_name = toString)]
9319 pub fn to_string(this: &JsString) -> JsString;
9320
9321 /// The `toUpperCase()` method returns the calling string value converted to
9322 /// uppercase (the value will be converted to a string if it isn't one).
9323 ///
9324 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase)
9325 #[wasm_bindgen(method, js_class = "String", js_name = toUpperCase)]
9326 pub fn to_upper_case(this: &JsString) -> JsString;
9327
9328 /// The `trim()` method removes whitespace from both ends of a string.
9329 /// Whitespace in this context is all the whitespace characters (space, tab,
9330 /// no-break space, etc.) and all the line terminator characters (LF, CR,
9331 /// etc.).
9332 ///
9333 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trim)
9334 #[wasm_bindgen(method, js_class = "String")]
9335 pub fn trim(this: &JsString) -> JsString;
9336
9337 /// The `trimEnd()` method removes whitespace from the end of a string.
9338 /// `trimRight()` is an alias of this method.
9339 ///
9340 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimEnd)
9341 #[wasm_bindgen(method, js_class = "String", js_name = trimEnd)]
9342 pub fn trim_end(this: &JsString) -> JsString;
9343
9344 /// The `trimEnd()` method removes whitespace from the end of a string.
9345 /// `trimRight()` is an alias of this method.
9346 ///
9347 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimEnd)
9348 #[wasm_bindgen(method, js_class = "String", js_name = trimRight)]
9349 pub fn trim_right(this: &JsString) -> JsString;
9350
9351 /// The `trimStart()` method removes whitespace from the beginning of a
9352 /// string. `trimLeft()` is an alias of this method.
9353 ///
9354 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimStart)
9355 #[wasm_bindgen(method, js_class = "String", js_name = trimStart)]
9356 pub fn trim_start(this: &JsString) -> JsString;
9357
9358 /// The `trimStart()` method removes whitespace from the beginning of a
9359 /// string. `trimLeft()` is an alias of this method.
9360 ///
9361 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimStart)
9362 #[wasm_bindgen(method, js_class = "String", js_name = trimLeft)]
9363 pub fn trim_left(this: &JsString) -> JsString;
9364
9365 /// The `valueOf()` method returns the primitive value of a `String` object.
9366 ///
9367 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/valueOf)
9368 #[wasm_bindgen(method, js_class = "String", js_name = valueOf)]
9369 pub fn value_of(this: &JsString) -> JsString;
9370
9371 /// The static `raw()` method is a tag function of template literals,
9372 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9373 ///
9374 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9375 #[wasm_bindgen(catch, variadic, static_method_of = JsString, js_class = "String")]
9376 pub fn raw(call_site: &Object, substitutions: &Array) -> Result<JsString, JsValue>;
9377
9378 /// The static `raw()` method is a tag function of template literals,
9379 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9380 ///
9381 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9382 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9383 pub fn raw_0(call_site: &Object) -> Result<JsString, JsValue>;
9384
9385 /// The static `raw()` method is a tag function of template literals,
9386 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9387 ///
9388 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9389 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9390 pub fn raw_1(call_site: &Object, substitutions_1: &str) -> Result<JsString, JsValue>;
9391
9392 /// The static `raw()` method is a tag function of template literals,
9393 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9394 ///
9395 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9396 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9397 pub fn raw_2(
9398 call_site: &Object,
9399 substitutions1: &str,
9400 substitutions2: &str,
9401 ) -> Result<JsString, JsValue>;
9402
9403 /// The static `raw()` method is a tag function of template literals,
9404 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9405 ///
9406 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9407 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9408 pub fn raw_3(
9409 call_site: &Object,
9410 substitutions1: &str,
9411 substitutions2: &str,
9412 substitutions3: &str,
9413 ) -> Result<JsString, JsValue>;
9414
9415 /// The static `raw()` method is a tag function of template literals,
9416 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9417 ///
9418 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9419 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9420 pub fn raw_4(
9421 call_site: &Object,
9422 substitutions1: &str,
9423 substitutions2: &str,
9424 substitutions3: &str,
9425 substitutions4: &str,
9426 ) -> Result<JsString, JsValue>;
9427
9428 /// The static `raw()` method is a tag function of template literals,
9429 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9430 ///
9431 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9432 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9433 pub fn raw_5(
9434 call_site: &Object,
9435 substitutions1: &str,
9436 substitutions2: &str,
9437 substitutions3: &str,
9438 substitutions4: &str,
9439 substitutions5: &str,
9440 ) -> Result<JsString, JsValue>;
9441
9442 /// The static `raw()` method is a tag function of template literals,
9443 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9444 ///
9445 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9446 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9447 pub fn raw_6(
9448 call_site: &Object,
9449 substitutions1: &str,
9450 substitutions2: &str,
9451 substitutions3: &str,
9452 substitutions4: &str,
9453 substitutions5: &str,
9454 substitutions6: &str,
9455 ) -> Result<JsString, JsValue>;
9456
9457 /// The static `raw()` method is a tag function of template literals,
9458 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9459 ///
9460 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9461 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9462 pub fn raw_7(
9463 call_site: &Object,
9464 substitutions1: &str,
9465 substitutions2: &str,
9466 substitutions3: &str,
9467 substitutions4: &str,
9468 substitutions5: &str,
9469 substitutions6: &str,
9470 substitutions7: &str,
9471 ) -> Result<JsString, JsValue>;
9472}
9473
9474// These upcasts are non-castable due to the constraints on the function
9475// but the UpcastFrom covariance must still extend through closure types.
9476// (impl UpcastFrom really just means CovariantGeneric relation)
9477impl UpcastFrom<String> for JsString {}
9478impl UpcastFrom<JsString> for String {}
9479
9480impl UpcastFrom<&str> for JsString {}
9481impl UpcastFrom<JsString> for &str {}
9482
9483impl UpcastFrom<char> for JsString {}
9484impl UpcastFrom<JsString> for char {}
9485
9486impl JsString {
9487 /// Returns the `JsString` value of this JS value if it's an instance of a
9488 /// string.
9489 ///
9490 /// If this JS value is not an instance of a string then this returns
9491 /// `None`.
9492 #[cfg(not(js_sys_unstable_apis))]
9493 #[deprecated(note = "recommended to use dyn_ref instead which is now equivalent")]
9494 pub fn try_from(val: &JsValue) -> Option<&JsString> {
9495 val.dyn_ref()
9496 }
9497
9498 /// Returns whether this string is a valid UTF-16 string.
9499 ///
9500 /// This is useful for learning whether `String::from(..)` will return a
9501 /// lossless representation of the JS string. If this string contains
9502 /// unpaired surrogates then `String::from` will succeed but it will be a
9503 /// lossy representation of the JS string because unpaired surrogates will
9504 /// become replacement characters.
9505 ///
9506 /// If this function returns `false` then to get a lossless representation
9507 /// of the string you'll need to manually use the `iter` method (or the
9508 /// `char_code_at` accessor) to view the raw character codes.
9509 ///
9510 /// For more information, see the documentation on [JS strings vs Rust
9511 /// strings][docs]
9512 ///
9513 /// [docs]: https://wasm-bindgen.github.io/wasm-bindgen/reference/types/str.html
9514 pub fn is_valid_utf16(&self) -> bool {
9515 core::char::decode_utf16(self.iter()).all(|i| i.is_ok())
9516 }
9517
9518 /// Returns an iterator over the `u16` character codes that make up this JS
9519 /// string.
9520 ///
9521 /// This method will call `char_code_at` for each code in this JS string,
9522 /// returning an iterator of the codes in sequence.
9523 pub fn iter(
9524 &self,
9525 ) -> impl ExactSizeIterator<Item = u16> + DoubleEndedIterator<Item = u16> + '_ {
9526 (0..self.length()).map(move |i| self.char_code_at(i) as u16)
9527 }
9528
9529 /// If this string consists of a single Unicode code point, then this method
9530 /// converts it into a Rust `char` without doing any allocations.
9531 ///
9532 /// If this JS value is not a valid UTF-8 or consists of more than a single
9533 /// codepoint, then this returns `None`.
9534 ///
9535 /// Note that a single Unicode code point might be represented as more than
9536 /// one code unit on the JavaScript side. For example, a JavaScript string
9537 /// `"\uD801\uDC37"` is actually a single Unicode code point U+10437 which
9538 /// corresponds to a character '𐐷'.
9539 pub fn as_char(&self) -> Option<char> {
9540 let len = self.length();
9541
9542 if len == 0 || len > 2 {
9543 return None;
9544 }
9545
9546 #[cfg(not(js_sys_unstable_apis))]
9547 let cp = self.code_point_at(0).as_f64().unwrap_throw() as u32;
9548 #[cfg(js_sys_unstable_apis)]
9549 let cp = self.code_point_at(0)?;
9550
9551 let c = core::char::from_u32(cp)?;
9552
9553 if c.len_utf16() as u32 == len {
9554 Some(c)
9555 } else {
9556 None
9557 }
9558 }
9559}
9560
9561impl PartialEq<str> for JsString {
9562 #[allow(clippy::cmp_owned)] // prevent infinite recursion
9563 fn eq(&self, other: &str) -> bool {
9564 String::from(self) == other
9565 }
9566}
9567
9568impl<'a> PartialEq<&'a str> for JsString {
9569 fn eq(&self, other: &&'a str) -> bool {
9570 <JsString as PartialEq<str>>::eq(self, other)
9571 }
9572}
9573
9574impl PartialEq<String> for JsString {
9575 fn eq(&self, other: &String) -> bool {
9576 <JsString as PartialEq<str>>::eq(self, other)
9577 }
9578}
9579
9580impl<'a> PartialEq<&'a String> for JsString {
9581 fn eq(&self, other: &&'a String) -> bool {
9582 <JsString as PartialEq<str>>::eq(self, other)
9583 }
9584}
9585
9586impl Default for JsString {
9587 fn default() -> Self {
9588 Self::from("")
9589 }
9590}
9591
9592impl<'a> From<&'a str> for JsString {
9593 fn from(s: &'a str) -> Self {
9594 JsString::unchecked_from_js(JsValue::from_str(s))
9595 }
9596}
9597
9598impl From<String> for JsString {
9599 fn from(s: String) -> Self {
9600 From::from(&*s)
9601 }
9602}
9603
9604impl From<char> for JsString {
9605 #[inline]
9606 fn from(c: char) -> Self {
9607 JsString::from_code_point1(c as u32).unwrap_throw()
9608 }
9609}
9610
9611impl<'a> From<&'a JsString> for String {
9612 fn from(s: &'a JsString) -> Self {
9613 s.obj.as_string().unwrap_throw()
9614 }
9615}
9616
9617impl From<JsString> for String {
9618 fn from(s: JsString) -> Self {
9619 From::from(&s)
9620 }
9621}
9622
9623impl fmt::Debug for JsString {
9624 #[inline]
9625 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9626 fmt::Debug::fmt(&String::from(self), f)
9627 }
9628}
9629
9630impl fmt::Display for JsString {
9631 #[inline]
9632 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9633 fmt::Display::fmt(&String::from(self), f)
9634 }
9635}
9636
9637impl str::FromStr for JsString {
9638 type Err = convert::Infallible;
9639 fn from_str(s: &str) -> Result<Self, Self::Err> {
9640 Ok(JsString::from(s))
9641 }
9642}
9643
9644// Symbol
9645#[wasm_bindgen]
9646extern "C" {
9647 #[wasm_bindgen(is_type_of = JsValue::is_symbol, typescript_type = "Symbol")]
9648 #[derive(Clone, Debug)]
9649 pub type Symbol;
9650
9651 /// The `Symbol.hasInstance` well-known symbol is used to determine
9652 /// if a constructor object recognizes an object as its instance.
9653 /// The `instanceof` operator's behavior can be customized by this symbol.
9654 ///
9655 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/hasInstance)
9656 #[wasm_bindgen(static_method_of = Symbol, getter, js_name = hasInstance)]
9657 pub fn has_instance() -> Symbol;
9658
9659 /// The `Symbol.isConcatSpreadable` well-known symbol is used to configure
9660 /// if an object should be flattened to its array elements when using the
9661 /// `Array.prototype.concat()` method.
9662 ///
9663 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/isConcatSpreadable)
9664 #[wasm_bindgen(static_method_of = Symbol, getter, js_name = isConcatSpreadable)]
9665 pub fn is_concat_spreadable() -> Symbol;
9666
9667 /// The `Symbol.asyncIterator` well-known symbol specifies the default AsyncIterator for an object.
9668 /// If this property is set on an object, it is an async iterable and can be used in a `for await...of` loop.
9669 ///
9670 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/asyncIterator)
9671 #[wasm_bindgen(static_method_of = Symbol, getter, js_name = asyncIterator)]
9672 pub fn async_iterator() -> Symbol;
9673
9674 /// The `Symbol.iterator` well-known symbol specifies the default iterator
9675 /// for an object. Used by `for...of`.
9676 ///
9677 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/iterator)
9678 #[wasm_bindgen(static_method_of = Symbol, getter)]
9679 pub fn iterator() -> Symbol;
9680
9681 /// The `Symbol.match` well-known symbol specifies the matching of a regular
9682 /// expression against a string. This function is called by the
9683 /// `String.prototype.match()` method.
9684 ///
9685 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/match)
9686 #[wasm_bindgen(static_method_of = Symbol, getter, js_name = match)]
9687 pub fn match_() -> Symbol;
9688
9689 /// The `Symbol.replace` well-known symbol specifies the method that
9690 /// replaces matched substrings of a string. This function is called by the
9691 /// `String.prototype.replace()` method.
9692 ///
9693 /// For more information, see `RegExp.prototype[@@replace]()` and
9694 /// `String.prototype.replace()`.
9695 ///
9696 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/replace)
9697 #[wasm_bindgen(static_method_of = Symbol, getter)]
9698 pub fn replace() -> Symbol;
9699
9700 /// The `Symbol.search` well-known symbol specifies the method that returns
9701 /// the index within a string that matches the regular expression. This
9702 /// function is called by the `String.prototype.search()` method.
9703 ///
9704 /// For more information, see `RegExp.prototype[@@search]()` and
9705 /// `String.prototype.search()`.
9706 ///
9707 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/search)
9708 #[wasm_bindgen(static_method_of = Symbol, getter)]
9709 pub fn search() -> Symbol;
9710
9711 /// The well-known symbol `Symbol.species` specifies a function-valued
9712 /// property that the constructor function uses to create derived objects.
9713 ///
9714 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/species)
9715 #[wasm_bindgen(static_method_of = Symbol, getter)]
9716 pub fn species() -> Symbol;
9717
9718 /// The `Symbol.split` well-known symbol specifies the method that splits a
9719 /// string at the indices that match a regular expression. This function is
9720 /// called by the `String.prototype.split()` method.
9721 ///
9722 /// For more information, see `RegExp.prototype[@@split]()` and
9723 /// `String.prototype.split()`.
9724 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/split)
9725 #[wasm_bindgen(static_method_of = Symbol, getter)]
9726 pub fn split() -> Symbol;
9727
9728 /// The `Symbol.toPrimitive` is a symbol that specifies a function valued
9729 /// property that is called to convert an object to a corresponding
9730 /// primitive value.
9731 ///
9732 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toPrimitive)
9733 #[wasm_bindgen(static_method_of = Symbol, getter, js_name = toPrimitive)]
9734 pub fn to_primitive() -> Symbol;
9735
9736 /// The `Symbol.toStringTag` well-known symbol is a string valued property
9737 /// that is used in the creation of the default string description of an
9738 /// object. It is accessed internally by the `Object.prototype.toString()`
9739 /// method.
9740 ///
9741 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toString)
9742 #[wasm_bindgen(static_method_of = Symbol, getter, js_name = toStringTag)]
9743 pub fn to_string_tag() -> Symbol;
9744
9745 /// The `Symbol.for(key)` method searches for existing symbols in a runtime-wide symbol registry with
9746 /// the given key and returns it if found.
9747 /// Otherwise a new symbol gets created in the global symbol registry with this key.
9748 ///
9749 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/for)
9750 #[wasm_bindgen(static_method_of = Symbol, js_name = for)]
9751 pub fn for_(key: &str) -> Symbol;
9752
9753 /// The `Symbol.keyFor(sym)` method retrieves a shared symbol key from the global symbol registry for the given symbol.
9754 ///
9755 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/keyFor)
9756 #[wasm_bindgen(static_method_of = Symbol, js_name = keyFor)]
9757 pub fn key_for(sym: &Symbol) -> JsValue;
9758
9759 // Next major: deprecate
9760 /// The `toString()` method returns a string representing the specified Symbol object.
9761 ///
9762 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toString)
9763 #[wasm_bindgen(method, js_name = toString)]
9764 pub fn to_string(this: &Symbol) -> JsString;
9765
9766 /// The `toString()` method returns a string representing the specified Symbol object.
9767 ///
9768 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toString)
9769 #[wasm_bindgen(method, js_name = toString)]
9770 pub fn to_js_string(this: &Symbol) -> JsString;
9771
9772 /// The `Symbol.unscopables` well-known symbol is used to specify an object
9773 /// value of whose own and inherited property names are excluded from the
9774 /// with environment bindings of the associated object.
9775 ///
9776 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/unscopables)
9777 #[wasm_bindgen(static_method_of = Symbol, getter)]
9778 pub fn unscopables() -> Symbol;
9779
9780 /// The `valueOf()` method returns the primitive value of a Symbol object.
9781 ///
9782 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/valueOf)
9783 #[wasm_bindgen(method, js_name = valueOf)]
9784 pub fn value_of(this: &Symbol) -> Symbol;
9785}
9786
9787#[allow(non_snake_case)]
9788pub mod Intl {
9789 use super::*;
9790
9791 // Intl
9792 #[wasm_bindgen]
9793 extern "C" {
9794 /// The `Intl.getCanonicalLocales()` method returns an array containing
9795 /// the canonical locale names. Duplicates will be omitted and elements
9796 /// will be validated as structurally valid language tags.
9797 ///
9798 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/getCanonicalLocales)
9799 #[cfg(not(js_sys_unstable_apis))]
9800 #[wasm_bindgen(js_name = getCanonicalLocales, js_namespace = Intl)]
9801 pub fn get_canonical_locales(s: &JsValue) -> Array;
9802
9803 /// The `Intl.getCanonicalLocales()` method returns an array containing
9804 /// the canonical locale names. Duplicates will be omitted and elements
9805 /// will be validated as structurally valid language tags.
9806 ///
9807 /// Throws a `RangeError` if any of the strings are not valid locale identifiers.
9808 ///
9809 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/getCanonicalLocales)
9810 #[cfg(js_sys_unstable_apis)]
9811 #[wasm_bindgen(js_name = getCanonicalLocales, js_namespace = Intl, catch)]
9812 pub fn get_canonical_locales(s: &[JsString]) -> Result<Array<JsString>, JsValue>;
9813
9814 /// The `Intl.supportedValuesOf()` method returns an array containing the
9815 /// supported calendar, collation, currency, numbering system, or unit values
9816 /// supported by the implementation.
9817 ///
9818 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/supportedValuesOf)
9819 #[wasm_bindgen(js_name = supportedValuesOf, js_namespace = Intl)]
9820 pub fn supported_values_of(key: SupportedValuesKey) -> Array<JsString>;
9821 }
9822
9823 // Intl string enums
9824
9825 /// Key for `Intl.supportedValuesOf()`.
9826 #[wasm_bindgen]
9827 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9828 pub enum SupportedValuesKey {
9829 Calendar = "calendar",
9830 Collation = "collation",
9831 Currency = "currency",
9832 NumberingSystem = "numberingSystem",
9833 TimeZone = "timeZone",
9834 Unit = "unit",
9835 }
9836
9837 /// Locale matching algorithm for Intl constructors.
9838 #[wasm_bindgen]
9839 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9840 pub enum LocaleMatcher {
9841 Lookup = "lookup",
9842 BestFit = "best fit",
9843 }
9844
9845 /// Usage for `Intl.Collator`.
9846 #[wasm_bindgen]
9847 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9848 pub enum CollatorUsage {
9849 Sort = "sort",
9850 Search = "search",
9851 }
9852
9853 /// Sensitivity for `Intl.Collator`.
9854 #[wasm_bindgen]
9855 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9856 pub enum CollatorSensitivity {
9857 Base = "base",
9858 Accent = "accent",
9859 Case = "case",
9860 Variant = "variant",
9861 }
9862
9863 /// Case first option for `Intl.Collator`.
9864 #[wasm_bindgen]
9865 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9866 pub enum CollatorCaseFirst {
9867 Upper = "upper",
9868 Lower = "lower",
9869 False = "false",
9870 }
9871
9872 /// Style for `Intl.NumberFormat`.
9873 #[wasm_bindgen]
9874 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9875 pub enum NumberFormatStyle {
9876 Decimal = "decimal",
9877 Currency = "currency",
9878 Percent = "percent",
9879 Unit = "unit",
9880 }
9881
9882 /// Currency display for `Intl.NumberFormat`.
9883 #[wasm_bindgen]
9884 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9885 pub enum CurrencyDisplay {
9886 Code = "code",
9887 Symbol = "symbol",
9888 NarrowSymbol = "narrowSymbol",
9889 Name = "name",
9890 }
9891
9892 /// Currency sign for `Intl.NumberFormat`.
9893 #[wasm_bindgen]
9894 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9895 pub enum CurrencySign {
9896 Standard = "standard",
9897 Accounting = "accounting",
9898 }
9899
9900 /// Unit display for `Intl.NumberFormat`.
9901 #[wasm_bindgen]
9902 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9903 pub enum UnitDisplay {
9904 Short = "short",
9905 Narrow = "narrow",
9906 Long = "long",
9907 }
9908
9909 /// Notation for `Intl.NumberFormat`.
9910 #[wasm_bindgen]
9911 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9912 pub enum NumberFormatNotation {
9913 Standard = "standard",
9914 Scientific = "scientific",
9915 Engineering = "engineering",
9916 Compact = "compact",
9917 }
9918
9919 /// Compact display for `Intl.NumberFormat`.
9920 #[wasm_bindgen]
9921 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9922 pub enum CompactDisplay {
9923 Short = "short",
9924 Long = "long",
9925 }
9926
9927 /// Sign display for `Intl.NumberFormat`.
9928 #[wasm_bindgen]
9929 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9930 pub enum SignDisplay {
9931 Auto = "auto",
9932 Never = "never",
9933 Always = "always",
9934 ExceptZero = "exceptZero",
9935 }
9936
9937 /// Rounding mode for `Intl.NumberFormat`.
9938 #[wasm_bindgen]
9939 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9940 pub enum RoundingMode {
9941 Ceil = "ceil",
9942 Floor = "floor",
9943 Expand = "expand",
9944 Trunc = "trunc",
9945 HalfCeil = "halfCeil",
9946 HalfFloor = "halfFloor",
9947 HalfExpand = "halfExpand",
9948 HalfTrunc = "halfTrunc",
9949 HalfEven = "halfEven",
9950 }
9951
9952 /// Rounding priority for `Intl.NumberFormat`.
9953 #[wasm_bindgen]
9954 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9955 pub enum RoundingPriority {
9956 Auto = "auto",
9957 MorePrecision = "morePrecision",
9958 LessPrecision = "lessPrecision",
9959 }
9960
9961 /// Trailing zero display for `Intl.NumberFormat`.
9962 #[wasm_bindgen]
9963 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9964 pub enum TrailingZeroDisplay {
9965 Auto = "auto",
9966 StripIfInteger = "stripIfInteger",
9967 }
9968
9969 /// Use grouping option for `Intl.NumberFormat`.
9970 ///
9971 /// Determines whether to use grouping separators, such as thousands
9972 /// separators or thousand/lakh/crore separators.
9973 ///
9974 /// The default is `Min2` if notation is "compact", and `Auto` otherwise.
9975 ///
9976 /// Note: The string values `"true"` and `"false"` are accepted by JavaScript
9977 /// but are always converted to the default value. Use `True` and `False`
9978 /// variants for the boolean behavior.
9979 ///
9980 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#usegrouping)
9981 #[wasm_bindgen]
9982 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9983 pub enum UseGrouping {
9984 /// Display grouping separators even if the locale prefers otherwise.
9985 Always = "always",
9986 /// Display grouping separators based on the locale preference,
9987 /// which may also be dependent on the currency.
9988 Auto = "auto",
9989 /// Display grouping separators when there are at least 2 digits in a group.
9990 Min2 = "min2",
9991 /// Same as `Always`. Display grouping separators even if the locale prefers otherwise.
9992 True = "true",
9993 /// Display no grouping separators.
9994 False = "false",
9995 }
9996
9997 /// Date/time style for `Intl.DateTimeFormat`.
9998 #[wasm_bindgen]
9999 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10000 pub enum DateTimeStyle {
10001 Full = "full",
10002 Long = "long",
10003 Medium = "medium",
10004 Short = "short",
10005 }
10006
10007 /// Hour cycle for `Intl.DateTimeFormat`.
10008 #[wasm_bindgen]
10009 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10010 pub enum HourCycle {
10011 H11 = "h11",
10012 H12 = "h12",
10013 H23 = "h23",
10014 H24 = "h24",
10015 }
10016
10017 /// Weekday format for `Intl.DateTimeFormat`.
10018 #[wasm_bindgen]
10019 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10020 pub enum WeekdayFormat {
10021 Narrow = "narrow",
10022 Short = "short",
10023 Long = "long",
10024 }
10025
10026 /// Era format for `Intl.DateTimeFormat`.
10027 #[wasm_bindgen]
10028 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10029 pub enum EraFormat {
10030 Narrow = "narrow",
10031 Short = "short",
10032 Long = "long",
10033 }
10034
10035 /// Year format for `Intl.DateTimeFormat`.
10036 #[wasm_bindgen]
10037 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10038 pub enum YearFormat {
10039 Numeric = "numeric",
10040 TwoDigit = "2-digit",
10041 }
10042
10043 /// Month format for `Intl.DateTimeFormat`.
10044 #[wasm_bindgen]
10045 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10046 pub enum MonthFormat {
10047 #[wasm_bindgen]
10048 Numeric = "numeric",
10049 #[wasm_bindgen]
10050 TwoDigit = "2-digit",
10051 #[wasm_bindgen]
10052 Narrow = "narrow",
10053 #[wasm_bindgen]
10054 Short = "short",
10055 #[wasm_bindgen]
10056 Long = "long",
10057 }
10058
10059 /// Day format for `Intl.DateTimeFormat`.
10060 #[wasm_bindgen]
10061 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10062 pub enum DayFormat {
10063 #[wasm_bindgen]
10064 Numeric = "numeric",
10065 #[wasm_bindgen]
10066 TwoDigit = "2-digit",
10067 }
10068
10069 /// Hour/minute/second format for `Intl.DateTimeFormat`.
10070 #[wasm_bindgen]
10071 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10072 pub enum NumericFormat {
10073 #[wasm_bindgen]
10074 Numeric = "numeric",
10075 #[wasm_bindgen]
10076 TwoDigit = "2-digit",
10077 }
10078
10079 /// Time zone name format for `Intl.DateTimeFormat`.
10080 #[wasm_bindgen]
10081 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10082 pub enum TimeZoneNameFormat {
10083 Short = "short",
10084 Long = "long",
10085 ShortOffset = "shortOffset",
10086 LongOffset = "longOffset",
10087 ShortGeneric = "shortGeneric",
10088 LongGeneric = "longGeneric",
10089 }
10090
10091 /// Day period format for `Intl.DateTimeFormat`.
10092 #[wasm_bindgen]
10093 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10094 pub enum DayPeriodFormat {
10095 Narrow = "narrow",
10096 Short = "short",
10097 Long = "long",
10098 }
10099
10100 /// Part type for `DateTimeFormat.formatToParts()`.
10101 #[wasm_bindgen]
10102 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10103 pub enum DateTimeFormatPartType {
10104 Day = "day",
10105 DayPeriod = "dayPeriod",
10106 Era = "era",
10107 FractionalSecond = "fractionalSecond",
10108 Hour = "hour",
10109 Literal = "literal",
10110 Minute = "minute",
10111 Month = "month",
10112 RelatedYear = "relatedYear",
10113 Second = "second",
10114 TimeZoneName = "timeZoneName",
10115 Weekday = "weekday",
10116 Year = "year",
10117 YearName = "yearName",
10118 }
10119
10120 /// Part type for `NumberFormat.formatToParts()`.
10121 #[wasm_bindgen]
10122 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10123 pub enum NumberFormatPartType {
10124 Compact = "compact",
10125 Currency = "currency",
10126 Decimal = "decimal",
10127 ExponentInteger = "exponentInteger",
10128 ExponentMinusSign = "exponentMinusSign",
10129 ExponentSeparator = "exponentSeparator",
10130 Fraction = "fraction",
10131 Group = "group",
10132 Infinity = "infinity",
10133 Integer = "integer",
10134 Literal = "literal",
10135 MinusSign = "minusSign",
10136 Nan = "nan",
10137 PercentSign = "percentSign",
10138 PlusSign = "plusSign",
10139 Unit = "unit",
10140 Unknown = "unknown",
10141 }
10142
10143 /// Type for `Intl.PluralRules` (cardinal or ordinal).
10144 #[wasm_bindgen]
10145 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10146 pub enum PluralRulesType {
10147 Cardinal = "cardinal",
10148 Ordinal = "ordinal",
10149 }
10150
10151 /// Plural category returned by `PluralRules.select()`.
10152 #[wasm_bindgen]
10153 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10154 pub enum PluralCategory {
10155 Zero = "zero",
10156 One = "one",
10157 Two = "two",
10158 Few = "few",
10159 Many = "many",
10160 Other = "other",
10161 }
10162
10163 /// Numeric option for `Intl.RelativeTimeFormat`.
10164 #[wasm_bindgen]
10165 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10166 pub enum RelativeTimeFormatNumeric {
10167 Always = "always",
10168 Auto = "auto",
10169 }
10170
10171 /// Style for `Intl.RelativeTimeFormat`.
10172 #[wasm_bindgen]
10173 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10174 pub enum RelativeTimeFormatStyle {
10175 Long = "long",
10176 Short = "short",
10177 Narrow = "narrow",
10178 }
10179
10180 /// Unit for `RelativeTimeFormat.format()`.
10181 #[wasm_bindgen]
10182 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10183 pub enum RelativeTimeFormatUnit {
10184 Year = "year",
10185 Years = "years",
10186 Quarter = "quarter",
10187 Quarters = "quarters",
10188 Month = "month",
10189 Months = "months",
10190 Week = "week",
10191 Weeks = "weeks",
10192 Day = "day",
10193 Days = "days",
10194 Hour = "hour",
10195 Hours = "hours",
10196 Minute = "minute",
10197 Minutes = "minutes",
10198 Second = "second",
10199 Seconds = "seconds",
10200 }
10201
10202 /// Part type for `RelativeTimeFormat.formatToParts()`.
10203 #[wasm_bindgen]
10204 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10205 pub enum RelativeTimeFormatPartType {
10206 Literal = "literal",
10207 Integer = "integer",
10208 Decimal = "decimal",
10209 Fraction = "fraction",
10210 }
10211
10212 /// Source indicator for range format parts.
10213 ///
10214 /// Indicates which part of the range (start, end, or shared) a formatted
10215 /// part belongs to when using `formatRangeToParts()`.
10216 ///
10217 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatRangeToParts#description)
10218 #[wasm_bindgen]
10219 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10220 pub enum RangeSource {
10221 /// The part is from the start of the range.
10222 StartRange = "startRange",
10223 /// The part is from the end of the range.
10224 EndRange = "endRange",
10225 /// The part is shared between start and end (e.g., a separator or common element).
10226 Shared = "shared",
10227 }
10228
10229 /// Type for `Intl.ListFormat`.
10230 #[wasm_bindgen]
10231 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10232 pub enum ListFormatType {
10233 /// For lists of standalone items (default).
10234 Conjunction = "conjunction",
10235 /// For lists representing alternatives.
10236 Disjunction = "disjunction",
10237 /// For lists of values with units.
10238 Unit = "unit",
10239 }
10240
10241 /// Style for `Intl.ListFormat`.
10242 #[wasm_bindgen]
10243 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10244 pub enum ListFormatStyle {
10245 /// "A, B, and C" (default).
10246 Long = "long",
10247 /// "A, B, C".
10248 Short = "short",
10249 /// "A B C".
10250 Narrow = "narrow",
10251 }
10252
10253 /// Part type for `Intl.ListFormat.formatToParts()`.
10254 #[wasm_bindgen]
10255 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10256 pub enum ListFormatPartType {
10257 /// A value from the list.
10258 Element = "element",
10259 /// A linguistic construct (e.g., ", ", " and ").
10260 Literal = "literal",
10261 }
10262
10263 /// Type for `Intl.Segmenter`.
10264 #[wasm_bindgen]
10265 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10266 pub enum SegmenterGranularity {
10267 /// Segment by grapheme clusters (user-perceived characters).
10268 Grapheme = "grapheme",
10269 /// Segment by words.
10270 Word = "word",
10271 /// Segment by sentences.
10272 Sentence = "sentence",
10273 }
10274
10275 /// Type for `Intl.DisplayNames`.
10276 #[wasm_bindgen]
10277 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10278 pub enum DisplayNamesType {
10279 /// Language display names.
10280 Language = "language",
10281 /// Region display names.
10282 Region = "region",
10283 /// Script display names.
10284 Script = "script",
10285 /// Currency display names.
10286 Currency = "currency",
10287 /// Calendar display names.
10288 Calendar = "calendar",
10289 /// Date/time field display names.
10290 DateTimeField = "dateTimeField",
10291 }
10292
10293 /// Style for `Intl.DisplayNames`.
10294 #[wasm_bindgen]
10295 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10296 pub enum DisplayNamesStyle {
10297 /// Full display name (default).
10298 Long = "long",
10299 /// Abbreviated display name.
10300 Short = "short",
10301 /// Minimal display name.
10302 Narrow = "narrow",
10303 }
10304
10305 /// Fallback for `Intl.DisplayNames`.
10306 #[wasm_bindgen]
10307 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10308 pub enum DisplayNamesFallback {
10309 /// Return the input code if no display name is available (default).
10310 Code = "code",
10311 /// Return undefined if no display name is available.
10312 None = "none",
10313 }
10314
10315 /// Language display for `Intl.DisplayNames`.
10316 #[wasm_bindgen]
10317 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10318 pub enum DisplayNamesLanguageDisplay {
10319 /// Use dialect names (e.g., "British English").
10320 Dialect = "dialect",
10321 /// Use standard names (e.g., "English (United Kingdom)").
10322 Standard = "standard",
10323 }
10324
10325 // Intl.RelativeTimeFormatOptions
10326 #[wasm_bindgen]
10327 extern "C" {
10328 /// Options for `Intl.RelativeTimeFormat` constructor.
10329 ///
10330 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/RelativeTimeFormat#options)
10331 #[wasm_bindgen(extends = Object)]
10332 #[derive(Clone, Debug)]
10333 pub type RelativeTimeFormatOptions;
10334
10335 #[wasm_bindgen(method, getter = localeMatcher)]
10336 pub fn get_locale_matcher(this: &RelativeTimeFormatOptions) -> Option<LocaleMatcher>;
10337 #[wasm_bindgen(method, setter = localeMatcher)]
10338 pub fn set_locale_matcher(this: &RelativeTimeFormatOptions, value: LocaleMatcher);
10339
10340 #[wasm_bindgen(method, getter = numeric)]
10341 pub fn get_numeric(this: &RelativeTimeFormatOptions) -> Option<RelativeTimeFormatNumeric>;
10342 #[wasm_bindgen(method, setter = numeric)]
10343 pub fn set_numeric(this: &RelativeTimeFormatOptions, value: RelativeTimeFormatNumeric);
10344
10345 #[wasm_bindgen(method, getter = style)]
10346 pub fn get_style(this: &RelativeTimeFormatOptions) -> Option<RelativeTimeFormatStyle>;
10347 #[wasm_bindgen(method, setter = style)]
10348 pub fn set_style(this: &RelativeTimeFormatOptions, value: RelativeTimeFormatStyle);
10349 }
10350
10351 impl RelativeTimeFormatOptions {
10352 pub fn new() -> RelativeTimeFormatOptions {
10353 JsCast::unchecked_into(Object::new())
10354 }
10355 }
10356
10357 impl Default for RelativeTimeFormatOptions {
10358 fn default() -> Self {
10359 RelativeTimeFormatOptions::new()
10360 }
10361 }
10362
10363 // Intl.ResolvedRelativeTimeFormatOptions
10364 #[wasm_bindgen]
10365 extern "C" {
10366 /// Resolved options returned by `Intl.RelativeTimeFormat.prototype.resolvedOptions()`.
10367 ///
10368 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/resolvedOptions)
10369 #[wasm_bindgen(extends = RelativeTimeFormatOptions)]
10370 #[derive(Clone, Debug)]
10371 pub type ResolvedRelativeTimeFormatOptions;
10372
10373 /// The resolved locale string.
10374 #[wasm_bindgen(method, getter = locale)]
10375 pub fn get_locale(this: &ResolvedRelativeTimeFormatOptions) -> JsString;
10376
10377 /// The numbering system used.
10378 #[wasm_bindgen(method, getter = numberingSystem)]
10379 pub fn get_numbering_system(this: &ResolvedRelativeTimeFormatOptions) -> JsString;
10380 }
10381
10382 // Intl.RelativeTimeFormatPart
10383 #[wasm_bindgen]
10384 extern "C" {
10385 /// A part of the formatted relative time returned by `formatToParts()`.
10386 ///
10387 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/formatToParts)
10388 #[wasm_bindgen(extends = Object)]
10389 #[derive(Clone, Debug)]
10390 pub type RelativeTimeFormatPart;
10391
10392 /// The type of this part.
10393 #[wasm_bindgen(method, getter = type)]
10394 pub fn type_(this: &RelativeTimeFormatPart) -> RelativeTimeFormatPartType;
10395
10396 /// The string value of this part.
10397 #[wasm_bindgen(method, getter = value)]
10398 pub fn value(this: &RelativeTimeFormatPart) -> JsString;
10399
10400 /// The unit used in this part (only for integer parts).
10401 #[wasm_bindgen(method, getter = unit)]
10402 pub fn unit(this: &RelativeTimeFormatPart) -> Option<JsString>;
10403 }
10404
10405 // Intl.LocaleMatcherOptions
10406 #[wasm_bindgen]
10407 extern "C" {
10408 /// Options for `supportedLocalesOf` methods.
10409 #[wasm_bindgen(extends = Object)]
10410 #[derive(Clone, Debug)]
10411 pub type LocaleMatcherOptions;
10412
10413 #[wasm_bindgen(method, getter = localeMatcher)]
10414 pub fn get_locale_matcher(this: &LocaleMatcherOptions) -> Option<LocaleMatcher>;
10415
10416 #[wasm_bindgen(method, setter = localeMatcher)]
10417 pub fn set_locale_matcher(this: &LocaleMatcherOptions, value: LocaleMatcher);
10418 }
10419
10420 impl LocaleMatcherOptions {
10421 pub fn new() -> LocaleMatcherOptions {
10422 JsCast::unchecked_into(Object::new())
10423 }
10424 }
10425
10426 impl Default for LocaleMatcherOptions {
10427 fn default() -> Self {
10428 LocaleMatcherOptions::new()
10429 }
10430 }
10431
10432 // Intl.Collator Options
10433 #[wasm_bindgen]
10434 extern "C" {
10435 /// Options for `Intl.Collator` and `String.prototype.localeCompare`.
10436 ///
10437 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Collator/Collator#options)
10438 #[wasm_bindgen(extends = Object)]
10439 #[derive(Clone, Debug)]
10440 pub type CollatorOptions;
10441
10442 #[wasm_bindgen(method, getter = localeMatcher)]
10443 pub fn get_locale_matcher(this: &CollatorOptions) -> Option<LocaleMatcher>;
10444 #[wasm_bindgen(method, setter = localeMatcher)]
10445 pub fn set_locale_matcher(this: &CollatorOptions, value: LocaleMatcher);
10446
10447 #[wasm_bindgen(method, getter = usage)]
10448 pub fn get_usage(this: &CollatorOptions) -> Option<CollatorUsage>;
10449 #[wasm_bindgen(method, setter = usage)]
10450 pub fn set_usage(this: &CollatorOptions, value: CollatorUsage);
10451
10452 #[wasm_bindgen(method, getter = sensitivity)]
10453 pub fn get_sensitivity(this: &CollatorOptions) -> Option<CollatorSensitivity>;
10454 #[wasm_bindgen(method, setter = sensitivity)]
10455 pub fn set_sensitivity(this: &CollatorOptions, value: CollatorSensitivity);
10456
10457 #[wasm_bindgen(method, getter = ignorePunctuation)]
10458 pub fn get_ignore_punctuation(this: &CollatorOptions) -> Option<bool>;
10459 #[wasm_bindgen(method, setter = ignorePunctuation)]
10460 pub fn set_ignore_punctuation(this: &CollatorOptions, value: bool);
10461
10462 #[wasm_bindgen(method, getter = numeric)]
10463 pub fn get_numeric(this: &CollatorOptions) -> Option<bool>;
10464 #[wasm_bindgen(method, setter = numeric)]
10465 pub fn set_numeric(this: &CollatorOptions, value: bool);
10466
10467 #[wasm_bindgen(method, getter = caseFirst)]
10468 pub fn get_case_first(this: &CollatorOptions) -> Option<CollatorCaseFirst>;
10469 #[wasm_bindgen(method, setter = caseFirst)]
10470 pub fn set_case_first(this: &CollatorOptions, value: CollatorCaseFirst);
10471 }
10472 impl CollatorOptions {
10473 pub fn new() -> CollatorOptions {
10474 JsCast::unchecked_into(Object::new())
10475 }
10476 }
10477 impl Default for CollatorOptions {
10478 fn default() -> Self {
10479 CollatorOptions::new()
10480 }
10481 }
10482
10483 // Intl.Collator ResolvedCollatorOptions
10484 #[wasm_bindgen]
10485 extern "C" {
10486 #[wasm_bindgen(extends = CollatorOptions)]
10487 pub type ResolvedCollatorOptions;
10488
10489 #[wasm_bindgen(method, getter = locale)]
10490 pub fn get_locale(this: &ResolvedCollatorOptions) -> JsString; // not Option, always present
10491 #[wasm_bindgen(method, getter = collation)]
10492 pub fn get_collation(this: &ResolvedCollatorOptions) -> JsString;
10493 }
10494
10495 // Intl.Collator
10496 #[wasm_bindgen]
10497 extern "C" {
10498 /// The `Intl.Collator` object is a constructor for collators, objects
10499 /// that enable language sensitive string comparison.
10500 ///
10501 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator)
10502 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.Collator")]
10503 #[derive(Clone, Debug)]
10504 pub type Collator;
10505
10506 /// The `Intl.Collator` object is a constructor for collators, objects
10507 /// that enable language sensitive string comparison.
10508 ///
10509 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator)
10510 #[cfg(not(js_sys_unstable_apis))]
10511 #[wasm_bindgen(constructor, js_namespace = Intl)]
10512 pub fn new(locales: &Array, options: &Object) -> Collator;
10513
10514 /// The `Intl.Collator` object is a constructor for collators, objects
10515 /// that enable language sensitive string comparison.
10516 ///
10517 /// Throws a `RangeError` if locales contain invalid values.
10518 ///
10519 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator)
10520 #[cfg(js_sys_unstable_apis)]
10521 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
10522 pub fn new(locales: &[JsString], options: &CollatorOptions) -> Result<Collator, JsValue>;
10523
10524 /// The Intl.Collator.prototype.compare property returns a function that
10525 /// compares two strings according to the sort order of this Collator
10526 /// object.
10527 ///
10528 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/compare)
10529 #[cfg(not(js_sys_unstable_apis))]
10530 #[wasm_bindgen(method, getter, js_class = "Intl.Collator")]
10531 pub fn compare(this: &Collator) -> Function;
10532
10533 /// Compares two strings according to the sort order of this Collator.
10534 ///
10535 /// Returns a negative value if `a` comes before `b`, positive if `a` comes
10536 /// after `b`, and zero if they are equal.
10537 ///
10538 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Collator/compare)
10539 #[cfg(js_sys_unstable_apis)]
10540 #[wasm_bindgen(method, js_class = "Intl.Collator")]
10541 pub fn compare(this: &Collator, a: &str, b: &str) -> i32;
10542
10543 /// The `Intl.Collator.prototype.resolvedOptions()` method returns a new
10544 /// object with properties reflecting the locale and collation options
10545 /// computed during initialization of this Collator object.
10546 ///
10547 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/resolvedOptions)
10548 #[cfg(not(js_sys_unstable_apis))]
10549 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
10550 pub fn resolved_options(this: &Collator) -> Object;
10551
10552 /// The `Intl.Collator.prototype.resolvedOptions()` method returns a new
10553 /// object with properties reflecting the locale and collation options
10554 /// computed during initialization of this Collator object.
10555 ///
10556 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/resolvedOptions)
10557 #[cfg(js_sys_unstable_apis)]
10558 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
10559 pub fn resolved_options(this: &Collator) -> ResolvedCollatorOptions;
10560
10561 /// The `Intl.Collator.supportedLocalesOf()` method returns an array
10562 /// containing those of the provided locales that are supported in
10563 /// collation without having to fall back to the runtime's default
10564 /// locale.
10565 ///
10566 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/supportedLocalesOf)
10567 #[cfg(not(js_sys_unstable_apis))]
10568 #[wasm_bindgen(static_method_of = Collator, js_namespace = Intl, js_name = supportedLocalesOf)]
10569 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
10570
10571 /// The `Intl.Collator.supportedLocalesOf()` method returns an array
10572 /// containing those of the provided locales that are supported in
10573 /// collation without having to fall back to the runtime's default
10574 /// locale.
10575 ///
10576 /// Throws a `RangeError` if locales contain invalid values.
10577 ///
10578 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/supportedLocalesOf)
10579 #[cfg(js_sys_unstable_apis)]
10580 #[wasm_bindgen(static_method_of = Collator, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
10581 pub fn supported_locales_of(
10582 locales: &[JsString],
10583 options: &LocaleMatcherOptions,
10584 ) -> Result<Array<JsString>, JsValue>;
10585 }
10586
10587 #[cfg(not(js_sys_unstable_apis))]
10588 impl Default for Collator {
10589 fn default() -> Self {
10590 Self::new(
10591 &JsValue::UNDEFINED.unchecked_into(),
10592 &JsValue::UNDEFINED.unchecked_into(),
10593 )
10594 }
10595 }
10596
10597 #[cfg(js_sys_unstable_apis)]
10598 impl Default for Collator {
10599 fn default() -> Self {
10600 Self::new(&[], &Default::default()).unwrap()
10601 }
10602 }
10603
10604 // Intl.DateTimeFormatOptions
10605 #[wasm_bindgen]
10606 extern "C" {
10607 /// Options for `Intl.DateTimeFormat` constructor.
10608 ///
10609 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat#options)
10610 #[wasm_bindgen(extends = Object)]
10611 #[derive(Clone, Debug)]
10612 pub type DateTimeFormatOptions;
10613
10614 // Locale matching
10615 #[wasm_bindgen(method, getter = localeMatcher)]
10616 pub fn get_locale_matcher(this: &DateTimeFormatOptions) -> Option<LocaleMatcher>;
10617 #[wasm_bindgen(method, setter = localeMatcher)]
10618 pub fn set_locale_matcher(this: &DateTimeFormatOptions, value: LocaleMatcher);
10619
10620 // Calendar/numbering (free-form strings, no enum)
10621 #[wasm_bindgen(method, getter = calendar)]
10622 pub fn get_calendar(this: &DateTimeFormatOptions) -> Option<JsString>;
10623 #[wasm_bindgen(method, setter = calendar)]
10624 pub fn set_calendar(this: &DateTimeFormatOptions, value: &str);
10625
10626 #[wasm_bindgen(method, getter = numberingSystem)]
10627 pub fn get_numbering_system(this: &DateTimeFormatOptions) -> Option<JsString>;
10628 #[wasm_bindgen(method, setter = numberingSystem)]
10629 pub fn set_numbering_system(this: &DateTimeFormatOptions, value: &str);
10630
10631 // Timezone (free-form string)
10632 #[wasm_bindgen(method, getter = timeZone)]
10633 pub fn get_time_zone(this: &DateTimeFormatOptions) -> Option<JsString>;
10634 #[wasm_bindgen(method, setter = timeZone)]
10635 pub fn set_time_zone(this: &DateTimeFormatOptions, value: &str);
10636
10637 // Hour cycle
10638 #[wasm_bindgen(method, getter = hour12)]
10639 pub fn get_hour12(this: &DateTimeFormatOptions) -> Option<bool>;
10640 #[wasm_bindgen(method, setter = hour12)]
10641 pub fn set_hour12(this: &DateTimeFormatOptions, value: bool);
10642
10643 #[wasm_bindgen(method, getter = hourCycle)]
10644 pub fn get_hour_cycle(this: &DateTimeFormatOptions) -> Option<HourCycle>;
10645 #[wasm_bindgen(method, setter = hourCycle)]
10646 pub fn set_hour_cycle(this: &DateTimeFormatOptions, value: HourCycle);
10647
10648 // Style shortcuts
10649 #[wasm_bindgen(method, getter = dateStyle)]
10650 pub fn get_date_style(this: &DateTimeFormatOptions) -> Option<DateTimeStyle>;
10651 #[wasm_bindgen(method, setter = dateStyle)]
10652 pub fn set_date_style(this: &DateTimeFormatOptions, value: DateTimeStyle);
10653
10654 #[wasm_bindgen(method, getter = timeStyle)]
10655 pub fn get_time_style(this: &DateTimeFormatOptions) -> Option<DateTimeStyle>;
10656 #[wasm_bindgen(method, setter = timeStyle)]
10657 pub fn set_time_style(this: &DateTimeFormatOptions, value: DateTimeStyle);
10658
10659 // Component options
10660 #[wasm_bindgen(method, getter = weekday)]
10661 pub fn get_weekday(this: &DateTimeFormatOptions) -> Option<WeekdayFormat>;
10662 #[wasm_bindgen(method, setter = weekday)]
10663 pub fn set_weekday(this: &DateTimeFormatOptions, value: WeekdayFormat);
10664
10665 #[wasm_bindgen(method, getter = era)]
10666 pub fn get_era(this: &DateTimeFormatOptions) -> Option<EraFormat>;
10667 #[wasm_bindgen(method, setter = era)]
10668 pub fn set_era(this: &DateTimeFormatOptions, value: EraFormat);
10669
10670 #[wasm_bindgen(method, getter = year)]
10671 pub fn get_year(this: &DateTimeFormatOptions) -> Option<YearFormat>;
10672 #[wasm_bindgen(method, setter = year)]
10673 pub fn set_year(this: &DateTimeFormatOptions, value: YearFormat);
10674
10675 #[wasm_bindgen(method, getter = month)]
10676 pub fn get_month(this: &DateTimeFormatOptions) -> Option<MonthFormat>;
10677 #[wasm_bindgen(method, setter = month)]
10678 pub fn set_month(this: &DateTimeFormatOptions, value: MonthFormat);
10679
10680 #[wasm_bindgen(method, getter = day)]
10681 pub fn get_day(this: &DateTimeFormatOptions) -> Option<DayFormat>;
10682 #[wasm_bindgen(method, setter = day)]
10683 pub fn set_day(this: &DateTimeFormatOptions, value: DayFormat);
10684
10685 #[wasm_bindgen(method, getter = hour)]
10686 pub fn get_hour(this: &DateTimeFormatOptions) -> Option<NumericFormat>;
10687 #[wasm_bindgen(method, setter = hour)]
10688 pub fn set_hour(this: &DateTimeFormatOptions, value: NumericFormat);
10689
10690 #[wasm_bindgen(method, getter = minute)]
10691 pub fn get_minute(this: &DateTimeFormatOptions) -> Option<NumericFormat>;
10692 #[wasm_bindgen(method, setter = minute)]
10693 pub fn set_minute(this: &DateTimeFormatOptions, value: NumericFormat);
10694
10695 #[wasm_bindgen(method, getter = second)]
10696 pub fn get_second(this: &DateTimeFormatOptions) -> Option<NumericFormat>;
10697 #[wasm_bindgen(method, setter = second)]
10698 pub fn set_second(this: &DateTimeFormatOptions, value: NumericFormat);
10699
10700 #[wasm_bindgen(method, getter = fractionalSecondDigits)]
10701 pub fn get_fractional_second_digits(this: &DateTimeFormatOptions) -> Option<u8>;
10702 #[wasm_bindgen(method, setter = fractionalSecondDigits)]
10703 pub fn set_fractional_second_digits(this: &DateTimeFormatOptions, value: u8);
10704
10705 #[wasm_bindgen(method, getter = timeZoneName)]
10706 pub fn get_time_zone_name(this: &DateTimeFormatOptions) -> Option<TimeZoneNameFormat>;
10707 #[wasm_bindgen(method, setter = timeZoneName)]
10708 pub fn set_time_zone_name(this: &DateTimeFormatOptions, value: TimeZoneNameFormat);
10709
10710 #[wasm_bindgen(method, getter = dayPeriod)]
10711 pub fn get_day_period(this: &DateTimeFormatOptions) -> Option<DayPeriodFormat>;
10712 #[wasm_bindgen(method, setter = dayPeriod)]
10713 pub fn set_day_period(this: &DateTimeFormatOptions, value: DayPeriodFormat);
10714 }
10715
10716 impl DateTimeFormatOptions {
10717 pub fn new() -> DateTimeFormatOptions {
10718 JsCast::unchecked_into(Object::new())
10719 }
10720 }
10721
10722 impl Default for DateTimeFormatOptions {
10723 fn default() -> Self {
10724 DateTimeFormatOptions::new()
10725 }
10726 }
10727
10728 // Intl.ResolvedDateTimeFormatOptions
10729 #[wasm_bindgen]
10730 extern "C" {
10731 /// Resolved options returned by `Intl.DateTimeFormat.prototype.resolvedOptions()`.
10732 ///
10733 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/resolvedOptions)
10734 #[wasm_bindgen(extends = DateTimeFormatOptions)]
10735 #[derive(Clone, Debug)]
10736 pub type ResolvedDateTimeFormatOptions;
10737
10738 /// The resolved locale string.
10739 #[wasm_bindgen(method, getter = locale)]
10740 pub fn get_locale(this: &ResolvedDateTimeFormatOptions) -> JsString;
10741 }
10742
10743 // Intl.DateTimeFormatPart
10744 #[wasm_bindgen]
10745 extern "C" {
10746 /// A part of the formatted date returned by `formatToParts()`.
10747 ///
10748 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatToParts)
10749 #[wasm_bindgen(extends = Object)]
10750 #[derive(Clone, Debug)]
10751 pub type DateTimeFormatPart;
10752
10753 /// The type of the part (e.g., "day", "month", "year", "literal", etc.)
10754 #[wasm_bindgen(method, getter = type)]
10755 pub fn type_(this: &DateTimeFormatPart) -> DateTimeFormatPartType;
10756
10757 /// The value of the part.
10758 #[wasm_bindgen(method, getter)]
10759 pub fn value(this: &DateTimeFormatPart) -> JsString;
10760 }
10761
10762 // Intl.DateTimeRangeFormatPart
10763 #[wasm_bindgen]
10764 extern "C" {
10765 /// A part of the formatted date range returned by `formatRangeToParts()`.
10766 ///
10767 /// Extends `DateTimeFormatPart` with a `source` property indicating whether
10768 /// the part is from the start date, end date, or shared between them.
10769 ///
10770 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatRangeToParts)
10771 #[wasm_bindgen(extends = DateTimeFormatPart)]
10772 #[derive(Clone, Debug)]
10773 pub type DateTimeRangeFormatPart;
10774
10775 /// The source of the part: "startRange", "endRange", or "shared".
10776 #[wasm_bindgen(method, getter)]
10777 pub fn source(this: &DateTimeRangeFormatPart) -> RangeSource;
10778 }
10779
10780 // Intl.DateTimeFormat
10781 #[wasm_bindgen]
10782 extern "C" {
10783 /// The `Intl.DateTimeFormat` object is a constructor for objects
10784 /// that enable language-sensitive date and time formatting.
10785 ///
10786 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat)
10787 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.DateTimeFormat")]
10788 #[derive(Clone, Debug)]
10789 pub type DateTimeFormat;
10790
10791 /// The `Intl.DateTimeFormat` object is a constructor for objects
10792 /// that enable language-sensitive date and time formatting.
10793 ///
10794 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat)
10795 #[cfg(not(js_sys_unstable_apis))]
10796 #[wasm_bindgen(constructor, js_namespace = Intl)]
10797 pub fn new(locales: &Array, options: &Object) -> DateTimeFormat;
10798
10799 /// The `Intl.DateTimeFormat` object is a constructor for objects
10800 /// that enable language-sensitive date and time formatting.
10801 ///
10802 /// Throws a `RangeError` if locales contain invalid values.
10803 ///
10804 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat)
10805 #[cfg(js_sys_unstable_apis)]
10806 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
10807 pub fn new(
10808 locales: &[JsString],
10809 options: &DateTimeFormatOptions,
10810 ) -> Result<DateTimeFormat, JsValue>;
10811
10812 /// The Intl.DateTimeFormat.prototype.format property returns a getter function that
10813 /// formats a date according to the locale and formatting options of this
10814 /// Intl.DateTimeFormat object.
10815 ///
10816 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/format)
10817 #[cfg(not(js_sys_unstable_apis))]
10818 #[wasm_bindgen(method, getter, js_class = "Intl.DateTimeFormat")]
10819 pub fn format(this: &DateTimeFormat) -> Function;
10820
10821 /// Formats a date according to the locale and formatting options of this
10822 /// `Intl.DateTimeFormat` object.
10823 ///
10824 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/format)
10825 #[cfg(js_sys_unstable_apis)]
10826 #[wasm_bindgen(method, js_class = "Intl.DateTimeFormat")]
10827 pub fn format(this: &DateTimeFormat, date: &Date) -> JsString;
10828
10829 /// The `Intl.DateTimeFormat.prototype.formatToParts()` method allows locale-aware
10830 /// formatting of strings produced by DateTimeFormat formatters.
10831 ///
10832 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/formatToParts)
10833 #[cfg(not(js_sys_unstable_apis))]
10834 #[wasm_bindgen(method, js_class = "Intl.DateTimeFormat", js_name = formatToParts)]
10835 pub fn format_to_parts(this: &DateTimeFormat, date: &Date) -> Array;
10836
10837 /// The `Intl.DateTimeFormat.prototype.formatToParts()` method allows locale-aware
10838 /// formatting of strings produced by DateTimeFormat formatters.
10839 ///
10840 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/formatToParts)
10841 #[cfg(js_sys_unstable_apis)]
10842 #[wasm_bindgen(method, js_class = "Intl.DateTimeFormat", js_name = formatToParts)]
10843 pub fn format_to_parts(this: &DateTimeFormat, date: &Date) -> Array<DateTimeFormatPart>;
10844
10845 /// The `Intl.DateTimeFormat.prototype.formatRange()` method formats a date range
10846 /// in the most concise way based on the locales and options provided when
10847 /// instantiating this `Intl.DateTimeFormat` object.
10848 ///
10849 /// Throws a `TypeError` if the dates are invalid.
10850 ///
10851 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatRange)
10852 #[wasm_bindgen(method, js_class = "Intl.DateTimeFormat", js_name = formatRange, catch)]
10853 pub fn format_range(
10854 this: &DateTimeFormat,
10855 start_date: &Date,
10856 end_date: &Date,
10857 ) -> Result<JsString, JsValue>;
10858
10859 /// The `Intl.DateTimeFormat.prototype.formatRangeToParts()` method returns an array
10860 /// of locale-specific tokens representing each part of the formatted date range
10861 /// produced by `Intl.DateTimeFormat` formatters.
10862 ///
10863 /// Throws a `TypeError` if the dates are invalid.
10864 ///
10865 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatRangeToParts)
10866 #[wasm_bindgen(method, js_class = "Intl.DateTimeFormat", js_name = formatRangeToParts, catch)]
10867 pub fn format_range_to_parts(
10868 this: &DateTimeFormat,
10869 start_date: &Date,
10870 end_date: &Date,
10871 ) -> Result<Array<DateTimeRangeFormatPart>, JsValue>;
10872
10873 /// The `Intl.DateTimeFormat.prototype.resolvedOptions()` method returns a new
10874 /// object with properties reflecting the locale and date and time formatting
10875 /// options computed during initialization of this DateTimeFormat object.
10876 ///
10877 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/resolvedOptions)
10878 #[cfg(not(js_sys_unstable_apis))]
10879 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
10880 pub fn resolved_options(this: &DateTimeFormat) -> Object;
10881
10882 /// The `Intl.DateTimeFormat.prototype.resolvedOptions()` method returns a new
10883 /// object with properties reflecting the locale and date and time formatting
10884 /// options computed during initialization of this DateTimeFormat object.
10885 ///
10886 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/resolvedOptions)
10887 #[cfg(js_sys_unstable_apis)]
10888 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
10889 pub fn resolved_options(this: &DateTimeFormat) -> ResolvedDateTimeFormatOptions;
10890
10891 /// The `Intl.DateTimeFormat.supportedLocalesOf()` method returns an array
10892 /// containing those of the provided locales that are supported in date
10893 /// and time formatting without having to fall back to the runtime's default
10894 /// locale.
10895 ///
10896 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/supportedLocalesOf)
10897 #[cfg(not(js_sys_unstable_apis))]
10898 #[wasm_bindgen(static_method_of = DateTimeFormat, js_namespace = Intl, js_name = supportedLocalesOf)]
10899 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
10900
10901 /// The `Intl.DateTimeFormat.supportedLocalesOf()` method returns an array
10902 /// containing those of the provided locales that are supported in date
10903 /// and time formatting without having to fall back to the runtime's default
10904 /// locale.
10905 ///
10906 /// Throws a `RangeError` if locales contain invalid values.
10907 ///
10908 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/supportedLocalesOf)
10909 #[cfg(js_sys_unstable_apis)]
10910 #[wasm_bindgen(static_method_of = DateTimeFormat, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
10911 pub fn supported_locales_of(
10912 locales: &[JsString],
10913 options: &LocaleMatcherOptions,
10914 ) -> Result<Array<JsString>, JsValue>;
10915 }
10916
10917 #[cfg(not(js_sys_unstable_apis))]
10918 impl Default for DateTimeFormat {
10919 fn default() -> Self {
10920 Self::new(
10921 &JsValue::UNDEFINED.unchecked_into(),
10922 &JsValue::UNDEFINED.unchecked_into(),
10923 )
10924 }
10925 }
10926
10927 #[cfg(js_sys_unstable_apis)]
10928 impl Default for DateTimeFormat {
10929 fn default() -> Self {
10930 Self::new(&[], &Default::default()).unwrap()
10931 }
10932 }
10933
10934 // Intl.NumberFormatOptions
10935 #[wasm_bindgen]
10936 extern "C" {
10937 /// Options for `Intl.NumberFormat` constructor.
10938 ///
10939 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#options)
10940 #[wasm_bindgen(extends = Object)]
10941 #[derive(Clone, Debug)]
10942 pub type NumberFormatOptions;
10943
10944 // Locale matching
10945 #[wasm_bindgen(method, getter = localeMatcher)]
10946 pub fn get_locale_matcher(this: &NumberFormatOptions) -> Option<LocaleMatcher>;
10947 #[wasm_bindgen(method, setter = localeMatcher)]
10948 pub fn set_locale_matcher(this: &NumberFormatOptions, value: LocaleMatcher);
10949
10950 // Numbering system (free-form string)
10951 #[wasm_bindgen(method, getter = numberingSystem)]
10952 pub fn get_numbering_system(this: &NumberFormatOptions) -> Option<JsString>;
10953 #[wasm_bindgen(method, setter = numberingSystem)]
10954 pub fn set_numbering_system(this: &NumberFormatOptions, value: &str);
10955
10956 // Style
10957 #[wasm_bindgen(method, getter = style)]
10958 pub fn get_style(this: &NumberFormatOptions) -> Option<NumberFormatStyle>;
10959 #[wasm_bindgen(method, setter = style)]
10960 pub fn set_style(this: &NumberFormatOptions, value: NumberFormatStyle);
10961
10962 // Currency options (currency code is free-form ISO 4217 string)
10963 #[wasm_bindgen(method, getter = currency)]
10964 pub fn get_currency(this: &NumberFormatOptions) -> Option<JsString>;
10965 #[wasm_bindgen(method, setter = currency)]
10966 pub fn set_currency(this: &NumberFormatOptions, value: &str);
10967
10968 #[wasm_bindgen(method, getter = currencyDisplay)]
10969 pub fn get_currency_display(this: &NumberFormatOptions) -> Option<CurrencyDisplay>;
10970 #[wasm_bindgen(method, setter = currencyDisplay)]
10971 pub fn set_currency_display(this: &NumberFormatOptions, value: CurrencyDisplay);
10972
10973 #[wasm_bindgen(method, getter = currencySign)]
10974 pub fn get_currency_sign(this: &NumberFormatOptions) -> Option<CurrencySign>;
10975 #[wasm_bindgen(method, setter = currencySign)]
10976 pub fn set_currency_sign(this: &NumberFormatOptions, value: CurrencySign);
10977
10978 // Unit options (unit name is free-form string)
10979 #[wasm_bindgen(method, getter = unit)]
10980 pub fn get_unit(this: &NumberFormatOptions) -> Option<JsString>;
10981 #[wasm_bindgen(method, setter = unit)]
10982 pub fn set_unit(this: &NumberFormatOptions, value: &str);
10983
10984 #[wasm_bindgen(method, getter = unitDisplay)]
10985 pub fn get_unit_display(this: &NumberFormatOptions) -> Option<UnitDisplay>;
10986 #[wasm_bindgen(method, setter = unitDisplay)]
10987 pub fn set_unit_display(this: &NumberFormatOptions, value: UnitDisplay);
10988
10989 // Notation
10990 #[wasm_bindgen(method, getter = notation)]
10991 pub fn get_notation(this: &NumberFormatOptions) -> Option<NumberFormatNotation>;
10992 #[wasm_bindgen(method, setter = notation)]
10993 pub fn set_notation(this: &NumberFormatOptions, value: NumberFormatNotation);
10994
10995 #[wasm_bindgen(method, getter = compactDisplay)]
10996 pub fn get_compact_display(this: &NumberFormatOptions) -> Option<CompactDisplay>;
10997 #[wasm_bindgen(method, setter = compactDisplay)]
10998 pub fn set_compact_display(this: &NumberFormatOptions, value: CompactDisplay);
10999
11000 // Sign display
11001 #[wasm_bindgen(method, getter = signDisplay)]
11002 pub fn get_sign_display(this: &NumberFormatOptions) -> Option<SignDisplay>;
11003 #[wasm_bindgen(method, setter = signDisplay)]
11004 pub fn set_sign_display(this: &NumberFormatOptions, value: SignDisplay);
11005
11006 // Digit options
11007 #[wasm_bindgen(method, getter = minimumIntegerDigits)]
11008 pub fn get_minimum_integer_digits(this: &NumberFormatOptions) -> Option<u8>;
11009 #[wasm_bindgen(method, setter = minimumIntegerDigits)]
11010 pub fn set_minimum_integer_digits(this: &NumberFormatOptions, value: u8);
11011
11012 #[wasm_bindgen(method, getter = minimumFractionDigits)]
11013 pub fn get_minimum_fraction_digits(this: &NumberFormatOptions) -> Option<u8>;
11014 #[wasm_bindgen(method, setter = minimumFractionDigits)]
11015 pub fn set_minimum_fraction_digits(this: &NumberFormatOptions, value: u8);
11016
11017 #[wasm_bindgen(method, getter = maximumFractionDigits)]
11018 pub fn get_maximum_fraction_digits(this: &NumberFormatOptions) -> Option<u8>;
11019 #[wasm_bindgen(method, setter = maximumFractionDigits)]
11020 pub fn set_maximum_fraction_digits(this: &NumberFormatOptions, value: u8);
11021
11022 #[wasm_bindgen(method, getter = minimumSignificantDigits)]
11023 pub fn get_minimum_significant_digits(this: &NumberFormatOptions) -> Option<u8>;
11024 #[wasm_bindgen(method, setter = minimumSignificantDigits)]
11025 pub fn set_minimum_significant_digits(this: &NumberFormatOptions, value: u8);
11026
11027 #[wasm_bindgen(method, getter = maximumSignificantDigits)]
11028 pub fn get_maximum_significant_digits(this: &NumberFormatOptions) -> Option<u8>;
11029 #[wasm_bindgen(method, setter = maximumSignificantDigits)]
11030 pub fn set_maximum_significant_digits(this: &NumberFormatOptions, value: u8);
11031
11032 // Grouping
11033 #[wasm_bindgen(method, getter = useGrouping)]
11034 pub fn get_use_grouping(this: &NumberFormatOptions) -> Option<UseGrouping>;
11035 #[wasm_bindgen(method, setter = useGrouping)]
11036 pub fn set_use_grouping(this: &NumberFormatOptions, value: UseGrouping);
11037
11038 // Rounding
11039 #[wasm_bindgen(method, getter = roundingMode)]
11040 pub fn get_rounding_mode(this: &NumberFormatOptions) -> Option<RoundingMode>;
11041 #[wasm_bindgen(method, setter = roundingMode)]
11042 pub fn set_rounding_mode(this: &NumberFormatOptions, value: RoundingMode);
11043
11044 #[wasm_bindgen(method, getter = roundingPriority)]
11045 pub fn get_rounding_priority(this: &NumberFormatOptions) -> Option<RoundingPriority>;
11046 #[wasm_bindgen(method, setter = roundingPriority)]
11047 pub fn set_rounding_priority(this: &NumberFormatOptions, value: RoundingPriority);
11048
11049 #[wasm_bindgen(method, getter = roundingIncrement)]
11050 pub fn get_rounding_increment(this: &NumberFormatOptions) -> Option<u32>;
11051 #[wasm_bindgen(method, setter = roundingIncrement)]
11052 pub fn set_rounding_increment(this: &NumberFormatOptions, value: u32);
11053
11054 #[wasm_bindgen(method, getter = trailingZeroDisplay)]
11055 pub fn get_trailing_zero_display(this: &NumberFormatOptions)
11056 -> Option<TrailingZeroDisplay>;
11057 #[wasm_bindgen(method, setter = trailingZeroDisplay)]
11058 pub fn set_trailing_zero_display(this: &NumberFormatOptions, value: TrailingZeroDisplay);
11059 }
11060
11061 impl NumberFormatOptions {
11062 pub fn new() -> NumberFormatOptions {
11063 JsCast::unchecked_into(Object::new())
11064 }
11065 }
11066
11067 impl Default for NumberFormatOptions {
11068 fn default() -> Self {
11069 NumberFormatOptions::new()
11070 }
11071 }
11072
11073 // Intl.ResolvedNumberFormatOptions
11074 #[wasm_bindgen]
11075 extern "C" {
11076 /// Resolved options returned by `Intl.NumberFormat.prototype.resolvedOptions()`.
11077 ///
11078 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/resolvedOptions)
11079 #[wasm_bindgen(extends = NumberFormatOptions)]
11080 #[derive(Clone, Debug)]
11081 pub type ResolvedNumberFormatOptions;
11082
11083 /// The resolved locale string.
11084 #[wasm_bindgen(method, getter = locale)]
11085 pub fn get_locale(this: &ResolvedNumberFormatOptions) -> JsString;
11086 }
11087
11088 // Intl.NumberFormatPart
11089 #[wasm_bindgen]
11090 extern "C" {
11091 /// A part of the formatted number returned by `formatToParts()`.
11092 ///
11093 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatToParts)
11094 #[wasm_bindgen(extends = Object)]
11095 #[derive(Clone, Debug)]
11096 pub type NumberFormatPart;
11097
11098 /// The type of the part (e.g., "integer", "decimal", "fraction", "currency", etc.)
11099 #[wasm_bindgen(method, getter = type)]
11100 pub fn type_(this: &NumberFormatPart) -> NumberFormatPartType;
11101
11102 /// The value of the part.
11103 #[wasm_bindgen(method, getter)]
11104 pub fn value(this: &NumberFormatPart) -> JsString;
11105 }
11106
11107 // Intl.NumberRangeFormatPart
11108 #[wasm_bindgen]
11109 extern "C" {
11110 /// A part of the formatted number range returned by `formatRangeToParts()`.
11111 ///
11112 /// Extends `NumberFormatPart` with a `source` property indicating whether
11113 /// the part is from the start number, end number, or shared between them.
11114 ///
11115 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatRangeToParts)
11116 #[wasm_bindgen(extends = NumberFormatPart)]
11117 #[derive(Clone, Debug)]
11118 pub type NumberRangeFormatPart;
11119
11120 /// The source of the part: "startRange", "endRange", or "shared".
11121 #[wasm_bindgen(method, getter)]
11122 pub fn source(this: &NumberRangeFormatPart) -> RangeSource;
11123 }
11124
11125 // Intl.NumberFormat
11126 #[wasm_bindgen]
11127 extern "C" {
11128 /// The `Intl.NumberFormat` object is a constructor for objects
11129 /// that enable language sensitive number formatting.
11130 ///
11131 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat)
11132 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.NumberFormat")]
11133 #[derive(Clone, Debug)]
11134 pub type NumberFormat;
11135
11136 /// The `Intl.NumberFormat` object is a constructor for objects
11137 /// that enable language sensitive number formatting.
11138 ///
11139 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat)
11140 #[cfg(not(js_sys_unstable_apis))]
11141 #[wasm_bindgen(constructor, js_namespace = Intl)]
11142 pub fn new(locales: &Array, options: &Object) -> NumberFormat;
11143
11144 /// The `Intl.NumberFormat` object is a constructor for objects
11145 /// that enable language sensitive number formatting.
11146 ///
11147 /// Throws a `RangeError` if locales contain invalid values.
11148 ///
11149 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat)
11150 #[cfg(js_sys_unstable_apis)]
11151 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
11152 pub fn new(
11153 locales: &[JsString],
11154 options: &NumberFormatOptions,
11155 ) -> Result<NumberFormat, JsValue>;
11156
11157 /// The Intl.NumberFormat.prototype.format property returns a getter function that
11158 /// formats a number according to the locale and formatting options of this
11159 /// NumberFormat object.
11160 ///
11161 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/format)
11162 #[cfg(not(js_sys_unstable_apis))]
11163 #[wasm_bindgen(method, getter, js_class = "Intl.NumberFormat")]
11164 pub fn format(this: &NumberFormat) -> Function;
11165
11166 /// Formats a number according to the locale and formatting options of this
11167 /// `Intl.NumberFormat` object.
11168 ///
11169 /// Accepts numeric strings for BigInt/arbitrary precision (e.g., `"123n"` → `"123"`,
11170 /// or use E notation: `"1000000E-6"` → `"1"`).
11171 ///
11172 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/format)
11173 #[cfg(js_sys_unstable_apis)]
11174 #[wasm_bindgen(method, js_class = "Intl.NumberFormat")]
11175 pub fn format(this: &NumberFormat, value: &JsString) -> JsString;
11176
11177 /// The `Intl.Numberformat.prototype.formatToParts()` method allows locale-aware
11178 /// formatting of strings produced by NumberTimeFormat formatters.
11179 ///
11180 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/formatToParts)
11181 #[cfg(not(js_sys_unstable_apis))]
11182 #[wasm_bindgen(method, js_class = "Intl.NumberFormat", js_name = formatToParts)]
11183 pub fn format_to_parts(this: &NumberFormat, number: f64) -> Array;
11184
11185 /// The `Intl.NumberFormat.prototype.formatToParts()` method allows locale-aware
11186 /// formatting of strings produced by `Intl.NumberFormat` formatters.
11187 ///
11188 /// Accepts numeric strings for BigInt/arbitrary precision (e.g., `"123n"` → `"123"`,
11189 /// or use E notation: `"1000000E-6"` → `"1"`).
11190 ///
11191 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatToParts)
11192 #[cfg(js_sys_unstable_apis)]
11193 #[wasm_bindgen(method, js_class = "Intl.NumberFormat", js_name = formatToParts)]
11194 pub fn format_to_parts(this: &NumberFormat, value: &JsString) -> Array<NumberFormatPart>;
11195
11196 /// Formats a range of numbers according to the locale and formatting options
11197 /// of this `Intl.NumberFormat` object.
11198 ///
11199 /// Accepts numeric strings for BigInt/arbitrary precision (e.g., `"123n"` → `"123"`,
11200 /// or use E notation: `"1000000E-6"` → `"1"`).
11201 ///
11202 /// Throws a `TypeError` if the values are invalid.
11203 ///
11204 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatRange)
11205 #[wasm_bindgen(method, js_class = "Intl.NumberFormat", js_name = formatRange, catch)]
11206 pub fn format_range(
11207 this: &NumberFormat,
11208 start: &JsString,
11209 end: &JsString,
11210 ) -> Result<JsString, JsValue>;
11211
11212 /// Returns an array of locale-specific tokens representing each part of
11213 /// the formatted number range.
11214 ///
11215 /// Accepts numeric strings for BigInt/arbitrary precision (e.g., `"123n"` → `"123"`,
11216 /// or use E notation: `"1000000E-6"` → `"1"`).
11217 ///
11218 /// Throws a `TypeError` if the values are invalid.
11219 ///
11220 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatRangeToParts)
11221 #[wasm_bindgen(method, js_class = "Intl.NumberFormat", js_name = formatRangeToParts, catch)]
11222 pub fn format_range_to_parts(
11223 this: &NumberFormat,
11224 start: &JsString,
11225 end: &JsString,
11226 ) -> Result<Array<NumberRangeFormatPart>, JsValue>;
11227
11228 /// The `Intl.NumberFormat.prototype.resolvedOptions()` method returns a new
11229 /// object with properties reflecting the locale and number formatting
11230 /// options computed during initialization of this NumberFormat object.
11231 ///
11232 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/resolvedOptions)
11233 #[cfg(not(js_sys_unstable_apis))]
11234 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11235 pub fn resolved_options(this: &NumberFormat) -> Object;
11236
11237 /// The `Intl.NumberFormat.prototype.resolvedOptions()` method returns a new
11238 /// object with properties reflecting the locale and number formatting
11239 /// options computed during initialization of this NumberFormat object.
11240 ///
11241 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/resolvedOptions)
11242 #[cfg(js_sys_unstable_apis)]
11243 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11244 pub fn resolved_options(this: &NumberFormat) -> ResolvedNumberFormatOptions;
11245
11246 /// The `Intl.NumberFormat.supportedLocalesOf()` method returns an array
11247 /// containing those of the provided locales that are supported in number
11248 /// formatting without having to fall back to the runtime's default locale.
11249 ///
11250 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/supportedLocalesOf)
11251 #[cfg(not(js_sys_unstable_apis))]
11252 #[wasm_bindgen(static_method_of = NumberFormat, js_namespace = Intl, js_name = supportedLocalesOf)]
11253 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
11254
11255 /// The `Intl.NumberFormat.supportedLocalesOf()` method returns an array
11256 /// containing those of the provided locales that are supported in number
11257 /// formatting without having to fall back to the runtime's default locale.
11258 ///
11259 /// Throws a `RangeError` if locales contain invalid values.
11260 ///
11261 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/supportedLocalesOf)
11262 #[cfg(js_sys_unstable_apis)]
11263 #[wasm_bindgen(static_method_of = NumberFormat, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
11264 pub fn supported_locales_of(
11265 locales: &[JsString],
11266 options: &LocaleMatcherOptions,
11267 ) -> Result<Array<JsString>, JsValue>;
11268 }
11269
11270 #[cfg(not(js_sys_unstable_apis))]
11271 impl Default for NumberFormat {
11272 fn default() -> Self {
11273 Self::new(
11274 &JsValue::UNDEFINED.unchecked_into(),
11275 &JsValue::UNDEFINED.unchecked_into(),
11276 )
11277 }
11278 }
11279
11280 #[cfg(js_sys_unstable_apis)]
11281 impl Default for NumberFormat {
11282 fn default() -> Self {
11283 Self::new(&[], &Default::default()).unwrap()
11284 }
11285 }
11286
11287 // Intl.PluralRulesOptions
11288 #[wasm_bindgen]
11289 extern "C" {
11290 /// Options for `Intl.PluralRules` constructor.
11291 ///
11292 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules/PluralRules#options)
11293 #[wasm_bindgen(extends = Object)]
11294 #[derive(Clone, Debug)]
11295 pub type PluralRulesOptions;
11296
11297 #[wasm_bindgen(method, getter = localeMatcher)]
11298 pub fn get_locale_matcher(this: &PluralRulesOptions) -> Option<LocaleMatcher>;
11299 #[wasm_bindgen(method, setter = localeMatcher)]
11300 pub fn set_locale_matcher(this: &PluralRulesOptions, value: LocaleMatcher);
11301
11302 #[wasm_bindgen(method, getter = type)]
11303 pub fn get_type(this: &PluralRulesOptions) -> Option<PluralRulesType>;
11304 #[wasm_bindgen(method, setter = type)]
11305 pub fn set_type(this: &PluralRulesOptions, value: PluralRulesType);
11306
11307 #[wasm_bindgen(method, getter = minimumIntegerDigits)]
11308 pub fn get_minimum_integer_digits(this: &PluralRulesOptions) -> Option<u8>;
11309 #[wasm_bindgen(method, setter = minimumIntegerDigits)]
11310 pub fn set_minimum_integer_digits(this: &PluralRulesOptions, value: u8);
11311
11312 #[wasm_bindgen(method, getter = minimumFractionDigits)]
11313 pub fn get_minimum_fraction_digits(this: &PluralRulesOptions) -> Option<u8>;
11314 #[wasm_bindgen(method, setter = minimumFractionDigits)]
11315 pub fn set_minimum_fraction_digits(this: &PluralRulesOptions, value: u8);
11316
11317 #[wasm_bindgen(method, getter = maximumFractionDigits)]
11318 pub fn get_maximum_fraction_digits(this: &PluralRulesOptions) -> Option<u8>;
11319 #[wasm_bindgen(method, setter = maximumFractionDigits)]
11320 pub fn set_maximum_fraction_digits(this: &PluralRulesOptions, value: u8);
11321
11322 #[wasm_bindgen(method, getter = minimumSignificantDigits)]
11323 pub fn get_minimum_significant_digits(this: &PluralRulesOptions) -> Option<u8>;
11324 #[wasm_bindgen(method, setter = minimumSignificantDigits)]
11325 pub fn set_minimum_significant_digits(this: &PluralRulesOptions, value: u8);
11326
11327 #[wasm_bindgen(method, getter = maximumSignificantDigits)]
11328 pub fn get_maximum_significant_digits(this: &PluralRulesOptions) -> Option<u8>;
11329 #[wasm_bindgen(method, setter = maximumSignificantDigits)]
11330 pub fn set_maximum_significant_digits(this: &PluralRulesOptions, value: u8);
11331
11332 #[wasm_bindgen(method, getter = roundingPriority)]
11333 pub fn get_rounding_priority(this: &PluralRulesOptions) -> Option<RoundingPriority>;
11334 #[wasm_bindgen(method, setter = roundingPriority)]
11335 pub fn set_rounding_priority(this: &PluralRulesOptions, value: RoundingPriority);
11336
11337 #[wasm_bindgen(method, getter = roundingIncrement)]
11338 pub fn get_rounding_increment(this: &PluralRulesOptions) -> Option<u32>;
11339 #[wasm_bindgen(method, setter = roundingIncrement)]
11340 pub fn set_rounding_increment(this: &PluralRulesOptions, value: u32);
11341
11342 #[wasm_bindgen(method, getter = roundingMode)]
11343 pub fn get_rounding_mode(this: &PluralRulesOptions) -> Option<RoundingMode>;
11344 #[wasm_bindgen(method, setter = roundingMode)]
11345 pub fn set_rounding_mode(this: &PluralRulesOptions, value: RoundingMode);
11346
11347 #[wasm_bindgen(method, getter = trailingZeroDisplay)]
11348 pub fn get_trailing_zero_display(this: &PluralRulesOptions) -> Option<TrailingZeroDisplay>;
11349 #[wasm_bindgen(method, setter = trailingZeroDisplay)]
11350 pub fn set_trailing_zero_display(this: &PluralRulesOptions, value: TrailingZeroDisplay);
11351 }
11352
11353 impl PluralRulesOptions {
11354 pub fn new() -> PluralRulesOptions {
11355 JsCast::unchecked_into(Object::new())
11356 }
11357 }
11358
11359 impl Default for PluralRulesOptions {
11360 fn default() -> Self {
11361 PluralRulesOptions::new()
11362 }
11363 }
11364
11365 // Intl.ResolvedPluralRulesOptions
11366 #[wasm_bindgen]
11367 extern "C" {
11368 /// Resolved options returned by `Intl.PluralRules.prototype.resolvedOptions()`.
11369 ///
11370 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules/resolvedOptions)
11371 #[wasm_bindgen(extends = PluralRulesOptions)]
11372 #[derive(Clone, Debug)]
11373 pub type ResolvedPluralRulesOptions;
11374
11375 /// The resolved locale string.
11376 #[wasm_bindgen(method, getter = locale)]
11377 pub fn get_locale(this: &ResolvedPluralRulesOptions) -> JsString;
11378
11379 /// The plural categories used by the locale.
11380 #[wasm_bindgen(method, getter = pluralCategories)]
11381 pub fn get_plural_categories(this: &ResolvedPluralRulesOptions) -> Array<JsString>;
11382 }
11383
11384 // Intl.PluralRules
11385 #[wasm_bindgen]
11386 extern "C" {
11387 /// The `Intl.PluralRules` object is a constructor for objects
11388 /// that enable plural sensitive formatting and plural language rules.
11389 ///
11390 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules)
11391 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.PluralRules")]
11392 #[derive(Clone, Debug)]
11393 pub type PluralRules;
11394
11395 /// The `Intl.PluralRules` object is a constructor for objects
11396 /// that enable plural sensitive formatting and plural language rules.
11397 ///
11398 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules)
11399 #[cfg(not(js_sys_unstable_apis))]
11400 #[wasm_bindgen(constructor, js_namespace = Intl)]
11401 pub fn new(locales: &Array, options: &Object) -> PluralRules;
11402
11403 /// The `Intl.PluralRules` object is a constructor for objects
11404 /// that enable plural sensitive formatting and plural language rules.
11405 ///
11406 /// Throws a `RangeError` if locales contain invalid values.
11407 ///
11408 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules)
11409 #[cfg(js_sys_unstable_apis)]
11410 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
11411 pub fn new(
11412 locales: &[JsString],
11413 options: &PluralRulesOptions,
11414 ) -> Result<PluralRules, JsValue>;
11415
11416 /// The `Intl.PluralRules.prototype.resolvedOptions()` method returns a new
11417 /// object with properties reflecting the locale and plural formatting
11418 /// options computed during initialization of this PluralRules object.
11419 ///
11420 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/resolvedOptions)
11421 #[cfg(not(js_sys_unstable_apis))]
11422 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11423 pub fn resolved_options(this: &PluralRules) -> Object;
11424
11425 /// The `Intl.PluralRules.prototype.resolvedOptions()` method returns a new
11426 /// object with properties reflecting the locale and plural formatting
11427 /// options computed during initialization of this PluralRules object.
11428 ///
11429 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/resolvedOptions)
11430 #[cfg(js_sys_unstable_apis)]
11431 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11432 pub fn resolved_options(this: &PluralRules) -> ResolvedPluralRulesOptions;
11433
11434 /// The `Intl.PluralRules.prototype.select()` method returns a String indicating
11435 /// which plural rule to use for locale-aware formatting.
11436 ///
11437 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/select)
11438 #[cfg(not(js_sys_unstable_apis))]
11439 #[wasm_bindgen(method, js_namespace = Intl)]
11440 pub fn select(this: &PluralRules, number: f64) -> JsString;
11441
11442 /// The `Intl.PluralRules.prototype.select()` method returns a String indicating
11443 /// which plural rule to use for locale-aware formatting.
11444 ///
11445 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/select)
11446 #[cfg(js_sys_unstable_apis)]
11447 #[wasm_bindgen(method, js_namespace = Intl)]
11448 pub fn select(this: &PluralRules, number: f64) -> PluralCategory;
11449
11450 /// The `Intl.PluralRules.prototype.selectRange()` method returns a string indicating
11451 /// which plural rule to use for locale-aware formatting of a range of numbers.
11452 ///
11453 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules/selectRange)
11454 #[cfg(not(js_sys_unstable_apis))]
11455 #[wasm_bindgen(method, js_namespace = Intl, js_name = selectRange)]
11456 pub fn select_range(this: &PluralRules, start: f64, end: f64) -> JsString;
11457
11458 /// The `Intl.PluralRules.prototype.selectRange()` method returns a string indicating
11459 /// which plural rule to use for locale-aware formatting of a range of numbers.
11460 ///
11461 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules/selectRange)
11462 #[cfg(js_sys_unstable_apis)]
11463 #[wasm_bindgen(method, js_namespace = Intl, js_name = selectRange)]
11464 pub fn select_range(this: &PluralRules, start: f64, end: f64) -> PluralCategory;
11465
11466 /// The `Intl.PluralRules.supportedLocalesOf()` method returns an array
11467 /// containing those of the provided locales that are supported in plural
11468 /// formatting without having to fall back to the runtime's default locale.
11469 ///
11470 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/supportedLocalesOf)
11471 #[cfg(not(js_sys_unstable_apis))]
11472 #[wasm_bindgen(static_method_of = PluralRules, js_namespace = Intl, js_name = supportedLocalesOf)]
11473 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
11474
11475 /// The `Intl.PluralRules.supportedLocalesOf()` method returns an array
11476 /// containing those of the provided locales that are supported in plural
11477 /// formatting without having to fall back to the runtime's default locale.
11478 ///
11479 /// Throws a `RangeError` if locales contain invalid values.
11480 ///
11481 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/supportedLocalesOf)
11482 #[cfg(js_sys_unstable_apis)]
11483 #[wasm_bindgen(static_method_of = PluralRules, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
11484 pub fn supported_locales_of(
11485 locales: &[JsString],
11486 options: &LocaleMatcherOptions,
11487 ) -> Result<Array<JsString>, JsValue>;
11488 }
11489
11490 #[cfg(not(js_sys_unstable_apis))]
11491 impl Default for PluralRules {
11492 fn default() -> Self {
11493 Self::new(
11494 &JsValue::UNDEFINED.unchecked_into(),
11495 &JsValue::UNDEFINED.unchecked_into(),
11496 )
11497 }
11498 }
11499
11500 #[cfg(js_sys_unstable_apis)]
11501 impl Default for PluralRules {
11502 fn default() -> Self {
11503 Self::new(&[], &Default::default()).unwrap()
11504 }
11505 }
11506
11507 // Intl.RelativeTimeFormat
11508 #[wasm_bindgen]
11509 extern "C" {
11510 /// The `Intl.RelativeTimeFormat` object is a constructor for objects
11511 /// that enable language-sensitive relative time formatting.
11512 ///
11513 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat)
11514 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.RelativeTimeFormat")]
11515 #[derive(Clone, Debug)]
11516 pub type RelativeTimeFormat;
11517
11518 /// The `Intl.RelativeTimeFormat` object is a constructor for objects
11519 /// that enable language-sensitive relative time formatting.
11520 ///
11521 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat)
11522 #[cfg(not(js_sys_unstable_apis))]
11523 #[wasm_bindgen(constructor, js_namespace = Intl)]
11524 pub fn new(locales: &Array, options: &Object) -> RelativeTimeFormat;
11525
11526 /// The `Intl.RelativeTimeFormat` object is a constructor for objects
11527 /// that enable language-sensitive relative time formatting.
11528 ///
11529 /// Throws a `RangeError` if locales contain invalid values.
11530 ///
11531 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat)
11532 #[cfg(js_sys_unstable_apis)]
11533 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
11534 pub fn new(locales: &[JsString]) -> Result<RelativeTimeFormat, JsValue>;
11535
11536 /// The `Intl.RelativeTimeFormat` object is a constructor for objects
11537 /// that enable language-sensitive relative time formatting.
11538 ///
11539 /// Throws a `RangeError` if locales or options contain invalid values.
11540 ///
11541 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat)
11542 #[cfg(js_sys_unstable_apis)]
11543 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
11544 pub fn new_with_options(
11545 locales: &[JsString],
11546 options: &RelativeTimeFormatOptions,
11547 ) -> Result<RelativeTimeFormat, JsValue>;
11548
11549 /// The `Intl.RelativeTimeFormat.prototype.format` method formats a `value` and `unit`
11550 /// according to the locale and formatting options of this Intl.RelativeTimeFormat object.
11551 ///
11552 /// Throws a `RangeError` if unit is invalid.
11553 ///
11554 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/format)
11555 #[cfg(not(js_sys_unstable_apis))]
11556 #[wasm_bindgen(method, js_class = "Intl.RelativeTimeFormat")]
11557 pub fn format(this: &RelativeTimeFormat, value: f64, unit: &str) -> JsString;
11558
11559 /// The `Intl.RelativeTimeFormat.prototype.format` method formats a `value` and `unit`
11560 /// according to the locale and formatting options of this Intl.RelativeTimeFormat object.
11561 ///
11562 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/format)
11563 #[cfg(js_sys_unstable_apis)]
11564 #[wasm_bindgen(method, js_class = "Intl.RelativeTimeFormat")]
11565 pub fn format(
11566 this: &RelativeTimeFormat,
11567 value: f64,
11568 unit: RelativeTimeFormatUnit,
11569 ) -> JsString;
11570
11571 /// The `Intl.RelativeTimeFormat.prototype.formatToParts()` method returns an array of
11572 /// objects representing the relative time format in parts that can be used for custom locale-aware formatting.
11573 ///
11574 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/formatToParts)
11575 #[cfg(not(js_sys_unstable_apis))]
11576 #[wasm_bindgen(method, js_class = "Intl.RelativeTimeFormat", js_name = formatToParts)]
11577 pub fn format_to_parts(this: &RelativeTimeFormat, value: f64, unit: &str) -> Array;
11578
11579 /// The `Intl.RelativeTimeFormat.prototype.formatToParts()` method returns an array of
11580 /// objects representing the relative time format in parts that can be used for custom locale-aware formatting.
11581 ///
11582 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/formatToParts)
11583 #[cfg(js_sys_unstable_apis)]
11584 #[wasm_bindgen(method, js_class = "Intl.RelativeTimeFormat", js_name = formatToParts)]
11585 pub fn format_to_parts(
11586 this: &RelativeTimeFormat,
11587 value: f64,
11588 unit: RelativeTimeFormatUnit,
11589 ) -> Array<RelativeTimeFormatPart>;
11590
11591 /// The `Intl.RelativeTimeFormat.prototype.resolvedOptions()` method returns a new
11592 /// object with properties reflecting the locale and relative time formatting
11593 /// options computed during initialization of this RelativeTimeFormat object.
11594 ///
11595 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/resolvedOptions)
11596 #[cfg(not(js_sys_unstable_apis))]
11597 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11598 pub fn resolved_options(this: &RelativeTimeFormat) -> Object;
11599
11600 /// The `Intl.RelativeTimeFormat.prototype.resolvedOptions()` method returns a new
11601 /// object with properties reflecting the locale and relative time formatting
11602 /// options computed during initialization of this RelativeTimeFormat object.
11603 ///
11604 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/resolvedOptions)
11605 #[cfg(js_sys_unstable_apis)]
11606 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11607 pub fn resolved_options(this: &RelativeTimeFormat) -> ResolvedRelativeTimeFormatOptions;
11608
11609 /// The `Intl.RelativeTimeFormat.supportedLocalesOf()` method returns an array
11610 /// containing those of the provided locales that are supported in date and time
11611 /// formatting without having to fall back to the runtime's default locale.
11612 ///
11613 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RelativeTimeFormat/supportedLocalesOf)
11614 #[cfg(not(js_sys_unstable_apis))]
11615 #[wasm_bindgen(static_method_of = RelativeTimeFormat, js_namespace = Intl, js_name = supportedLocalesOf)]
11616 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
11617
11618 /// The `Intl.RelativeTimeFormat.supportedLocalesOf()` method returns an array
11619 /// containing those of the provided locales that are supported in date and time
11620 /// formatting without having to fall back to the runtime's default locale.
11621 ///
11622 /// Throws a `RangeError` if locales contain invalid values.
11623 ///
11624 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RelativeTimeFormat/supportedLocalesOf)
11625 #[cfg(js_sys_unstable_apis)]
11626 #[wasm_bindgen(static_method_of = RelativeTimeFormat, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
11627 pub fn supported_locales_of(
11628 locales: &[JsString],
11629 options: &LocaleMatcherOptions,
11630 ) -> Result<Array<JsString>, JsValue>;
11631 }
11632
11633 #[cfg(not(js_sys_unstable_apis))]
11634 impl Default for RelativeTimeFormat {
11635 fn default() -> Self {
11636 Self::new(
11637 &JsValue::UNDEFINED.unchecked_into(),
11638 &JsValue::UNDEFINED.unchecked_into(),
11639 )
11640 }
11641 }
11642
11643 #[cfg(js_sys_unstable_apis)]
11644 impl Default for RelativeTimeFormat {
11645 fn default() -> Self {
11646 Self::new(&[]).unwrap()
11647 }
11648 }
11649
11650 // Intl.ListFormatOptions
11651 #[wasm_bindgen]
11652 extern "C" {
11653 /// Options for `Intl.ListFormat` constructor.
11654 ///
11655 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/ListFormat#options)
11656 #[wasm_bindgen(extends = Object)]
11657 #[derive(Clone, Debug)]
11658 pub type ListFormatOptions;
11659
11660 #[wasm_bindgen(method, getter = localeMatcher)]
11661 pub fn get_locale_matcher(this: &ListFormatOptions) -> Option<LocaleMatcher>;
11662 #[wasm_bindgen(method, setter = localeMatcher)]
11663 pub fn set_locale_matcher(this: &ListFormatOptions, value: LocaleMatcher);
11664
11665 #[wasm_bindgen(method, getter = type)]
11666 pub fn get_type(this: &ListFormatOptions) -> Option<ListFormatType>;
11667 #[wasm_bindgen(method, setter = type)]
11668 pub fn set_type(this: &ListFormatOptions, value: ListFormatType);
11669
11670 #[wasm_bindgen(method, getter = style)]
11671 pub fn get_style(this: &ListFormatOptions) -> Option<ListFormatStyle>;
11672 #[wasm_bindgen(method, setter = style)]
11673 pub fn set_style(this: &ListFormatOptions, value: ListFormatStyle);
11674 }
11675
11676 impl ListFormatOptions {
11677 pub fn new() -> ListFormatOptions {
11678 JsCast::unchecked_into(Object::new())
11679 }
11680 }
11681
11682 impl Default for ListFormatOptions {
11683 fn default() -> Self {
11684 ListFormatOptions::new()
11685 }
11686 }
11687
11688 // Intl.ResolvedListFormatOptions
11689 #[wasm_bindgen]
11690 extern "C" {
11691 /// Resolved options returned by `Intl.ListFormat.prototype.resolvedOptions()`.
11692 ///
11693 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/resolvedOptions)
11694 #[wasm_bindgen(extends = ListFormatOptions)]
11695 #[derive(Clone, Debug)]
11696 pub type ResolvedListFormatOptions;
11697
11698 /// The resolved locale string.
11699 #[wasm_bindgen(method, getter = locale)]
11700 pub fn get_locale(this: &ResolvedListFormatOptions) -> JsString;
11701 }
11702
11703 // Intl.ListFormatPart
11704 #[wasm_bindgen]
11705 extern "C" {
11706 /// A part of the formatted list returned by `formatToParts()`.
11707 ///
11708 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/formatToParts)
11709 #[wasm_bindgen(extends = Object)]
11710 #[derive(Clone, Debug)]
11711 pub type ListFormatPart;
11712
11713 /// The type of the part ("element" or "literal").
11714 #[wasm_bindgen(method, getter = type)]
11715 pub fn type_(this: &ListFormatPart) -> ListFormatPartType;
11716
11717 /// The value of the part.
11718 #[wasm_bindgen(method, getter)]
11719 pub fn value(this: &ListFormatPart) -> JsString;
11720 }
11721
11722 // Intl.ListFormat
11723 #[wasm_bindgen]
11724 extern "C" {
11725 /// The `Intl.ListFormat` object enables language-sensitive list formatting.
11726 ///
11727 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat)
11728 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.ListFormat")]
11729 #[derive(Clone, Debug)]
11730 pub type ListFormat;
11731
11732 /// Creates a new `Intl.ListFormat` object.
11733 ///
11734 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/ListFormat)
11735 #[cfg(not(js_sys_unstable_apis))]
11736 #[wasm_bindgen(constructor, js_namespace = Intl)]
11737 pub fn new(locales: &Array, options: &Object) -> ListFormat;
11738
11739 /// Creates a new `Intl.ListFormat` object.
11740 ///
11741 /// Throws a `RangeError` if locales or options contain invalid values.
11742 ///
11743 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/ListFormat)
11744 #[cfg(js_sys_unstable_apis)]
11745 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
11746 pub fn new(
11747 locales: &[JsString],
11748 options: &ListFormatOptions,
11749 ) -> Result<ListFormat, JsValue>;
11750
11751 /// Formats a list of strings according to the locale and options.
11752 ///
11753 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/format)
11754 #[cfg(not(js_sys_unstable_apis))]
11755 #[wasm_bindgen(method, js_class = "Intl.ListFormat")]
11756 pub fn format(this: &ListFormat, list: &Array) -> JsString;
11757
11758 /// Formats a list of strings according to the locale and options.
11759 ///
11760 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/format)
11761 #[cfg(js_sys_unstable_apis)]
11762 #[wasm_bindgen(method, js_class = "Intl.ListFormat")]
11763 pub fn format(this: &ListFormat, list: &[JsString]) -> JsString;
11764
11765 /// Returns an array of objects representing the list in parts.
11766 ///
11767 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/formatToParts)
11768 #[cfg(not(js_sys_unstable_apis))]
11769 #[wasm_bindgen(method, js_class = "Intl.ListFormat", js_name = formatToParts)]
11770 pub fn format_to_parts(this: &ListFormat, list: &Array) -> Array;
11771
11772 /// Returns an array of objects representing the list in parts.
11773 ///
11774 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/formatToParts)
11775 #[cfg(js_sys_unstable_apis)]
11776 #[wasm_bindgen(method, js_class = "Intl.ListFormat", js_name = formatToParts)]
11777 pub fn format_to_parts(this: &ListFormat, list: &[JsString]) -> Array<ListFormatPart>;
11778
11779 /// Returns an object with properties reflecting the options used.
11780 ///
11781 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/resolvedOptions)
11782 #[cfg(not(js_sys_unstable_apis))]
11783 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11784 pub fn resolved_options(this: &ListFormat) -> Object;
11785
11786 /// Returns an object with properties reflecting the options used.
11787 ///
11788 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/resolvedOptions)
11789 #[cfg(js_sys_unstable_apis)]
11790 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11791 pub fn resolved_options(this: &ListFormat) -> ResolvedListFormatOptions;
11792
11793 /// Returns an array of supported locales.
11794 ///
11795 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/supportedLocalesOf)
11796 #[cfg(not(js_sys_unstable_apis))]
11797 #[wasm_bindgen(static_method_of = ListFormat, js_namespace = Intl, js_name = supportedLocalesOf)]
11798 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
11799
11800 /// Returns an array of supported locales.
11801 ///
11802 /// Throws a `RangeError` if locales contain invalid values.
11803 ///
11804 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/supportedLocalesOf)
11805 #[cfg(js_sys_unstable_apis)]
11806 #[wasm_bindgen(static_method_of = ListFormat, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
11807 pub fn supported_locales_of(
11808 locales: &[JsString],
11809 options: &LocaleMatcherOptions,
11810 ) -> Result<Array<JsString>, JsValue>;
11811 }
11812
11813 #[cfg(not(js_sys_unstable_apis))]
11814 impl Default for ListFormat {
11815 fn default() -> Self {
11816 Self::new(
11817 &JsValue::UNDEFINED.unchecked_into(),
11818 &JsValue::UNDEFINED.unchecked_into(),
11819 )
11820 }
11821 }
11822
11823 #[cfg(js_sys_unstable_apis)]
11824 impl Default for ListFormat {
11825 fn default() -> Self {
11826 Self::new(&[], &Default::default()).unwrap()
11827 }
11828 }
11829
11830 // Intl.SegmenterOptions
11831 #[wasm_bindgen]
11832 extern "C" {
11833 /// Options for `Intl.Segmenter` constructor.
11834 ///
11835 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/Segmenter#options)
11836 #[wasm_bindgen(extends = Object)]
11837 #[derive(Clone, Debug)]
11838 pub type SegmenterOptions;
11839
11840 #[wasm_bindgen(method, getter = localeMatcher)]
11841 pub fn get_locale_matcher(this: &SegmenterOptions) -> Option<LocaleMatcher>;
11842 #[wasm_bindgen(method, setter = localeMatcher)]
11843 pub fn set_locale_matcher(this: &SegmenterOptions, value: LocaleMatcher);
11844
11845 #[wasm_bindgen(method, getter = granularity)]
11846 pub fn get_granularity(this: &SegmenterOptions) -> Option<SegmenterGranularity>;
11847 #[wasm_bindgen(method, setter = granularity)]
11848 pub fn set_granularity(this: &SegmenterOptions, value: SegmenterGranularity);
11849 }
11850
11851 impl SegmenterOptions {
11852 pub fn new() -> SegmenterOptions {
11853 JsCast::unchecked_into(Object::new())
11854 }
11855 }
11856
11857 impl Default for SegmenterOptions {
11858 fn default() -> Self {
11859 SegmenterOptions::new()
11860 }
11861 }
11862
11863 // Intl.ResolvedSegmenterOptions
11864 #[wasm_bindgen]
11865 extern "C" {
11866 /// Resolved options returned by `Intl.Segmenter.prototype.resolvedOptions()`.
11867 ///
11868 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/resolvedOptions)
11869 #[wasm_bindgen(extends = SegmenterOptions)]
11870 #[derive(Clone, Debug)]
11871 pub type ResolvedSegmenterOptions;
11872
11873 /// The resolved locale string.
11874 #[wasm_bindgen(method, getter = locale)]
11875 pub fn get_locale(this: &ResolvedSegmenterOptions) -> JsString;
11876 }
11877
11878 // Intl.SegmentData
11879 #[wasm_bindgen]
11880 extern "C" {
11881 /// Data about a segment returned by the Segments iterator.
11882 ///
11883 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/segment/Segments#segment_data)
11884 #[wasm_bindgen(extends = Object)]
11885 #[derive(Clone, Debug)]
11886 pub type SegmentData;
11887
11888 /// The segment string.
11889 #[wasm_bindgen(method, getter)]
11890 pub fn segment(this: &SegmentData) -> JsString;
11891
11892 /// The index of the segment in the original string.
11893 #[wasm_bindgen(method, getter)]
11894 pub fn index(this: &SegmentData) -> u32;
11895
11896 /// The original input string.
11897 #[wasm_bindgen(method, getter)]
11898 pub fn input(this: &SegmentData) -> JsString;
11899
11900 /// Whether the segment is word-like (only for word granularity).
11901 #[wasm_bindgen(method, getter = isWordLike)]
11902 pub fn is_word_like(this: &SegmentData) -> Option<bool>;
11903 }
11904
11905 // Intl.Segments
11906 #[wasm_bindgen]
11907 extern "C" {
11908 /// The Segments object is an iterable collection of segments of a string.
11909 ///
11910 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/segment/Segments)
11911 #[wasm_bindgen(extends = Object)]
11912 #[derive(Clone, Debug)]
11913 pub type Segments;
11914
11915 /// Returns segment data for the segment containing the character at the given index.
11916 ///
11917 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/segment/Segments/containing)
11918 #[wasm_bindgen(method)]
11919 pub fn containing(this: &Segments, index: u32) -> Option<SegmentData>;
11920 }
11921
11922 // Intl.Segmenter
11923 #[wasm_bindgen]
11924 extern "C" {
11925 /// The `Intl.Segmenter` object enables locale-sensitive text segmentation.
11926 ///
11927 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter)
11928 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.Segmenter")]
11929 #[derive(Clone, Debug)]
11930 pub type Segmenter;
11931
11932 /// Creates a new `Intl.Segmenter` object.
11933 ///
11934 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/Segmenter)
11935 #[cfg(not(js_sys_unstable_apis))]
11936 #[wasm_bindgen(constructor, js_namespace = Intl)]
11937 pub fn new(locales: &Array, options: &Object) -> Segmenter;
11938
11939 /// Creates a new `Intl.Segmenter` object.
11940 ///
11941 /// Throws a `RangeError` if locales or options contain invalid values.
11942 ///
11943 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/Segmenter)
11944 #[cfg(js_sys_unstable_apis)]
11945 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
11946 pub fn new(locales: &[JsString], options: &SegmenterOptions) -> Result<Segmenter, JsValue>;
11947
11948 /// Returns a Segments object containing the segments of the input string.
11949 ///
11950 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/segment)
11951 #[wasm_bindgen(method, js_class = "Intl.Segmenter")]
11952 pub fn segment(this: &Segmenter, input: &str) -> Segments;
11953
11954 /// Returns an object with properties reflecting the options used.
11955 ///
11956 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/resolvedOptions)
11957 #[cfg(not(js_sys_unstable_apis))]
11958 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11959 pub fn resolved_options(this: &Segmenter) -> Object;
11960
11961 /// Returns an object with properties reflecting the options used.
11962 ///
11963 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/resolvedOptions)
11964 #[cfg(js_sys_unstable_apis)]
11965 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11966 pub fn resolved_options(this: &Segmenter) -> ResolvedSegmenterOptions;
11967
11968 /// Returns an array of supported locales.
11969 ///
11970 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/supportedLocalesOf)
11971 #[cfg(not(js_sys_unstable_apis))]
11972 #[wasm_bindgen(static_method_of = Segmenter, js_namespace = Intl, js_name = supportedLocalesOf)]
11973 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
11974
11975 /// Returns an array of supported locales.
11976 ///
11977 /// Throws a `RangeError` if locales contain invalid values.
11978 ///
11979 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/supportedLocalesOf)
11980 #[cfg(js_sys_unstable_apis)]
11981 #[wasm_bindgen(static_method_of = Segmenter, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
11982 pub fn supported_locales_of(
11983 locales: &[JsString],
11984 options: &LocaleMatcherOptions,
11985 ) -> Result<Array<JsString>, JsValue>;
11986 }
11987
11988 #[cfg(not(js_sys_unstable_apis))]
11989 impl Default for Segmenter {
11990 fn default() -> Self {
11991 Self::new(
11992 &JsValue::UNDEFINED.unchecked_into(),
11993 &JsValue::UNDEFINED.unchecked_into(),
11994 )
11995 }
11996 }
11997
11998 #[cfg(js_sys_unstable_apis)]
11999 impl Default for Segmenter {
12000 fn default() -> Self {
12001 Self::new(&[], &Default::default()).unwrap()
12002 }
12003 }
12004
12005 // Intl.DisplayNamesOptions
12006 #[wasm_bindgen]
12007 extern "C" {
12008 /// Options for `Intl.DisplayNames` constructor.
12009 ///
12010 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/DisplayNames#options)
12011 #[wasm_bindgen(extends = Object)]
12012 #[derive(Clone, Debug)]
12013 pub type DisplayNamesOptions;
12014
12015 #[wasm_bindgen(method, getter = localeMatcher)]
12016 pub fn get_locale_matcher(this: &DisplayNamesOptions) -> Option<LocaleMatcher>;
12017 #[wasm_bindgen(method, setter = localeMatcher)]
12018 pub fn set_locale_matcher(this: &DisplayNamesOptions, value: LocaleMatcher);
12019
12020 #[wasm_bindgen(method, getter = type)]
12021 pub fn get_type(this: &DisplayNamesOptions) -> Option<DisplayNamesType>;
12022 #[wasm_bindgen(method, setter = type)]
12023 pub fn set_type(this: &DisplayNamesOptions, value: DisplayNamesType);
12024
12025 #[wasm_bindgen(method, getter = style)]
12026 pub fn get_style(this: &DisplayNamesOptions) -> Option<DisplayNamesStyle>;
12027 #[wasm_bindgen(method, setter = style)]
12028 pub fn set_style(this: &DisplayNamesOptions, value: DisplayNamesStyle);
12029
12030 #[wasm_bindgen(method, getter = fallback)]
12031 pub fn get_fallback(this: &DisplayNamesOptions) -> Option<DisplayNamesFallback>;
12032 #[wasm_bindgen(method, setter = fallback)]
12033 pub fn set_fallback(this: &DisplayNamesOptions, value: DisplayNamesFallback);
12034
12035 #[wasm_bindgen(method, getter = languageDisplay)]
12036 pub fn get_language_display(
12037 this: &DisplayNamesOptions,
12038 ) -> Option<DisplayNamesLanguageDisplay>;
12039 #[wasm_bindgen(method, setter = languageDisplay)]
12040 pub fn set_language_display(this: &DisplayNamesOptions, value: DisplayNamesLanguageDisplay);
12041 }
12042
12043 impl DisplayNamesOptions {
12044 pub fn new() -> DisplayNamesOptions {
12045 JsCast::unchecked_into(Object::new())
12046 }
12047 }
12048
12049 impl Default for DisplayNamesOptions {
12050 fn default() -> Self {
12051 DisplayNamesOptions::new()
12052 }
12053 }
12054
12055 // Intl.ResolvedDisplayNamesOptions
12056 #[wasm_bindgen]
12057 extern "C" {
12058 /// Resolved options returned by `Intl.DisplayNames.prototype.resolvedOptions()`.
12059 ///
12060 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/resolvedOptions)
12061 #[wasm_bindgen(extends = DisplayNamesOptions)]
12062 #[derive(Clone, Debug)]
12063 pub type ResolvedDisplayNamesOptions;
12064
12065 /// The resolved locale string.
12066 #[wasm_bindgen(method, getter = locale)]
12067 pub fn get_locale(this: &ResolvedDisplayNamesOptions) -> JsString;
12068 }
12069
12070 // Intl.DisplayNames
12071 #[wasm_bindgen]
12072 extern "C" {
12073 /// The `Intl.DisplayNames` object enables the consistent translation of
12074 /// language, region, and script display names.
12075 ///
12076 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames)
12077 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.DisplayNames")]
12078 #[derive(Clone, Debug)]
12079 pub type DisplayNames;
12080
12081 /// Creates a new `Intl.DisplayNames` object.
12082 ///
12083 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/DisplayNames)
12084 #[cfg(not(js_sys_unstable_apis))]
12085 #[wasm_bindgen(constructor, js_namespace = Intl)]
12086 pub fn new(locales: &Array, options: &Object) -> DisplayNames;
12087
12088 /// Creates a new `Intl.DisplayNames` object.
12089 ///
12090 /// Throws a `RangeError` if locales or options contain invalid values.
12091 ///
12092 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/DisplayNames)
12093 #[cfg(js_sys_unstable_apis)]
12094 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
12095 pub fn new(
12096 locales: &[JsString],
12097 options: &DisplayNamesOptions,
12098 ) -> Result<DisplayNames, JsValue>;
12099
12100 /// Returns the display name for the given code.
12101 ///
12102 /// Returns `undefined` if fallback is "none" and no name is available.
12103 ///
12104 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/of)
12105 #[wasm_bindgen(method, js_class = "Intl.DisplayNames")]
12106 pub fn of(this: &DisplayNames, code: &str) -> Option<JsString>;
12107
12108 /// Returns an object with properties reflecting the options used.
12109 ///
12110 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/resolvedOptions)
12111 #[cfg(not(js_sys_unstable_apis))]
12112 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
12113 pub fn resolved_options(this: &DisplayNames) -> Object;
12114
12115 /// Returns an object with properties reflecting the options used.
12116 ///
12117 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/resolvedOptions)
12118 #[cfg(js_sys_unstable_apis)]
12119 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
12120 pub fn resolved_options(this: &DisplayNames) -> ResolvedDisplayNamesOptions;
12121
12122 /// Returns an array of supported locales.
12123 ///
12124 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/supportedLocalesOf)
12125 #[cfg(not(js_sys_unstable_apis))]
12126 #[wasm_bindgen(static_method_of = DisplayNames, js_namespace = Intl, js_name = supportedLocalesOf)]
12127 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
12128
12129 /// Returns an array of supported locales.
12130 ///
12131 /// Throws a `RangeError` if locales contain invalid values.
12132 ///
12133 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/supportedLocalesOf)
12134 #[cfg(js_sys_unstable_apis)]
12135 #[wasm_bindgen(static_method_of = DisplayNames, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
12136 pub fn supported_locales_of(
12137 locales: &[JsString],
12138 options: &LocaleMatcherOptions,
12139 ) -> Result<Array<JsString>, JsValue>;
12140 }
12141
12142 // Intl.Locale
12143 #[wasm_bindgen]
12144 extern "C" {
12145 /// The `Intl.Locale` object is a standard built-in property of the Intl object
12146 /// that represents a Unicode locale identifier.
12147 ///
12148 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale)
12149 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.Locale")]
12150 #[derive(Clone, Debug)]
12151 pub type Locale;
12152
12153 /// Creates a new `Intl.Locale` object.
12154 ///
12155 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/Locale)
12156 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
12157 pub fn new(tag: &str) -> Result<Locale, JsValue>;
12158
12159 /// Creates a new `Intl.Locale` object with options.
12160 ///
12161 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/Locale)
12162 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
12163 pub fn new_with_options(tag: &str, options: &Object) -> Result<Locale, JsValue>;
12164
12165 /// The base name of the locale (language + region + script).
12166 ///
12167 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/baseName)
12168 #[wasm_bindgen(method, getter = baseName)]
12169 pub fn base_name(this: &Locale) -> JsString;
12170
12171 /// The calendar type for the locale.
12172 ///
12173 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/calendar)
12174 #[wasm_bindgen(method, getter)]
12175 pub fn calendar(this: &Locale) -> Option<JsString>;
12176
12177 /// The case first sorting option.
12178 ///
12179 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/caseFirst)
12180 #[wasm_bindgen(method, getter = caseFirst)]
12181 pub fn case_first(this: &Locale) -> Option<JsString>;
12182
12183 /// The collation type for the locale.
12184 ///
12185 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/collation)
12186 #[wasm_bindgen(method, getter)]
12187 pub fn collation(this: &Locale) -> Option<JsString>;
12188
12189 /// The hour cycle for the locale.
12190 ///
12191 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/hourCycle)
12192 #[wasm_bindgen(method, getter = hourCycle)]
12193 pub fn hour_cycle(this: &Locale) -> Option<JsString>;
12194
12195 /// The language code for the locale.
12196 ///
12197 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/language)
12198 #[wasm_bindgen(method, getter)]
12199 pub fn language(this: &Locale) -> JsString;
12200
12201 /// The numbering system for the locale.
12202 ///
12203 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/numberingSystem)
12204 #[wasm_bindgen(method, getter = numberingSystem)]
12205 pub fn numbering_system(this: &Locale) -> Option<JsString>;
12206
12207 /// Whether the locale uses numeric collation.
12208 ///
12209 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/numeric)
12210 #[wasm_bindgen(method, getter)]
12211 pub fn numeric(this: &Locale) -> bool;
12212
12213 /// The region code for the locale.
12214 ///
12215 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/region)
12216 #[wasm_bindgen(method, getter)]
12217 pub fn region(this: &Locale) -> Option<JsString>;
12218
12219 /// The script code for the locale.
12220 ///
12221 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/script)
12222 #[wasm_bindgen(method, getter)]
12223 pub fn script(this: &Locale) -> Option<JsString>;
12224
12225 /// Returns an array of available calendars for the locale.
12226 ///
12227 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getCalendars)
12228 #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getCalendars)]
12229 pub fn get_calendars(this: &Locale) -> Array<JsString>;
12230
12231 /// Returns an array of available collations for the locale.
12232 ///
12233 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getCollations)
12234 #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getCollations)]
12235 pub fn get_collations(this: &Locale) -> Array<JsString>;
12236
12237 /// Returns an array of available hour cycles for the locale.
12238 ///
12239 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getHourCycles)
12240 #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getHourCycles)]
12241 pub fn get_hour_cycles(this: &Locale) -> Array<JsString>;
12242
12243 /// Returns an array of available numbering systems for the locale.
12244 ///
12245 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getNumberingSystems)
12246 #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getNumberingSystems)]
12247 pub fn get_numbering_systems(this: &Locale) -> Array<JsString>;
12248
12249 /// Returns an array of available time zones for the locale's region.
12250 ///
12251 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getTimeZones)
12252 #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getTimeZones)]
12253 pub fn get_time_zones(this: &Locale) -> Option<Array<JsString>>;
12254
12255 /// Returns week information for the locale.
12256 ///
12257 /// May not be available in all environments.
12258 ///
12259 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getWeekInfo)
12260 #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getWeekInfo, catch)]
12261 pub fn get_week_info(this: &Locale) -> Result<WeekInfo, JsValue>;
12262
12263 /// Returns text layout information for the locale.
12264 ///
12265 /// May not be available in all environments.
12266 ///
12267 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getTextInfo)
12268 #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getTextInfo, catch)]
12269 pub fn get_text_info(this: &Locale) -> Result<TextInfo, JsValue>;
12270
12271 /// Returns a new Locale with the specified calendar.
12272 ///
12273 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/maximize)
12274 #[wasm_bindgen(method, js_class = "Intl.Locale")]
12275 pub fn maximize(this: &Locale) -> Locale;
12276
12277 /// Returns a new Locale with the minimal subtags.
12278 ///
12279 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/minimize)
12280 #[wasm_bindgen(method, js_class = "Intl.Locale")]
12281 pub fn minimize(this: &Locale) -> Locale;
12282 }
12283
12284 // Intl.Locale WeekInfo
12285 #[wasm_bindgen]
12286 extern "C" {
12287 /// Week information for a locale.
12288 ///
12289 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getWeekInfo)
12290 #[wasm_bindgen(extends = Object)]
12291 #[derive(Clone, Debug)]
12292 pub type WeekInfo;
12293
12294 /// The first day of the week (1 = Monday, 7 = Sunday).
12295 #[wasm_bindgen(method, getter = firstDay)]
12296 pub fn first_day(this: &WeekInfo) -> u8;
12297
12298 /// Array of weekend days.
12299 #[wasm_bindgen(method, getter)]
12300 pub fn weekend(this: &WeekInfo) -> Array<Number>;
12301
12302 /// Minimal days in the first week of the year.
12303 #[wasm_bindgen(method, getter = minimalDays)]
12304 pub fn minimal_days(this: &WeekInfo) -> u8;
12305 }
12306
12307 // Intl.Locale TextInfo
12308 #[wasm_bindgen]
12309 extern "C" {
12310 /// Text layout information for a locale.
12311 ///
12312 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getTextInfo)
12313 #[wasm_bindgen(extends = Object)]
12314 #[derive(Clone, Debug)]
12315 pub type TextInfo;
12316
12317 /// The text direction ("ltr" or "rtl").
12318 #[wasm_bindgen(method, getter)]
12319 pub fn direction(this: &TextInfo) -> JsString;
12320 }
12321
12322 // Intl.DurationFormat enums
12323
12324 /// The style for duration formatting.
12325 ///
12326 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat#style)
12327 #[wasm_bindgen]
12328 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
12329 pub enum DurationFormatStyle {
12330 Long = "long",
12331 Short = "short",
12332 Narrow = "narrow",
12333 Digital = "digital",
12334 }
12335
12336 /// The display style for individual duration units.
12337 ///
12338 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat#years)
12339 #[wasm_bindgen]
12340 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
12341 pub enum DurationUnitStyle {
12342 Long = "long",
12343 Short = "short",
12344 Narrow = "narrow",
12345 }
12346
12347 /// The display style for time duration units (hours, minutes, seconds).
12348 ///
12349 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat#hours)
12350 #[wasm_bindgen]
12351 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
12352 pub enum DurationTimeUnitStyle {
12353 Long = "long",
12354 Short = "short",
12355 Narrow = "narrow",
12356 Numeric = "numeric",
12357 #[wasm_bindgen(js_name = "2-digit")]
12358 TwoDigit = "2-digit",
12359 }
12360
12361 /// The display option for duration units.
12362 ///
12363 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat#yearsdisplay)
12364 #[wasm_bindgen]
12365 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
12366 pub enum DurationUnitDisplay {
12367 Auto = "auto",
12368 Always = "always",
12369 }
12370
12371 /// The type of a duration format part.
12372 ///
12373 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/formatToParts#type)
12374 #[wasm_bindgen]
12375 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
12376 pub enum DurationFormatPartType {
12377 Years = "years",
12378 Months = "months",
12379 Weeks = "weeks",
12380 Days = "days",
12381 Hours = "hours",
12382 Minutes = "minutes",
12383 Seconds = "seconds",
12384 Milliseconds = "milliseconds",
12385 Microseconds = "microseconds",
12386 Nanoseconds = "nanoseconds",
12387 Literal = "literal",
12388 Integer = "integer",
12389 Decimal = "decimal",
12390 Fraction = "fraction",
12391 }
12392
12393 // Intl.DurationFormatOptions
12394 #[wasm_bindgen]
12395 extern "C" {
12396 /// Options for `Intl.DurationFormat` constructor.
12397 ///
12398 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat#options)
12399 #[wasm_bindgen(extends = Object)]
12400 #[derive(Clone, Debug)]
12401 pub type DurationFormatOptions;
12402
12403 #[wasm_bindgen(method, getter = localeMatcher)]
12404 pub fn get_locale_matcher(this: &DurationFormatOptions) -> Option<LocaleMatcher>;
12405 #[wasm_bindgen(method, setter = localeMatcher)]
12406 pub fn set_locale_matcher(this: &DurationFormatOptions, value: LocaleMatcher);
12407
12408 #[wasm_bindgen(method, getter = style)]
12409 pub fn get_style(this: &DurationFormatOptions) -> Option<DurationFormatStyle>;
12410 #[wasm_bindgen(method, setter = style)]
12411 pub fn set_style(this: &DurationFormatOptions, value: DurationFormatStyle);
12412
12413 #[wasm_bindgen(method, getter = years)]
12414 pub fn get_years(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
12415 #[wasm_bindgen(method, setter = years)]
12416 pub fn set_years(this: &DurationFormatOptions, value: DurationUnitStyle);
12417
12418 #[wasm_bindgen(method, getter = yearsDisplay)]
12419 pub fn get_years_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
12420 #[wasm_bindgen(method, setter = yearsDisplay)]
12421 pub fn set_years_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12422
12423 #[wasm_bindgen(method, getter = months)]
12424 pub fn get_months(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
12425 #[wasm_bindgen(method, setter = months)]
12426 pub fn set_months(this: &DurationFormatOptions, value: DurationUnitStyle);
12427
12428 #[wasm_bindgen(method, getter = monthsDisplay)]
12429 pub fn get_months_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
12430 #[wasm_bindgen(method, setter = monthsDisplay)]
12431 pub fn set_months_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12432
12433 #[wasm_bindgen(method, getter = weeks)]
12434 pub fn get_weeks(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
12435 #[wasm_bindgen(method, setter = weeks)]
12436 pub fn set_weeks(this: &DurationFormatOptions, value: DurationUnitStyle);
12437
12438 #[wasm_bindgen(method, getter = weeksDisplay)]
12439 pub fn get_weeks_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
12440 #[wasm_bindgen(method, setter = weeksDisplay)]
12441 pub fn set_weeks_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12442
12443 #[wasm_bindgen(method, getter = days)]
12444 pub fn get_days(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
12445 #[wasm_bindgen(method, setter = days)]
12446 pub fn set_days(this: &DurationFormatOptions, value: DurationUnitStyle);
12447
12448 #[wasm_bindgen(method, getter = daysDisplay)]
12449 pub fn get_days_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
12450 #[wasm_bindgen(method, setter = daysDisplay)]
12451 pub fn set_days_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12452
12453 #[wasm_bindgen(method, getter = hours)]
12454 pub fn get_hours(this: &DurationFormatOptions) -> Option<DurationTimeUnitStyle>;
12455 #[wasm_bindgen(method, setter = hours)]
12456 pub fn set_hours(this: &DurationFormatOptions, value: DurationTimeUnitStyle);
12457
12458 #[wasm_bindgen(method, getter = hoursDisplay)]
12459 pub fn get_hours_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
12460 #[wasm_bindgen(method, setter = hoursDisplay)]
12461 pub fn set_hours_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12462
12463 #[wasm_bindgen(method, getter = minutes)]
12464 pub fn get_minutes(this: &DurationFormatOptions) -> Option<DurationTimeUnitStyle>;
12465 #[wasm_bindgen(method, setter = minutes)]
12466 pub fn set_minutes(this: &DurationFormatOptions, value: DurationTimeUnitStyle);
12467
12468 #[wasm_bindgen(method, getter = minutesDisplay)]
12469 pub fn get_minutes_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
12470 #[wasm_bindgen(method, setter = minutesDisplay)]
12471 pub fn set_minutes_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12472
12473 #[wasm_bindgen(method, getter = seconds)]
12474 pub fn get_seconds(this: &DurationFormatOptions) -> Option<DurationTimeUnitStyle>;
12475 #[wasm_bindgen(method, setter = seconds)]
12476 pub fn set_seconds(this: &DurationFormatOptions, value: DurationTimeUnitStyle);
12477
12478 #[wasm_bindgen(method, getter = secondsDisplay)]
12479 pub fn get_seconds_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
12480 #[wasm_bindgen(method, setter = secondsDisplay)]
12481 pub fn set_seconds_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12482
12483 #[wasm_bindgen(method, getter = milliseconds)]
12484 pub fn get_milliseconds(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
12485 #[wasm_bindgen(method, setter = milliseconds)]
12486 pub fn set_milliseconds(this: &DurationFormatOptions, value: DurationUnitStyle);
12487
12488 #[wasm_bindgen(method, getter = millisecondsDisplay)]
12489 pub fn get_milliseconds_display(
12490 this: &DurationFormatOptions,
12491 ) -> Option<DurationUnitDisplay>;
12492 #[wasm_bindgen(method, setter = millisecondsDisplay)]
12493 pub fn set_milliseconds_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12494
12495 #[wasm_bindgen(method, getter = microseconds)]
12496 pub fn get_microseconds(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
12497 #[wasm_bindgen(method, setter = microseconds)]
12498 pub fn set_microseconds(this: &DurationFormatOptions, value: DurationUnitStyle);
12499
12500 #[wasm_bindgen(method, getter = microsecondsDisplay)]
12501 pub fn get_microseconds_display(
12502 this: &DurationFormatOptions,
12503 ) -> Option<DurationUnitDisplay>;
12504 #[wasm_bindgen(method, setter = microsecondsDisplay)]
12505 pub fn set_microseconds_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12506
12507 #[wasm_bindgen(method, getter = nanoseconds)]
12508 pub fn get_nanoseconds(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
12509 #[wasm_bindgen(method, setter = nanoseconds)]
12510 pub fn set_nanoseconds(this: &DurationFormatOptions, value: DurationUnitStyle);
12511
12512 #[wasm_bindgen(method, getter = nanosecondsDisplay)]
12513 pub fn get_nanoseconds_display(this: &DurationFormatOptions)
12514 -> Option<DurationUnitDisplay>;
12515 #[wasm_bindgen(method, setter = nanosecondsDisplay)]
12516 pub fn set_nanoseconds_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12517
12518 #[wasm_bindgen(method, getter = fractionalDigits)]
12519 pub fn get_fractional_digits(this: &DurationFormatOptions) -> Option<u8>;
12520 #[wasm_bindgen(method, setter = fractionalDigits)]
12521 pub fn set_fractional_digits(this: &DurationFormatOptions, value: u8);
12522 }
12523
12524 impl DurationFormatOptions {
12525 pub fn new() -> DurationFormatOptions {
12526 JsCast::unchecked_into(Object::new())
12527 }
12528 }
12529
12530 impl Default for DurationFormatOptions {
12531 fn default() -> Self {
12532 DurationFormatOptions::new()
12533 }
12534 }
12535
12536 // Intl.ResolvedDurationFormatOptions
12537 #[wasm_bindgen]
12538 extern "C" {
12539 /// Resolved options returned by `Intl.DurationFormat.prototype.resolvedOptions()`.
12540 ///
12541 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/resolvedOptions)
12542 #[wasm_bindgen(extends = DurationFormatOptions)]
12543 #[derive(Clone, Debug)]
12544 pub type ResolvedDurationFormatOptions;
12545
12546 /// The resolved locale string.
12547 #[wasm_bindgen(method, getter = locale)]
12548 pub fn get_locale(this: &ResolvedDurationFormatOptions) -> JsString;
12549
12550 /// The resolved numbering system.
12551 #[wasm_bindgen(method, getter = numberingSystem)]
12552 pub fn get_numbering_system(this: &ResolvedDurationFormatOptions) -> JsString;
12553 }
12554
12555 // Intl.Duration (input object for DurationFormat)
12556 #[wasm_bindgen]
12557 extern "C" {
12558 /// A duration object used as input to `Intl.DurationFormat.format()`.
12559 ///
12560 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/format#duration)
12561 #[wasm_bindgen(extends = Object)]
12562 #[derive(Clone, Debug)]
12563 pub type Duration;
12564
12565 #[wasm_bindgen(method, getter)]
12566 pub fn years(this: &Duration) -> Option<f64>;
12567 #[wasm_bindgen(method, setter)]
12568 pub fn set_years(this: &Duration, value: f64);
12569
12570 #[wasm_bindgen(method, getter)]
12571 pub fn months(this: &Duration) -> Option<f64>;
12572 #[wasm_bindgen(method, setter)]
12573 pub fn set_months(this: &Duration, value: f64);
12574
12575 #[wasm_bindgen(method, getter)]
12576 pub fn weeks(this: &Duration) -> Option<f64>;
12577 #[wasm_bindgen(method, setter)]
12578 pub fn set_weeks(this: &Duration, value: f64);
12579
12580 #[wasm_bindgen(method, getter)]
12581 pub fn days(this: &Duration) -> Option<f64>;
12582 #[wasm_bindgen(method, setter)]
12583 pub fn set_days(this: &Duration, value: f64);
12584
12585 #[wasm_bindgen(method, getter)]
12586 pub fn hours(this: &Duration) -> Option<f64>;
12587 #[wasm_bindgen(method, setter)]
12588 pub fn set_hours(this: &Duration, value: f64);
12589
12590 #[wasm_bindgen(method, getter)]
12591 pub fn minutes(this: &Duration) -> Option<f64>;
12592 #[wasm_bindgen(method, setter)]
12593 pub fn set_minutes(this: &Duration, value: f64);
12594
12595 #[wasm_bindgen(method, getter)]
12596 pub fn seconds(this: &Duration) -> Option<f64>;
12597 #[wasm_bindgen(method, setter)]
12598 pub fn set_seconds(this: &Duration, value: f64);
12599
12600 #[wasm_bindgen(method, getter)]
12601 pub fn milliseconds(this: &Duration) -> Option<f64>;
12602 #[wasm_bindgen(method, setter)]
12603 pub fn set_milliseconds(this: &Duration, value: f64);
12604
12605 #[wasm_bindgen(method, getter)]
12606 pub fn microseconds(this: &Duration) -> Option<f64>;
12607 #[wasm_bindgen(method, setter)]
12608 pub fn set_microseconds(this: &Duration, value: f64);
12609
12610 #[wasm_bindgen(method, getter)]
12611 pub fn nanoseconds(this: &Duration) -> Option<f64>;
12612 #[wasm_bindgen(method, setter)]
12613 pub fn set_nanoseconds(this: &Duration, value: f64);
12614 }
12615
12616 impl Duration {
12617 pub fn new() -> Duration {
12618 JsCast::unchecked_into(Object::new())
12619 }
12620 }
12621
12622 impl Default for Duration {
12623 fn default() -> Self {
12624 Duration::new()
12625 }
12626 }
12627
12628 // Intl.DurationFormatPart
12629 #[wasm_bindgen]
12630 extern "C" {
12631 /// A part of the formatted duration returned by `formatToParts()`.
12632 ///
12633 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/formatToParts)
12634 #[wasm_bindgen(extends = Object)]
12635 #[derive(Clone, Debug)]
12636 pub type DurationFormatPart;
12637
12638 /// The type of the part.
12639 #[wasm_bindgen(method, getter = type)]
12640 pub fn type_(this: &DurationFormatPart) -> DurationFormatPartType;
12641
12642 /// The value of the part.
12643 #[wasm_bindgen(method, getter)]
12644 pub fn value(this: &DurationFormatPart) -> JsString;
12645
12646 /// The unit this part represents (if applicable).
12647 #[wasm_bindgen(method, getter)]
12648 pub fn unit(this: &DurationFormatPart) -> Option<JsString>;
12649 }
12650
12651 // Intl.DurationFormat
12652 #[wasm_bindgen]
12653 extern "C" {
12654 /// The `Intl.DurationFormat` object enables language-sensitive duration formatting.
12655 ///
12656 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat)
12657 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.DurationFormat")]
12658 #[derive(Clone, Debug)]
12659 pub type DurationFormat;
12660
12661 /// Creates a new `Intl.DurationFormat` object.
12662 ///
12663 /// Throws a `RangeError` if locales or options contain invalid values.
12664 ///
12665 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat)
12666 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
12667 pub fn new(
12668 locales: &[JsString],
12669 options: &DurationFormatOptions,
12670 ) -> Result<DurationFormat, JsValue>;
12671
12672 /// Formats a duration according to the locale and formatting options.
12673 ///
12674 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/format)
12675 #[wasm_bindgen(method, js_class = "Intl.DurationFormat")]
12676 pub fn format(this: &DurationFormat, duration: &Duration) -> JsString;
12677
12678 /// Returns an array of objects representing the formatted duration in parts.
12679 ///
12680 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/formatToParts)
12681 #[wasm_bindgen(method, js_class = "Intl.DurationFormat", js_name = formatToParts)]
12682 pub fn format_to_parts(
12683 this: &DurationFormat,
12684 duration: &Duration,
12685 ) -> Array<DurationFormatPart>;
12686
12687 /// Returns an object with properties reflecting the options used.
12688 ///
12689 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/resolvedOptions)
12690 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
12691 pub fn resolved_options(this: &DurationFormat) -> ResolvedDurationFormatOptions;
12692
12693 /// Returns an array of supported locales.
12694 ///
12695 /// Throws a `RangeError` if locales contain invalid values.
12696 ///
12697 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/supportedLocalesOf)
12698 #[wasm_bindgen(static_method_of = DurationFormat, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
12699 pub fn supported_locales_of(
12700 locales: &[JsString],
12701 options: &LocaleMatcherOptions,
12702 ) -> Result<Array<JsString>, JsValue>;
12703 }
12704
12705 impl Default for DurationFormat {
12706 fn default() -> Self {
12707 Self::new(&[], &Default::default()).unwrap()
12708 }
12709 }
12710}
12711
12712#[wasm_bindgen]
12713extern "C" {
12714 /// The `PromiseState` object represents the the status of the promise,
12715 /// as used in `allSettled`.
12716 ///
12717 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled)
12718 #[must_use]
12719 #[wasm_bindgen(extends = Object, typescript_type = "any")]
12720 #[derive(Clone, Debug)]
12721 pub type PromiseState<T = JsValue>;
12722
12723 /// A string, either "fulfilled" or "rejected", indicating the eventual state of the promise.
12724 #[wasm_bindgen(method, getter = status)]
12725 pub fn get_status<T>(this: &PromiseState<T>) -> String;
12726
12727 /// Only present if status is "fulfilled". The value that the promise was fulfilled with.
12728 #[wasm_bindgen(method, getter = value)]
12729 pub fn get_value<T>(this: &PromiseState<T>) -> Option<T>;
12730
12731 /// Only present if status is "rejected". The reason that the promise was rejected with.
12732 #[wasm_bindgen(method, getter = reason)]
12733 pub fn get_reason<T>(this: &PromiseState<T>) -> Option<JsValue>;
12734}
12735
12736impl<T> PromiseState<T> {
12737 pub fn is_fulfilled(&self) -> bool {
12738 self.get_status() == "fulfilled"
12739 }
12740
12741 pub fn is_rejected(&self) -> bool {
12742 self.get_status() == "rejected"
12743 }
12744}
12745
12746// Promise
12747#[wasm_bindgen]
12748extern "C" {
12749 /// The `Promise` object represents the eventual completion (or failure) of
12750 /// an asynchronous operation, and its resulting value.
12751 ///
12752 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
12753 #[must_use]
12754 #[wasm_bindgen(extends = Object, typescript_type = "Promise<any>", no_promising)]
12755 #[derive(Clone, Debug)]
12756 pub type Promise<T = JsValue>;
12757
12758 /// Creates a new `Promise` with the provided executor `cb`
12759 ///
12760 /// The `cb` is a function that is passed with the arguments `resolve` and
12761 /// `reject`. The `cb` function is executed immediately by the `Promise`
12762 /// implementation, passing `resolve` and `reject` functions (the executor
12763 /// is called before the `Promise` constructor even returns the created
12764 /// object). The `resolve` and `reject` functions, when called, resolve or
12765 /// reject the promise, respectively. The executor normally initiates
12766 /// some asynchronous work, and then, once that completes, either calls
12767 /// the `resolve` function to resolve the promise or else rejects it if an
12768 /// error occurred.
12769 ///
12770 /// If an error is thrown in the executor function, the promise is rejected.
12771 /// The return value of the executor is ignored.
12772 ///
12773 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
12774 #[cfg(not(js_sys_unstable_apis))]
12775 #[wasm_bindgen(constructor)]
12776 pub fn new(cb: &mut dyn FnMut(Function, Function)) -> Promise;
12777
12778 /// Creates a new `Promise` with the provided executor `cb`
12779 ///
12780 /// The `cb` is a function that is passed with the arguments `resolve` and
12781 /// `reject`. The `cb` function is executed immediately by the `Promise`
12782 /// implementation, passing `resolve` and `reject` functions (the executor
12783 /// is called before the `Promise` constructor even returns the created
12784 /// object). The `resolve` and `reject` functions, when called, resolve or
12785 /// reject the promise, respectively. The executor normally initiates
12786 /// some asynchronous work, and then, once that completes, either calls
12787 /// the `resolve` function to resolve the promise or else rejects it if an
12788 /// error occurred.
12789 ///
12790 /// If an error is thrown in the executor function, the promise is rejected.
12791 /// The return value of the executor is ignored.
12792 ///
12793 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
12794 #[cfg(js_sys_unstable_apis)]
12795 #[wasm_bindgen(constructor)]
12796 pub fn new<T: JsGeneric>(
12797 cb: &mut dyn FnMut(Function<fn(T) -> Undefined>, Function<fn(JsValue) -> Undefined>),
12798 ) -> Promise<T>;
12799
12800 // Next major: deprecate
12801 /// Creates a new `Promise` with the provided executor `cb`
12802 ///
12803 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
12804 #[wasm_bindgen(constructor)]
12805 pub fn new_typed<T: JsGeneric>(
12806 cb: &mut dyn FnMut(Function<fn(T) -> Undefined>, Function<fn(JsValue) -> Undefined>),
12807 ) -> Promise<T>;
12808
12809 /// The `Promise.all(iterable)` method returns a single `Promise` that
12810 /// resolves when all of the promises in the iterable argument have resolved
12811 /// or when the iterable argument contains no promises. It rejects with the
12812 /// reason of the first promise that rejects.
12813 ///
12814 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all)
12815 #[cfg(not(js_sys_unstable_apis))]
12816 #[wasm_bindgen(static_method_of = Promise)]
12817 pub fn all(obj: &JsValue) -> Promise;
12818
12819 /// The `Promise.all(iterable)` method returns a single `Promise` that
12820 /// resolves when all of the promises in the iterable argument have resolved
12821 /// or when the iterable argument contains no promises. It rejects with the
12822 /// reason of the first promise that rejects.
12823 ///
12824 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all)
12825 #[cfg(js_sys_unstable_apis)]
12826 #[wasm_bindgen(static_method_of = Promise, js_name = all)]
12827 pub fn all<I: Iterable>(obj: &I) -> Promise<Array<<I::Item as Promising>::Resolution>>
12828 where
12829 I::Item: Promising;
12830
12831 // Next major: deprecate
12832 /// The `Promise.all(iterable)` method returns a single `Promise` that
12833 /// resolves when all of the promises in the iterable argument have resolved
12834 /// or when the iterable argument contains no promises. It rejects with the
12835 /// reason of the first promise that rejects.
12836 ///
12837 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all)
12838 #[wasm_bindgen(static_method_of = Promise, js_name = all)]
12839 pub fn all_iterable<I: Iterable>(obj: &I) -> Promise<Array<<I::Item as Promising>::Resolution>>
12840 where
12841 I::Item: Promising;
12842
12843 /// The `Promise.allSettled(iterable)` method returns a single `Promise` that
12844 /// resolves when all of the promises in the iterable argument have either
12845 /// fulfilled or rejected or when the iterable argument contains no promises.
12846 ///
12847 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled)
12848 #[cfg(not(js_sys_unstable_apis))]
12849 #[wasm_bindgen(static_method_of = Promise, js_name = allSettled)]
12850 pub fn all_settled(obj: &JsValue) -> Promise;
12851
12852 /// The `Promise.allSettled(iterable)` method returns a single `Promise` that
12853 /// resolves when all of the promises in the iterable argument have either
12854 /// fulfilled or rejected or when the iterable argument contains no promises.
12855 ///
12856 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled)
12857 #[cfg(js_sys_unstable_apis)]
12858 #[wasm_bindgen(static_method_of = Promise, js_name = allSettled)]
12859 pub fn all_settled<I: Iterable>(
12860 obj: &I,
12861 ) -> Promise<Array<PromiseState<<I::Item as Promising>::Resolution>>>
12862 where
12863 I::Item: Promising;
12864
12865 // Next major: deprecate
12866 /// The `Promise.allSettled(iterable)` method returns a single `Promise` that
12867 /// resolves when all of the promises in the iterable argument have either
12868 /// fulfilled or rejected or when the iterable argument contains no promises.
12869 ///
12870 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled)
12871 #[wasm_bindgen(static_method_of = Promise, js_name = allSettled)]
12872 pub fn all_settled_iterable<I: Iterable>(
12873 obj: &I,
12874 ) -> Promise<Array<PromiseState<<I::Item as Promising>::Resolution>>>
12875 where
12876 I::Item: Promising;
12877
12878 /// The `Promise.any(iterable)` method returns a single `Promise` that
12879 /// resolves when any of the promises in the iterable argument have resolved
12880 /// or when the iterable argument contains no promises. It rejects with an
12881 /// `AggregateError` if all promises in the iterable rejected.
12882 ///
12883 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/any)
12884 #[cfg(not(js_sys_unstable_apis))]
12885 #[wasm_bindgen(static_method_of = Promise)]
12886 pub fn any(obj: &JsValue) -> Promise;
12887
12888 /// The `Promise.any(iterable)` method returns a single `Promise` that
12889 /// resolves when any of the promises in the iterable argument have resolved
12890 /// or when the iterable argument contains no promises. It rejects with an
12891 /// `AggregateError` if all promises in the iterable rejected.
12892 ///
12893 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/any)
12894 #[cfg(js_sys_unstable_apis)]
12895 #[wasm_bindgen(static_method_of = Promise, js_name = any)]
12896 pub fn any<I: Iterable>(obj: &I) -> Promise<<I::Item as Promising>::Resolution>
12897 where
12898 I::Item: Promising;
12899
12900 // Next major: deprecate
12901 /// The `Promise.any(iterable)` method returns a single `Promise` that
12902 /// resolves when any of the promises in the iterable argument have resolved
12903 /// or when the iterable argument contains no promises. It rejects with an
12904 /// `AggregateError` if all promises in the iterable rejected.
12905 ///
12906 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/any)
12907 #[cfg(not(js_sys_unstable_apis))]
12908 #[wasm_bindgen(static_method_of = Promise, js_name = any)]
12909 pub fn any_iterable<I: Iterable>(obj: &I) -> Promise<<I::Item as Promising>::Resolution>
12910 where
12911 I::Item: Promising;
12912
12913 /// The `Promise.race(iterable)` method returns a promise that resolves or
12914 /// rejects as soon as one of the promises in the iterable resolves or
12915 /// rejects, with the value or reason from that promise.
12916 ///
12917 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/race)
12918 #[cfg(not(js_sys_unstable_apis))]
12919 #[wasm_bindgen(static_method_of = Promise)]
12920 pub fn race(obj: &JsValue) -> Promise;
12921
12922 /// The `Promise.race(iterable)` method returns a promise that resolves or
12923 /// rejects as soon as one of the promises in the iterable resolves or
12924 /// rejects, with the value or reason from that promise.
12925 ///
12926 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/race)
12927 #[cfg(js_sys_unstable_apis)]
12928 #[wasm_bindgen(static_method_of = Promise, js_name = race)]
12929 pub fn race<I: Iterable>(obj: &I) -> Promise<<I::Item as Promising>::Resolution>
12930 where
12931 I::Item: Promising;
12932
12933 // Next major: deprecate
12934 /// The `Promise.race(iterable)` method returns a promise that resolves or
12935 /// rejects as soon as one of the promises in the iterable resolves or
12936 /// rejects, with the value or reason from that promise.
12937 ///
12938 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/race)
12939 #[wasm_bindgen(static_method_of = Promise, js_name = race)]
12940 pub fn race_iterable<I: Iterable>(obj: &I) -> Promise<<I::Item as Promising>::Resolution>
12941 where
12942 I::Item: Promising;
12943
12944 /// The `Promise.reject(reason)` method returns a `Promise` object that is
12945 /// rejected with the given reason.
12946 ///
12947 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/reject)
12948 #[cfg(not(js_sys_unstable_apis))]
12949 #[wasm_bindgen(static_method_of = Promise)]
12950 pub fn reject(obj: &JsValue) -> Promise;
12951
12952 /// The `Promise.reject(reason)` method returns a `Promise` object that is
12953 /// rejected with the given reason.
12954 ///
12955 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/reject)
12956 #[cfg(js_sys_unstable_apis)]
12957 #[wasm_bindgen(static_method_of = Promise, js_name = reject)]
12958 pub fn reject<T>(obj: &JsValue) -> Promise<T>;
12959
12960 // Next major: deprecate
12961 /// The `Promise.reject(reason)` method returns a `Promise` object that is
12962 /// rejected with the given reason.
12963 ///
12964 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/reject)
12965 #[wasm_bindgen(static_method_of = Promise, js_name = reject)]
12966 pub fn reject_typed<T>(obj: &JsValue) -> Promise<T>;
12967
12968 /// The `Promise.resolve(value)` method returns a `Promise` object that is
12969 /// resolved with the given value. If the value is a promise, that promise
12970 /// is returned; if the value is a thenable (i.e. has a "then" method), the
12971 /// returned promise will "follow" that thenable, adopting its eventual
12972 /// state; otherwise the returned promise will be fulfilled with the value.
12973 ///
12974 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/resolve)
12975 #[wasm_bindgen(static_method_of = Promise, js_name = resolve)]
12976 pub fn resolve<U: Promising>(obj: &U) -> Promise<U::Resolution>;
12977
12978 /// The `catch()` method returns a `Promise` and deals with rejected cases
12979 /// only. It behaves the same as calling `Promise.prototype.then(undefined,
12980 /// onRejected)` (in fact, calling `obj.catch(onRejected)` internally calls
12981 /// `obj.then(undefined, onRejected)`).
12982 ///
12983 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch)
12984 #[cfg(not(js_sys_unstable_apis))]
12985 #[wasm_bindgen(method)]
12986 pub fn catch<T>(this: &Promise<T>, cb: &ScopedClosure<dyn FnMut(JsValue)>) -> Promise<JsValue>;
12987
12988 /// The `catch()` method returns a `Promise` and deals with rejected cases
12989 /// only. It behaves the same as calling `Promise.prototype.then(undefined,
12990 /// onRejected)` (in fact, calling `obj.catch(onRejected)` internally calls
12991 /// `obj.then(undefined, onRejected)`).
12992 ///
12993 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch)
12994 #[cfg(js_sys_unstable_apis)]
12995 #[wasm_bindgen(method, js_name = catch)]
12996 pub fn catch<'a, T, R: Promising>(
12997 this: &Promise<T>,
12998 cb: &ScopedClosure<'a, dyn FnMut(T) -> Result<R, JsError>>,
12999 ) -> Promise<R::Resolution>;
13000
13001 // Next major: deprecate
13002 /// Same as `catch`, but returning a result to become the new Promise value.
13003 #[wasm_bindgen(method, js_name = catch)]
13004 pub fn catch_map<'a, T, R: Promising>(
13005 this: &Promise<T>,
13006 cb: &ScopedClosure<'a, dyn FnMut(T) -> Result<R, JsError>>,
13007 ) -> Promise<R::Resolution>;
13008
13009 /// The `then()` method returns a `Promise`. It takes up to two arguments:
13010 /// callback functions for the success and failure cases of the `Promise`.
13011 ///
13012 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then)
13013 #[cfg(not(js_sys_unstable_apis))]
13014 #[wasm_bindgen(method)]
13015 pub fn then<'a, T>(this: &Promise<T>, cb: &ScopedClosure<'a, dyn FnMut(T)>)
13016 -> Promise<JsValue>;
13017
13018 /// The `then()` method returns a `Promise`. It takes up to two arguments:
13019 /// callback functions for the success and failure cases of the `Promise`.
13020 ///
13021 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then)
13022 #[cfg(js_sys_unstable_apis)]
13023 #[wasm_bindgen(method, js_name = then)]
13024 pub fn then<'a, T, R: Promising>(
13025 this: &Promise<T>,
13026 cb: &ScopedClosure<'a, dyn FnMut(T) -> Result<R, JsError>>,
13027 ) -> Promise<R::Resolution>;
13028
13029 /// The `then()` method returns a `Promise`. It takes up to two arguments:
13030 /// callback functions for the success and failure cases of the `Promise`.
13031 ///
13032 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then)
13033 #[wasm_bindgen(method, js_name = then)]
13034 pub fn then_with_reject<'a, T, R: Promising>(
13035 this: &Promise<T>,
13036 resolve: &ScopedClosure<'a, dyn FnMut(T) -> Result<R, JsError>>,
13037 reject: &ScopedClosure<'a, dyn FnMut(JsValue) -> Result<R, JsError>>,
13038 ) -> Promise<R::Resolution>;
13039
13040 // Next major: deprecate
13041 /// Alias for `then()` with a return value.
13042 /// The `then()` method returns a `Promise`. It takes up to two arguments:
13043 /// callback functions for the success and failure cases of the `Promise`.
13044 ///
13045 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then)
13046 #[wasm_bindgen(method, js_name = then)]
13047 pub fn then_map<'a, T, R: Promising>(
13048 this: &Promise<T>,
13049 cb: &ScopedClosure<'a, dyn FnMut(T) -> Result<R, JsError>>,
13050 ) -> Promise<R::Resolution>;
13051
13052 /// Same as `then`, only with both arguments provided.
13053 ///
13054 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then)
13055 #[wasm_bindgen(method, js_name = then)]
13056 pub fn then2(
13057 this: &Promise,
13058 resolve: &ScopedClosure<dyn FnMut(JsValue)>,
13059 reject: &ScopedClosure<dyn FnMut(JsValue)>,
13060 ) -> Promise;
13061
13062 /// The `finally()` method returns a `Promise`. When the promise is settled,
13063 /// whether fulfilled or rejected, the specified callback function is
13064 /// executed. This provides a way for code that must be executed once the
13065 /// `Promise` has been dealt with to be run whether the promise was
13066 /// fulfilled successfully or rejected.
13067 ///
13068 /// This lets you avoid duplicating code in both the promise's `then()` and
13069 /// `catch()` handlers.
13070 ///
13071 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/finally)
13072 #[wasm_bindgen(method)]
13073 pub fn finally<T>(this: &Promise<T>, cb: &ScopedClosure<dyn FnMut()>) -> Promise<JsValue>;
13074}
13075
13076impl<T: JsGeneric> Promising for Promise<T> {
13077 type Resolution = T;
13078}
13079
13080/// Returns a handle to the global scope object.
13081///
13082/// This allows access to the global properties and global names by accessing
13083/// the `Object` returned.
13084pub fn global() -> Object {
13085 use once_cell::unsync::Lazy;
13086
13087 struct Wrapper<T>(Lazy<T>);
13088
13089 #[cfg(not(target_feature = "atomics"))]
13090 unsafe impl<T> Sync for Wrapper<T> {}
13091
13092 #[cfg(not(target_feature = "atomics"))]
13093 unsafe impl<T> Send for Wrapper<T> {}
13094
13095 #[cfg_attr(target_feature = "atomics", thread_local)]
13096 static GLOBAL: Wrapper<Object> = Wrapper(Lazy::new(get_global_object));
13097
13098 return GLOBAL.0.clone();
13099
13100 fn get_global_object() -> Object {
13101 // Accessing the global object is not an easy thing to do, and what we
13102 // basically want is `globalThis` but we can't rely on that existing
13103 // everywhere. In the meantime we've got the fallbacks mentioned in:
13104 //
13105 // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis
13106 //
13107 // Note that this is pretty heavy code-size wise but it at least gets
13108 // the job largely done for now and avoids the `Function` constructor at
13109 // the end which triggers CSP errors.
13110 #[wasm_bindgen]
13111 extern "C" {
13112 type Global;
13113
13114 #[wasm_bindgen(thread_local_v2, js_name = globalThis)]
13115 static GLOBAL_THIS: Option<Object>;
13116
13117 #[wasm_bindgen(thread_local_v2, js_name = self)]
13118 static SELF: Option<Object>;
13119
13120 #[wasm_bindgen(thread_local_v2, js_name = window)]
13121 static WINDOW: Option<Object>;
13122
13123 #[wasm_bindgen(thread_local_v2, js_name = global)]
13124 static GLOBAL: Option<Object>;
13125 }
13126
13127 // The order is important: in Firefox Extension Content Scripts `globalThis`
13128 // is a Sandbox (not Window), so `globalThis` must be checked after `window`.
13129 let static_object = SELF
13130 .with(Option::clone)
13131 .or_else(|| WINDOW.with(Option::clone))
13132 .or_else(|| GLOBAL_THIS.with(Option::clone))
13133 .or_else(|| GLOBAL.with(Option::clone));
13134 if let Some(obj) = static_object {
13135 if !obj.is_undefined() {
13136 return obj;
13137 }
13138 }
13139
13140 // Global object not found
13141 JsValue::undefined().unchecked_into()
13142 }
13143}
13144
13145macro_rules! arrays {
13146 ($(#[doc = $ctor:literal] #[doc = $mdn:literal] $name:ident: $ty:ident,)*) => ($(
13147 #[wasm_bindgen]
13148 extern "C" {
13149 #[wasm_bindgen(extends = Object, typescript_type = $name)]
13150 #[derive(Clone, Debug)]
13151 pub type $name;
13152
13153 /// The
13154 #[doc = $ctor]
13155 /// constructor creates a new array.
13156 ///
13157 /// [MDN documentation](
13158 #[doc = $mdn]
13159 /// )
13160 #[wasm_bindgen(constructor)]
13161 pub fn new(constructor_arg: &JsValue) -> $name;
13162
13163 /// An
13164 #[doc = $ctor]
13165 /// which creates an array with an internal buffer large
13166 /// enough for `length` elements.
13167 ///
13168 /// [MDN documentation](
13169 #[doc = $mdn]
13170 /// )
13171 #[wasm_bindgen(constructor)]
13172 pub fn new_with_length(length: u32) -> $name;
13173
13174 /// An
13175 #[doc = $ctor]
13176 /// which creates an array from a Rust slice.
13177 ///
13178 /// [MDN documentation](
13179 #[doc = $mdn]
13180 /// )
13181 #[wasm_bindgen(constructor)]
13182 pub fn new_from_slice(slice: &[$ty]) -> $name;
13183
13184 /// An
13185 #[doc = $ctor]
13186 /// which creates an array with the given buffer but is a
13187 /// view starting at `byte_offset`.
13188 ///
13189 /// [MDN documentation](
13190 #[doc = $mdn]
13191 /// )
13192 #[wasm_bindgen(constructor)]
13193 pub fn new_with_byte_offset(buffer: &JsValue, byte_offset: u32) -> $name;
13194
13195 /// An
13196 #[doc = $ctor]
13197 /// which creates an array with the given buffer but is a
13198 /// view starting at `byte_offset` for `length` elements.
13199 ///
13200 /// [MDN documentation](
13201 #[doc = $mdn]
13202 /// )
13203 #[wasm_bindgen(constructor)]
13204 pub fn new_with_byte_offset_and_length(
13205 buffer: &JsValue,
13206 byte_offset: u32,
13207 length: u32,
13208 ) -> $name;
13209
13210 /// The `fill()` method fills all the elements of an array from a start index
13211 /// to an end index with a static value. The end index is not included.
13212 ///
13213 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/fill)
13214 #[wasm_bindgen(method)]
13215 pub fn fill(this: &$name, value: $ty, start: u32, end: u32) -> $name;
13216
13217 /// The buffer accessor property represents the `ArrayBuffer` referenced
13218 /// by a `TypedArray` at construction time.
13219 #[wasm_bindgen(getter, method)]
13220 pub fn buffer(this: &$name) -> ArrayBuffer;
13221
13222 /// The `subarray()` method returns a new `TypedArray` on the same
13223 /// `ArrayBuffer` store and with the same element types as for this
13224 /// `TypedArray` object.
13225 #[wasm_bindgen(method)]
13226 pub fn subarray(this: &$name, begin: u32, end: u32) -> $name;
13227
13228 /// The `slice()` method returns a shallow copy of a portion of a typed
13229 /// array into a new typed array object. This method has the same algorithm
13230 /// as `Array.prototype.slice()`.
13231 #[wasm_bindgen(method)]
13232 pub fn slice(this: &$name, begin: u32, end: u32) -> $name;
13233
13234 /// The `forEach()` method executes a provided function once per array
13235 /// element. This method has the same algorithm as
13236 /// `Array.prototype.forEach()`. `TypedArray` is one of the typed array
13237 /// types here.
13238 #[wasm_bindgen(method, js_name = forEach)]
13239 pub fn for_each(this: &$name, callback: &mut dyn FnMut($ty, u32, $name));
13240
13241 /// The `forEach()` method executes a provided function once per array
13242 /// element. This method has the same algorithm as
13243 /// `Array.prototype.forEach()`. `TypedArray` is one of the typed array
13244 /// types here.
13245 #[wasm_bindgen(method, js_name = forEach, catch)]
13246 pub fn try_for_each(this: &$name, callback: &mut dyn FnMut($ty, u32, $name) -> Result<(), JsError>) -> Result<(), JsValue>;
13247
13248 /// The length accessor property represents the length (in elements) of a
13249 /// typed array.
13250 #[wasm_bindgen(method, getter)]
13251 pub fn length(this: &$name) -> u32;
13252
13253 /// The byteLength accessor property represents the length (in bytes) of a
13254 /// typed array.
13255 #[wasm_bindgen(method, getter, js_name = byteLength)]
13256 pub fn byte_length(this: &$name) -> u32;
13257
13258 /// The byteOffset accessor property represents the offset (in bytes) of a
13259 /// typed array from the start of its `ArrayBuffer`.
13260 #[wasm_bindgen(method, getter, js_name = byteOffset)]
13261 pub fn byte_offset(this: &$name) -> u32;
13262
13263 /// The `set()` method stores multiple values in the typed array, reading
13264 /// input values from a specified array.
13265 #[wasm_bindgen(method)]
13266 pub fn set(this: &$name, src: &JsValue, offset: u32);
13267
13268 /// Gets the value at `idx`, counting from the end if negative.
13269 #[wasm_bindgen(method)]
13270 pub fn at(this: &$name, idx: i32) -> Option<$ty>;
13271
13272 /// The `copyWithin()` method shallow copies part of a typed array to another
13273 /// location in the same typed array and returns it, without modifying its size.
13274 ///
13275 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin)
13276 #[wasm_bindgen(method, js_name = copyWithin)]
13277 pub fn copy_within(this: &$name, target: i32, start: i32, end: i32) -> $name;
13278
13279 /// Gets the value at `idx`, equivalent to the javascript `my_var = arr[idx]`.
13280 #[wasm_bindgen(method, indexing_getter)]
13281 pub fn get_index(this: &$name, idx: u32) -> $ty;
13282
13283 /// Sets the value at `idx`, equivalent to the javascript `arr[idx] = value`.
13284 #[wasm_bindgen(method, indexing_setter)]
13285 pub fn set_index(this: &$name, idx: u32, value: $ty);
13286
13287 /// Copies the Rust slice's data to self.
13288 ///
13289 /// This method is not expected to be public. It requires the length of the
13290 /// TypedArray to be the same as the slice, use `self.copy_from(slice)` instead.
13291 #[wasm_bindgen(method, js_name = set)]
13292 fn copy_from_slice(this: &$name, slice: &[$ty]);
13293
13294 /// Copies this TypedArray's data to Rust slice;
13295 ///
13296 /// This method is not expected to be public. It requires the length of the
13297 /// TypedArray to be the same as the slice, use `self.copy_to(slice)` instead.
13298 ///
13299 /// # Workaround
13300 ///
13301 /// We actually need `slice.set(typed_array)` here, but since slice cannot be treated as
13302 /// `Uint8Array` on the Rust side, we use `Uint8Array.prototype.set.call`, which allows
13303 /// us to specify the `this` value inside the function.
13304 ///
13305 /// Therefore, `Uint8Array.prototype.set.call(slice, typed_array)` is equivalent to
13306 /// `slice.set(typed_array)`.
13307 #[wasm_bindgen(js_namespace = $name, js_name = "prototype.set.call")]
13308 fn copy_to_slice(slice: &mut [$ty], this: &$name);
13309 }
13310
13311 impl $name {
13312 /// Creates a JS typed array which is a view into wasm's linear
13313 /// memory at the slice specified.
13314 ///
13315 /// This function returns a new typed array which is a view into
13316 /// wasm's memory. This view does not copy the underlying data.
13317 ///
13318 /// # Safety
13319 ///
13320 /// Views into WebAssembly memory are only valid so long as the
13321 /// backing buffer isn't resized in JS. Once this function is called
13322 /// any future calls to `Box::new` (or malloc of any form) may cause
13323 /// the returned value here to be invalidated. Use with caution!
13324 ///
13325 /// Additionally the returned object can be safely mutated but the
13326 /// input slice isn't guaranteed to be mutable.
13327 ///
13328 /// Finally, the returned object is disconnected from the input
13329 /// slice's lifetime, so there's no guarantee that the data is read
13330 /// at the right time.
13331 pub unsafe fn view(rust: &[$ty]) -> $name {
13332 wasm_bindgen::__rt::wbg_cast(rust)
13333 }
13334
13335 /// Creates a JS typed array which is a view into wasm's linear
13336 /// memory at the specified pointer with specified length.
13337 ///
13338 /// This function returns a new typed array which is a view into
13339 /// wasm's memory. This view does not copy the underlying data.
13340 ///
13341 /// # Safety
13342 ///
13343 /// Views into WebAssembly memory are only valid so long as the
13344 /// backing buffer isn't resized in JS. Once this function is called
13345 /// any future calls to `Box::new` (or malloc of any form) may cause
13346 /// the returned value here to be invalidated. Use with caution!
13347 ///
13348 /// Additionally the returned object can be safely mutated,
13349 /// the changes are guaranteed to be reflected in the input array.
13350 pub unsafe fn view_mut_raw(ptr: *mut $ty, length: usize) -> $name {
13351 let slice = core::slice::from_raw_parts_mut(ptr, length);
13352 Self::view(slice)
13353 }
13354
13355 /// Copy the contents of this JS typed array into the destination
13356 /// Rust pointer.
13357 ///
13358 /// This function will efficiently copy the memory from a typed
13359 /// array into this Wasm module's own linear memory, initializing
13360 /// the memory destination provided.
13361 ///
13362 /// # Safety
13363 ///
13364 /// This function requires `dst` to point to a buffer
13365 /// large enough to fit this array's contents.
13366 pub unsafe fn raw_copy_to_ptr(&self, dst: *mut $ty) {
13367 let slice = core::slice::from_raw_parts_mut(dst, self.length() as usize);
13368 self.copy_to(slice);
13369 }
13370
13371 /// Copy the contents of this JS typed array into the destination
13372 /// Rust slice.
13373 ///
13374 /// This function will efficiently copy the memory from a typed
13375 /// array into this Wasm module's own linear memory, initializing
13376 /// the memory destination provided.
13377 ///
13378 /// # Panics
13379 ///
13380 /// This function will panic if this typed array's length is
13381 /// different than the length of the provided `dst` array.
13382 pub fn copy_to(&self, dst: &mut [$ty]) {
13383 core::assert_eq!(self.length() as usize, dst.len());
13384 $name::copy_to_slice(dst, self);
13385 }
13386
13387 /// Copy the contents of this JS typed array into the destination
13388 /// Rust slice.
13389 ///
13390 /// This function will efficiently copy the memory from a typed
13391 /// array into this Wasm module's own linear memory, initializing
13392 /// the memory destination provided.
13393 ///
13394 /// # Panics
13395 ///
13396 /// This function will panic if this typed array's length is
13397 /// different than the length of the provided `dst` array.
13398 pub fn copy_to_uninit<'dst>(&self, dst: &'dst mut [MaybeUninit<$ty>]) -> &'dst mut [$ty] {
13399 core::assert_eq!(self.length() as usize, dst.len());
13400 let dst = unsafe { &mut *(dst as *mut [MaybeUninit<$ty>] as *mut [$ty]) };
13401 self.copy_to(dst);
13402 dst
13403 }
13404
13405 /// Copy the contents of the source Rust slice into this
13406 /// JS typed array.
13407 ///
13408 /// This function will efficiently copy the memory from within
13409 /// the Wasm module's own linear memory to this typed array.
13410 ///
13411 /// # Panics
13412 ///
13413 /// This function will panic if this typed array's length is
13414 /// different than the length of the provided `src` array.
13415 pub fn copy_from(&self, src: &[$ty]) {
13416 core::assert_eq!(self.length() as usize, src.len());
13417 self.copy_from_slice(src);
13418 }
13419
13420 /// Efficiently copies the contents of this JS typed array into a new Vec.
13421 pub fn to_vec(&self) -> Vec<$ty> {
13422 let len = self.length() as usize;
13423 let mut output = Vec::with_capacity(len);
13424 // Safety: the capacity has been set
13425 unsafe {
13426 self.raw_copy_to_ptr(output.as_mut_ptr());
13427 output.set_len(len);
13428 }
13429 output
13430 }
13431 }
13432
13433 impl<'a> From<&'a [$ty]> for $name {
13434 #[inline]
13435 fn from(slice: &'a [$ty]) -> $name {
13436 // This is safe because the `new` function makes a copy if its argument is a TypedArray
13437 $name::new_from_slice(slice)
13438 }
13439 }
13440
13441 impl Default for $name {
13442 fn default() -> Self {
13443 Self::new(&JsValue::UNDEFINED.unchecked_into())
13444 }
13445 }
13446
13447 impl TypedArray for $name {}
13448
13449
13450 )*);
13451}
13452
13453arrays! {
13454 /// `Int8Array()`
13455 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int8Array
13456 Int8Array: i8,
13457
13458 /// `Int16Array()`
13459 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int16Array
13460 Int16Array: i16,
13461
13462 /// `Int32Array()`
13463 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int32Array
13464 Int32Array: i32,
13465
13466 /// `Uint8Array()`
13467 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array
13468 Uint8Array: u8,
13469
13470 /// `Uint8ClampedArray()`
13471 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8ClampedArray
13472 Uint8ClampedArray: u8,
13473
13474 /// `Uint16Array()`
13475 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint16Array
13476 Uint16Array: u16,
13477
13478 /// `Uint32Array()`
13479 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint32Array
13480 Uint32Array: u32,
13481
13482 /// `Float32Array()`
13483 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array
13484 Float32Array: f32,
13485
13486 /// `Float64Array()`
13487 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float64Array
13488 Float64Array: f64,
13489
13490 /// `BigInt64Array()`
13491 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt64Array
13492 BigInt64Array: i64,
13493
13494 /// `BigUint64Array()`
13495 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigUint64Array
13496 BigUint64Array: u64,
13497}
13498
13499/// Bridging between JavaScript `Promise`s and Rust `Future`s.
13500///
13501/// Enables `promise.await` directly on any [`Promise`] when this feature is active.
13502/// This module is automatically available when depending on `wasm-bindgen-futures`.
13503#[cfg(feature = "futures")]
13504pub mod futures;