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
31extern crate alloc;
32
33use alloc::string::String;
34use alloc::vec::Vec;
35use core::cmp::Ordering;
36#[cfg(not(js_sys_unstable_apis))]
37use core::convert::Infallible;
38use core::convert::{self, TryFrom};
39use core::f64;
40use core::fmt;
41use core::iter::{self, Product, Sum};
42use core::mem::MaybeUninit;
43use core::ops::{Add, BitAnd, BitOr, BitXor, Div, Mul, Neg, Not, Rem, Shl, Shr, Sub};
44use core::str;
45use core::str::FromStr;
46pub use wasm_bindgen;
47use wasm_bindgen::closure::{ScopedClosure, WasmClosure};
48use wasm_bindgen::convert::{FromWasmAbi, IntoWasmAbi, Upcast, UpcastFrom};
49use wasm_bindgen::prelude::*;
50use wasm_bindgen::JsError;
51
52// Re-export sys types as js-sys types
53pub use wasm_bindgen::sys::{JsOption, Null, Promising, Undefined};
54pub use wasm_bindgen::JsGeneric;
55
56// When adding new imports:
57//
58// * Keep imports in alphabetical order.
59//
60// * Rename imports with `js_name = ...` according to the note about `camelCase`
61// and `snake_case` in the module's documentation above.
62//
63// * Include the one sentence summary of the import from the MDN link in the
64// module's documentation above, and the MDN link itself.
65//
66// * If a function or method can throw an exception, make it catchable by adding
67// `#[wasm_bindgen(catch)]`.
68//
69// * Add a new `#[test]` into the appropriate file in the
70// `crates/js-sys/tests/wasm/` directory. If the imported function or method
71// can throw an exception, make sure to also add test coverage for that case.
72//
73// * Arguments that are `JsValue`s or imported JavaScript types should be taken
74// by reference.
75//
76// * Name JavaScript's `toString()` method as `to_js_string()` to avoid conflict
77// with Rust's `ToString` trait.
78
79macro_rules! forward_deref_unop {
80 (impl $imp:ident, $method:ident for $t:ty) => {
81 impl $imp for $t {
82 type Output = <&'static $t as $imp>::Output;
83
84 #[inline]
85 fn $method(self) -> Self::Output {
86 $imp::$method(&self)
87 }
88 }
89 };
90 (impl<$($gen:ident),+> $imp:ident, $method:ident for $t:ty) => {
91 impl<$($gen),+> $imp for $t {
92 type Output = <&'static $t as $imp>::Output;
93
94 #[inline]
95 fn $method(self) -> Self::Output {
96 $imp::$method(&self)
97 }
98 }
99 };
100}
101
102macro_rules! forward_deref_binop {
103 (impl $imp:ident, $method:ident for $t:ty) => {
104 impl<'a> $imp<$t> for &'a $t {
105 type Output = <&'static $t as $imp<&'static $t>>::Output;
106
107 #[inline]
108 fn $method(self, other: $t) -> Self::Output {
109 $imp::$method(self, &other)
110 }
111 }
112
113 impl $imp<&$t> for $t {
114 type Output = <&'static $t as $imp<&'static $t>>::Output;
115
116 #[inline]
117 fn $method(self, other: &$t) -> Self::Output {
118 $imp::$method(&self, other)
119 }
120 }
121
122 impl $imp<$t> for $t {
123 type Output = <&'static $t as $imp<&'static $t>>::Output;
124
125 #[inline]
126 fn $method(self, other: $t) -> Self::Output {
127 $imp::$method(&self, &other)
128 }
129 }
130 };
131 (impl<$($gen:ident),+> $imp:ident, $method:ident for $t:ty) => {
132 impl<'a, $($gen),+> $imp<$t> for &'a $t {
133 type Output = <&'static $t as $imp<&'static $t>>::Output;
134
135 #[inline]
136 fn $method(self, other: $t) -> Self::Output {
137 $imp::$method(self, &other)
138 }
139 }
140
141 impl<$($gen),+> $imp<&$t> for $t {
142 type Output = <&'static $t as $imp<&'static $t>>::Output;
143
144 #[inline]
145 fn $method(self, other: &$t) -> Self::Output {
146 $imp::$method(&self, other)
147 }
148 }
149
150 impl<$($gen),+> $imp<$t> for $t {
151 type Output = <&'static $t as $imp<&'static $t>>::Output;
152
153 #[inline]
154 fn $method(self, other: $t) -> Self::Output {
155 $imp::$method(&self, &other)
156 }
157 }
158 };
159}
160
161macro_rules! forward_js_unop {
162 (impl $imp:ident, $method:ident for $t:ty) => {
163 impl $imp for &$t {
164 type Output = $t;
165
166 #[inline]
167 fn $method(self) -> Self::Output {
168 $imp::$method(JsValue::as_ref(self)).unchecked_into()
169 }
170 }
171
172 forward_deref_unop!(impl $imp, $method for $t);
173 };
174 (impl<$($gen:ident),+> $imp:ident, $method:ident for $t:ty) => {
175 impl<$($gen),+> $imp for &$t {
176 type Output = $t;
177
178 #[inline]
179 fn $method(self) -> Self::Output {
180 $imp::$method(JsValue::as_ref(self)).unchecked_into()
181 }
182 }
183
184 forward_deref_unop!(impl<$($gen),+> $imp, $method for $t);
185 };
186}
187
188macro_rules! forward_js_binop {
189 (impl $imp:ident, $method:ident for $t:ty) => {
190 impl $imp<&$t> for &$t {
191 type Output = $t;
192
193 #[inline]
194 fn $method(self, other: &$t) -> Self::Output {
195 $imp::$method(JsValue::as_ref(self), JsValue::as_ref(other)).unchecked_into()
196 }
197 }
198
199 forward_deref_binop!(impl $imp, $method for $t);
200 };
201 (impl<$($gen:ident),+> $imp:ident, $method:ident for $t:ty) => {
202 impl<$($gen),+> $imp<&$t> for &$t {
203 type Output = $t;
204
205 #[inline]
206 fn $method(self, other: &$t) -> Self::Output {
207 $imp::$method(JsValue::as_ref(self), JsValue::as_ref(other)).unchecked_into()
208 }
209 }
210
211 forward_deref_binop!(impl<$($gen),+> $imp, $method for $t);
212 };
213}
214
215macro_rules! sum_product {
216 ($($a:ident)*) => ($(
217 impl Sum for $a {
218 #[inline]
219 fn sum<I: iter::Iterator<Item=Self>>(iter: I) -> Self {
220 iter.fold(
221 $a::from(0),
222 |a, b| a + b,
223 )
224 }
225 }
226
227 impl Product for $a {
228 #[inline]
229 fn product<I: iter::Iterator<Item=Self>>(iter: I) -> Self {
230 iter.fold(
231 $a::from(1),
232 |a, b| a * b,
233 )
234 }
235 }
236
237 impl<'a> Sum<&'a $a> for $a {
238 fn sum<I: iter::Iterator<Item=&'a Self>>(iter: I) -> Self {
239 iter.fold(
240 $a::from(0),
241 |a, b| a + b,
242 )
243 }
244 }
245
246 impl<'a> Product<&'a $a> for $a {
247 #[inline]
248 fn product<I: iter::Iterator<Item=&'a Self>>(iter: I) -> Self {
249 iter.fold(
250 $a::from(1),
251 |a, b| a * b,
252 )
253 }
254 }
255 )*);
256 // Generic variant: impl<T> for Type<T>
257 (impl<$gen:ident> $a:ident<$g2:ident>) => {
258 impl<$gen> Sum for $a<$g2>
259 where
260 $a<$g2>: From<$gen>,
261 $g2: From<u32>
262 {
263 #[inline]
264 fn sum<I: iter::Iterator<Item=Self>>(iter: I) -> Self {
265 iter.fold(
266 $a::from($g2::from(0)),
267 |a, b| a + b,
268 )
269 }
270 }
271
272 impl<$gen> Product for $a<$g2>
273 where
274 $a<$g2>: From<$gen>,
275 $g2: From<u32>
276 {
277 #[inline]
278 fn product<I: iter::Iterator<Item=Self>>(iter: I) -> Self {
279 iter.fold(
280 $a::from($g2::from(1)),
281 |a, b| a * b,
282 )
283 }
284 }
285
286 impl<'a, $gen> Sum<&'a $a<$g2>> for $a<$g2>
287 where
288 $a<$g2>: From<$gen>,
289 $g2: From<u32>
290 {
291 fn sum<I: iter::Iterator<Item=&'a Self>>(iter: I) -> Self {
292 iter.fold(
293 $a::from($g2::from(0)),
294 |a, b| a + b,
295 )
296 }
297 }
298
299 impl<'a, $gen> Product<&'a $a<$g2>> for $a<$g2>
300 where
301 $a<$g2>: From<$gen>,
302 $g2: From<u32>
303 {
304 #[inline]
305 fn product<I: iter::Iterator<Item=&'a Self>>(iter: I) -> Self {
306 iter.fold(
307 $a::from($g2::from(1)),
308 |a, b| a * b,
309 )
310 }
311 }
312 };
313}
314
315macro_rules! partialord_ord {
316 ($t:ident) => {
317 impl PartialOrd for $t {
318 #[inline]
319 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
320 Some(self.cmp(other))
321 }
322
323 #[inline]
324 fn lt(&self, other: &Self) -> bool {
325 JsValue::as_ref(self).lt(JsValue::as_ref(other))
326 }
327
328 #[inline]
329 fn le(&self, other: &Self) -> bool {
330 JsValue::as_ref(self).le(JsValue::as_ref(other))
331 }
332
333 #[inline]
334 fn ge(&self, other: &Self) -> bool {
335 JsValue::as_ref(self).ge(JsValue::as_ref(other))
336 }
337
338 #[inline]
339 fn gt(&self, other: &Self) -> bool {
340 JsValue::as_ref(self).gt(JsValue::as_ref(other))
341 }
342 }
343
344 impl Ord for $t {
345 #[inline]
346 fn cmp(&self, other: &Self) -> Ordering {
347 if self == other {
348 Ordering::Equal
349 } else if self.lt(other) {
350 Ordering::Less
351 } else {
352 Ordering::Greater
353 }
354 }
355 }
356 };
357}
358
359#[wasm_bindgen]
360extern "C" {
361 /// The `decodeURI()` function decodes a Uniform Resource Identifier (URI)
362 /// previously created by `encodeURI` or by a similar routine.
363 ///
364 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURI)
365 #[wasm_bindgen(catch, js_name = decodeURI)]
366 pub fn decode_uri(encoded: &str) -> Result<JsString, JsValue>;
367
368 /// The `decodeURIComponent()` function decodes a Uniform Resource Identifier (URI) component
369 /// previously created by `encodeURIComponent` or by a similar routine.
370 ///
371 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURIComponent)
372 #[wasm_bindgen(catch, js_name = decodeURIComponent)]
373 pub fn decode_uri_component(encoded: &str) -> Result<JsString, JsValue>;
374
375 /// The `encodeURI()` function encodes a Uniform Resource Identifier (URI)
376 /// by replacing each instance of certain characters by one, two, three, or
377 /// four escape sequences representing the UTF-8 encoding of the character
378 /// (will only be four escape sequences for characters composed of two
379 /// "surrogate" characters).
380 ///
381 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURI)
382 #[wasm_bindgen(js_name = encodeURI)]
383 pub fn encode_uri(decoded: &str) -> JsString;
384
385 /// The `encodeURIComponent()` function encodes a Uniform Resource Identifier (URI) component
386 /// by replacing each instance of certain characters by one, two, three, or four escape sequences
387 /// representing the UTF-8 encoding of the character
388 /// (will only be four escape sequences for characters composed of two "surrogate" characters).
389 ///
390 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent)
391 #[wasm_bindgen(js_name = encodeURIComponent)]
392 pub fn encode_uri_component(decoded: &str) -> JsString;
393
394 /// The `eval()` function evaluates JavaScript code represented as a string.
395 ///
396 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval)
397 #[cfg(feature = "unsafe-eval")]
398 #[wasm_bindgen(catch)]
399 pub fn eval(js_source_text: &str) -> Result<JsValue, JsValue>;
400
401 /// The global `isFinite()` function determines whether the passed value is a finite number.
402 /// If needed, the parameter is first converted to a number.
403 ///
404 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isFinite)
405 #[wasm_bindgen(js_name = isFinite)]
406 pub fn is_finite(value: &JsValue) -> bool;
407
408 /// The `parseInt()` function parses a string argument and returns an integer
409 /// of the specified radix (the base in mathematical numeral systems), or NaN on error.
410 ///
411 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt)
412 #[wasm_bindgen(js_name = parseInt)]
413 pub fn parse_int(text: &str, radix: u8) -> f64;
414
415 /// The `parseFloat()` function parses an argument and returns a floating point number,
416 /// or NaN on error.
417 ///
418 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseFloat)
419 #[wasm_bindgen(js_name = parseFloat)]
420 pub fn parse_float(text: &str) -> f64;
421
422 /// The `escape()` function computes a new string in which certain characters have been
423 /// replaced by a hexadecimal escape sequence.
424 ///
425 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/escape)
426 #[wasm_bindgen]
427 pub fn escape(string: &str) -> JsString;
428
429 /// The `unescape()` function computes a new string in which hexadecimal escape
430 /// sequences are replaced with the character that it represents. The escape sequences might
431 /// be introduced by a function like `escape`. Usually, `decodeURI` or `decodeURIComponent`
432 /// are preferred over `unescape`.
433 ///
434 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/unescape)
435 #[wasm_bindgen]
436 pub fn unescape(string: &str) -> JsString;
437}
438
439// Array
440#[wasm_bindgen]
441extern "C" {
442 #[wasm_bindgen(extends = Object, is_type_of = Array::is_array, typescript_type = "Array<any>")]
443 #[derive(Clone, Debug, PartialEq, Eq)]
444 pub type Array<T = JsValue>;
445
446 /// Creates a new empty array.
447 ///
448 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Array)
449 #[cfg(not(js_sys_unstable_apis))]
450 #[wasm_bindgen(constructor)]
451 pub fn new() -> Array;
452
453 /// Creates a new empty array.
454 ///
455 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Array)
456 #[cfg(js_sys_unstable_apis)]
457 #[wasm_bindgen(constructor)]
458 pub fn new<T>() -> Array<T>;
459
460 // Next major: deprecate
461 /// Creates a new empty array.
462 ///
463 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Array)
464 #[wasm_bindgen(constructor)]
465 pub fn new_typed<T>() -> Array<T>;
466
467 /// Creates a new array with the specified length (elements are initialized to `undefined`).
468 ///
469 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Array)
470 #[cfg(not(js_sys_unstable_apis))]
471 #[wasm_bindgen(constructor)]
472 pub fn new_with_length(len: u32) -> Array;
473
474 /// Creates a new array with the specified length (elements are initialized to `undefined`).
475 ///
476 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Array)
477 #[cfg(js_sys_unstable_apis)]
478 #[wasm_bindgen(constructor)]
479 pub fn new_with_length<T>(len: u32) -> Array<T>;
480
481 // Next major: deprecate
482 /// Creates a new array with the specified length (elements are initialized to `undefined`).
483 ///
484 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Array)
485 #[wasm_bindgen(constructor)]
486 pub fn new_with_length_typed<T>(len: u32) -> Array<T>;
487
488 /// Retrieves the element at the index, counting from the end if negative
489 /// (returns `undefined` if the index is out of range).
490 ///
491 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at)
492 #[cfg(not(js_sys_unstable_apis))]
493 #[wasm_bindgen(method)]
494 pub fn at<T>(this: &Array<T>, index: i32) -> T;
495
496 /// Retrieves the element at the index, counting from the end if negative
497 /// (returns `None` if the index is out of range).
498 ///
499 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at)
500 #[cfg(js_sys_unstable_apis)]
501 #[wasm_bindgen(method)]
502 pub fn at<T>(this: &Array<T>, index: i32) -> Option<T>;
503
504 /// Retrieves the element at the index (returns `undefined` if the index is out of range).
505 ///
506 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at)
507 #[cfg(not(js_sys_unstable_apis))]
508 #[wasm_bindgen(method, indexing_getter)]
509 pub fn get<T>(this: &Array<T>, index: u32) -> T;
510
511 /// Retrieves the element at the index (returns `None` if the index is out of range).
512 ///
513 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at)
514 #[cfg(js_sys_unstable_apis)]
515 #[wasm_bindgen(method, indexing_getter)]
516 pub fn get<T>(this: &Array<T>, index: u32) -> Option<T>;
517
518 /// Retrieves the element at the index (returns `undefined` if the index is out of range).
519 ///
520 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at)
521 #[wasm_bindgen(method, indexing_getter)]
522 pub fn get_unchecked<T>(this: &Array<T>, index: u32) -> T;
523
524 // Next major: deprecate
525 /// Retrieves the element at the index (returns `None` if the index is out of range,
526 /// or if the element is explicitly `undefined`).
527 #[wasm_bindgen(method, indexing_getter)]
528 pub fn get_checked<T>(this: &Array<T>, index: u32) -> Option<T>;
529
530 /// Sets the element at the index (auto-enlarges the array if the index is out of range).
531 #[cfg(not(js_sys_unstable_apis))]
532 #[wasm_bindgen(method, indexing_setter)]
533 pub fn set<T>(this: &Array<T>, index: u32, value: T);
534
535 /// Sets the element at the index (auto-enlarges the array if the index is out of range).
536 #[cfg(js_sys_unstable_apis)]
537 #[wasm_bindgen(method, indexing_setter)]
538 pub fn set<T>(this: &Array<T>, index: u32, value: &T);
539
540 // Next major: deprecate
541 /// Sets the element at the index (auto-enlarges the array if the index is out of range).
542 #[wasm_bindgen(method, indexing_setter)]
543 pub fn set_ref<T>(this: &Array<T>, index: u32, value: &T);
544
545 /// Deletes the element at the index (does nothing if the index is out of range).
546 ///
547 /// The element at the index is set to `undefined`.
548 ///
549 /// This does not resize the array, the array will still be the same length.
550 #[wasm_bindgen(method, indexing_deleter)]
551 pub fn delete<T>(this: &Array<T>, index: u32);
552
553 /// The `Array.from()` static method creates a new, shallow-copied `Array` instance
554 /// from an array-like or iterable object.
555 ///
556 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from)
557 #[cfg(not(js_sys_unstable_apis))]
558 #[wasm_bindgen(static_method_of = Array)]
559 pub fn from(val: &JsValue) -> Array;
560
561 /// The `Array.from()` static method creates a new, shallow-copied `Array` instance
562 /// from an array-like or iterable object.
563 ///
564 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from)
565 #[cfg(js_sys_unstable_apis)]
566 #[wasm_bindgen(static_method_of = Array, catch, js_name = from)]
567 pub fn from<I: Iterable>(val: &I) -> Result<Array<I::Item>, JsValue>;
568
569 // Next major: deprecate
570 /// The `Array.from()` static method creates a new, shallow-copied `Array` instance
571 /// from an array-like or iterable object.
572 ///
573 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from)
574 #[wasm_bindgen(static_method_of = Array, catch, js_name = from)]
575 pub fn from_iterable<I: Iterable>(val: &I) -> Result<Array<I::Item>, JsValue>;
576
577 /// The `Array.from()` static method with a map function creates a new, shallow-copied
578 /// `Array` instance from an array-like or iterable object, applying the map function
579 /// to each value.
580 ///
581 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from)
582 #[wasm_bindgen(static_method_of = Array, catch, js_name = from)]
583 pub fn from_iterable_map<'a, I: Iterable, U>(
584 val: &I,
585 map: ImmediateClosure<'a, dyn FnMut(I::Item, u32) -> Result<U, JsError> + 'a>,
586 ) -> Result<Array<U>, JsValue>;
587
588 /// The `Array.fromAsync()` static method creates a new, shallow-copied `Array` instance
589 /// from an async iterable, iterable or array-like object.
590 ///
591 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fromAsync)
592 #[wasm_bindgen(static_method_of = Array, catch, js_name = fromAsync)]
593 pub fn from_async<I: AsyncIterable>(val: &I) -> Result<Promise<Array<I::Item>>, JsValue>;
594
595 /// The `Array.fromAsync()` static method with a map function creates a new, shallow-copied
596 /// `Array` instance from an async iterable, iterable or array-like object, applying the map
597 /// function to each value.
598 ///
599 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fromAsync)
600 #[wasm_bindgen(static_method_of = Array, catch, js_name = fromAsync)]
601 pub fn from_async_map<'a, I: AsyncIterable, R: Promising>(
602 val: &I,
603 map: &ScopedClosure<'a, dyn FnMut(I::Item, u32) -> Result<R, JsError>>,
604 ) -> Result<Promise<Array<R::Resolution>>, JsValue>;
605
606 /// The `copyWithin()` method shallow copies part of an array to another
607 /// location in the same array and returns it, without modifying its size.
608 ///
609 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin)
610 #[wasm_bindgen(method, js_name = copyWithin)]
611 pub fn copy_within<T>(this: &Array<T>, target: i32, start: i32, end: i32) -> Array<T>;
612
613 /// The `concat()` method is used to merge two or more arrays. This method
614 /// does not change the existing arrays, but instead returns a new array.
615 ///
616 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat)
617 #[wasm_bindgen(method)]
618 pub fn concat<T, U: Upcast<T>>(this: &Array<T>, array: &Array<U>) -> Array<T>;
619
620 /// The `concat()` method is used to merge two or more arrays. This method
621 /// does not change the existing arrays, but instead returns a new array.
622 ///
623 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat)
624 #[wasm_bindgen(method)]
625 pub fn concat_many<T, U: Upcast<T>>(this: &Array<T>, array: &[Array<U>]) -> Array<T>;
626
627 /// The `every()` method tests whether all elements in the array pass the test
628 /// implemented by the provided function.
629 ///
630 /// **Note:** Consider using [`Array::try_every`] if the predicate might throw an error.
631 ///
632 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every)
633 #[wasm_bindgen(method)]
634 pub fn every<T>(this: &Array<T>, predicate: &mut dyn FnMut(T, u32, Array<T>) -> bool) -> bool;
635
636 /// The `every()` method tests whether all elements in the array pass the test
637 /// implemented by the provided function. _(Fallible variation)_
638 ///
639 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every)
640 #[wasm_bindgen(method, js_name = every, catch)]
641 pub fn try_every<'a, T>(
642 this: &Array<T>,
643 predicate: ImmediateClosure<'a, dyn FnMut(T, u32) -> Result<bool, JsError> + 'a>,
644 ) -> Result<bool, JsValue>;
645
646 /// The `fill()` method fills all the elements of an array from a start index
647 /// to an end index with a static value. The end index is not included.
648 ///
649 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill)
650 #[wasm_bindgen(method)]
651 pub fn fill<T>(this: &Array<T>, value: &T, start: u32, end: u32) -> Array<T>;
652
653 /// The `filter()` method creates a new array with all elements that pass the
654 /// test implemented by the provided function.
655 ///
656 /// **Note:** Consider using [`Array::try_filter`] if the predicate might throw an error.
657 ///
658 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter)
659 #[wasm_bindgen(method)]
660 pub fn filter<T>(
661 this: &Array<T>,
662 predicate: &mut dyn FnMut(T, u32, Array<T>) -> bool,
663 ) -> Array<T>;
664
665 /// The `filter()` method creates a new array with all elements that pass the
666 /// test implemented by the provided function. _(Fallible variation)_
667 ///
668 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter)
669 #[wasm_bindgen(method, js_name = filter, catch)]
670 pub fn try_filter<'a, T>(
671 this: &Array<T>,
672 predicate: ImmediateClosure<'a, dyn FnMut(T, u32) -> Result<bool, JsError> + 'a>,
673 ) -> Result<Array<T>, JsValue>;
674
675 /// The `find()` method returns the value of the first element in the array that satisfies
676 /// the provided testing function. Otherwise `undefined` is returned.
677 ///
678 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)
679 #[cfg(not(js_sys_unstable_apis))]
680 #[wasm_bindgen(method)]
681 pub fn find<T>(this: &Array<T>, predicate: &mut dyn FnMut(T, u32, Array<T>) -> bool) -> T;
682
683 /// The `find()` method returns the value of the first element in the array that satisfies
684 /// the provided testing function. Returns `None` if no element matches.
685 ///
686 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)
687 #[cfg(js_sys_unstable_apis)]
688 #[wasm_bindgen(method)]
689 pub fn find<'a, T>(
690 this: &Array<T>,
691 predicate: ImmediateClosure<'a, dyn FnMut(T, u32, Array<T>) -> bool + 'a>,
692 ) -> Option<T>;
693
694 /// The `find()` method returns the value of the first element in the array that satisfies
695 /// the provided testing function. Otherwise `undefined` is returned. _(Fallible variation)_
696 ///
697 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)
698 #[wasm_bindgen(method, js_name = find, catch)]
699 pub fn try_find<'a, T>(
700 this: &Array<T>,
701 predicate: ImmediateClosure<'a, dyn FnMut(T, u32) -> Result<bool, JsError> + 'a>,
702 ) -> Result<Option<T>, JsValue>;
703
704 /// The `findIndex()` method returns the index of the first element in the array that
705 /// satisfies the provided testing function. Otherwise -1 is returned.
706 ///
707 /// **Note:** Consider using [`Array::try_find_index`] if the predicate might throw an error.
708 ///
709 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex)
710 #[wasm_bindgen(method, js_name = findIndex)]
711 pub fn find_index<T>(
712 this: &Array<T>,
713 predicate: &mut dyn FnMut(T, u32, Array<T>) -> bool,
714 ) -> i32;
715
716 /// The `findIndex()` method returns the index of the first element in the array that
717 /// satisfies the provided testing function. Otherwise -1 is returned. _(Fallible variation)_
718 ///
719 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex)
720 #[wasm_bindgen(method, js_name = findIndex, catch)]
721 pub fn try_find_index<'a, T>(
722 this: &Array<T>,
723 predicate: ImmediateClosure<'a, dyn FnMut(T, u32) -> Result<bool, JsError> + 'a>,
724 ) -> Result<i32, JsValue>;
725
726 /// The `findLast()` method of Array instances iterates the array in reverse order
727 /// and returns the value of the first element that satisfies the provided testing function.
728 /// If no elements satisfy the testing function, undefined is returned.
729 ///
730 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLast)
731 #[cfg(not(js_sys_unstable_apis))]
732 #[wasm_bindgen(method, js_name = findLast)]
733 pub fn find_last<T>(this: &Array<T>, predicate: &mut dyn FnMut(T, u32, Array<T>) -> bool) -> T;
734
735 /// The `findLast()` method of Array instances iterates the array in reverse order
736 /// and returns the value of the first element that satisfies the provided testing function.
737 /// Returns `None` if no element matches.
738 ///
739 /// **Note:** Consider using [`Array::try_find_last`] if the predicate might throw an error.
740 ///
741 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLast)
742 #[cfg(js_sys_unstable_apis)]
743 #[wasm_bindgen(method, js_name = findLast)]
744 pub fn find_last<T>(this: &Array<T>, predicate: &mut dyn FnMut(T, u32) -> bool) -> Option<T>;
745
746 /// The `findLast()` method of Array instances iterates the array in reverse order
747 /// and returns the value of the first element that satisfies the provided testing function.
748 /// If no elements satisfy the testing function, undefined is returned. _(Fallible variation)_
749 ///
750 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLast)
751 #[wasm_bindgen(method, js_name = findLast, catch)]
752 pub fn try_find_last<'a, T>(
753 this: &Array<T>,
754 predicate: ImmediateClosure<'a, dyn FnMut(T, u32) -> Result<bool, JsError> + 'a>,
755 ) -> Result<Option<T>, JsValue>;
756
757 /// The `findLastIndex()` method of Array instances iterates the array in reverse order
758 /// and returns the index of the first element that satisfies the provided testing function.
759 /// If no elements satisfy the testing function, -1 is returned.
760 ///
761 /// **Note:** Consider using [`Array::try_find_last_index`] if the predicate might throw an error.
762 ///
763 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLastIndex)
764 #[wasm_bindgen(method, js_name = findLastIndex)]
765 pub fn find_last_index<T>(
766 this: &Array<T>,
767 predicate: &mut dyn FnMut(T, u32, Array<T>) -> bool,
768 ) -> i32;
769
770 /// The `findLastIndex()` method of Array instances iterates the array in reverse order
771 /// and returns the index of the first element that satisfies the provided testing function.
772 /// If no elements satisfy the testing function, -1 is returned. _(Fallible variation)_
773 ///
774 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLastIndex)
775 #[wasm_bindgen(method, js_name = findLastIndex, catch)]
776 pub fn try_find_last_index<'a, T>(
777 this: &Array<T>,
778 predicate: ImmediateClosure<'a, dyn FnMut(T, u32) -> Result<bool, JsError> + 'a>,
779 ) -> Result<i32, JsValue>;
780
781 /// The `flat()` method creates a new array with all sub-array elements concatenated into it
782 /// recursively up to the specified depth.
783 ///
784 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat)
785 #[wasm_bindgen(method)]
786 pub fn flat<T>(this: &Array<T>, depth: i32) -> Array<JsValue>;
787
788 /// The `flatMap()` method first maps each element using a mapping function, then flattens
789 /// the result into a new array.
790 ///
791 /// **Note:** Consider using [`Array::try_flat_map`] for safer fallible handling.
792 ///
793 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap)
794 #[wasm_bindgen(method, js_name = flatMap)]
795 pub fn flat_map<T, U>(
796 this: &Array<T>,
797 callback: &mut dyn FnMut(T, u32, Array<T>) -> Vec<U>,
798 ) -> Array<U>;
799
800 /// The `flatMap()` method first maps each element using a mapping function, then flattens
801 /// the result into a new array.
802 ///
803 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap)
804 #[wasm_bindgen(method, js_name = flatMap, catch)]
805 pub fn try_flat_map<'a, T, U>(
806 this: &Array<T>,
807 callback: ImmediateClosure<'a, dyn FnMut(T, u32) -> Vec<U> + 'a>,
808 ) -> Result<Array<U>, JsValue>;
809
810 /// The `forEach()` method executes a provided function once for each array element.
811 ///
812 /// **Note:** Consider using [`Array::try_for_each`] if the callback might throw an error.
813 ///
814 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach)
815 #[wasm_bindgen(method, js_name = forEach)]
816 pub fn for_each<T: JsGeneric>(this: &Array<T>, callback: &mut dyn FnMut(T, u32, Array<T>));
817
818 /// The `forEach()` method executes a provided function once for each array element. _(Fallible variation)_
819 ///
820 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach)
821 #[wasm_bindgen(method, js_name = forEach, catch)]
822 pub fn try_for_each<'a, T>(
823 this: &Array<T>,
824 callback: ImmediateClosure<'a, dyn FnMut(T, u32) -> Result<(), JsError> + 'a>,
825 ) -> Result<(), JsValue>;
826
827 /// The `includes()` method determines whether an array includes a certain
828 /// element, returning true or false as appropriate.
829 ///
830 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes)
831 #[wasm_bindgen(method)]
832 pub fn includes<T>(this: &Array<T>, value: &T, from_index: i32) -> bool;
833
834 /// The `indexOf()` method returns the first index at which a given element
835 /// can be found in the array, or -1 if it is not present.
836 ///
837 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf)
838 #[wasm_bindgen(method, js_name = indexOf)]
839 pub fn index_of<T>(this: &Array<T>, value: &T, from_index: i32) -> i32;
840
841 /// The `Array.isArray()` method determines whether the passed value is an Array.
842 ///
843 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray)
844 #[wasm_bindgen(static_method_of = Array, js_name = isArray)]
845 pub fn is_array(value: &JsValue) -> bool;
846
847 /// The `join()` method joins all elements of an array (or an array-like object)
848 /// into a string and returns this string.
849 ///
850 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join)
851 #[wasm_bindgen(method)]
852 pub fn join<T>(this: &Array<T>, delimiter: &str) -> JsString;
853
854 /// The `lastIndexOf()` method returns the last index at which a given element
855 /// can be found in the array, or -1 if it is not present. The array is
856 /// searched backwards, starting at fromIndex.
857 ///
858 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/lastIndexOf)
859 #[wasm_bindgen(method, js_name = lastIndexOf)]
860 pub fn last_index_of<T>(this: &Array<T>, value: &T, from_index: i32) -> i32;
861
862 /// The length property of an object which is an instance of type Array
863 /// sets or returns the number of elements in that array. The value is an
864 /// unsigned, 32-bit integer that is always numerically greater than the
865 /// highest index in the array.
866 ///
867 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/length)
868 #[wasm_bindgen(method, getter)]
869 pub fn length<T>(this: &Array<T>) -> u32;
870
871 /// Sets the length of the array.
872 ///
873 /// If it is set to less than the current length of the array, it will
874 /// shrink the array.
875 ///
876 /// If it is set to more than the current length of the array, it will
877 /// increase the length of the array, filling the new space with empty
878 /// slots.
879 ///
880 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/length)
881 #[wasm_bindgen(method, setter)]
882 pub fn set_length<T>(this: &Array<T>, value: u32);
883
884 /// `map()` calls a provided callback function once for each element in an array,
885 /// in order, and constructs a new array from the results. callback is invoked
886 /// only for indexes of the array which have assigned values, including undefined.
887 /// It is not called for missing elements of the array (that is, indexes that have
888 /// never been set, which have been deleted or which have never been assigned a value).
889 ///
890 /// **Note:** Consider using [`Array::try_map`] for safer fallible handling.
891 ///
892 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map)
893 #[wasm_bindgen(method)]
894 pub fn map<T, U>(this: &Array<T>, predicate: &mut dyn FnMut(T, u32, Array<T>) -> U)
895 -> Array<U>;
896
897 /// `map()` calls a provided callback function once for each element in an array,
898 /// in order, and constructs a new array from the results. callback is invoked
899 /// only for indexes of the array which have assigned values, including undefined.
900 /// It is not called for missing elements of the array (that is, indexes that have
901 /// never been set, which have been deleted or which have never been assigned a value).
902 /// _(Fallible variation)_
903 ///
904 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map)
905 #[wasm_bindgen(method, js_name = map, catch)]
906 pub fn try_map<'a, T, U>(
907 this: &Array<T>,
908 predicate: ImmediateClosure<'a, dyn FnMut(T, u32) -> Result<U, JsError> + 'a>,
909 ) -> Result<Array<U>, JsValue>;
910
911 /// The `Array.of()` method creates a new Array instance with a variable
912 /// number of arguments, regardless of number or type of the arguments.
913 ///
914 /// Note: For type inference use `Array::<T>::of(&[T])`.
915 ///
916 /// The difference between `Array.of()` and the `Array` constructor is in the
917 /// handling of integer arguments: `Array.of(7)` creates an array with a single
918 /// element, `7`, whereas `Array(7)` creates an empty array with a `length`
919 /// property of `7` (Note: this implies an array of 7 empty slots, not slots
920 /// with actual undefined values).
921 ///
922 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of)
923 #[wasm_bindgen(static_method_of = Array, js_name = of, variadic)]
924 pub fn of<T>(values: &[T]) -> Array<T>;
925
926 // Next major: deprecate these
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)]
929 pub fn of1(a: &JsValue) -> Array;
930
931 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of)
932 #[wasm_bindgen(static_method_of = Array, js_name = of)]
933 pub fn of2(a: &JsValue, b: &JsValue) -> Array;
934
935 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of)
936 #[wasm_bindgen(static_method_of = Array, js_name = of)]
937 pub fn of3(a: &JsValue, b: &JsValue, c: &JsValue) -> Array;
938
939 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of)
940 #[wasm_bindgen(static_method_of = Array, js_name = of)]
941 pub fn of4(a: &JsValue, b: &JsValue, c: &JsValue, d: &JsValue) -> Array;
942
943 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of)
944 #[wasm_bindgen(static_method_of = Array, js_name = of)]
945 pub fn of5(a: &JsValue, b: &JsValue, c: &JsValue, d: &JsValue, e: &JsValue) -> Array;
946
947 /// The `pop()` method removes the last element from an array and returns that
948 /// element. This method changes the length of the array.
949 ///
950 /// **Note:** Consider using [`Array::pop_checked`] for handling empty arrays.
951 ///
952 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pop)
953 #[cfg(not(js_sys_unstable_apis))]
954 #[wasm_bindgen(method)]
955 pub fn pop<T>(this: &Array<T>) -> T;
956
957 /// The `pop()` method removes the last element from an array and returns that
958 /// element. This method changes the length of the array.
959 /// Returns `None` if the array is empty.
960 ///
961 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pop)
962 #[cfg(js_sys_unstable_apis)]
963 #[wasm_bindgen(method)]
964 pub fn pop<T>(this: &Array<T>) -> Option<T>;
965
966 // Next major: deprecate
967 /// The `pop()` method removes the last element from an array and returns that
968 /// element. This method changes the length of the array.
969 ///
970 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pop)
971 #[wasm_bindgen(method, js_name = pop)]
972 pub fn pop_checked<T>(this: &Array<T>) -> Option<T>;
973
974 /// The `push()` method adds one element to the end of an array and
975 /// returns the new length of the array.
976 ///
977 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push)
978 #[wasm_bindgen(method)]
979 pub fn push<T>(this: &Array<T>, value: &T) -> u32;
980
981 /// The `push()` method adds one or more elements to the end of an array and
982 /// returns the new length of the array.
983 ///
984 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push)
985 #[wasm_bindgen(method, js_name = push, variadic)]
986 pub fn push_many<T>(this: &Array<T>, values: &[T]) -> u32;
987
988 /// The `reduce()` method applies a function against an accumulator and each element in
989 /// the array (from left to right) to reduce it to a single value.
990 ///
991 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce)
992 #[cfg(not(js_sys_unstable_apis))]
993 #[wasm_bindgen(method)]
994 pub fn reduce<T>(
995 this: &Array<T>,
996 predicate: &mut dyn FnMut(JsValue, T, u32, Array<T>) -> JsValue,
997 initial_value: &JsValue,
998 ) -> JsValue;
999
1000 /// The `reduce()` method applies a function against an accumulator and each element in
1001 /// the array (from left to right) to reduce it to a single value.
1002 ///
1003 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce)
1004 #[cfg(js_sys_unstable_apis)]
1005 #[wasm_bindgen(method)]
1006 pub fn reduce<'a, T, A>(
1007 this: &Array<T>,
1008 predicate: ImmediateClosure<'a, dyn FnMut(A, T, u32, Array<T>) -> A + 'a>,
1009 initial_value: &A,
1010 ) -> A;
1011
1012 /// The `reduce()` method applies a function against an accumulator and each element in
1013 /// the array (from left to right) to reduce it to a single value. _(Fallible variation)_
1014 ///
1015 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce)
1016 #[wasm_bindgen(method, js_name = reduce, catch)]
1017 pub fn try_reduce<'a, T, A>(
1018 this: &Array<T>,
1019 predicate: ImmediateClosure<'a, dyn FnMut(A, T, u32) -> Result<A, JsError> + 'a>,
1020 initial_value: &A,
1021 ) -> Result<A, JsValue>;
1022
1023 /// The `reduceRight()` method applies a function against an accumulator and each value
1024 /// of the array (from right-to-left) to reduce it to a single value.
1025 ///
1026 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/ReduceRight)
1027 #[cfg(not(js_sys_unstable_apis))]
1028 #[wasm_bindgen(method, js_name = reduceRight)]
1029 pub fn reduce_right<T>(
1030 this: &Array<T>,
1031 predicate: &mut dyn FnMut(JsValue, T, u32, Array<T>) -> JsValue,
1032 initial_value: &JsValue,
1033 ) -> JsValue;
1034
1035 /// The `reduceRight()` method applies a function against an accumulator and each value
1036 /// of the array (from right-to-left) to reduce it to a single value.
1037 ///
1038 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/ReduceRight)
1039 #[cfg(js_sys_unstable_apis)]
1040 #[wasm_bindgen(method, js_name = reduceRight)]
1041 pub fn reduce_right<'a, T, A>(
1042 this: &Array<T>,
1043 predicate: ImmediateClosure<'a, dyn FnMut(A, T, u32, Array<T>) -> A + 'a>,
1044 initial_value: &A,
1045 ) -> A;
1046
1047 /// The `reduceRight()` method applies a function against an accumulator and each value
1048 /// of the array (from right-to-left) to reduce it to a single value. _(Fallible variation)_
1049 ///
1050 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/ReduceRight)
1051 #[wasm_bindgen(method, js_name = reduceRight, catch)]
1052 pub fn try_reduce_right<'a, T, A>(
1053 this: &Array<T>,
1054 predicate: ImmediateClosure<'a, dyn FnMut(JsValue, T, u32) -> Result<A, JsError> + 'a>,
1055 initial_value: &A,
1056 ) -> Result<A, JsValue>;
1057
1058 /// The `reverse()` method reverses an array in place. The first array
1059 /// element becomes the last, and the last array element becomes the first.
1060 ///
1061 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse)
1062 #[wasm_bindgen(method)]
1063 pub fn reverse<T>(this: &Array<T>) -> Array<T>;
1064
1065 /// The `shift()` method removes the first element from an array and returns
1066 /// that removed element. This method changes the length of the array.
1067 ///
1068 /// **Note:** Consider using [`Array::shift_checked`] for handling empty arrays.
1069 ///
1070 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift)
1071 #[cfg(not(js_sys_unstable_apis))]
1072 #[wasm_bindgen(method)]
1073 pub fn shift<T>(this: &Array<T>) -> T;
1074
1075 /// The `shift()` method removes the first element from an array and returns
1076 /// that removed element. This method changes the length of the array.
1077 /// Returns `None` if the array is empty.
1078 ///
1079 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift)
1080 #[cfg(js_sys_unstable_apis)]
1081 #[wasm_bindgen(method)]
1082 pub fn shift<T>(this: &Array<T>) -> Option<T>;
1083
1084 // Next major: deprecate
1085 /// The `shift()` method removes the first element from an array and returns
1086 /// that removed element. This method changes the length of the array.
1087 ///
1088 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift)
1089 #[wasm_bindgen(method, js_name = shift)]
1090 pub fn shift_checked<T>(this: &Array<T>) -> Option<T>;
1091
1092 /// The `slice()` method returns a shallow copy of a portion of an array into
1093 /// a new array object selected from begin to end (end not included).
1094 /// The original array will not be modified.
1095 ///
1096 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)
1097 #[cfg(not(js_sys_unstable_apis))]
1098 #[wasm_bindgen(method)]
1099 pub fn slice<T>(this: &Array<T>, start: u32, end: u32) -> Array<T>;
1100
1101 /// The `slice()` method returns a shallow copy of a portion of an array into
1102 /// a new array object selected from begin to end (end not included).
1103 /// The original array will not be modified. Negative indices count from the end.
1104 ///
1105 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)
1106 #[cfg(js_sys_unstable_apis)]
1107 #[wasm_bindgen(method)]
1108 pub fn slice<T>(this: &Array<T>, start: i32, end: i32) -> Array<T>;
1109
1110 /// The `slice()` method returns a shallow copy of a portion of an array into
1111 /// a new array object selected from the given index to the end.
1112 /// The original array will not be modified.
1113 ///
1114 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)
1115 #[cfg(not(js_sys_unstable_apis))]
1116 #[wasm_bindgen(method, js_name = slice)]
1117 pub fn slice_from<T>(this: &Array<T>, start: u32) -> Array<T>;
1118
1119 /// The `slice()` method returns a shallow copy of a portion of an array into
1120 /// a new array object selected from the given index to the end.
1121 /// The original array will not be modified. Negative indices count from the end.
1122 ///
1123 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)
1124 #[cfg(js_sys_unstable_apis)]
1125 #[wasm_bindgen(method, js_name = slice)]
1126 pub fn slice_from<T>(this: &Array<T>, start: i32) -> Array<T>;
1127
1128 /// The `some()` method tests whether at least one element in the array passes the test implemented
1129 /// by the provided function.
1130 /// Note: This method returns false for any condition put on an empty array.
1131 ///
1132 /// **Note:** Consider using [`Array::try_some`] if the predicate might throw an error.
1133 ///
1134 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some)
1135 #[wasm_bindgen(method)]
1136 pub fn some<T>(this: &Array<T>, predicate: &mut dyn FnMut(T) -> bool) -> bool;
1137
1138 /// The `some()` method tests whether at least one element in the array passes the test implemented
1139 /// by the provided function. _(Fallible variation)_
1140 /// Note: This method returns false for any condition put on an empty array.
1141 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some)
1142 #[wasm_bindgen(method, js_name = some, catch)]
1143 pub fn try_some<'a, T>(
1144 this: &Array<T>,
1145 predicate: ImmediateClosure<'a, dyn FnMut(T) -> Result<bool, JsError> + 'a>,
1146 ) -> Result<bool, JsValue>;
1147
1148 /// The `sort()` method sorts the elements of an array in place and returns
1149 /// the array. The sort is not necessarily stable. The default sort
1150 /// order is according to string Unicode code points.
1151 ///
1152 /// The time and space complexity of the sort cannot be guaranteed as it
1153 /// is implementation dependent.
1154 ///
1155 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)
1156 #[wasm_bindgen(method)]
1157 pub fn sort<T>(this: &Array<T>) -> Array<T>;
1158
1159 /// The `sort()` method with a custom compare function.
1160 ///
1161 /// **Note:** Consider using [`Array::try_sort_by`] if the predicate might throw an error.
1162 ///
1163 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)
1164 #[wasm_bindgen(method, js_name = sort)]
1165 pub fn sort_by<T>(this: &Array<T>, compare_fn: &mut dyn FnMut(T, T) -> i32) -> Array<T>;
1166
1167 /// The `sort()` method with a custom compare function. _(Fallible variation)_
1168 ///
1169 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)
1170 #[wasm_bindgen(method, js_name = sort, catch)]
1171 pub fn try_sort_by<'a, T>(
1172 this: &Array<T>,
1173 compare_fn: ImmediateClosure<'a, dyn FnMut(T, T) -> Result<i32, JsError> + 'a>,
1174 ) -> Result<Array<T>, JsValue>;
1175
1176 /// The `splice()` method changes the contents of an array by removing existing elements and/or
1177 /// adding new elements.
1178 ///
1179 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice)
1180 #[wasm_bindgen(method)]
1181 pub fn splice<T>(this: &Array<T>, start: u32, delete_count: u32, item: &T) -> Array<T>;
1182
1183 /// The `splice()` method changes the contents of an array by removing existing elements and/or
1184 /// adding new elements.
1185 ///
1186 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice)
1187 #[wasm_bindgen(method, js_name = splice, variadic)]
1188 pub fn splice_many<T>(this: &Array<T>, start: u32, delete_count: u32, items: &[T]) -> Array<T>;
1189
1190 /// The `toLocaleString()` method returns a string representing the elements of the array.
1191 /// The elements are converted to Strings using their toLocaleString methods and these
1192 /// Strings are separated by a locale-specific String (such as a comma ",").
1193 ///
1194 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toLocaleString)
1195 #[cfg(not(js_sys_unstable_apis))]
1196 #[wasm_bindgen(method, js_name = toLocaleString)]
1197 pub fn to_locale_string<T>(this: &Array<T>, locales: &JsValue, options: &JsValue) -> JsString;
1198
1199 /// The `toLocaleString()` method returns a string representing the elements of the array.
1200 /// The elements are converted to Strings using their toLocaleString methods and these
1201 /// Strings are separated by a locale-specific String (such as a comma ",").
1202 ///
1203 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toLocaleString)
1204 #[cfg(js_sys_unstable_apis)]
1205 #[wasm_bindgen(method, js_name = toLocaleString)]
1206 pub fn to_locale_string<T>(
1207 this: &Array<T>,
1208 locales: &[JsString],
1209 options: &Intl::NumberFormatOptions,
1210 ) -> JsString;
1211
1212 /// The `toReversed()` method returns a new array with the elements in reversed order,
1213 /// without modifying the original array.
1214 ///
1215 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toReversed)
1216 #[wasm_bindgen(method, js_name = toReversed)]
1217 pub fn to_reversed<T>(this: &Array<T>) -> Array<T>;
1218
1219 /// The `toSorted()` method returns a new array with the elements sorted in ascending order,
1220 /// without modifying the original array.
1221 ///
1222 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toSorted)
1223 #[wasm_bindgen(method, js_name = toSorted)]
1224 pub fn to_sorted<T>(this: &Array<T>) -> Array<T>;
1225
1226 /// The `toSorted()` method with a custom compare function.
1227 ///
1228 /// **Note:** Consider using [`Array::try_to_sorted_by`] if the predicate might throw an error.
1229 ///
1230 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toSorted)
1231 #[wasm_bindgen(method, js_name = toSorted)]
1232 pub fn to_sorted_by<T>(this: &Array<T>, compare_fn: &mut dyn FnMut(T, T) -> i32) -> Array<T>;
1233
1234 /// The `toSorted()` method with a custom compare function. _(Fallible variation)_
1235 ///
1236 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toSorted)
1237 #[wasm_bindgen(method, js_name = toSorted, catch)]
1238 pub fn try_to_sorted_by<'a, T>(
1239 this: &Array<T>,
1240 compare_fn: ImmediateClosure<'a, dyn FnMut(T, T) -> Result<i32, JsError> + 'a>,
1241 ) -> Result<Array<T>, JsValue>;
1242
1243 /// The `toSpliced()` method returns a new array with some elements removed and/or
1244 /// replaced at a given index, without modifying the original array.
1245 ///
1246 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toSpliced)
1247 #[wasm_bindgen(method, js_name = toSpliced, variadic)]
1248 pub fn to_spliced<T>(this: &Array<T>, start: u32, delete_count: u32, items: &[T]) -> Array<T>;
1249
1250 /// The `toString()` method returns a string representing the specified array
1251 /// and its elements.
1252 ///
1253 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toString)
1254 #[cfg(not(js_sys_unstable_apis))]
1255 #[wasm_bindgen(method, js_name = toString)]
1256 pub fn to_string<T>(this: &Array<T>) -> JsString;
1257
1258 /// Converts the Array into a Vector.
1259 #[wasm_bindgen(method, js_name = slice)]
1260 pub fn to_vec<T>(this: &Array<T>) -> Vec<T>;
1261
1262 /// The `unshift()` method adds one element to the beginning of an
1263 /// array and returns the new length of the array.
1264 ///
1265 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift)
1266 #[wasm_bindgen(method)]
1267 pub fn unshift<T>(this: &Array<T>, value: &T) -> u32;
1268
1269 /// The `unshift()` method adds one or more elements to the beginning of an
1270 /// array and returns the new length of the array.
1271 ///
1272 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift)
1273 #[wasm_bindgen(method, js_name = unshift, variadic)]
1274 pub fn unshift_many<T>(this: &Array<T>, values: &[T]) -> u32;
1275
1276 /// The `with()` method returns a new array with the element at the given index
1277 /// replaced with the given value, without modifying the original array.
1278 ///
1279 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/with)
1280 #[wasm_bindgen(method, js_name = with)]
1281 pub fn with<T>(this: &Array<T>, index: u32, value: &T) -> Array<T>;
1282}
1283
1284// Tuples as a typed array variant
1285#[wasm_bindgen]
1286extern "C" {
1287 #[wasm_bindgen(extends = Object, js_name = Array, is_type_of = Array::is_array, no_upcast, typescript_type = "Array<any>")]
1288 #[derive(Clone, Debug)]
1289 pub type ArrayTuple<T: JsTuple = (JsValue,)>;
1290
1291 /// Creates a new JS array typed as a 1-tuple.
1292 #[wasm_bindgen(js_class = Array, static_method_of = ArrayTuple, js_name = of)]
1293 pub fn new1<T1>(t1: &T1) -> ArrayTuple<(T1,)>;
1294
1295 /// Creates a new JS array typed as a 2-tuple.
1296 #[wasm_bindgen(js_class = Array, static_method_of = ArrayTuple, js_name = of)]
1297 pub fn new2<T1, T2>(t1: &T1, t2: &T2) -> ArrayTuple<(T1, T2)>;
1298
1299 /// Creates a new JS array typed as a 3-tuple.
1300 #[wasm_bindgen(js_class = Array, static_method_of = ArrayTuple, js_name = of)]
1301 pub fn new3<T1, T2, T3>(t1: &T1, t2: &T2, t3: &T3) -> ArrayTuple<(T1, T2, T3)>;
1302
1303 /// Creates a new JS array typed as a 4-tuple.
1304 #[wasm_bindgen(js_class = Array, static_method_of = ArrayTuple, js_name = of)]
1305 pub fn new4<T1, T2, T3, T4>(t1: &T1, t2: &T2, t3: &T3, t4: &T4)
1306 -> ArrayTuple<(T1, T2, T3, T4)>;
1307
1308 /// Creates a new JS array typed as a 5-tuple.
1309 #[wasm_bindgen(js_class = Array, static_method_of = ArrayTuple, js_name = of)]
1310 pub fn new5<T1, T2, T3, T4, T5>(
1311 t1: &T1,
1312 t2: &T2,
1313 t3: &T3,
1314 t4: &T4,
1315 t5: &T5,
1316 ) -> ArrayTuple<(T1, T2, T3, T4, T5)>;
1317
1318 /// Creates a new JS array typed as a 6-tuple.
1319 #[wasm_bindgen(js_class = Array, static_method_of = ArrayTuple, js_name = of)]
1320 pub fn new6<T1, T2, T3, T4, T5, T6>(
1321 t1: &T1,
1322 t2: &T2,
1323 t3: &T3,
1324 t4: &T4,
1325 t5: &T5,
1326 t6: &T6,
1327 ) -> ArrayTuple<(T1, T2, T3, T4, T5, T6)>;
1328
1329 /// Creates a new JS array typed as a 7-tuple.
1330 #[wasm_bindgen(js_class = Array, static_method_of = ArrayTuple, js_name = of)]
1331 pub fn new7<T1, T2, T3, T4, T5, T6, T7>(
1332 t1: &T1,
1333 t2: &T2,
1334 t3: &T3,
1335 t4: &T4,
1336 t5: &T5,
1337 t6: &T6,
1338 t7: &T7,
1339 ) -> ArrayTuple<(T1, T2, T3, T4, T5, T6, T7)>;
1340
1341 /// Creates a new JS array typed as a 8-tuple.
1342 #[wasm_bindgen(js_class = Array, static_method_of = ArrayTuple, js_name = of)]
1343 pub fn new8<T1, T2, T3, T4, T5, T6, T7, T8>(
1344 t1: &T1,
1345 t2: &T2,
1346 t3: &T3,
1347 t4: &T4,
1348 t5: &T5,
1349 t6: &T6,
1350 t7: &T7,
1351 t8: &T8,
1352 ) -> ArrayTuple<(T1, T2, T3, T4, T5, T6, T7, T8)>;
1353
1354 /// Gets the 1st item
1355 #[wasm_bindgen(
1356 method,
1357 js_class = Array,
1358 getter,
1359 js_name = "0"
1360 )]
1361 pub fn get0<T: JsTuple1 = (JsValue,)>(this: &ArrayTuple<T>) -> <T as JsTuple1>::T1;
1362
1363 /// Gets the 2nd item
1364 #[wasm_bindgen(
1365 method,
1366 js_class = Array,
1367 getter,
1368 js_name = "1"
1369 )]
1370 pub fn get1<T: JsTuple2 = (JsValue, JsValue)>(this: &ArrayTuple<T>) -> <T as JsTuple2>::T2;
1371
1372 /// Gets the 3rd item
1373 #[wasm_bindgen(
1374 method,
1375 js_class = Array,
1376 getter,
1377 js_name = "2"
1378 )]
1379 pub fn get2<T: JsTuple3 = (JsValue, JsValue, JsValue)>(
1380 this: &ArrayTuple<T>,
1381 ) -> <T as JsTuple3>::T3;
1382
1383 /// Gets the 4th item
1384 #[wasm_bindgen(
1385 method,
1386 js_class = Array,
1387 getter,
1388 js_name = "3"
1389 )]
1390 pub fn get3<T: JsTuple4 = (JsValue, JsValue, JsValue, JsValue)>(
1391 this: &ArrayTuple<T>,
1392 ) -> <T as JsTuple4>::T4;
1393
1394 /// Gets the 5th item
1395 #[wasm_bindgen(
1396 method,
1397 js_class = Array,
1398 getter,
1399 js_name = "4"
1400 )]
1401 pub fn get4<T: JsTuple5 = (JsValue, JsValue, JsValue, JsValue, JsValue)>(
1402 this: &ArrayTuple<T>,
1403 ) -> <T as JsTuple5>::T5;
1404
1405 /// Gets the 6th item
1406 #[wasm_bindgen(
1407 method,
1408 js_class = Array,
1409 getter,
1410 js_name = "5"
1411 )]
1412 pub fn get5<T: JsTuple6 = (JsValue, JsValue, JsValue, JsValue, JsValue, JsValue)>(
1413 this: &ArrayTuple<T>,
1414 ) -> <T as JsTuple6>::T6;
1415
1416 /// Gets the 7th item
1417 #[wasm_bindgen(
1418 method,
1419 js_class = Array,
1420 getter,
1421 js_name = "6"
1422 )]
1423 pub fn get6<
1424 T: JsTuple7 = (
1425 JsValue,
1426 JsValue,
1427 JsValue,
1428 JsValue,
1429 JsValue,
1430 JsValue,
1431 JsValue,
1432 ),
1433 >(
1434 this: &ArrayTuple<T>,
1435 ) -> <T as JsTuple7>::T7;
1436
1437 /// Gets the 8th item
1438 #[wasm_bindgen(
1439 method,
1440 js_class = Array,
1441 getter,
1442 js_name = "7"
1443 )]
1444 pub fn get7<
1445 T: JsTuple8 = (
1446 JsValue,
1447 JsValue,
1448 JsValue,
1449 JsValue,
1450 JsValue,
1451 JsValue,
1452 JsValue,
1453 JsValue,
1454 ),
1455 >(
1456 this: &ArrayTuple<T>,
1457 ) -> <T as JsTuple8>::T8;
1458
1459 /// Sets the 1st item
1460 #[wasm_bindgen(
1461 method,
1462 js_class = Array,
1463 setter,
1464 js_name = "0"
1465 )]
1466 pub fn set0<T: JsTuple1 = (JsValue,)>(this: &ArrayTuple<T>, value: &<T as JsTuple1>::T1);
1467
1468 /// Sets the 2nd item
1469 #[wasm_bindgen(
1470 method,
1471 js_class = Array,
1472 setter,
1473 js_name = "1"
1474 )]
1475 pub fn set1<T: JsTuple2 = (JsValue, JsValue)>(
1476 this: &ArrayTuple<T>,
1477 value: &<T as JsTuple2>::T2,
1478 );
1479
1480 /// Sets the 3rd item
1481 #[wasm_bindgen(
1482 method,
1483 js_class = Array,
1484 setter,
1485 js_name = "2"
1486 )]
1487 pub fn set2<T: JsTuple3 = (JsValue, JsValue, JsValue)>(
1488 this: &ArrayTuple<T>,
1489 value: &<T as JsTuple3>::T3,
1490 );
1491
1492 /// Sets the 4th item
1493 #[wasm_bindgen(
1494 method,
1495 js_class = Array,
1496 setter,
1497 js_name = "3"
1498 )]
1499 pub fn set3<T: JsTuple4 = (JsValue, JsValue, JsValue, JsValue)>(
1500 this: &ArrayTuple<T>,
1501 value: &<T as JsTuple4>::T4,
1502 );
1503
1504 /// Sets the 5th item
1505 #[wasm_bindgen(
1506 method,
1507 js_class = Array,
1508 setter,
1509 js_name = "4"
1510 )]
1511 pub fn set4<T: JsTuple5 = (JsValue, JsValue, JsValue, JsValue, JsValue)>(
1512 this: &ArrayTuple<T>,
1513 value: &<T as JsTuple5>::T5,
1514 );
1515
1516 /// Sets the 6th item
1517 #[wasm_bindgen(
1518 method,
1519 js_class = Array,
1520 setter,
1521 js_name = "5"
1522 )]
1523 pub fn set5<T: JsTuple6 = (JsValue, JsValue, JsValue, JsValue, JsValue, JsValue)>(
1524 this: &ArrayTuple<T>,
1525 value: &<T as JsTuple6>::T6,
1526 );
1527
1528 /// Sets the 7th item
1529 #[wasm_bindgen(
1530 method,
1531 js_class = Array,
1532 setter,
1533 js_name = "6"
1534 )]
1535 pub fn set6<
1536 T: JsTuple7 = (
1537 JsValue,
1538 JsValue,
1539 JsValue,
1540 JsValue,
1541 JsValue,
1542 JsValue,
1543 JsValue,
1544 ),
1545 >(
1546 this: &ArrayTuple<T>,
1547 value: &<T as JsTuple7>::T7,
1548 );
1549
1550 /// Sets the 8th item
1551 #[wasm_bindgen(
1552 method,
1553 js_class = Array,
1554 setter,
1555 js_name = "7"
1556 )]
1557 pub fn set7<
1558 T: JsTuple8 = (
1559 JsValue,
1560 JsValue,
1561 JsValue,
1562 JsValue,
1563 JsValue,
1564 JsValue,
1565 JsValue,
1566 JsValue,
1567 ),
1568 >(
1569 this: &ArrayTuple<T>,
1570 value: &<T as JsTuple8>::T8,
1571 );
1572}
1573
1574/// Base trait for tuple types.
1575pub trait JsTuple {
1576 const ARITY: usize;
1577}
1578
1579macro_rules! impl_tuple_traits {
1580 // Base case: first trait has no parent (besides JsTuple)
1581 ($name:ident $ty:tt) => {
1582 pub trait $name: JsTuple {
1583 type $ty;
1584 }
1585 };
1586
1587 // Recursive case: define trait with parent, then recurse
1588 ($name:ident $ty:tt $($rest_name:ident $rest_ty:tt)+) => {
1589 pub trait $name: JsTuple {
1590 type $ty;
1591 }
1592
1593 impl_tuple_traits!(@with_parent $name $($rest_name $rest_ty)+);
1594 };
1595
1596 // Internal: traits that have a parent
1597 (@with_parent $trait:ident $name:ident $ty:tt) => {
1598 pub trait $name: $trait {
1599 type $ty;
1600 }
1601 };
1602
1603 (@with_parent $trait:ident $name:ident $ty:tt $($rest_name:ident $rest_ty:tt)+) => {
1604 pub trait $name: $trait {
1605 type $ty;
1606 }
1607
1608 impl_tuple_traits!(@with_parent $name $($rest_name $rest_ty)+);
1609 };
1610}
1611
1612macro_rules! impl_parent_traits {
1613 ([$($types:tt),+] [] []) => {};
1614
1615 ([$($types:tt),+] [$trait:ident $($rest_traits:ident)*] [$ty:tt $($rest_tys:tt)*]) => {
1616 impl<$($types),+> $trait for ($($types),+,) {
1617 type $ty = $ty;
1618 }
1619
1620 impl_parent_traits!([$($types),+] [$($rest_traits)*] [$($rest_tys)*]);
1621 };
1622}
1623
1624// Define the trait hierarchy once
1625impl_tuple_traits!(
1626 JsTuple1 T1
1627 JsTuple2 T2
1628 JsTuple3 T3
1629 JsTuple4 T4
1630 JsTuple5 T5
1631 JsTuple6 T6
1632 JsTuple7 T7
1633 JsTuple8 T8
1634);
1635
1636impl<T: JsTuple> ArrayTuple<T> {
1637 /// Get the static arity of the ArrayTuple type.
1638 #[allow(clippy::len_without_is_empty)]
1639 pub fn len(&self) -> usize {
1640 <T as JsTuple>::ARITY
1641 }
1642}
1643
1644macro_rules! impl_tuple {
1645 ($arity:literal [$($traits:ident)*] [$($T:tt)+] [$($vars:tt)+] $new:ident $last:ident $last_ty:tt) => {
1646 impl<$($T),+> JsTuple for ($($T),+,) {
1647 const ARITY: usize = $arity;
1648 }
1649
1650 impl_parent_traits!([$($T),+] [$($traits)*] [$($T)*]);
1651
1652 impl<$($T: JsGeneric),+> From<($($T,)+)> for ArrayTuple<($($T),+,)> {
1653 fn from(($($vars,)+): ($($T,)+)) -> Self {
1654 let arr = [$(
1655 unsafe { core::mem::transmute_copy::<$T, JsValue>(&$vars) }
1656 ),+];
1657 core::mem::forget(($($vars,)+));
1658 Array::of(&arr).unchecked_into()
1659 }
1660 }
1661
1662 impl<$($T: JsGeneric + Default),+> Default for ArrayTuple<($($T),+,)> {
1663 fn default() -> Self {
1664 $(
1665 let $vars: $T = Default::default();
1666 )+
1667 let arr = [$(
1668 unsafe { core::mem::transmute_copy::<$T, JsValue>(&$vars) }
1669 ),+];
1670 core::mem::forget(($($vars,)+));
1671 Array::of(&arr).unchecked_into()
1672 }
1673 }
1674
1675 impl<$($T: JsGeneric),+> ArrayTuple<($($T),+,)> {
1676 /// Get the first element of the ArrayTuple
1677 pub fn first(&self) -> T1 {
1678 self.get0()
1679 }
1680
1681 /// Get the last element of the ArrayTuple
1682 pub fn last(&self) -> $last_ty {
1683 self.$last()
1684 }
1685
1686 /// Convert the ArrayTuple into its corresponding Rust tuple
1687 pub fn into_parts(self) -> ($($T,)+) {
1688 ($(self.$vars(),)+)
1689 }
1690
1691 /// Create a new ArrayTuple from the corresponding parts.
1692 ///
1693 /// # Example
1694 ///
1695 /// ```
1696 /// use js_sys::{ArrayTuple, JsString};
1697 ///
1698 /// let tuple = ArrayTuple::<JsString, JsString>::new(&"a".into(), &"b".into());
1699 /// ```
1700 ///
1701 /// Note: You must specify the T using `::<...>` syntax on `ArrayTuple`.
1702 /// Alternatively, use `new1`, `new2`, etc. for type inference from the left-hand side.
1703 pub fn new($($vars: &$T),+) -> ArrayTuple<($($T),+,)> {
1704 ArrayTuple::$new($($vars),+)
1705 }
1706 }
1707 };
1708}
1709
1710// Implement for each tuple size
1711impl_tuple!(1 [JsTuple1] [T1] [get0] new1 get0 T1);
1712impl_tuple!(2 [JsTuple1 JsTuple2] [T1 T2] [get0 get1] new2 get1 T2);
1713impl_tuple!(3 [JsTuple1 JsTuple2 JsTuple3] [T1 T2 T3] [get0 get1 get2] new3 get2 T3);
1714impl_tuple!(4 [JsTuple1 JsTuple2 JsTuple3 JsTuple4] [T1 T2 T3 T4] [get0 get1 get2 get3] new4 get3 T4);
1715impl_tuple!(5 [JsTuple1 JsTuple2 JsTuple3 JsTuple4 JsTuple5] [T1 T2 T3 T4 T5] [get0 get1 get2 get3 get4] new5 get4 T5);
1716impl_tuple!(6 [JsTuple1 JsTuple2 JsTuple3 JsTuple4 JsTuple5 JsTuple6] [T1 T2 T3 T4 T5 T6] [get0 get1 get2 get3 get4 get5] new6 get5 T6);
1717impl_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);
1718impl_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);
1719
1720// Macro to generate structural covariance impls for each arity
1721macro_rules! impl_tuple_covariance {
1722 ([$($T:ident)+] [$($Target:ident)+] [$($Ts:ident)+]) => {
1723 // ArrayTuple -> Array
1724 // Allows (T1, T2, ...) to be used where (Target) is expected
1725 // when all T1, T2, ... are covariant to Target
1726 impl<$($T,)+ Target> UpcastFrom<ArrayTuple<($($T,)+)>> for Array<Target>
1727 where
1728 $(Target: UpcastFrom<$T>,)+
1729 {
1730 }
1731 impl<$($T,)+ Target> UpcastFrom<ArrayTuple<($($T,)+)>> for JsOption<Array<Target>>
1732 where
1733 $(Target: UpcastFrom<$T>,)+
1734 {}
1735 // Array<T> -> ArrayTuple<T, ...>
1736 impl<T> UpcastFrom<Array<T>> for ArrayTuple<($($Ts,)+)> {}
1737 impl<T: JsGeneric> UpcastFrom<Array<T>> for ArrayTuple<($(JsOption<$Ts>,)+)> {}
1738 };
1739}
1740
1741impl_tuple_covariance!([T1][Target1][T]);
1742impl_tuple_covariance!([T1 T2] [Target1 Target2] [T T]);
1743impl_tuple_covariance!([T1 T2 T3] [Target1 Target2 Target3] [T T T]);
1744impl_tuple_covariance!([T1 T2 T3 T4] [Target1 Target2 Target3 Target4] [T T T T]);
1745impl_tuple_covariance!([T1 T2 T3 T4 T5] [Target1 Target2 Target3 Target4 Target5] [T T T T T]);
1746impl_tuple_covariance!([T1 T2 T3 T4 T5 T6] [Target1 Target2 Target3 Target4 Target5 Target6] [T T T T T T]);
1747impl_tuple_covariance!([T1 T2 T3 T4 T5 T6 T7] [Target1 Target2 Target3 Target4 Target5 Target6 Target7] [T T T T T T T]);
1748impl_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]);
1749
1750// Tuple casting is implemented in core
1751impl<T: JsTuple, U: JsTuple> UpcastFrom<ArrayTuple<T>> for ArrayTuple<U> where U: UpcastFrom<T> {}
1752impl<T: JsTuple> UpcastFrom<ArrayTuple<T>> for JsValue {}
1753impl<T: JsTuple> UpcastFrom<ArrayTuple<T>> for JsOption<JsValue> {}
1754
1755/// Iterator returned by `Array::into_iter`
1756#[derive(Debug, Clone)]
1757pub struct ArrayIntoIter<T: JsGeneric> {
1758 range: core::ops::Range<u32>,
1759 array: Array<T>,
1760}
1761
1762#[cfg(not(js_sys_unstable_apis))]
1763impl<T: JsGeneric> core::iter::Iterator for ArrayIntoIter<T> {
1764 type Item = T;
1765
1766 fn next(&mut self) -> Option<Self::Item> {
1767 let index = self.range.next()?;
1768 Some(self.array.get(index))
1769 }
1770
1771 #[inline]
1772 fn size_hint(&self) -> (usize, Option<usize>) {
1773 self.range.size_hint()
1774 }
1775
1776 #[inline]
1777 fn count(self) -> usize
1778 where
1779 Self: Sized,
1780 {
1781 self.range.count()
1782 }
1783
1784 #[inline]
1785 fn last(self) -> Option<Self::Item>
1786 where
1787 Self: Sized,
1788 {
1789 let Self { range, array } = self;
1790 range.last().map(|index| array.get(index))
1791 }
1792
1793 #[inline]
1794 fn nth(&mut self, n: usize) -> Option<Self::Item> {
1795 self.range.nth(n).map(|index| self.array.get(index))
1796 }
1797}
1798
1799#[cfg(js_sys_unstable_apis)]
1800impl<T: JsGeneric> core::iter::Iterator for ArrayIntoIter<T> {
1801 type Item = T;
1802
1803 fn next(&mut self) -> Option<Self::Item> {
1804 let index = self.range.next()?;
1805 self.array.get(index)
1806 }
1807
1808 #[inline]
1809 fn size_hint(&self) -> (usize, Option<usize>) {
1810 self.range.size_hint()
1811 }
1812
1813 #[inline]
1814 fn count(self) -> usize
1815 where
1816 Self: Sized,
1817 {
1818 self.range.count()
1819 }
1820
1821 #[inline]
1822 fn last(self) -> Option<Self::Item>
1823 where
1824 Self: Sized,
1825 {
1826 let Self { range, array } = self;
1827 range.last().and_then(|index| array.get(index))
1828 }
1829
1830 #[inline]
1831 fn nth(&mut self, n: usize) -> Option<Self::Item> {
1832 self.range.nth(n).and_then(|index| self.array.get(index))
1833 }
1834}
1835
1836#[cfg(not(js_sys_unstable_apis))]
1837impl<T: JsGeneric> core::iter::DoubleEndedIterator for ArrayIntoIter<T> {
1838 fn next_back(&mut self) -> Option<Self::Item> {
1839 let index = self.range.next_back()?;
1840 Some(self.array.get(index))
1841 }
1842
1843 fn nth_back(&mut self, n: usize) -> Option<Self::Item> {
1844 self.range.nth_back(n).map(|index| self.array.get(index))
1845 }
1846}
1847
1848#[cfg(js_sys_unstable_apis)]
1849impl<T: JsGeneric> core::iter::DoubleEndedIterator for ArrayIntoIter<T> {
1850 fn next_back(&mut self) -> Option<Self::Item> {
1851 let index = self.range.next_back()?;
1852 self.array.get(index)
1853 }
1854
1855 fn nth_back(&mut self, n: usize) -> Option<Self::Item> {
1856 self.range
1857 .nth_back(n)
1858 .and_then(|index| self.array.get(index))
1859 }
1860}
1861
1862impl<T: JsGeneric> core::iter::FusedIterator for ArrayIntoIter<T> {}
1863
1864impl<T: JsGeneric> core::iter::ExactSizeIterator for ArrayIntoIter<T> {}
1865
1866/// Iterator returned by `Array::iter`
1867#[derive(Debug, Clone)]
1868pub struct ArrayIter<'a, T: JsGeneric> {
1869 range: core::ops::Range<u32>,
1870 array: &'a Array<T>,
1871}
1872
1873impl<T: JsGeneric> core::iter::Iterator for ArrayIter<'_, T> {
1874 type Item = T;
1875
1876 fn next(&mut self) -> Option<Self::Item> {
1877 let index = self.range.next()?;
1878 Some(self.array.get_unchecked(index))
1879 }
1880
1881 #[inline]
1882 fn size_hint(&self) -> (usize, Option<usize>) {
1883 self.range.size_hint()
1884 }
1885
1886 #[inline]
1887 fn count(self) -> usize
1888 where
1889 Self: Sized,
1890 {
1891 self.range.count()
1892 }
1893
1894 #[inline]
1895 fn last(self) -> Option<Self::Item>
1896 where
1897 Self: Sized,
1898 {
1899 let Self { range, array } = self;
1900 range.last().map(|index| array.get_unchecked(index))
1901 }
1902
1903 #[inline]
1904 fn nth(&mut self, n: usize) -> Option<Self::Item> {
1905 self.range
1906 .nth(n)
1907 .map(|index| self.array.get_unchecked(index))
1908 }
1909}
1910
1911impl<T: JsGeneric> core::iter::DoubleEndedIterator for ArrayIter<'_, T> {
1912 fn next_back(&mut self) -> Option<Self::Item> {
1913 let index = self.range.next_back()?;
1914 Some(self.array.get_unchecked(index))
1915 }
1916
1917 fn nth_back(&mut self, n: usize) -> Option<Self::Item> {
1918 self.range
1919 .nth_back(n)
1920 .map(|index| self.array.get_unchecked(index))
1921 }
1922}
1923
1924impl<T: JsGeneric> core::iter::FusedIterator for ArrayIter<'_, T> {}
1925
1926impl<T: JsGeneric> core::iter::ExactSizeIterator for ArrayIter<'_, T> {}
1927
1928impl<T: JsGeneric> Array<T> {
1929 /// Returns an iterator over the values of the JS array.
1930 pub fn iter(&self) -> ArrayIter<'_, T> {
1931 ArrayIter {
1932 range: 0..self.length(),
1933 array: self,
1934 }
1935 }
1936}
1937
1938impl<T: JsGeneric> core::iter::IntoIterator for Array<T> {
1939 type Item = T;
1940 type IntoIter = ArrayIntoIter<T>;
1941
1942 fn into_iter(self) -> Self::IntoIter {
1943 ArrayIntoIter {
1944 range: 0..self.length(),
1945 array: self,
1946 }
1947 }
1948}
1949
1950#[cfg(not(js_sys_unstable_apis))]
1951impl<A, T: JsGeneric> core::iter::FromIterator<A> for Array<T>
1952where
1953 A: AsRef<T>,
1954{
1955 fn from_iter<I>(iter: I) -> Array<T>
1956 where
1957 I: IntoIterator<Item = A>,
1958 {
1959 let iter = iter.into_iter();
1960 let mut out = Array::new_typed();
1961 out.extend(iter);
1962 out
1963 }
1964}
1965
1966#[cfg(js_sys_unstable_apis)]
1967impl<A, T: JsGeneric> core::iter::FromIterator<A> for Array<T>
1968where
1969 A: AsRef<T>,
1970{
1971 fn from_iter<I>(iter: I) -> Array<T>
1972 where
1973 I: IntoIterator<Item = A>,
1974 {
1975 let iter = iter.into_iter();
1976 let (lower, upper) = iter.size_hint();
1977 let capacity = upper.unwrap_or(lower);
1978 let out = Array::new_with_length_typed(capacity as u32);
1979 let mut i = 0;
1980 for value in iter {
1981 out.set(i, value.as_ref());
1982 i += 1;
1983 }
1984 out
1985 }
1986}
1987
1988impl<A, T: JsGeneric> core::iter::Extend<A> for Array<T>
1989where
1990 A: AsRef<T>,
1991{
1992 fn extend<I>(&mut self, iter: I)
1993 where
1994 I: IntoIterator<Item = A>,
1995 {
1996 for value in iter {
1997 self.push(value.as_ref());
1998 }
1999 }
2000}
2001
2002impl Default for Array<JsValue> {
2003 fn default() -> Self {
2004 Self::new()
2005 }
2006}
2007
2008impl<T> Iterable for Array<T> {
2009 type Item = T;
2010}
2011
2012impl<T: JsTuple> Iterable for ArrayTuple<T> {
2013 type Item = JsValue;
2014}
2015
2016// ArrayBufferOptions
2017#[wasm_bindgen]
2018extern "C" {
2019 #[wasm_bindgen(extends = Object, typescript_type = "ArrayBufferOptions")]
2020 #[derive(Clone, Debug, PartialEq, Eq)]
2021 pub type ArrayBufferOptions;
2022
2023 /// The maximum size, in bytes, that the array buffer can be resized to.
2024 #[wasm_bindgen(method, setter, js_name = maxByteLength)]
2025 pub fn set_max_byte_length(this: &ArrayBufferOptions, max_byte_length: usize);
2026
2027 /// The maximum size, in bytes, that the array buffer can be resized to.
2028 #[wasm_bindgen(method, getter, js_name = maxByteLength)]
2029 pub fn get_max_byte_length(this: &ArrayBufferOptions) -> usize;
2030}
2031
2032impl ArrayBufferOptions {
2033 #[cfg(not(js_sys_unstable_apis))]
2034 pub fn new(max_byte_length: usize) -> ArrayBufferOptions {
2035 let options = JsCast::unchecked_into::<ArrayBufferOptions>(Object::new());
2036 options.set_max_byte_length(max_byte_length);
2037 options
2038 }
2039
2040 #[cfg(js_sys_unstable_apis)]
2041 pub fn new(max_byte_length: usize) -> ArrayBufferOptions {
2042 let options = JsCast::unchecked_into::<ArrayBufferOptions>(Object::<JsValue>::new());
2043 options.set_max_byte_length(max_byte_length);
2044 options
2045 }
2046}
2047
2048// ArrayBuffer
2049#[wasm_bindgen]
2050extern "C" {
2051 #[wasm_bindgen(extends = Object, typescript_type = "ArrayBuffer")]
2052 #[derive(Clone, Debug, PartialEq, Eq)]
2053 pub type ArrayBuffer;
2054
2055 /// The `ArrayBuffer` object is used to represent a generic,
2056 /// fixed-length raw binary data buffer. You cannot directly
2057 /// manipulate the contents of an `ArrayBuffer`; instead, you
2058 /// create one of the typed array objects or a `DataView` object
2059 /// which represents the buffer in a specific format, and use that
2060 /// to read and write the contents of the buffer.
2061 ///
2062 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer)
2063 #[cfg(not(js_sys_unstable_apis))]
2064 #[wasm_bindgen(constructor)]
2065 pub fn new(length: u32) -> ArrayBuffer;
2066
2067 /// The `ArrayBuffer` object is used to represent a generic,
2068 /// fixed-length raw binary data buffer. You cannot directly
2069 /// manipulate the contents of an `ArrayBuffer`; instead, you
2070 /// create one of the typed array objects or a `DataView` object
2071 /// which represents the buffer in a specific format, and use that
2072 /// to read and write the contents of the buffer.
2073 ///
2074 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer)
2075 #[cfg(js_sys_unstable_apis)]
2076 #[wasm_bindgen(constructor)]
2077 pub fn new(length: usize) -> ArrayBuffer;
2078
2079 /// The `ArrayBuffer` object is used to represent a generic,
2080 /// fixed-length raw binary data buffer. You cannot directly
2081 /// manipulate the contents of an `ArrayBuffer`; instead, you
2082 /// create one of the typed array objects or a `DataView` object
2083 /// which represents the buffer in a specific format, and use that
2084 /// to read and write the contents of the buffer.
2085 ///
2086 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer)
2087 #[wasm_bindgen(constructor)]
2088 pub fn new_with_options(length: usize, options: &ArrayBufferOptions) -> ArrayBuffer;
2089
2090 /// The `byteLength` property of an object which is an instance of type ArrayBuffer
2091 /// it's an accessor property whose set accessor function is undefined,
2092 /// meaning that you can only read this property.
2093 /// The value is established when the array is constructed and cannot be changed.
2094 /// This property returns 0 if this ArrayBuffer has been detached.
2095 ///
2096 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/byteLength)
2097 #[cfg(not(js_sys_unstable_apis))]
2098 #[wasm_bindgen(method, getter, js_name = byteLength)]
2099 pub fn byte_length(this: &ArrayBuffer) -> u32;
2100
2101 /// The `byteLength` property of an object which is an instance of type ArrayBuffer
2102 /// it's an accessor property whose set accessor function is undefined,
2103 /// meaning that you can only read this property.
2104 /// The value is established when the array is constructed and cannot be changed.
2105 /// This property returns 0 if this ArrayBuffer has been detached.
2106 ///
2107 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/byteLength)
2108 #[cfg(js_sys_unstable_apis)]
2109 #[wasm_bindgen(method, getter, js_name = byteLength)]
2110 pub fn byte_length(this: &ArrayBuffer) -> usize;
2111
2112 /// The `detached` accessor property of `ArrayBuffer` instances returns a boolean indicating
2113 /// whether or not this buffer has been detached (transferred).
2114 ///
2115 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/detached)
2116 #[wasm_bindgen(method, getter)]
2117 pub fn detached(this: &ArrayBuffer) -> bool;
2118
2119 /// The `isView()` method returns true if arg is one of the `ArrayBuffer`
2120 /// views, such as typed array objects or a DataView; false otherwise.
2121 ///
2122 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/isView)
2123 #[wasm_bindgen(static_method_of = ArrayBuffer, js_name = isView)]
2124 pub fn is_view(value: &JsValue) -> bool;
2125
2126 /// The `maxByteLength` accessor property of ArrayBuffer instances returns the maximum
2127 /// length (in bytes) that this array buffer can be resized to.
2128 ///
2129 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/maxByteLength)
2130 #[wasm_bindgen(method, getter, js_name = maxByteLength)]
2131 pub fn max_byte_length(this: &ArrayBuffer) -> usize;
2132
2133 /// The `resizable` accessor property of `ArrayBuffer` instances returns whether this array buffer
2134 /// can be resized or not.
2135 ///
2136 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/resizable)
2137 #[wasm_bindgen(method, getter)]
2138 pub fn resizable(this: &ArrayBuffer) -> bool;
2139
2140 /// The `resize()` method of ArrayBuffer instances resizes the ArrayBuffer to the
2141 /// specified size, in bytes.
2142 ///
2143 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/resize)
2144 #[wasm_bindgen(method, catch)]
2145 pub fn resize(this: &ArrayBuffer, new_len: usize) -> Result<(), JsValue>;
2146
2147 /// The `slice()` method returns a new `ArrayBuffer` whose contents
2148 /// are a copy of this `ArrayBuffer`'s bytes from begin, inclusive,
2149 /// up to end, exclusive.
2150 ///
2151 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/slice)
2152 #[cfg(not(js_sys_unstable_apis))]
2153 #[wasm_bindgen(method)]
2154 pub fn slice(this: &ArrayBuffer, begin: u32) -> ArrayBuffer;
2155
2156 /// The `slice()` method returns a new `ArrayBuffer` whose contents
2157 /// are a copy of this `ArrayBuffer`'s bytes from begin, inclusive,
2158 /// up to end, exclusive. Negative indices count from the end.
2159 ///
2160 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/slice)
2161 #[cfg(js_sys_unstable_apis)]
2162 #[wasm_bindgen(method)]
2163 pub fn slice(this: &ArrayBuffer, begin: isize, end: isize) -> ArrayBuffer;
2164
2165 /// The `slice()` method returns a new `ArrayBuffer` whose contents
2166 /// are a copy of this `ArrayBuffer`'s bytes from begin, inclusive,
2167 /// up to end, exclusive.
2168 ///
2169 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/slice)
2170 #[cfg(not(js_sys_unstable_apis))]
2171 #[wasm_bindgen(method, js_name = slice)]
2172 pub fn slice_from(this: &ArrayBuffer, begin: isize) -> ArrayBuffer;
2173
2174 /// The `slice()` method returns a new `ArrayBuffer` whose contents
2175 /// are a copy of this `ArrayBuffer`'s bytes from begin to the end.
2176 /// Negative indices count from the end.
2177 ///
2178 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/slice)
2179 #[cfg(js_sys_unstable_apis)]
2180 #[wasm_bindgen(method, js_name = slice)]
2181 pub fn slice_from(this: &ArrayBuffer, begin: isize) -> ArrayBuffer;
2182
2183 // Next major: deprecate
2184 /// Like `slice()` but with the `end` argument.
2185 ///
2186 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/slice)
2187 #[wasm_bindgen(method, js_name = slice)]
2188 pub fn slice_with_end(this: &ArrayBuffer, begin: u32, end: u32) -> ArrayBuffer;
2189
2190 /// The `transfer()` method of ArrayBuffer instances creates a new `ArrayBuffer`
2191 /// with the same byte content as this buffer, then detaches this buffer.
2192 ///
2193 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/transfer)
2194 #[wasm_bindgen(method, catch)]
2195 pub fn transfer(this: &ArrayBuffer) -> Result<ArrayBuffer, JsValue>;
2196
2197 /// The `transfer()` method of `ArrayBuffer` instances creates a new `ArrayBuffer`
2198 /// with the same byte content as this buffer, then detaches this buffer.
2199 ///
2200 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/transfer)
2201 #[wasm_bindgen(method, catch, js_name = transfer)]
2202 pub fn transfer_with_length(
2203 this: &ArrayBuffer,
2204 new_byte_length: usize,
2205 ) -> Result<ArrayBuffer, JsValue>;
2206
2207 /// The `transferToFixedLength()` method of `ArrayBuffer` instances creates a new non-resizable
2208 /// ArrayBuffer with the same byte content as this buffer, then detaches this buffer.
2209 ///
2210 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/transferToFixedLength)
2211 #[wasm_bindgen(method, catch, js_name = transferToFixedLength)]
2212 pub fn transfer_to_fixed_length(this: &ArrayBuffer) -> Result<ArrayBuffer, JsValue>;
2213
2214 /// The `transferToFixedLength()` method of `ArrayBuffer` instances creates a new non-resizable
2215 /// `ArrayBuffer` with the same byte content as this buffer, then detaches this buffer.
2216 ///
2217 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/transferToFixedLength)
2218 #[wasm_bindgen(method, catch, js_name = transferToFixedLength)]
2219 pub fn transfer_to_fixed_length_with_length(
2220 this: &ArrayBuffer,
2221 new_byte_length: usize,
2222 ) -> Result<ArrayBuffer, JsValue>;
2223}
2224
2225impl UpcastFrom<&[u8]> for ArrayBuffer {}
2226
2227// SharedArrayBuffer
2228#[wasm_bindgen]
2229extern "C" {
2230 #[wasm_bindgen(extends = Object, typescript_type = "SharedArrayBuffer")]
2231 #[derive(Clone, Debug)]
2232 pub type SharedArrayBuffer;
2233
2234 /// The `SharedArrayBuffer` object is used to represent a generic,
2235 /// fixed-length raw binary data buffer, similar to the `ArrayBuffer`
2236 /// object, but in a way that they can be used to create views
2237 /// on shared memory. Unlike an `ArrayBuffer`, a `SharedArrayBuffer`
2238 /// cannot become detached.
2239 ///
2240 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer)
2241 #[cfg(not(js_sys_unstable_apis))]
2242 #[wasm_bindgen(constructor)]
2243 pub fn new(length: u32) -> SharedArrayBuffer;
2244
2245 /// The `SharedArrayBuffer` object is used to represent a generic,
2246 /// fixed-length raw binary data buffer, similar to the `ArrayBuffer`
2247 /// object, but in a way that they can be used to create views
2248 /// on shared memory. Unlike an `ArrayBuffer`, a `SharedArrayBuffer`
2249 /// cannot become detached.
2250 ///
2251 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer)
2252 #[cfg(js_sys_unstable_apis)]
2253 #[wasm_bindgen(constructor)]
2254 pub fn new(length: usize) -> SharedArrayBuffer;
2255
2256 /// The `SharedArrayBuffer` object is used to represent a generic,
2257 /// fixed-length raw binary data buffer, similar to the `ArrayBuffer`
2258 /// object, but in a way that they can be used to create views
2259 /// on shared memory. Unlike an `ArrayBuffer`, a `SharedArrayBuffer`
2260 /// cannot become detached.
2261 ///
2262 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer)
2263 #[wasm_bindgen(constructor)]
2264 pub fn new_with_options(length: usize, options: &ArrayBufferOptions) -> SharedArrayBuffer;
2265
2266 /// The `byteLength` accessor property represents the length of
2267 /// an `SharedArrayBuffer` in bytes. This is established when
2268 /// the `SharedArrayBuffer` is constructed and cannot be changed.
2269 ///
2270 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/byteLength)
2271 #[cfg(not(js_sys_unstable_apis))]
2272 #[wasm_bindgen(method, getter, js_name = byteLength)]
2273 pub fn byte_length(this: &SharedArrayBuffer) -> u32;
2274
2275 /// The `byteLength` accessor property represents the length of
2276 /// an `SharedArrayBuffer` in bytes. This is established when
2277 /// the `SharedArrayBuffer` is constructed and cannot be changed.
2278 ///
2279 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/byteLength)
2280 #[cfg(js_sys_unstable_apis)]
2281 #[wasm_bindgen(method, getter, js_name = byteLength)]
2282 pub fn byte_length(this: &SharedArrayBuffer) -> usize;
2283
2284 /// The `growable` accessor property of `SharedArrayBuffer` instances returns whether
2285 /// this `SharedArrayBuffer` can be grown or not.
2286 ///
2287 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/growable)
2288 #[wasm_bindgen(method, getter)]
2289 pub fn growable(this: &SharedArrayBuffer) -> bool;
2290
2291 /// The `grow()` method of `SharedArrayBuffer` instances grows the
2292 /// `SharedArrayBuffer` to the specified size, in bytes.
2293 ///
2294 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/grow)
2295 #[wasm_bindgen(method, catch)]
2296 pub fn grow(this: &SharedArrayBuffer, new_byte_length: usize) -> Result<(), JsValue>;
2297
2298 /// The `maxByteLength` accessor property of `SharedArrayBuffer` instances returns the maximum
2299 /// length (in bytes) that this `SharedArrayBuffer` can be resized to.
2300 ///
2301 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/maxByteLength)
2302 #[wasm_bindgen(method, getter, js_name = maxByteLength)]
2303 pub fn max_byte_length(this: &SharedArrayBuffer) -> usize;
2304
2305 /// The `slice()` method returns a new `SharedArrayBuffer` whose contents
2306 /// are a copy of this `SharedArrayBuffer`'s bytes from begin, inclusive,
2307 /// up to end, exclusive.
2308 ///
2309 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/slice)
2310 #[cfg(not(js_sys_unstable_apis))]
2311 #[wasm_bindgen(method)]
2312 pub fn slice(this: &SharedArrayBuffer, begin: u32) -> SharedArrayBuffer;
2313
2314 /// The `slice()` method returns a new `SharedArrayBuffer` whose contents
2315 /// are a copy of this `SharedArrayBuffer`'s bytes from begin, inclusive,
2316 /// up to end, exclusive. Negative indices count from the end.
2317 ///
2318 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/slice)
2319 #[cfg(js_sys_unstable_apis)]
2320 #[wasm_bindgen(method)]
2321 pub fn slice(this: &SharedArrayBuffer, begin: isize, end: isize) -> SharedArrayBuffer;
2322
2323 /// The `slice()` method returns a new `SharedArrayBuffer` whose contents
2324 /// are a copy of this `SharedArrayBuffer`'s bytes from begin, inclusive,
2325 /// up to end, exclusive.
2326 ///
2327 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/slice)
2328 #[cfg(not(js_sys_unstable_apis))]
2329 #[wasm_bindgen(method)]
2330 pub fn slice_from(this: &SharedArrayBuffer, begin: isize) -> SharedArrayBuffer;
2331
2332 /// The `slice()` method returns a new `SharedArrayBuffer` whose contents
2333 /// are a copy of this `SharedArrayBuffer`'s bytes from begin to end.
2334 /// Negative indices count from the end.
2335 ///
2336 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/slice)
2337 #[cfg(js_sys_unstable_apis)]
2338 #[wasm_bindgen(method)]
2339 pub fn slice_from(this: &SharedArrayBuffer, begin: isize) -> SharedArrayBuffer;
2340
2341 // Next major: deprecate
2342 /// Like `slice()` but with the `end` argument.
2343 ///
2344 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/slice)
2345 #[wasm_bindgen(method, js_name = slice)]
2346 pub fn slice_with_end(this: &SharedArrayBuffer, begin: u32, end: u32) -> SharedArrayBuffer;
2347}
2348
2349// Array Iterator
2350#[wasm_bindgen]
2351extern "C" {
2352 /// The `keys()` method returns a new Array Iterator object that contains the
2353 /// keys for each index in the array.
2354 ///
2355 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/keys)
2356 #[wasm_bindgen(method)]
2357 pub fn keys<T>(this: &Array<T>) -> Iterator<T>;
2358
2359 /// The `entries()` method returns a new Array Iterator object that contains
2360 /// the key/value pairs for each index in the array.
2361 ///
2362 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries)
2363 #[cfg(not(js_sys_unstable_apis))]
2364 #[wasm_bindgen(method)]
2365 #[deprecated(note = "recommended to use `Array::entries_typed` instead for typing")]
2366 #[allow(deprecated)]
2367 pub fn entries<T>(this: &Array<T>) -> Iterator<T>;
2368
2369 /// The `entries()` method returns a new Array Iterator object that contains
2370 /// the key/value pairs for each index in the array.
2371 ///
2372 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries)
2373 #[cfg(js_sys_unstable_apis)]
2374 #[wasm_bindgen(method)]
2375 pub fn entries<T: JsGeneric>(this: &Array<T>) -> Iterator<ArrayTuple<(Number, T)>>;
2376
2377 // Next major: deprecate
2378 /// The `entries()` method returns a new Array Iterator object that contains
2379 /// the key/value pairs for each index in the array.
2380 ///
2381 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries)
2382 #[wasm_bindgen(method, js_name = entries)]
2383 pub fn entries_typed<T: JsGeneric>(this: &Array<T>) -> Iterator<ArrayTuple<(Number, T)>>;
2384
2385 /// The `values()` method returns a new Array Iterator object that
2386 /// contains the values for each index in the array.
2387 ///
2388 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/values)
2389 #[wasm_bindgen(method)]
2390 pub fn values<T>(this: &Array<T>) -> Iterator<T>;
2391}
2392
2393pub trait TypedArray: JsGeneric {}
2394
2395// Next major: use usize/isize for indices
2396/// The `Atomics` object provides atomic operations as static methods.
2397/// They are used with `SharedArrayBuffer` objects.
2398///
2399/// The Atomic operations are installed on an `Atomics` module. Unlike
2400/// the other global objects, `Atomics` is not a constructor. You cannot
2401/// use it with a new operator or invoke the `Atomics` object as a
2402/// function. All properties and methods of `Atomics` are static
2403/// (as is the case with the Math object, for example).
2404/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics)
2405#[allow(non_snake_case)]
2406pub mod Atomics {
2407 use super::*;
2408
2409 #[wasm_bindgen]
2410 extern "C" {
2411 /// The static `Atomics.add()` method adds a given value at a given
2412 /// position in the array and returns the old value at that position.
2413 /// This atomic operation guarantees that no other write happens
2414 /// until the modified value is written back.
2415 ///
2416 /// You should use `add_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2417 ///
2418 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/add)
2419 #[wasm_bindgen(js_namespace = Atomics, catch)]
2420 pub fn add<T: TypedArray = Int32Array>(
2421 typed_array: &T,
2422 index: u32,
2423 value: i32,
2424 ) -> Result<i32, JsValue>;
2425
2426 /// The static `Atomics.add()` method adds a given value at a given
2427 /// position in the array and returns the old value at that position.
2428 /// This atomic operation guarantees that no other write happens
2429 /// until the modified value is written back.
2430 ///
2431 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2432 ///
2433 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/add)
2434 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = add)]
2435 pub fn add_bigint<T: TypedArray = Int32Array>(
2436 typed_array: &T,
2437 index: u32,
2438 value: i64,
2439 ) -> Result<i64, JsValue>;
2440
2441 /// The static `Atomics.and()` method computes a bitwise AND with a given
2442 /// value at a given position in the array, and returns the old value
2443 /// at that position.
2444 /// This atomic operation guarantees that no other write happens
2445 /// until the modified value is written back.
2446 ///
2447 /// You should use `and_bigint` 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/and)
2450 #[wasm_bindgen(js_namespace = Atomics, catch)]
2451 pub fn and<T: TypedArray = Int32Array>(
2452 typed_array: &T,
2453 index: u32,
2454 value: i32,
2455 ) -> Result<i32, 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 /// This method is used 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, js_name = and)]
2467 pub fn and_bigint<T: TypedArray = Int32Array>(
2468 typed_array: &T,
2469 index: u32,
2470 value: i64,
2471 ) -> Result<i64, JsValue>;
2472
2473 /// The static `Atomics.compareExchange()` method exchanges a given
2474 /// replacement value at a given position in the array, if a given expected
2475 /// value equals the old value. It returns the old value at that position
2476 /// whether it was equal to the expected value or not.
2477 /// This atomic operation guarantees that no other write happens
2478 /// until the modified value is written back.
2479 ///
2480 /// You should use `compare_exchange_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2481 ///
2482 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/compareExchange)
2483 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = compareExchange)]
2484 pub fn compare_exchange<T: TypedArray = Int32Array>(
2485 typed_array: &T,
2486 index: u32,
2487 expected_value: i32,
2488 replacement_value: i32,
2489 ) -> Result<i32, JsValue>;
2490
2491 /// The static `Atomics.compareExchange()` method exchanges a given
2492 /// replacement value at a given position in the array, if a given expected
2493 /// value equals the old value. It returns the old value at that position
2494 /// whether it was equal to the expected value or not.
2495 /// This atomic operation guarantees that no other write happens
2496 /// until the modified value is written back.
2497 ///
2498 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2499 ///
2500 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/compareExchange)
2501 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = compareExchange)]
2502 pub fn compare_exchange_bigint<T: TypedArray = Int32Array>(
2503 typed_array: &T,
2504 index: u32,
2505 expected_value: i64,
2506 replacement_value: i64,
2507 ) -> Result<i64, JsValue>;
2508
2509 /// The static `Atomics.exchange()` method stores a given value at a given
2510 /// position in the array and returns the old value at that position.
2511 /// This atomic operation guarantees that no other write happens
2512 /// until the modified value is written back.
2513 ///
2514 /// You should use `exchange_bigint` 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/exchange)
2517 #[wasm_bindgen(js_namespace = Atomics, catch)]
2518 pub fn exchange<T: TypedArray = Int32Array>(
2519 typed_array: &T,
2520 index: u32,
2521 value: i32,
2522 ) -> Result<i32, JsValue>;
2523
2524 /// The static `Atomics.exchange()` method stores a given value at a given
2525 /// position in the array and returns the old value at that position.
2526 /// This atomic operation guarantees that no other write happens
2527 /// until the modified value is written back.
2528 ///
2529 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2530 ///
2531 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/exchange)
2532 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = exchange)]
2533 pub fn exchange_bigint<T: TypedArray = Int32Array>(
2534 typed_array: &T,
2535 index: u32,
2536 value: i64,
2537 ) -> Result<i64, JsValue>;
2538
2539 /// The static `Atomics.isLockFree()` method is used to determine
2540 /// whether to use locks or atomic operations. It returns true,
2541 /// if the given size is one of the `BYTES_PER_ELEMENT` property
2542 /// of integer `TypedArray` types.
2543 ///
2544 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/isLockFree)
2545 #[wasm_bindgen(js_namespace = Atomics, js_name = isLockFree)]
2546 pub fn is_lock_free(size: u32) -> bool;
2547
2548 /// The static `Atomics.load()` method returns a value at a given
2549 /// position in the array.
2550 ///
2551 /// You should use `load_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2552 ///
2553 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/load)
2554 #[wasm_bindgen(js_namespace = Atomics, catch)]
2555 pub fn load<T: TypedArray = Int32Array>(
2556 typed_array: &T,
2557 index: u32,
2558 ) -> Result<i32, JsValue>;
2559
2560 /// The static `Atomics.load()` method returns a value at a given
2561 /// position in the array.
2562 ///
2563 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2564 ///
2565 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/load)
2566 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = load)]
2567 pub fn load_bigint<T: TypedArray = Int32Array>(
2568 typed_array: &T,
2569 index: i64,
2570 ) -> Result<i64, JsValue>;
2571
2572 /// The static `Atomics.notify()` method notifies up some agents that
2573 /// are sleeping in the wait queue.
2574 /// Note: This operation works with a shared `Int32Array` only.
2575 /// If `count` is not provided, notifies all the agents in the queue.
2576 ///
2577 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/notify)
2578 #[wasm_bindgen(js_namespace = Atomics, catch)]
2579 pub fn notify(typed_array: &Int32Array, index: u32) -> Result<u32, JsValue>;
2580
2581 /// The static `Atomics.notify()` method notifies up some agents that
2582 /// are sleeping in the wait queue.
2583 /// Note: This operation works with a shared `Int32Array` only.
2584 /// If `count` is not provided, notifies all the agents in the queue.
2585 ///
2586 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/notify)
2587 #[wasm_bindgen(js_namespace = Atomics, catch)]
2588 pub fn notify_bigint(typed_array: &BigInt64Array, index: u32) -> Result<u32, JsValue>;
2589
2590 /// Notifies up to `count` agents in the wait queue.
2591 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = notify)]
2592 pub fn notify_with_count(
2593 typed_array: &Int32Array,
2594 index: u32,
2595 count: u32,
2596 ) -> Result<u32, JsValue>;
2597
2598 /// Notifies up to `count` agents in the wait queue.
2599 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = notify)]
2600 pub fn notify_bigint_with_count(
2601 typed_array: &BigInt64Array,
2602 index: u32,
2603 count: u32,
2604 ) -> Result<u32, JsValue>;
2605
2606 /// The static `Atomics.or()` method computes a bitwise OR with a given value
2607 /// at a given position in the array, and returns the old value at that position.
2608 /// This atomic operation guarantees that no other write happens
2609 /// until the modified value is written back.
2610 ///
2611 /// You should use `or_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2612 ///
2613 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/or)
2614 #[wasm_bindgen(js_namespace = Atomics, catch)]
2615 pub fn or<T: TypedArray = Int32Array>(
2616 typed_array: &T,
2617 index: u32,
2618 value: i32,
2619 ) -> Result<i32, JsValue>;
2620
2621 /// The static `Atomics.or()` method computes a bitwise OR with a given value
2622 /// at a given position in the array, and returns the old value at that position.
2623 /// This atomic operation guarantees that no other write happens
2624 /// until the modified value is written back.
2625 ///
2626 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2627 ///
2628 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/or)
2629 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = or)]
2630 pub fn or_bigint<T: TypedArray = Int32Array>(
2631 typed_array: &T,
2632 index: u32,
2633 value: i64,
2634 ) -> Result<i64, JsValue>;
2635
2636 /// The static `Atomics.pause()` static method provides a micro-wait primitive that hints to the CPU
2637 /// that the caller is spinning while waiting on access to a shared resource. This allows the system
2638 /// to reduce the resources allocated to the core (such as power) or thread, without yielding the
2639 /// current thread.
2640 ///
2641 /// `pause()` has no observable behavior other than timing. The exact behavior is dependent on the CPU
2642 /// architecture and the operating system. For example, in Intel x86, it may be a pause instruction as
2643 /// per Intel's optimization manual. It could be a no-op in certain platforms.
2644 ///
2645 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2646 ///
2647 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/xor)
2648 #[wasm_bindgen(js_namespace = Atomics)]
2649 pub fn pause();
2650
2651 /// The static `Atomics.pause()` static method provides a micro-wait primitive that hints to the CPU
2652 /// that the caller is spinning while waiting on access to a shared resource. This allows the system
2653 /// to reduce the resources allocated to the core (such as power) or thread, without yielding the
2654 /// current thread.
2655 ///
2656 /// `pause()` has no observable behavior other than timing. The exact behavior is dependent on the CPU
2657 /// architecture and the operating system. For example, in Intel x86, it may be a pause instruction as
2658 /// per Intel's optimization manual. It could be a no-op in certain platforms.
2659 ///
2660 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2661 ///
2662 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/xor)
2663 #[wasm_bindgen(js_namespace = Atomics)]
2664 pub fn pause_with_hint(duration_hint: u32);
2665
2666 /// The static `Atomics.store()` method stores a given value at the given
2667 /// position in the array and returns that value.
2668 ///
2669 /// You should use `store_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2670 ///
2671 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/store)
2672 #[wasm_bindgen(js_namespace = Atomics, catch)]
2673 pub fn store<T: TypedArray = Int32Array>(
2674 typed_array: &T,
2675 index: u32,
2676 value: i32,
2677 ) -> Result<i32, JsValue>;
2678
2679 /// The static `Atomics.store()` method stores a given value at the given
2680 /// position in the array and returns that value.
2681 ///
2682 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2683 ///
2684 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/store)
2685 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = store)]
2686 pub fn store_bigint<T: TypedArray = Int32Array>(
2687 typed_array: &T,
2688 index: u32,
2689 value: i64,
2690 ) -> Result<i64, JsValue>;
2691
2692 /// The static `Atomics.sub()` method subtracts a given value at a
2693 /// given position in the array and returns the old value at that position.
2694 /// This atomic operation guarantees that no other write happens
2695 /// until the modified value is written back.
2696 ///
2697 /// You should use `sub_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2698 ///
2699 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/sub)
2700 #[wasm_bindgen(js_namespace = Atomics, catch)]
2701 pub fn sub<T: TypedArray = Int32Array>(
2702 typed_array: &T,
2703 index: u32,
2704 value: i32,
2705 ) -> Result<i32, JsValue>;
2706
2707 /// The static `Atomics.sub()` method subtracts a given value at a
2708 /// given position in the array and returns the old value at that position.
2709 /// This atomic operation guarantees that no other write happens
2710 /// until the modified value is written back.
2711 ///
2712 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2713 ///
2714 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/sub)
2715 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = sub)]
2716 pub fn sub_bigint<T: TypedArray = Int32Array>(
2717 typed_array: &T,
2718 index: u32,
2719 value: i64,
2720 ) -> Result<i64, JsValue>;
2721
2722 /// The static `Atomics.wait()` method verifies that a given
2723 /// position in an `Int32Array` still contains a given value
2724 /// and if so sleeps, awaiting a wakeup or a timeout.
2725 /// It returns a string which is either "ok", "not-equal", or "timed-out".
2726 /// Note: This operation only works with a shared `Int32Array`
2727 /// and may not be allowed on the main thread.
2728 ///
2729 /// You should use `wait_bigint` to operate on a `BigInt64Array`.
2730 ///
2731 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait)
2732 #[wasm_bindgen(js_namespace = Atomics, catch)]
2733 pub fn wait(typed_array: &Int32Array, index: u32, value: i32) -> Result<JsString, JsValue>;
2734
2735 /// The static `Atomics.wait()` method verifies that a given
2736 /// position in an `BigInt64Array` still contains a given value
2737 /// and if so sleeps, awaiting a wakeup or a timeout.
2738 /// It returns a string which is either "ok", "not-equal", or "timed-out".
2739 /// Note: This operation only works with a shared `BigInt64Array`
2740 /// and may not be allowed on the main thread.
2741 ///
2742 /// You should use `wait` to operate on a `Int32Array`.
2743 ///
2744 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait)
2745 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = wait)]
2746 pub fn wait_bigint(
2747 typed_array: &BigInt64Array,
2748 index: u32,
2749 value: i64,
2750 ) -> Result<JsString, JsValue>;
2751
2752 /// Like `wait()`, but with timeout
2753 ///
2754 /// You should use `wait_with_timeout_bigint` to operate on a `BigInt64Array`.
2755 ///
2756 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait)
2757 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = wait)]
2758 pub fn wait_with_timeout(
2759 typed_array: &Int32Array,
2760 index: u32,
2761 value: i32,
2762 timeout: f64,
2763 ) -> Result<JsString, JsValue>;
2764
2765 /// Like `wait()`, but with timeout
2766 ///
2767 /// You should use `wait_with_timeout` to operate on a `Int32Array`.
2768 ///
2769 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait)
2770 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = wait)]
2771 pub fn wait_with_timeout_bigint(
2772 typed_array: &BigInt64Array,
2773 index: u32,
2774 value: i64,
2775 timeout: f64,
2776 ) -> Result<JsString, JsValue>;
2777
2778 /// The static `Atomics.waitAsync()` method verifies that a given position in an
2779 /// `Int32Array` still contains a given value and if so sleeps, awaiting a
2780 /// wakeup or a timeout. It returns an object with two properties. The first
2781 /// property `async` is a boolean which if true indicates that the second
2782 /// property `value` is a promise. If `async` is false then value is a string
2783 /// whether equal to either "not-equal" or "timed-out".
2784 /// Note: This operation only works with a shared `Int32Array` and may be used
2785 /// on the main thread.
2786 ///
2787 /// You should use `wait_async_bigint` to operate on a `BigInt64Array`.
2788 ///
2789 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/waitAsync)
2790 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = waitAsync)]
2791 pub fn wait_async(
2792 typed_array: &Int32Array,
2793 index: u32,
2794 value: i32,
2795 ) -> Result<Object, JsValue>;
2796
2797 /// The static `Atomics.waitAsync()` method verifies that a given position in an
2798 /// `Int32Array` still contains a given value and if so sleeps, awaiting a
2799 /// wakeup or a timeout. It returns an object with two properties. The first
2800 /// property `async` is a boolean which if true indicates that the second
2801 /// property `value` is a promise. If `async` is false then value is a string
2802 /// whether equal to either "not-equal" or "timed-out".
2803 /// Note: This operation only works with a shared `BigInt64Array` and may be used
2804 /// on the main thread.
2805 ///
2806 /// You should use `wait_async` to operate on a `Int32Array`.
2807 ///
2808 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/waitAsync)
2809 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = waitAsync)]
2810 pub fn wait_async_bigint(
2811 typed_array: &BigInt64Array,
2812 index: u32,
2813 value: i64,
2814 ) -> Result<Object, JsValue>;
2815
2816 /// Like `waitAsync()`, but with timeout
2817 ///
2818 /// You should use `wait_async_with_timeout_bigint` to operate on a `BigInt64Array`.
2819 ///
2820 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/waitAsync)
2821 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = waitAsync)]
2822 pub fn wait_async_with_timeout(
2823 typed_array: &Int32Array,
2824 index: u32,
2825 value: i32,
2826 timeout: f64,
2827 ) -> Result<Object, JsValue>;
2828
2829 /// Like `waitAsync()`, but with timeout
2830 ///
2831 /// You should use `wait_async_with_timeout` to operate on a `Int32Array`.
2832 ///
2833 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/waitAsync)
2834 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = waitAsync)]
2835 pub fn wait_async_with_timeout_bigint(
2836 typed_array: &BigInt64Array,
2837 index: u32,
2838 value: i64,
2839 timeout: f64,
2840 ) -> Result<Object, JsValue>;
2841
2842 /// The static `Atomics.xor()` method computes a bitwise XOR
2843 /// with a given value at a given position in the array,
2844 /// and returns the old value at that position.
2845 /// This atomic operation guarantees that no other write happens
2846 /// until the modified value is written back.
2847 ///
2848 /// You should use `xor_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2849 ///
2850 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/xor)
2851 #[wasm_bindgen(js_namespace = Atomics, catch)]
2852 pub fn xor<T: TypedArray = Int32Array>(
2853 typed_array: &T,
2854 index: u32,
2855 value: i32,
2856 ) -> Result<i32, 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 /// This method is used 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, js_name = xor)]
2868 pub fn xor_bigint<T: TypedArray = Int32Array>(
2869 typed_array: &T,
2870 index: u32,
2871 value: i64,
2872 ) -> Result<i64, JsValue>;
2873 }
2874}
2875
2876// BigInt
2877#[wasm_bindgen]
2878extern "C" {
2879 #[wasm_bindgen(extends = Object, is_type_of = |v| v.is_bigint(), typescript_type = "bigint")]
2880 #[derive(Clone, PartialEq, Eq)]
2881 pub type BigInt;
2882
2883 #[wasm_bindgen(catch, js_name = BigInt)]
2884 fn new_bigint(value: &JsValue) -> Result<BigInt, Error>;
2885
2886 #[wasm_bindgen(js_name = BigInt)]
2887 fn new_bigint_unchecked(value: &JsValue) -> BigInt;
2888
2889 /// Clamps a BigInt value to a signed integer value, and returns that value.
2890 ///
2891 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/asIntN)
2892 #[wasm_bindgen(static_method_of = BigInt, js_name = asIntN)]
2893 pub fn as_int_n(bits: f64, bigint: &BigInt) -> BigInt;
2894
2895 /// Clamps a BigInt value to an unsigned integer value, and returns that value.
2896 ///
2897 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/asUintN)
2898 #[wasm_bindgen(static_method_of = BigInt, js_name = asUintN)]
2899 pub fn as_uint_n(bits: f64, bigint: &BigInt) -> BigInt;
2900
2901 /// 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.
2902 ///
2903 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/toLocaleString)
2904 #[cfg(not(js_sys_unstable_apis))]
2905 #[wasm_bindgen(method, js_name = toLocaleString)]
2906 pub fn to_locale_string(this: &BigInt, locales: &JsValue, options: &JsValue) -> JsString;
2907
2908 /// 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.
2909 ///
2910 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/toLocaleString)
2911 #[cfg(js_sys_unstable_apis)]
2912 #[wasm_bindgen(method, js_name = toLocaleString)]
2913 pub fn to_locale_string(
2914 this: &BigInt,
2915 locales: &[JsString],
2916 options: &Intl::NumberFormatOptions,
2917 ) -> JsString;
2918
2919 // Next major: deprecate
2920 /// 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.
2921 ///
2922 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/toString)
2923 #[wasm_bindgen(catch, method, js_name = toString)]
2924 pub fn to_string(this: &BigInt, radix: u8) -> Result<JsString, RangeError>;
2925
2926 /// Returns a string representing this BigInt value in the specified radix (base).
2927 ///
2928 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/toString)
2929 #[cfg(js_sys_unstable_apis)]
2930 #[wasm_bindgen(catch, method, js_name = toString)]
2931 pub fn to_string_with_radix(this: &BigInt, radix: u8) -> Result<JsString, RangeError>;
2932
2933 #[wasm_bindgen(method, js_name = toString)]
2934 fn to_string_unchecked(this: &BigInt, radix: u8) -> String;
2935
2936 /// Returns this BigInt value. Overrides the [`Object.prototype.valueOf()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf) method.
2937 ///
2938 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/valueOf)
2939 #[wasm_bindgen(method, js_name = valueOf)]
2940 pub fn value_of(this: &BigInt, radix: u8) -> BigInt;
2941}
2942
2943impl BigInt {
2944 /// Creates a new BigInt value.
2945 ///
2946 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/BigInt)
2947 #[inline]
2948 pub fn new(value: &JsValue) -> Result<BigInt, Error> {
2949 new_bigint(value)
2950 }
2951
2952 /// Applies the binary `/` JS operator on two `BigInt`s, catching and returning any `RangeError` thrown.
2953 ///
2954 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Division)
2955 pub fn checked_div(&self, rhs: &Self) -> Result<Self, RangeError> {
2956 let result = JsValue::as_ref(self).checked_div(JsValue::as_ref(rhs));
2957
2958 if result.is_instance_of::<RangeError>() {
2959 Err(result.unchecked_into())
2960 } else {
2961 Ok(result.unchecked_into())
2962 }
2963 }
2964
2965 /// Applies the binary `**` JS operator on the two `BigInt`s.
2966 ///
2967 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Exponentiation)
2968 #[inline]
2969 pub fn pow(&self, rhs: &Self) -> Self {
2970 JsValue::as_ref(self)
2971 .pow(JsValue::as_ref(rhs))
2972 .unchecked_into()
2973 }
2974
2975 /// Returns a tuple of this [`BigInt`]'s absolute value along with a
2976 /// [`bool`] indicating whether the [`BigInt`] was negative.
2977 fn abs(&self) -> (Self, bool) {
2978 if self < &BigInt::from(0) {
2979 (-self, true)
2980 } else {
2981 (self.clone(), false)
2982 }
2983 }
2984}
2985
2986macro_rules! bigint_from {
2987 ($($x:ident)*) => ($(
2988 impl From<$x> for BigInt {
2989 #[inline]
2990 fn from(x: $x) -> BigInt {
2991 new_bigint_unchecked(&JsValue::from(x))
2992 }
2993 }
2994
2995 impl PartialEq<$x> for BigInt {
2996 #[inline]
2997 fn eq(&self, other: &$x) -> bool {
2998 JsValue::from(self) == JsValue::from(BigInt::from(*other))
2999 }
3000 }
3001 )*)
3002}
3003bigint_from!(i8 u8 i16 u16 i32 u32 isize usize);
3004
3005macro_rules! bigint_from_big {
3006 ($($x:ident)*) => ($(
3007 impl From<$x> for BigInt {
3008 #[inline]
3009 fn from(x: $x) -> BigInt {
3010 JsValue::from(x).unchecked_into()
3011 }
3012 }
3013
3014 impl PartialEq<$x> for BigInt {
3015 #[inline]
3016 fn eq(&self, other: &$x) -> bool {
3017 self == &BigInt::from(*other)
3018 }
3019 }
3020
3021 impl TryFrom<BigInt> for $x {
3022 type Error = BigInt;
3023
3024 #[inline]
3025 fn try_from(x: BigInt) -> Result<Self, BigInt> {
3026 Self::try_from(JsValue::from(x)).map_err(JsCast::unchecked_into)
3027 }
3028 }
3029 )*)
3030}
3031bigint_from_big!(i64 u64 i128 u128);
3032
3033impl PartialEq<Number> for BigInt {
3034 #[inline]
3035 fn eq(&self, other: &Number) -> bool {
3036 JsValue::as_ref(self).loose_eq(JsValue::as_ref(other))
3037 }
3038}
3039
3040impl Not for &BigInt {
3041 type Output = BigInt;
3042
3043 #[inline]
3044 fn not(self) -> Self::Output {
3045 JsValue::as_ref(self).bit_not().unchecked_into()
3046 }
3047}
3048
3049forward_deref_unop!(impl Not, not for BigInt);
3050forward_js_unop!(impl Neg, neg for BigInt);
3051forward_js_binop!(impl BitAnd, bitand for BigInt);
3052forward_js_binop!(impl BitOr, bitor for BigInt);
3053forward_js_binop!(impl BitXor, bitxor for BigInt);
3054forward_js_binop!(impl Shl, shl for BigInt);
3055forward_js_binop!(impl Shr, shr for BigInt);
3056forward_js_binop!(impl Add, add for BigInt);
3057forward_js_binop!(impl Sub, sub for BigInt);
3058forward_js_binop!(impl Div, div for BigInt);
3059forward_js_binop!(impl Mul, mul for BigInt);
3060forward_js_binop!(impl Rem, rem for BigInt);
3061sum_product!(BigInt);
3062
3063partialord_ord!(BigInt);
3064
3065impl Default for BigInt {
3066 fn default() -> Self {
3067 BigInt::from(i32::default())
3068 }
3069}
3070
3071impl FromStr for BigInt {
3072 type Err = Error;
3073
3074 #[inline]
3075 fn from_str(s: &str) -> Result<Self, Self::Err> {
3076 BigInt::new(&s.into())
3077 }
3078}
3079
3080impl fmt::Debug for BigInt {
3081 #[inline]
3082 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3083 fmt::Display::fmt(self, f)
3084 }
3085}
3086
3087impl fmt::Display for BigInt {
3088 #[inline]
3089 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3090 let (abs, is_neg) = self.abs();
3091 f.pad_integral(!is_neg, "", &abs.to_string_unchecked(10))
3092 }
3093}
3094
3095impl fmt::Binary for BigInt {
3096 #[inline]
3097 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3098 let (abs, is_neg) = self.abs();
3099 f.pad_integral(!is_neg, "0b", &abs.to_string_unchecked(2))
3100 }
3101}
3102
3103impl fmt::Octal 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, "0o", &abs.to_string_unchecked(8))
3108 }
3109}
3110
3111impl fmt::LowerHex 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, "0x", &abs.to_string_unchecked(16))
3116 }
3117}
3118
3119impl fmt::UpperHex for BigInt {
3120 #[inline]
3121 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3122 let (abs, is_neg) = self.abs();
3123 let mut s: String = abs.to_string_unchecked(16);
3124 s.make_ascii_uppercase();
3125 f.pad_integral(!is_neg, "0x", &s)
3126 }
3127}
3128
3129// Boolean
3130#[wasm_bindgen]
3131extern "C" {
3132 #[wasm_bindgen(extends = Object, is_type_of = |v| v.as_bool().is_some(), typescript_type = "boolean")]
3133 #[derive(Clone, PartialEq, Eq)]
3134 pub type Boolean;
3135
3136 /// The `Boolean()` constructor creates an object wrapper for a boolean value.
3137 ///
3138 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)
3139 #[cfg(not(js_sys_unstable_apis))]
3140 #[wasm_bindgen(constructor)]
3141 #[deprecated(note = "recommended to use `Boolean::from` instead")]
3142 #[allow(deprecated)]
3143 pub fn new(value: &JsValue) -> Boolean;
3144
3145 /// The `valueOf()` method returns the primitive value of a `Boolean` object.
3146 ///
3147 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean/valueOf)
3148 #[wasm_bindgen(method, js_name = valueOf)]
3149 pub fn value_of(this: &Boolean) -> bool;
3150}
3151
3152impl UpcastFrom<bool> for Boolean {}
3153impl UpcastFrom<Boolean> for bool {}
3154
3155impl Boolean {
3156 /// Typed Boolean true constant.
3157 pub const TRUE: Boolean = unsafe { core::mem::transmute(JsValue::TRUE) };
3158
3159 /// Typed Boolean false constant.
3160 pub const FALSE: Boolean = unsafe { core::mem::transmute(JsValue::FALSE) };
3161}
3162
3163impl From<bool> for Boolean {
3164 #[inline]
3165 fn from(b: bool) -> Boolean {
3166 Boolean::unchecked_from_js(JsValue::from(b))
3167 }
3168}
3169
3170impl From<Boolean> for bool {
3171 #[inline]
3172 fn from(b: Boolean) -> bool {
3173 b.value_of()
3174 }
3175}
3176
3177impl PartialEq<bool> for Boolean {
3178 #[inline]
3179 fn eq(&self, other: &bool) -> bool {
3180 self.value_of() == *other
3181 }
3182}
3183
3184impl fmt::Debug for Boolean {
3185 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3186 fmt::Debug::fmt(&self.value_of(), f)
3187 }
3188}
3189
3190impl fmt::Display for Boolean {
3191 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3192 fmt::Display::fmt(&self.value_of(), f)
3193 }
3194}
3195
3196impl Default for Boolean {
3197 fn default() -> Self {
3198 Self::from(bool::default())
3199 }
3200}
3201
3202impl Not for &Boolean {
3203 type Output = Boolean;
3204
3205 #[inline]
3206 fn not(self) -> Self::Output {
3207 (!JsValue::as_ref(self)).into()
3208 }
3209}
3210
3211forward_deref_unop!(impl Not, not for Boolean);
3212
3213partialord_ord!(Boolean);
3214
3215// DataView
3216#[wasm_bindgen]
3217extern "C" {
3218 #[wasm_bindgen(extends = Object, typescript_type = "DataView")]
3219 #[derive(Clone, Debug, PartialEq, Eq)]
3220 pub type DataView;
3221
3222 /// The `DataView` view provides a low-level interface for reading and
3223 /// writing multiple number types in an `ArrayBuffer` irrespective of the
3224 /// platform's endianness.
3225 ///
3226 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView)
3227 #[wasm_bindgen(constructor)]
3228 pub fn new(buffer: &ArrayBuffer, byteOffset: usize, byteLength: usize) -> DataView;
3229
3230 /// The `DataView` view provides a low-level interface for reading and
3231 /// writing multiple number types in an `ArrayBuffer` irrespective of the
3232 /// platform's endianness.
3233 ///
3234 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView)
3235 #[wasm_bindgen(constructor)]
3236 pub fn new_with_shared_array_buffer(
3237 buffer: &SharedArrayBuffer,
3238 byteOffset: usize,
3239 byteLength: usize,
3240 ) -> DataView;
3241
3242 /// The ArrayBuffer referenced by this view. Fixed at construction time and thus read only.
3243 ///
3244 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/buffer)
3245 #[wasm_bindgen(method, getter)]
3246 pub fn buffer(this: &DataView) -> ArrayBuffer;
3247
3248 /// The length (in bytes) of this view from the start of its ArrayBuffer.
3249 /// Fixed at construction time and thus read only.
3250 ///
3251 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/byteLength)
3252 #[wasm_bindgen(method, getter, js_name = byteLength)]
3253 pub fn byte_length(this: &DataView) -> usize;
3254
3255 /// The offset (in bytes) of this view from the start of its ArrayBuffer.
3256 /// Fixed at construction time and thus read only.
3257 ///
3258 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/byteOffset)
3259 #[wasm_bindgen(method, getter, js_name = byteOffset)]
3260 pub fn byte_offset(this: &DataView) -> usize;
3261
3262 /// The `getInt8()` method gets a signed 8-bit integer (byte) at the
3263 /// specified byte offset from the start of the DataView.
3264 ///
3265 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt8)
3266 #[wasm_bindgen(method, js_name = getInt8)]
3267 pub fn get_int8(this: &DataView, byte_offset: usize) -> i8;
3268
3269 /// The `getUint8()` method gets a unsigned 8-bit integer (byte) at the specified
3270 /// byte offset from the start of the DataView.
3271 ///
3272 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint8)
3273 #[wasm_bindgen(method, js_name = getUint8)]
3274 pub fn get_uint8(this: &DataView, byte_offset: usize) -> u8;
3275
3276 /// The `getInt16()` method gets a signed 16-bit integer (short) at the specified
3277 /// byte offset from the start of the DataView.
3278 ///
3279 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt16)
3280 #[wasm_bindgen(method, js_name = getInt16)]
3281 pub fn get_int16(this: &DataView, byte_offset: usize) -> i16;
3282
3283 /// The `getInt16()` method gets a signed 16-bit integer (short) at the specified
3284 /// byte offset from the start of the DataView.
3285 ///
3286 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt16)
3287 #[wasm_bindgen(method, js_name = getInt16)]
3288 pub fn get_int16_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> i16;
3289
3290 /// The `getUint16()` method gets an unsigned 16-bit integer (unsigned short) at the specified
3291 /// byte offset from the start of the view.
3292 ///
3293 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint16)
3294 #[wasm_bindgen(method, js_name = getUint16)]
3295 pub fn get_uint16(this: &DataView, byte_offset: usize) -> u16;
3296
3297 /// The `getUint16()` method gets an unsigned 16-bit integer (unsigned short) at the specified
3298 /// byte offset from the start of the view.
3299 ///
3300 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint16)
3301 #[wasm_bindgen(method, js_name = getUint16)]
3302 pub fn get_uint16_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> u16;
3303
3304 /// The `getInt32()` method gets a signed 32-bit integer (long) at the specified
3305 /// byte offset from the start of the DataView.
3306 ///
3307 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt32)
3308 #[wasm_bindgen(method, js_name = getInt32)]
3309 pub fn get_int32(this: &DataView, byte_offset: usize) -> i32;
3310
3311 /// The `getInt32()` method gets a signed 32-bit integer (long) at the specified
3312 /// byte offset from the start of the DataView.
3313 ///
3314 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt32)
3315 #[wasm_bindgen(method, js_name = getInt32)]
3316 pub fn get_int32_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> i32;
3317
3318 /// The `getUint32()` method gets an unsigned 32-bit integer (unsigned long) at the specified
3319 /// byte offset from the start of the view.
3320 ///
3321 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint32)
3322 #[wasm_bindgen(method, js_name = getUint32)]
3323 pub fn get_uint32(this: &DataView, byte_offset: usize) -> u32;
3324
3325 /// The `getUint32()` method gets an unsigned 32-bit integer (unsigned long) at the specified
3326 /// byte offset from the start of the view.
3327 ///
3328 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint32)
3329 #[wasm_bindgen(method, js_name = getUint32)]
3330 pub fn get_uint32_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> u32;
3331
3332 /// The `getFloat32()` method gets a signed 32-bit float (float) at the specified
3333 /// byte offset from the start of the DataView.
3334 ///
3335 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat32)
3336 #[wasm_bindgen(method, js_name = getFloat32)]
3337 pub fn get_float32(this: &DataView, byte_offset: usize) -> f32;
3338
3339 /// The `getFloat32()` method gets a signed 32-bit float (float) at the specified
3340 /// byte offset from the start of the DataView.
3341 ///
3342 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat32)
3343 #[wasm_bindgen(method, js_name = getFloat32)]
3344 pub fn get_float32_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> f32;
3345
3346 /// The `getFloat64()` method gets a signed 64-bit float (double) at the specified
3347 /// byte offset from the start of the DataView.
3348 ///
3349 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat64)
3350 #[wasm_bindgen(method, js_name = getFloat64)]
3351 pub fn get_float64(this: &DataView, byte_offset: usize) -> f64;
3352
3353 /// The `getFloat64()` method gets a signed 64-bit float (double) at the specified
3354 /// byte offset from the start of the DataView.
3355 ///
3356 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat64)
3357 #[wasm_bindgen(method, js_name = getFloat64)]
3358 pub fn get_float64_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> f64;
3359
3360 /// The `setInt8()` method stores a signed 8-bit integer (byte) value at the
3361 /// specified byte offset from the start of the DataView.
3362 ///
3363 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt8)
3364 #[wasm_bindgen(method, js_name = setInt8)]
3365 pub fn set_int8(this: &DataView, byte_offset: usize, value: i8);
3366
3367 /// The `setUint8()` method stores an unsigned 8-bit integer (byte) value at the
3368 /// specified byte offset from the start of the DataView.
3369 ///
3370 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint8)
3371 #[wasm_bindgen(method, js_name = setUint8)]
3372 pub fn set_uint8(this: &DataView, byte_offset: usize, value: u8);
3373
3374 /// The `setInt16()` method stores a signed 16-bit integer (short) value at the
3375 /// specified byte offset from the start of the DataView.
3376 ///
3377 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt16)
3378 #[wasm_bindgen(method, js_name = setInt16)]
3379 pub fn set_int16(this: &DataView, byte_offset: usize, value: i16);
3380
3381 /// The `setInt16()` method stores a signed 16-bit integer (short) value at the
3382 /// specified byte offset from the start of the DataView.
3383 ///
3384 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt16)
3385 #[wasm_bindgen(method, js_name = setInt16)]
3386 pub fn set_int16_endian(this: &DataView, byte_offset: usize, value: i16, little_endian: bool);
3387
3388 /// The `setUint16()` method stores an unsigned 16-bit integer (unsigned short) value at the
3389 /// specified byte offset from the start of the DataView.
3390 ///
3391 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint16)
3392 #[wasm_bindgen(method, js_name = setUint16)]
3393 pub fn set_uint16(this: &DataView, byte_offset: usize, value: u16);
3394
3395 /// The `setUint16()` method stores an unsigned 16-bit integer (unsigned short) value at the
3396 /// specified byte offset from the start of the DataView.
3397 ///
3398 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint16)
3399 #[wasm_bindgen(method, js_name = setUint16)]
3400 pub fn set_uint16_endian(this: &DataView, byte_offset: usize, value: u16, little_endian: bool);
3401
3402 /// The `setInt32()` method stores a signed 32-bit integer (long) value at the
3403 /// specified byte offset from the start of the DataView.
3404 ///
3405 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt32)
3406 #[wasm_bindgen(method, js_name = setInt32)]
3407 pub fn set_int32(this: &DataView, byte_offset: usize, value: i32);
3408
3409 /// The `setInt32()` method stores a signed 32-bit integer (long) value at the
3410 /// specified byte offset from the start of the DataView.
3411 ///
3412 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt32)
3413 #[wasm_bindgen(method, js_name = setInt32)]
3414 pub fn set_int32_endian(this: &DataView, byte_offset: usize, value: i32, little_endian: bool);
3415
3416 /// The `setUint32()` method stores an unsigned 32-bit integer (unsigned long) value at the
3417 /// specified byte offset from the start of the DataView.
3418 ///
3419 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint32)
3420 #[wasm_bindgen(method, js_name = setUint32)]
3421 pub fn set_uint32(this: &DataView, byte_offset: usize, value: u32);
3422
3423 /// The `setUint32()` method stores an unsigned 32-bit integer (unsigned long) value at the
3424 /// specified byte offset from the start of the DataView.
3425 ///
3426 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint32)
3427 #[wasm_bindgen(method, js_name = setUint32)]
3428 pub fn set_uint32_endian(this: &DataView, byte_offset: usize, value: u32, little_endian: bool);
3429
3430 /// The `setFloat32()` method stores a signed 32-bit float (float) value at the
3431 /// specified byte offset from the start of the DataView.
3432 ///
3433 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat32)
3434 #[wasm_bindgen(method, js_name = setFloat32)]
3435 pub fn set_float32(this: &DataView, byte_offset: usize, value: f32);
3436
3437 /// The `setFloat32()` method stores a signed 32-bit float (float) value at the
3438 /// specified byte offset from the start of the DataView.
3439 ///
3440 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat32)
3441 #[wasm_bindgen(method, js_name = setFloat32)]
3442 pub fn set_float32_endian(this: &DataView, byte_offset: usize, value: f32, little_endian: bool);
3443
3444 /// The `setFloat64()` method stores a signed 64-bit float (double) value at the
3445 /// specified byte offset from the start of the DataView.
3446 ///
3447 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat64)
3448 #[wasm_bindgen(method, js_name = setFloat64)]
3449 pub fn set_float64(this: &DataView, byte_offset: usize, value: f64);
3450
3451 /// The `setFloat64()` method stores a signed 64-bit float (double) value at the
3452 /// specified byte offset from the start of the DataView.
3453 ///
3454 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat64)
3455 #[wasm_bindgen(method, js_name = setFloat64)]
3456 pub fn set_float64_endian(this: &DataView, byte_offset: usize, value: f64, little_endian: bool);
3457}
3458
3459// Error
3460#[wasm_bindgen]
3461extern "C" {
3462 #[wasm_bindgen(extends = Object, typescript_type = "Error")]
3463 #[derive(Clone, Debug, PartialEq, Eq)]
3464 pub type Error;
3465
3466 /// The Error constructor creates an error object.
3467 /// Instances of Error objects are thrown when runtime errors occur.
3468 /// The Error object can also be used as a base object for user-defined exceptions.
3469 /// See below for standard built-in error types.
3470 ///
3471 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)
3472 #[wasm_bindgen(constructor)]
3473 pub fn new(message: &str) -> Error;
3474 #[wasm_bindgen(constructor)]
3475 pub fn new_with_options(message: &str, options: &Object) -> Error;
3476
3477 /// The cause property is the underlying cause of the error.
3478 /// Usually this is used to add context to re-thrown errors.
3479 ///
3480 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error#differentiate_between_similar_errors)
3481 #[wasm_bindgen(method, getter)]
3482 pub fn cause(this: &Error) -> JsValue;
3483 #[wasm_bindgen(method, setter)]
3484 pub fn set_cause(this: &Error, cause: &JsValue);
3485
3486 /// The message property is a human-readable description of the error.
3487 ///
3488 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/message)
3489 #[wasm_bindgen(method, getter)]
3490 pub fn message(this: &Error) -> JsString;
3491 #[wasm_bindgen(method, setter)]
3492 pub fn set_message(this: &Error, message: &str);
3493
3494 /// The name property represents a name for the type of error. The initial value is "Error".
3495 ///
3496 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/name)
3497 #[wasm_bindgen(method, getter)]
3498 pub fn name(this: &Error) -> JsString;
3499 #[wasm_bindgen(method, setter)]
3500 pub fn set_name(this: &Error, name: &str);
3501
3502 /// The `toString()` method returns a string representing the specified Error object
3503 ///
3504 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/toString)
3505 #[cfg(not(js_sys_unstable_apis))]
3506 #[wasm_bindgen(method, js_name = toString)]
3507 pub fn to_string(this: &Error) -> JsString;
3508}
3509
3510partialord_ord!(JsString);
3511
3512// EvalError
3513#[wasm_bindgen]
3514extern "C" {
3515 #[wasm_bindgen(extends = Object, extends = Error, typescript_type = "EvalError")]
3516 #[derive(Clone, Debug, PartialEq, Eq)]
3517 pub type EvalError;
3518
3519 /// The `EvalError` object indicates an error regarding the global eval() function. This
3520 /// exception is not thrown by JavaScript anymore, however the EvalError object remains for
3521 /// compatibility.
3522 ///
3523 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/EvalError)
3524 #[wasm_bindgen(constructor)]
3525 pub fn new(message: &str) -> EvalError;
3526}
3527
3528#[wasm_bindgen]
3529extern "C" {
3530 #[wasm_bindgen(extends = Object, is_type_of = JsValue::is_function, no_upcast, typescript_type = "Function")]
3531 #[derive(Clone, Debug, PartialEq, Eq)]
3532 /// `Function` represents any generic Function in JS, by treating all arguments as `JsValue`.
3533 ///
3534 /// It takes a generic parameter of phantom type `fn (Arg1, ..., Argn) -> Ret` which
3535 /// is used to type the JS function. For example, `Function<fn () -> Number>` represents
3536 /// a function taking no arguments that returns a number.
3537 ///
3538 /// The 8 generic argument parameters (`Arg1` through `Arg8`) are the argument
3539 /// types. Arguments not provided enable strict arity checking at compile time.
3540 ///
3541 /// A void function is represented by `fn (Arg) -> Undefined`, and **not** the `()` unit
3542 /// type. This is because generics must be based on JS values in the JS generic type system.
3543 ///
3544 /// _The default without any parameters is as a void function - no arguments, `Undefined` return._
3545 ///
3546 /// _The default generic for `Function` is `fn (JsValue, JsValue, ...) -> JsValue`,
3547 /// representing any function, since all functions safely upcast into this function._
3548 ///
3549 /// ### Arity Enforcement
3550 ///
3551 /// It is not possible to use `call4` or `bind4` on a function that does not have
3552 /// at least 4 arguments — the compiler will reject this because only arguments that
3553 /// are not `None` support the trait bound for `ErasableGeneric`.
3554 ///
3555 /// ### Examples
3556 ///
3557 /// ```ignore
3558 /// // A function taking no args, returning Number
3559 /// let f: Function<Number> = get_some_fn();
3560 ///
3561 /// // A function taking (String, Number) and returning Boolean
3562 /// let f: Function<Boolean, String, Number> = get_some_fn();
3563 ///
3564 /// ### Upcasting
3565 ///
3566 /// To pass a typed `Function` where a different generic Function is expected, `upcast()` may be used
3567 /// to convert into any generic `Function` at zero cost with type-safety.
3568 ///
3569 /// MDN documentation (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
3570 pub type Function<
3571 T: JsFunction = fn(
3572 JsValue,
3573 JsValue,
3574 JsValue,
3575 JsValue,
3576 JsValue,
3577 JsValue,
3578 JsValue,
3579 JsValue,
3580 ) -> JsValue,
3581 >;
3582}
3583
3584#[wasm_bindgen]
3585extern "C" {
3586 /// The `Function` constructor creates a new `Function` object. Calling the
3587 /// constructor directly can create functions dynamically, but suffers from
3588 /// security and similar (but far less significant) performance issues
3589 /// similar to `eval`. However, unlike `eval`, the `Function` constructor
3590 /// allows executing code in the global scope, prompting better programming
3591 /// habits and allowing for more efficient code minification.
3592 ///
3593 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
3594 #[cfg(all(feature = "unsafe-eval", not(js_sys_unstable_apis)))]
3595 #[wasm_bindgen(constructor)]
3596 pub fn new_with_args(args: &str, body: &str) -> Function;
3597
3598 /// The `Function` constructor creates a new `Function` object. Calling the
3599 /// constructor directly can create functions dynamically, but suffers from
3600 /// security and similar (but far less significant) performance issues
3601 /// similar to `eval`. However, unlike `eval`, the `Function` constructor
3602 /// allows executing code in the global scope, prompting better programming
3603 /// habits and allowing for more efficient code minification.
3604 ///
3605 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
3606 #[cfg(all(feature = "unsafe-eval", js_sys_unstable_apis))]
3607 #[wasm_bindgen(constructor)]
3608 pub fn new_with_args<T: JsFunction = fn() -> JsValue>(args: &str, body: &str) -> Function<T>;
3609
3610 // Next major: deprecate
3611 /// The `Function` constructor creates a new `Function` object. Calling the
3612 /// constructor directly can create functions dynamically, but suffers from
3613 /// security and similar (but far less significant) performance issues
3614 /// similar to `eval`. However, unlike `eval`, the `Function` constructor
3615 /// allows executing code in the global scope, prompting better programming
3616 /// habits and allowing for more efficient code minification.
3617 ///
3618 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
3619 #[cfg(feature = "unsafe-eval")]
3620 #[wasm_bindgen(constructor)]
3621 pub fn new_with_args_typed<T: JsFunction = fn() -> JsValue>(
3622 args: &str,
3623 body: &str,
3624 ) -> Function<T>;
3625
3626 /// The `Function` constructor creates a new `Function` object. Calling the
3627 /// constructor directly can create functions dynamically, but suffers from
3628 /// security and similar (but far less significant) performance issues
3629 /// similar to `eval`. However, unlike `eval`, the `Function` constructor
3630 /// allows executing code in the global scope, prompting better programming
3631 /// habits and allowing for more efficient code minification.
3632 ///
3633 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
3634 #[cfg(all(feature = "unsafe-eval", not(js_sys_unstable_apis)))]
3635 #[wasm_bindgen(constructor)]
3636 pub fn new_no_args(body: &str) -> Function;
3637
3638 /// The `Function` constructor creates a new `Function` object. Calling the
3639 /// constructor directly can create functions dynamically, but suffers from
3640 /// security and similar (but far less significant) performance issues
3641 /// similar to `eval`. However, unlike `eval`, the `Function` constructor
3642 /// allows executing code in the global scope, prompting better programming
3643 /// habits and allowing for more efficient code minification.
3644 ///
3645 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
3646 #[cfg(all(feature = "unsafe-eval", js_sys_unstable_apis))]
3647 #[wasm_bindgen(constructor)]
3648 pub fn new_no_args<T: JsFunction = fn() -> JsValue>(body: &str) -> Function<T>;
3649
3650 // Next major: deprecate
3651 /// The `Function` constructor creates a new `Function` object.
3652 ///
3653 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
3654 #[cfg(feature = "unsafe-eval")]
3655 #[wasm_bindgen(constructor)]
3656 pub fn new_no_args_typed<T: JsFunction = fn() -> JsValue>(body: &str) -> Function<T>;
3657
3658 /// The `apply()` method calls a function with a given this value, and arguments provided as an array
3659 /// (or an array-like object).
3660 ///
3661 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply)
3662 #[wasm_bindgen(method, catch)]
3663 pub fn apply<T: JsFunction = fn() -> JsValue>(
3664 this: &Function<T>,
3665 context: &JsValue,
3666 args: &Array,
3667 ) -> Result<<T as JsFunction>::Ret, JsValue>;
3668
3669 // Next major: Deprecate, and separately provide provide impl
3670 /// The `call()` method calls a function with a given this value and
3671 /// arguments provided individually.
3672 ///
3673 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3674 ///
3675 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3676 #[wasm_bindgen(method, catch, js_name = call)]
3677 pub fn call0<Ret: JsGeneric, F: JsFunction<Ret = Ret> = fn() -> JsValue>(
3678 this: &Function<F>,
3679 context: &JsValue,
3680 ) -> Result<Ret, JsValue>;
3681
3682 // Next major: Deprecate, and separately provide provide impl
3683 /// The `call()` method calls a function with a given this value and
3684 /// arguments provided individually.
3685 ///
3686 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3687 ///
3688 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3689 #[wasm_bindgen(method, catch, js_name = call)]
3690 pub fn call1<
3691 Ret: JsGeneric,
3692 Arg1: JsGeneric,
3693 F: JsFunction<Ret = Ret> + JsFunction1<Arg1 = Arg1> = fn(JsValue) -> JsValue,
3694 >(
3695 this: &Function<F>,
3696 context: &JsValue,
3697 arg1: &Arg1,
3698 ) -> Result<Ret, JsValue>;
3699
3700 // Next major: Deprecate, and separately provide provide impl
3701 /// The `call()` method calls a function with a given this value and
3702 /// arguments provided individually.
3703 ///
3704 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3705 ///
3706 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3707 #[wasm_bindgen(method, catch, js_name = call)]
3708 pub fn call2<
3709 Ret: JsGeneric,
3710 Arg1: JsGeneric,
3711 Arg2: JsGeneric,
3712 F: JsFunction<Ret = Ret> + JsFunction1<Arg1 = Arg1> + JsFunction2<Arg2 = Arg2> = fn(
3713 JsValue,
3714 JsValue,
3715 ) -> JsValue,
3716 >(
3717 this: &Function<F>,
3718 context: &JsValue,
3719 arg1: &Arg1,
3720 arg2: &Arg2,
3721 ) -> Result<Ret, JsValue>;
3722
3723 // Next major: Deprecate, and separately provide provide impl
3724 /// The `call()` method calls a function with a given this value and
3725 /// arguments provided individually.
3726 ///
3727 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3728 ///
3729 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3730 #[wasm_bindgen(method, catch, js_name = call)]
3731 pub fn call3<
3732 Ret: JsGeneric,
3733 Arg1: JsGeneric,
3734 Arg2: JsGeneric,
3735 Arg3: JsGeneric,
3736 F: JsFunction<Ret = Ret> + JsFunction3<Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3> = fn(
3737 JsValue,
3738 JsValue,
3739 JsValue,
3740 ) -> JsValue,
3741 >(
3742 this: &Function<F>,
3743 context: &JsValue,
3744 arg1: &Arg1,
3745 arg2: &Arg2,
3746 arg3: &Arg3,
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 call4<
3758 Ret: JsGeneric,
3759 Arg1: JsGeneric,
3760 Arg2: JsGeneric,
3761 Arg3: JsGeneric,
3762 Arg4: JsGeneric,
3763 F: JsFunction<Ret = Ret> + JsFunction4<Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3, Arg4 = Arg4> = fn(
3764 JsValue,
3765 JsValue,
3766 JsValue,
3767 JsValue,
3768 ) -> JsValue,
3769 >(
3770 this: &Function<F>,
3771 context: &JsValue,
3772 arg1: &Arg1,
3773 arg2: &Arg2,
3774 arg3: &Arg3,
3775 arg4: &Arg4,
3776 ) -> Result<Ret, JsValue>;
3777
3778 // Next major: Deprecate, and separately provide provide impl
3779 /// The `call()` method calls a function with a given this value and
3780 /// arguments provided individually.
3781 ///
3782 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3783 ///
3784 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3785 #[wasm_bindgen(method, catch, js_name = call)]
3786 pub fn call5<
3787 Ret: JsGeneric,
3788 Arg1: JsGeneric,
3789 Arg2: JsGeneric,
3790 Arg3: JsGeneric,
3791 Arg4: JsGeneric,
3792 Arg5: JsGeneric,
3793 F: JsFunction<Ret = Ret>
3794 + JsFunction5<Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3, Arg4 = Arg4, Arg5 = Arg5> = fn(
3795 JsValue,
3796 JsValue,
3797 JsValue,
3798 JsValue,
3799 JsValue,
3800 ) -> JsValue,
3801 >(
3802 this: &Function<F>,
3803 context: &JsValue,
3804 arg1: &Arg1,
3805 arg2: &Arg2,
3806 arg3: &Arg3,
3807 arg4: &Arg4,
3808 arg5: &Arg5,
3809 ) -> Result<Ret, JsValue>;
3810
3811 // Next major: Deprecate, and separately provide provide impl
3812 /// The `call()` method calls a function with a given this value and
3813 /// arguments provided individually.
3814 ///
3815 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3816 ///
3817 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3818 #[wasm_bindgen(method, catch, js_name = call)]
3819 pub fn call6<
3820 Ret: JsGeneric,
3821 Arg1: JsGeneric,
3822 Arg2: JsGeneric,
3823 Arg3: JsGeneric,
3824 Arg4: JsGeneric,
3825 Arg5: JsGeneric,
3826 Arg6: JsGeneric,
3827 F: JsFunction<Ret = Ret>
3828 + JsFunction6<
3829 Arg1 = Arg1,
3830 Arg2 = Arg2,
3831 Arg3 = Arg3,
3832 Arg4 = Arg4,
3833 Arg5 = Arg5,
3834 Arg6 = Arg6,
3835 > = fn(JsValue, JsValue, JsValue, JsValue, JsValue, JsValue) -> JsValue,
3836 >(
3837 this: &Function<F>,
3838 context: &JsValue,
3839 arg1: &Arg1,
3840 arg2: &Arg2,
3841 arg3: &Arg3,
3842 arg4: &Arg4,
3843 arg5: &Arg5,
3844 arg6: &Arg6,
3845 ) -> Result<Ret, JsValue>;
3846
3847 // Next major: Deprecate, and separately provide provide impl
3848 /// The `call()` method calls a function with a given this value and
3849 /// arguments provided individually.
3850 ///
3851 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3852 ///
3853 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3854 #[wasm_bindgen(method, catch, js_name = call)]
3855 pub fn call7<
3856 Ret: JsGeneric,
3857 Arg1: JsGeneric,
3858 Arg2: JsGeneric,
3859 Arg3: JsGeneric,
3860 Arg4: JsGeneric,
3861 Arg5: JsGeneric,
3862 Arg6: JsGeneric,
3863 Arg7: JsGeneric,
3864 F: JsFunction<Ret = Ret>
3865 + JsFunction7<
3866 Arg1 = Arg1,
3867 Arg2 = Arg2,
3868 Arg3 = Arg3,
3869 Arg4 = Arg4,
3870 Arg5 = Arg5,
3871 Arg6 = Arg6,
3872 Arg7 = Arg7,
3873 > = fn(
3874 JsValue,
3875 JsValue,
3876 JsValue,
3877 JsValue,
3878 JsValue,
3879 JsValue,
3880 JsValue,
3881 ) -> JsValue,
3882 >(
3883 this: &Function<F>,
3884 context: &JsValue,
3885 arg1: &Arg1,
3886 arg2: &Arg2,
3887 arg3: &Arg3,
3888 arg4: &Arg4,
3889 arg5: &Arg5,
3890 arg6: &Arg6,
3891 arg7: &Arg7,
3892 ) -> Result<Ret, JsValue>;
3893
3894 // Next major: Deprecate, and separately provide provide impl
3895 /// The `call()` method calls a function with a given this value and
3896 /// arguments provided individually.
3897 ///
3898 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3899 ///
3900 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3901 #[wasm_bindgen(method, catch, js_name = call)]
3902 pub fn call8<
3903 Ret: JsGeneric,
3904 Arg1: JsGeneric,
3905 Arg2: JsGeneric,
3906 Arg3: JsGeneric,
3907 Arg4: JsGeneric,
3908 Arg5: JsGeneric,
3909 Arg6: JsGeneric,
3910 Arg7: JsGeneric,
3911 Arg8: JsGeneric,
3912 F: JsFunction8<
3913 Ret = Ret,
3914 Arg1 = Arg1,
3915 Arg2 = Arg2,
3916 Arg3 = Arg3,
3917 Arg4 = Arg4,
3918 Arg5 = Arg5,
3919 Arg6 = Arg6,
3920 Arg7 = Arg7,
3921 Arg8 = Arg8,
3922 > = fn(
3923 JsValue,
3924 JsValue,
3925 JsValue,
3926 JsValue,
3927 JsValue,
3928 JsValue,
3929 JsValue,
3930 JsValue,
3931 ) -> JsValue,
3932 >(
3933 this: &Function<F>,
3934 context: &JsValue,
3935 arg1: &Arg1,
3936 arg2: &Arg2,
3937 arg3: &Arg3,
3938 arg4: &Arg4,
3939 arg5: &Arg5,
3940 arg6: &Arg6,
3941 arg7: &Arg7,
3942 arg8: &Arg8,
3943 ) -> Result<Ret, JsValue>;
3944
3945 /// The `call()` method calls a function with a given this value and
3946 /// arguments provided individually.
3947 ///
3948 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3949 ///
3950 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3951 #[deprecated]
3952 #[allow(deprecated)]
3953 #[wasm_bindgen(method, catch, js_name = call)]
3954 pub fn call9<
3955 Ret: JsGeneric,
3956 Arg1: JsGeneric,
3957 Arg2: JsGeneric,
3958 Arg3: JsGeneric,
3959 Arg4: JsGeneric,
3960 Arg5: JsGeneric,
3961 Arg6: JsGeneric,
3962 Arg7: JsGeneric,
3963 Arg8: JsGeneric,
3964 F: JsFunction8<
3965 Ret = Ret,
3966 Arg1 = Arg1,
3967 Arg2 = Arg2,
3968 Arg3 = Arg3,
3969 Arg4 = Arg4,
3970 Arg5 = Arg5,
3971 Arg6 = Arg6,
3972 Arg7 = Arg7,
3973 Arg8 = Arg8,
3974 > = fn(
3975 JsValue,
3976 JsValue,
3977 JsValue,
3978 JsValue,
3979 JsValue,
3980 JsValue,
3981 JsValue,
3982 JsValue,
3983 ) -> JsValue,
3984 >(
3985 this: &Function<F>,
3986 context: &JsValue,
3987 arg1: &Arg1,
3988 arg2: &Arg2,
3989 arg3: &Arg3,
3990 arg4: &Arg4,
3991 arg5: &Arg5,
3992 arg6: &Arg6,
3993 arg7: &Arg7,
3994 arg8: &Arg8,
3995 arg9: &JsValue,
3996 ) -> Result<Ret, JsValue>;
3997
3998 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
3999 /// with a given sequence of arguments preceding any provided when the new function is called.
4000 ///
4001 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4002 #[cfg(not(js_sys_unstable_apis))]
4003 #[deprecated(note = "Use `Function::bind0` instead.")]
4004 #[allow(deprecated)]
4005 #[wasm_bindgen(method, js_name = bind)]
4006 pub fn bind<T: JsFunction = fn() -> JsValue>(
4007 this: &Function<T>,
4008 context: &JsValue,
4009 ) -> Function<T>;
4010
4011 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4012 /// with a given sequence of arguments preceding any provided when the new function is called.
4013 ///
4014 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4015 ///
4016 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4017 #[wasm_bindgen(method, js_name = bind)]
4018 pub fn bind0<T: JsFunction = fn() -> JsValue>(
4019 this: &Function<T>,
4020 context: &JsValue,
4021 ) -> Function<T>;
4022
4023 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4024 /// with a given sequence of arguments preceding any provided when the new function is called.
4025 ///
4026 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4027 ///
4028 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4029 #[wasm_bindgen(method, js_name = bind)]
4030 pub fn bind1<
4031 Ret: JsGeneric,
4032 Arg1: JsGeneric,
4033 F: JsFunction1<Ret = Ret, Arg1 = Arg1> = fn(JsValue) -> JsValue,
4034 >(
4035 this: &Function<F>,
4036 context: &JsValue,
4037 arg1: &Arg1,
4038 ) -> Function<<F as JsFunction1>::Bind1>;
4039
4040 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4041 /// with a given sequence of arguments preceding any provided when the new function is called.
4042 ///
4043 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4044 ///
4045 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4046 #[wasm_bindgen(method, js_name = bind)]
4047 pub fn bind2<
4048 Ret: JsGeneric,
4049 Arg1: JsGeneric,
4050 Arg2: JsGeneric,
4051 F: JsFunction2<Ret = Ret, Arg1 = Arg1, Arg2 = Arg2> = fn(JsValue, JsValue) -> JsValue,
4052 >(
4053 this: &Function<F>,
4054 context: &JsValue,
4055 arg1: &Arg1,
4056 arg2: &Arg2,
4057 ) -> Function<<F as JsFunction2>::Bind2>;
4058
4059 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4060 /// with a given sequence of arguments preceding any provided when the new function is called.
4061 ///
4062 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4063 ///
4064 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4065 #[wasm_bindgen(method, js_name = bind)]
4066 pub fn bind3<
4067 Ret: JsGeneric,
4068 Arg1: JsGeneric,
4069 Arg2: JsGeneric,
4070 Arg3: JsGeneric,
4071 F: JsFunction3<Ret = Ret, Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3> = fn(
4072 JsValue,
4073 JsValue,
4074 JsValue,
4075 ) -> JsValue,
4076 >(
4077 this: &Function<F>,
4078 context: &JsValue,
4079 arg1: &Arg1,
4080 arg2: &Arg2,
4081 arg3: &Arg3,
4082 ) -> Function<<F as JsFunction3>::Bind3>;
4083
4084 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4085 /// with a given sequence of arguments preceding any provided when the new function is called.
4086 ///
4087 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4088 ///
4089 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4090 #[wasm_bindgen(method, js_name = bind)]
4091 pub fn bind4<
4092 Ret: JsGeneric,
4093 Arg1: JsGeneric,
4094 Arg2: JsGeneric,
4095 Arg3: JsGeneric,
4096 Arg4: JsGeneric,
4097 F: JsFunction4<Ret = Ret, Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3, Arg4 = Arg4> = fn(
4098 JsValue,
4099 JsValue,
4100 JsValue,
4101 JsValue,
4102 ) -> JsValue,
4103 >(
4104 this: &Function<F>,
4105 context: &JsValue,
4106 arg1: &Arg1,
4107 arg2: &Arg2,
4108 arg3: &Arg3,
4109 arg4: &Arg4,
4110 ) -> Function<<F as JsFunction4>::Bind4>;
4111
4112 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4113 /// with a given sequence of arguments preceding any provided when the new function is called.
4114 ///
4115 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4116 ///
4117 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4118 #[wasm_bindgen(method, js_name = bind)]
4119 pub fn bind5<
4120 Ret: JsGeneric,
4121 Arg1: JsGeneric,
4122 Arg2: JsGeneric,
4123 Arg3: JsGeneric,
4124 Arg4: JsGeneric,
4125 Arg5: JsGeneric,
4126 F: JsFunction5<Ret = Ret, Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3, Arg4 = Arg4, Arg5 = Arg5> = fn(
4127 JsValue,
4128 JsValue,
4129 JsValue,
4130 JsValue,
4131 JsValue,
4132 ) -> JsValue,
4133 >(
4134 this: &Function<F>,
4135 context: &JsValue,
4136 arg1: &Arg1,
4137 arg2: &Arg2,
4138 arg3: &Arg3,
4139 arg4: &Arg4,
4140 arg5: &Arg5,
4141 ) -> Function<<F as JsFunction5>::Bind5>;
4142
4143 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4144 /// with a given sequence of arguments preceding any provided when the new function is called.
4145 ///
4146 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4147 ///
4148 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4149 #[wasm_bindgen(method, js_name = bind)]
4150 pub fn bind6<
4151 Ret: JsGeneric,
4152 Arg1: JsGeneric,
4153 Arg2: JsGeneric,
4154 Arg3: JsGeneric,
4155 Arg4: JsGeneric,
4156 Arg5: JsGeneric,
4157 Arg6: JsGeneric,
4158 F: JsFunction6<
4159 Ret = Ret,
4160 Arg1 = Arg1,
4161 Arg2 = Arg2,
4162 Arg3 = Arg3,
4163 Arg4 = Arg4,
4164 Arg5 = Arg5,
4165 Arg6 = Arg6,
4166 > = fn(JsValue, JsValue, JsValue, JsValue, JsValue, JsValue) -> JsValue,
4167 >(
4168 this: &Function<F>,
4169 context: &JsValue,
4170 arg1: &Arg1,
4171 arg2: &Arg2,
4172 arg3: &Arg3,
4173 arg4: &Arg4,
4174 arg5: &Arg5,
4175 arg6: &Arg6,
4176 ) -> Function<<F as JsFunction6>::Bind6>;
4177
4178 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4179 /// with a given sequence of arguments preceding any provided when the new function is called.
4180 ///
4181 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4182 ///
4183 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4184 #[wasm_bindgen(method, js_name = bind)]
4185 pub fn bind7<
4186 Ret: JsGeneric,
4187 Arg1: JsGeneric,
4188 Arg2: JsGeneric,
4189 Arg3: JsGeneric,
4190 Arg4: JsGeneric,
4191 Arg5: JsGeneric,
4192 Arg6: JsGeneric,
4193 Arg7: JsGeneric,
4194 F: JsFunction7<
4195 Ret = Ret,
4196 Arg1 = Arg1,
4197 Arg2 = Arg2,
4198 Arg3 = Arg3,
4199 Arg4 = Arg4,
4200 Arg5 = Arg5,
4201 Arg6 = Arg6,
4202 Arg7 = Arg7,
4203 > = fn(
4204 JsValue,
4205 JsValue,
4206 JsValue,
4207 JsValue,
4208 JsValue,
4209 JsValue,
4210 JsValue,
4211 ) -> JsValue,
4212 >(
4213 this: &Function<F>,
4214 context: &JsValue,
4215 arg1: &Arg1,
4216 arg2: &Arg2,
4217 arg3: &Arg3,
4218 arg4: &Arg4,
4219 arg5: &Arg5,
4220 arg6: &Arg6,
4221 arg7: &Arg7,
4222 ) -> Function<<F as JsFunction7>::Bind7>;
4223
4224 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4225 /// with a given sequence of arguments preceding any provided when the new function is called.
4226 ///
4227 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4228 ///
4229 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4230 #[wasm_bindgen(method, js_name = bind)]
4231 pub fn bind8<
4232 Ret: JsGeneric,
4233 Arg1: JsGeneric,
4234 Arg2: JsGeneric,
4235 Arg3: JsGeneric,
4236 Arg4: JsGeneric,
4237 Arg5: JsGeneric,
4238 Arg6: JsGeneric,
4239 Arg7: JsGeneric,
4240 Arg8: JsGeneric,
4241 F: JsFunction8<
4242 Ret = Ret,
4243 Arg1 = Arg1,
4244 Arg2 = Arg2,
4245 Arg3 = Arg3,
4246 Arg4 = Arg4,
4247 Arg5 = Arg5,
4248 Arg6 = Arg6,
4249 Arg7 = Arg7,
4250 Arg8 = Arg8,
4251 > = fn(
4252 JsValue,
4253 JsValue,
4254 JsValue,
4255 JsValue,
4256 JsValue,
4257 JsValue,
4258 JsValue,
4259 JsValue,
4260 ) -> JsValue,
4261 >(
4262 this: &Function<F>,
4263 context: &JsValue,
4264 arg1: &Arg1,
4265 arg2: &Arg2,
4266 arg3: &Arg3,
4267 arg4: &Arg4,
4268 arg5: &Arg5,
4269 arg6: &Arg6,
4270 arg7: &Arg7,
4271 arg8: &Arg8,
4272 ) -> Function<<F as JsFunction8>::Bind8>;
4273
4274 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4275 /// with a given sequence of arguments preceding any provided when the new function is called.
4276 ///
4277 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4278 ///
4279 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4280 #[deprecated]
4281 #[allow(deprecated)]
4282 #[wasm_bindgen(method, js_name = bind)]
4283 pub fn bind9<
4284 Ret: JsGeneric,
4285 Arg1: JsGeneric,
4286 Arg2: JsGeneric,
4287 Arg3: JsGeneric,
4288 Arg4: JsGeneric,
4289 Arg5: JsGeneric,
4290 Arg6: JsGeneric,
4291 Arg7: JsGeneric,
4292 Arg8: JsGeneric,
4293 F: JsFunction8<
4294 Ret = Ret,
4295 Arg1 = Arg1,
4296 Arg2 = Arg2,
4297 Arg3 = Arg3,
4298 Arg4 = Arg4,
4299 Arg5 = Arg5,
4300 Arg6 = Arg6,
4301 Arg7 = Arg7,
4302 Arg8 = Arg8,
4303 > = fn(
4304 JsValue,
4305 JsValue,
4306 JsValue,
4307 JsValue,
4308 JsValue,
4309 JsValue,
4310 JsValue,
4311 JsValue,
4312 ) -> JsValue,
4313 >(
4314 this: &Function<F>,
4315 context: &JsValue,
4316 arg1: &Arg1,
4317 arg2: &Arg2,
4318 arg3: &Arg3,
4319 arg4: &Arg4,
4320 arg5: &Arg5,
4321 arg6: &Arg6,
4322 arg7: &Arg7,
4323 arg8: &Arg8,
4324 arg9: &JsValue,
4325 ) -> Function<fn() -> Ret>;
4326
4327 /// The length property indicates the number of arguments expected by the function.
4328 ///
4329 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/length)
4330 #[wasm_bindgen(method, getter)]
4331 pub fn length<T: JsFunction = fn() -> JsValue>(this: &Function<T>) -> u32;
4332
4333 /// A Function object's read-only name property indicates the function's
4334 /// name as specified when it was created or "anonymous" for functions
4335 /// created anonymously.
4336 ///
4337 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name)
4338 #[wasm_bindgen(method, getter)]
4339 pub fn name<T: JsFunction = fn() -> JsValue>(this: &Function<T>) -> JsString;
4340
4341 /// The `toString()` method returns a string representing the source code of the function.
4342 ///
4343 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/toString)
4344 #[cfg(not(js_sys_unstable_apis))]
4345 #[wasm_bindgen(method, js_name = toString)]
4346 pub fn to_string<T: JsFunction = fn() -> JsValue>(this: &Function<T>) -> JsString;
4347}
4348
4349// Basic UpcastFrom impls for Function<T>
4350impl<T: JsFunction> UpcastFrom<Function<T>> for JsValue {}
4351impl<T: JsFunction> UpcastFrom<Function<T>> for JsOption<JsValue> {}
4352impl<T: JsFunction> UpcastFrom<Function<T>> for Object {}
4353impl<T: JsFunction> UpcastFrom<Function<T>> for JsOption<Object> {}
4354
4355// Blanket trait for Function upcast
4356// Function<T> upcasts to Function<U> when the underlying fn type T upcasts to U.
4357// The fn signature UpcastFrom impls already encode correct variance (covariant return, contravariant args).
4358impl<T: JsFunction, U: JsFunction> UpcastFrom<Function<T>> for Function<U> where U: UpcastFrom<T> {}
4359
4360// len() method for Function<T> using JsFunction::ARITY
4361impl<T: JsFunction> Function<T> {
4362 /// Get the static arity of this function type.
4363 #[allow(clippy::len_without_is_empty)]
4364 pub fn len(&self) -> usize {
4365 T::ARITY
4366 }
4367
4368 /// Returns true if this is a zero-argument function.
4369 pub fn is_empty(&self) -> bool {
4370 T::ARITY == 0
4371 }
4372}
4373
4374// Base traits for function signature types.
4375pub trait JsFunction {
4376 type Ret: JsGeneric;
4377 const ARITY: usize;
4378}
4379
4380pub trait JsFunction1: JsFunction {
4381 type Arg1: JsGeneric;
4382 type Bind1: JsFunction;
4383}
4384pub trait JsFunction2: JsFunction1 {
4385 type Arg2: JsGeneric;
4386 type Bind2: JsFunction;
4387}
4388pub trait JsFunction3: JsFunction2 {
4389 type Arg3: JsGeneric;
4390 type Bind3: JsFunction;
4391}
4392pub trait JsFunction4: JsFunction3 {
4393 type Arg4: JsGeneric;
4394 type Bind4: JsFunction;
4395}
4396pub trait JsFunction5: JsFunction4 {
4397 type Arg5: JsGeneric;
4398 type Bind5: JsFunction;
4399}
4400pub trait JsFunction6: JsFunction5 {
4401 type Arg6: JsGeneric;
4402 type Bind6: JsFunction;
4403}
4404pub trait JsFunction7: JsFunction6 {
4405 type Arg7: JsGeneric;
4406 type Bind7: JsFunction;
4407}
4408pub trait JsFunction8: JsFunction7 {
4409 type Arg8: JsGeneric;
4410 type Bind8: JsFunction;
4411}
4412
4413// Manual impl for fn() -> R
4414impl<Ret: JsGeneric> JsFunction for fn() -> Ret {
4415 type Ret = Ret;
4416 const ARITY: usize = 0;
4417}
4418
4419macro_rules! impl_fn {
4420 () => {
4421 impl_fn!(@impl 1 [Arg1] [
4422 JsFunction1 Arg1 Bind1 {fn() -> Ret}
4423 ]);
4424 impl_fn!(@impl 2 [Arg1 Arg2] [
4425 JsFunction1 Arg1 Bind1 {fn(Arg2) -> Ret}
4426 JsFunction2 Arg2 Bind2 {fn() -> Ret}
4427 ]);
4428 impl_fn!(@impl 3 [Arg1 Arg2 Arg3] [
4429 JsFunction1 Arg1 Bind1 {fn(Arg2, Arg3) -> Ret}
4430 JsFunction2 Arg2 Bind2 {fn(Arg3) -> Ret}
4431 JsFunction3 Arg3 Bind3 {fn() -> Ret}
4432 ]);
4433 impl_fn!(@impl 4 [Arg1 Arg2 Arg3 Arg4] [
4434 JsFunction1 Arg1 Bind1 {fn(Arg2, Arg3, Arg4) -> Ret}
4435 JsFunction2 Arg2 Bind2 {fn(Arg3, Arg4) -> Ret}
4436 JsFunction3 Arg3 Bind3 {fn(Arg4) -> Ret}
4437 JsFunction4 Arg4 Bind4 {fn() -> Ret}
4438 ]);
4439 impl_fn!(@impl 5 [Arg1 Arg2 Arg3 Arg4 Arg5] [
4440 JsFunction1 Arg1 Bind1 {fn(Arg2, Arg3, Arg4, Arg5) -> Ret}
4441 JsFunction2 Arg2 Bind2 {fn(Arg3, Arg4, Arg5) -> Ret}
4442 JsFunction3 Arg3 Bind3 {fn(Arg4, Arg5) -> Ret}
4443 JsFunction4 Arg4 Bind4 {fn(Arg5) -> Ret}
4444 JsFunction5 Arg5 Bind5 {fn() -> Ret}
4445 ]);
4446 impl_fn!(@impl 6 [Arg1 Arg2 Arg3 Arg4 Arg5 Arg6] [
4447 JsFunction1 Arg1 Bind1 {fn(Arg2, Arg3, Arg4, Arg5, Arg6) -> Ret}
4448 JsFunction2 Arg2 Bind2 {fn(Arg3, Arg4, Arg5, Arg6) -> Ret}
4449 JsFunction3 Arg3 Bind3 {fn(Arg4, Arg5, Arg6) -> Ret}
4450 JsFunction4 Arg4 Bind4 {fn(Arg5, Arg6) -> Ret}
4451 JsFunction5 Arg5 Bind5 {fn(Arg6) -> Ret}
4452 JsFunction6 Arg6 Bind6 {fn() -> Ret}
4453 ]);
4454 impl_fn!(@impl 7 [Arg1 Arg2 Arg3 Arg4 Arg5 Arg6 Arg7] [
4455 JsFunction1 Arg1 Bind1 {fn(Arg2, Arg3, Arg4, Arg5, Arg6, Arg7) -> Ret}
4456 JsFunction2 Arg2 Bind2 {fn(Arg3, Arg4, Arg5, Arg6, Arg7) -> Ret}
4457 JsFunction3 Arg3 Bind3 {fn(Arg4, Arg5, Arg6, Arg7) -> Ret}
4458 JsFunction4 Arg4 Bind4 {fn(Arg5, Arg6, Arg7) -> Ret}
4459 JsFunction5 Arg5 Bind5 {fn(Arg6, Arg7) -> Ret}
4460 JsFunction6 Arg6 Bind6 {fn(Arg7) -> Ret}
4461 JsFunction7 Arg7 Bind7 {fn() -> Ret}
4462 ]);
4463 impl_fn!(@impl 8 [Arg1 Arg2 Arg3 Arg4 Arg5 Arg6 Arg7 Arg8] [
4464 JsFunction1 Arg1 Bind1 {fn(Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8) -> Ret}
4465 JsFunction2 Arg2 Bind2 {fn(Arg3, Arg4, Arg5, Arg6, Arg7, Arg8) -> Ret}
4466 JsFunction3 Arg3 Bind3 {fn(Arg4, Arg5, Arg6, Arg7, Arg8) -> Ret}
4467 JsFunction4 Arg4 Bind4 {fn(Arg5, Arg6, Arg7, Arg8) -> Ret}
4468 JsFunction5 Arg5 Bind5 {fn(Arg6, Arg7, Arg8) -> Ret}
4469 JsFunction6 Arg6 Bind6 {fn(Arg7, Arg8) -> Ret}
4470 JsFunction7 Arg7 Bind7 {fn(Arg8) -> Ret}
4471 JsFunction8 Arg8 Bind8 {fn() -> Ret}
4472 ]);
4473 };
4474
4475 (@impl $arity:literal [$($A:ident)+] [$($trait:ident $arg:ident $bind:ident {$bind_ty:ty})+]) => {
4476 impl<Ret: JsGeneric $(, $A: JsGeneric)+> JsFunction for fn($($A),+) -> Ret {
4477 type Ret = Ret;
4478 const ARITY: usize = $arity;
4479 }
4480
4481 impl_fn!(@traits [$($A)+] [$($trait $arg $bind {$bind_ty})+]);
4482 };
4483
4484 (@traits [$($A:ident)+] []) => {};
4485
4486 (@traits [$($A:ident)+] [$trait:ident $arg:ident $bind:ident {$bind_ty:ty} $($rest:tt)*]) => {
4487 impl<Ret: JsGeneric $(, $A: JsGeneric)+> $trait for fn($($A),+) -> Ret {
4488 type $arg = $arg;
4489 type $bind = $bind_ty;
4490 }
4491
4492 impl_fn!(@traits [$($A)+] [$($rest)*]);
4493 };
4494}
4495
4496impl_fn!();
4497
4498/// Trait for argument tuples that can call or bind a `Function<T>`.
4499pub trait JsArgs<T: JsFunction> {
4500 type BindOutput;
4501 fn apply_call(self, func: &Function<T>, context: &JsValue) -> Result<T::Ret, JsValue>;
4502 fn apply_bind(self, func: &Function<T>, context: &JsValue) -> Self::BindOutput;
4503}
4504
4505// Manual impl for 0-arg
4506impl<Ret: JsGeneric, F: JsFunction<Ret = Ret>> JsArgs<F> for () {
4507 type BindOutput = Function<F>;
4508
4509 #[inline]
4510 fn apply_call(self, func: &Function<F>, context: &JsValue) -> Result<Ret, JsValue> {
4511 func.call0(context)
4512 }
4513
4514 #[inline]
4515 fn apply_bind(self, func: &Function<F>, context: &JsValue) -> Self::BindOutput {
4516 func.bind0(context)
4517 }
4518}
4519
4520macro_rules! impl_js_args {
4521 ($arity:literal $trait:ident $bind_output:ident [$($A:ident)+] [$($idx:tt)+] $call:ident $bind:ident) => {
4522 impl<Ret: JsGeneric, $($A: JsGeneric,)+ F: $trait<Ret = Ret, $($A = $A,)*>> JsArgs<F> for ($(&$A,)+)
4523 {
4524 type BindOutput = Function<<F as $trait>::$bind_output>;
4525
4526 #[inline]
4527 fn apply_call(self, func: &Function<F>, context: &JsValue) -> Result<Ret, JsValue> {
4528 func.$call(context, $(self.$idx),+)
4529 }
4530
4531 #[inline]
4532 fn apply_bind(self, func: &Function<F>, context: &JsValue) -> Self::BindOutput {
4533 func.$bind(context, $(self.$idx),+)
4534 }
4535 }
4536 };
4537}
4538
4539impl_js_args!(1 JsFunction1 Bind1 [Arg1] [0] call1 bind1);
4540impl_js_args!(2 JsFunction2 Bind2 [Arg1 Arg2] [0 1] call2 bind2);
4541impl_js_args!(3 JsFunction3 Bind3 [Arg1 Arg2 Arg3] [0 1 2] call3 bind3);
4542impl_js_args!(4 JsFunction4 Bind4 [Arg1 Arg2 Arg3 Arg4] [0 1 2 3] call4 bind4);
4543impl_js_args!(5 JsFunction5 Bind5 [Arg1 Arg2 Arg3 Arg4 Arg5] [0 1 2 3 4] call5 bind5);
4544impl_js_args!(6 JsFunction6 Bind6 [Arg1 Arg2 Arg3 Arg4 Arg5 Arg6] [0 1 2 3 4 5] call6 bind6);
4545impl_js_args!(7 JsFunction7 Bind7 [Arg1 Arg2 Arg3 Arg4 Arg5 Arg6 Arg7] [0 1 2 3 4 5 6] call7 bind7);
4546impl_js_args!(8 JsFunction8 Bind8 [Arg1 Arg2 Arg3 Arg4 Arg5 Arg6 Arg7 Arg8] [0 1 2 3 4 5 6 7] call8 bind8);
4547
4548impl<T: JsFunction> Function<T> {
4549 /// The `call()` method calls a function with a given `this` value and
4550 /// arguments provided as a tuple.
4551 ///
4552 /// This method accepts a tuple of references matching the function's
4553 /// argument types.
4554 ///
4555 /// # Example
4556 ///
4557 /// ```ignore
4558 /// // 0-arg function
4559 /// let f: Function<fn() -> Number> = get_fn();
4560 /// let result = f.call(&JsValue::NULL, ())?;
4561 ///
4562 /// // 1-arg function (note trailing comma for 1-tuple)
4563 /// let f: Function<fn(JsString) -> Number> = get_fn();
4564 /// let result = f.call(&JsValue::NULL, (&name,))?;
4565 ///
4566 /// // 2-arg function
4567 /// let f: Function<fn(JsString, Boolean) -> Number> = get_fn();
4568 /// let result = f.call(&JsValue::NULL, (&name, &flag))?;
4569 /// ```
4570 ///
4571 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
4572 #[inline]
4573 pub fn call<Args: JsArgs<T>>(&self, context: &JsValue, args: Args) -> Result<T::Ret, JsValue> {
4574 args.apply_call(self, context)
4575 }
4576
4577 /// The `bind()` method creates a new function that, when called, has its
4578 /// `this` keyword set to the provided value, with a given sequence of
4579 /// arguments preceding any provided when the new function is called.
4580 ///
4581 /// This method accepts a tuple of references to bind.
4582 ///
4583 /// # Example
4584 ///
4585 /// ```ignore
4586 /// let f: Function<fn(JsString, Boolean) -> Number> = get_fn();
4587 ///
4588 /// // Bind no args - same signature
4589 /// let bound: Function<fn(JsString, Boolean) -> Number> = f.bind(&ctx, ());
4590 ///
4591 /// // Bind one arg (use 1-tuple of references)
4592 /// let bound: Function<fn(Boolean) -> Number> = f.bind(&ctx, (&my_string,));
4593 ///
4594 /// // Bind two args - becomes 0-arg function
4595 /// let bound: Function<fn() -> Number> = f.bind(&ctx, (&my_string, &my_bool));
4596 /// ```
4597 ///
4598 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4599 #[inline]
4600 pub fn bindn<Args: JsArgs<T>>(&self, context: &JsValue, args: Args) -> Args::BindOutput {
4601 args.apply_bind(self, context)
4602 }
4603
4604 /// The `bind()` method creates a new function that, when called, has its
4605 /// `this` keyword set to the provided value, with a given sequence of
4606 /// arguments preceding any provided when the new function is called.
4607 ///
4608 /// This method accepts a tuple of references to bind.
4609 ///
4610 /// # Example
4611 ///
4612 /// ```ignore
4613 /// let f: Function<fn(JsString, Boolean) -> Number> = get_fn();
4614 ///
4615 /// // Bind no args - same signature
4616 /// let bound: Function<fn(JsString, Boolean) -> Number> = f.bind(&ctx, ());
4617 ///
4618 /// // Bind one arg (use 1-tuple of references)
4619 /// let bound: Function<fn(Boolean) -> Number> = f.bind(&ctx, (&my_string,));
4620 ///
4621 /// // Bind two args - becomes 0-arg function
4622 /// let bound: Function<fn() -> Number> = f.bind(&ctx, (&my_string, &my_bool));
4623 /// ```
4624 ///
4625 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4626 #[cfg(js_sys_unstable_apis)]
4627 #[inline]
4628 pub fn bind<Args: JsArgs<T>>(&self, context: &JsValue, args: Args) -> Args::BindOutput {
4629 args.apply_bind(self, context)
4630 }
4631}
4632
4633pub trait FunctionIntoClosure: JsFunction {
4634 type ClosureTypeMut: WasmClosure + ?Sized;
4635}
4636
4637macro_rules! impl_function_into_closure {
4638 ( $(($($var:ident)*))* ) => {$(
4639 impl<$($var: FromWasmAbi + JsGeneric,)* R: IntoWasmAbi + JsGeneric> FunctionIntoClosure for fn($($var),*) -> R {
4640 type ClosureTypeMut = dyn FnMut($($var),*) -> R;
4641 }
4642 )*};
4643}
4644
4645impl_function_into_closure! {
4646 ()
4647 (A)
4648 (A B)
4649 (A B C)
4650 (A B C D)
4651 (A B C D E)
4652 (A B C D E F)
4653 (A B C D E F G)
4654 (A B C D E F G H)
4655}
4656
4657impl<F: JsFunction> Function<F> {
4658 /// Convert a borrowed `ScopedClosure` into a typed JavaScript Function reference.
4659 ///
4660 /// The conversion is a direct type-safe conversion and upcast of a
4661 /// closure into its corresponding typed JavaScript Function,
4662 /// based on covariance and contravariance [`Upcast`] trait hierarchy.
4663 ///
4664 /// For transferring ownership to JS, use [`Function::from_closure`].
4665 #[inline]
4666 pub fn closure_ref<'a, C>(closure: &'a ScopedClosure<'_, C>) -> &'a Self
4667 where
4668 F: FunctionIntoClosure,
4669 C: WasmClosure + ?Sized,
4670 <F as FunctionIntoClosure>::ClosureTypeMut: UpcastFrom<<C as WasmClosure>::AsMut>,
4671 {
4672 closure.as_js_value().unchecked_ref()
4673 }
4674
4675 /// Convert a Rust closure into a typed JavaScript Function.
4676 ///
4677 /// This function releases ownership of the closure to JS, and provides
4678 /// an owned function handle for the same closure.
4679 ///
4680 /// The conversion is a direct type-safe conversion and upcast of a
4681 /// closure into its corresponding typed JavaScript Function,
4682 /// based on covariance and contravariance [`Upcast`] trait hierarchy.
4683 ///
4684 /// This method is only supported for static closures which do not have
4685 /// borrowed lifetime data, and thus can be released into JS.
4686 ///
4687 /// For borrowed closures, which cannot cede ownership to JS,
4688 /// instead use [`Function::closure_ref`].
4689 #[inline]
4690 pub fn from_closure<C>(closure: ScopedClosure<'static, C>) -> Self
4691 where
4692 F: FunctionIntoClosure,
4693 C: WasmClosure + ?Sized,
4694 <F as FunctionIntoClosure>::ClosureTypeMut: UpcastFrom<<C as WasmClosure>::AsMut>,
4695 {
4696 closure.into_js_value().unchecked_into()
4697 }
4698}
4699
4700#[cfg(not(js_sys_unstable_apis))]
4701impl Function {
4702 /// Returns the `Function` value of this JS value if it's an instance of a
4703 /// function.
4704 ///
4705 /// If this JS value is not an instance of a function then this returns
4706 /// `None`.
4707 #[deprecated(note = "recommended to use dyn_ref instead which is now equivalent")]
4708 pub fn try_from(val: &JsValue) -> Option<&Function> {
4709 val.dyn_ref()
4710 }
4711}
4712
4713#[cfg(feature = "unsafe-eval")]
4714impl Default for Function {
4715 fn default() -> Self {
4716 Self::new_no_args("")
4717 }
4718}
4719
4720// Generator
4721#[wasm_bindgen]
4722extern "C" {
4723 #[wasm_bindgen(extends = Object, typescript_type = "Generator<any, any, any>")]
4724 #[derive(Clone, Debug, PartialEq, Eq)]
4725 pub type Generator<T = JsValue>;
4726
4727 /// The `next()` method returns an object with two properties done and value.
4728 /// You can also provide a parameter to the next method to send a value to the generator.
4729 ///
4730 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/next)
4731 #[cfg(not(js_sys_unstable_apis))]
4732 #[wasm_bindgen(method, catch)]
4733 pub fn next<T>(this: &Generator<T>, value: &T) -> Result<JsValue, JsValue>;
4734
4735 /// The `next()` method returns an object with two properties done and value.
4736 /// You can also provide a parameter to the next method to send a value to the generator.
4737 ///
4738 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/next)
4739 #[cfg(js_sys_unstable_apis)]
4740 #[wasm_bindgen(method, catch, js_name = next)]
4741 pub fn next<T: FromWasmAbi>(this: &Generator<T>, value: &T)
4742 -> Result<IteratorNext<T>, JsValue>;
4743
4744 // Next major: deprecate
4745 /// The `next()` method returns an object with two properties done and value.
4746 /// You can also provide a parameter to the next method to send a value to the generator.
4747 ///
4748 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/next)
4749 #[wasm_bindgen(method, catch)]
4750 pub fn next_iterator<T: FromWasmAbi>(
4751 this: &Generator<T>,
4752 value: &T,
4753 ) -> Result<IteratorNext<T>, JsValue>;
4754
4755 /// The `return()` method returns the given value and finishes the generator.
4756 ///
4757 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/return)
4758 #[cfg(not(js_sys_unstable_apis))]
4759 #[wasm_bindgen(method, js_name = "return")]
4760 pub fn return_<T>(this: &Generator<T>, value: &T) -> JsValue;
4761
4762 /// The `return()` method returns the given value and finishes the generator.
4763 ///
4764 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/return)
4765 #[cfg(js_sys_unstable_apis)]
4766 #[wasm_bindgen(method, catch, js_name = "return")]
4767 pub fn return_<T: FromWasmAbi>(
4768 this: &Generator<T>,
4769 value: &T,
4770 ) -> Result<IteratorNext<T>, JsValue>;
4771
4772 // Next major: deprecate
4773 /// The `return()` method returns the given value and finishes the generator.
4774 ///
4775 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/return)
4776 #[wasm_bindgen(method, catch, js_name = "return")]
4777 pub fn try_return<T: FromWasmAbi>(
4778 this: &Generator<T>,
4779 value: &T,
4780 ) -> Result<IteratorNext<T>, JsValue>;
4781
4782 /// The `throw()` method resumes the execution of a generator by throwing an error into it
4783 /// and returns an object with two properties done and value.
4784 ///
4785 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/throw)
4786 #[cfg(not(js_sys_unstable_apis))]
4787 #[wasm_bindgen(method, catch)]
4788 pub fn throw<T>(this: &Generator<T>, error: &Error) -> Result<JsValue, JsValue>;
4789
4790 /// The `throw()` method resumes the execution of a generator by throwing an error into it
4791 /// and returns an object with two properties done and value.
4792 ///
4793 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/throw)
4794 #[cfg(js_sys_unstable_apis)]
4795 #[wasm_bindgen(method, catch, js_name = throw)]
4796 pub fn throw<T: FromWasmAbi>(
4797 this: &Generator<T>,
4798 error: &JsValue,
4799 ) -> Result<IteratorNext<T>, JsValue>;
4800
4801 // Next major: deprecate
4802 /// The `throw()` method resumes the execution of a generator by throwing an error into it
4803 /// and returns an object with two properties done and value.
4804 ///
4805 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/throw)
4806 #[wasm_bindgen(method, catch, js_name = throw)]
4807 pub fn throw_value<T: FromWasmAbi>(
4808 this: &Generator<T>,
4809 error: &JsValue,
4810 ) -> Result<IteratorNext<T>, JsValue>;
4811}
4812
4813impl<T: FromWasmAbi> Iterable for Generator<T> {
4814 type Item = T;
4815}
4816
4817// AsyncGenerator
4818#[wasm_bindgen]
4819extern "C" {
4820 #[wasm_bindgen(extends = Object, typescript_type = "AsyncGenerator<any, any, any>")]
4821 #[derive(Clone, Debug, PartialEq, Eq)]
4822 pub type AsyncGenerator<T = JsValue>;
4823
4824 /// The `next()` method returns an object with two properties done and value.
4825 /// You can also provide a parameter to the next method to send a value to the generator.
4826 ///
4827 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncGenerator/next)
4828 #[wasm_bindgen(method, catch)]
4829 pub fn next<T>(
4830 this: &AsyncGenerator<T>,
4831 value: &T,
4832 ) -> Result<Promise<IteratorNext<T>>, JsValue>;
4833
4834 /// The `return()` method returns the given value and finishes the generator.
4835 ///
4836 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncGenerator/return)
4837 #[wasm_bindgen(method, js_name = "return", catch)]
4838 pub fn return_<T>(
4839 this: &AsyncGenerator<T>,
4840 value: &T,
4841 ) -> Result<Promise<IteratorNext<T>>, JsValue>;
4842
4843 /// The `throw()` method resumes the execution of a generator by throwing an error into it
4844 /// and returns an object with two properties done and value.
4845 ///
4846 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncGenerator/throw)
4847 #[wasm_bindgen(method, catch)]
4848 pub fn throw<T>(
4849 this: &AsyncGenerator<T>,
4850 error: &JsValue,
4851 ) -> Result<Promise<IteratorNext<T>>, JsValue>;
4852}
4853
4854impl<T: FromWasmAbi> AsyncIterable for AsyncGenerator<T> {
4855 type Item = T;
4856}
4857
4858// Map
4859#[wasm_bindgen]
4860extern "C" {
4861 #[wasm_bindgen(extends = Object, typescript_type = "Map<any, any>")]
4862 #[derive(Clone, Debug, PartialEq, Eq)]
4863 pub type Map<K = JsValue, V = JsValue>;
4864
4865 /// The Map object holds key-value pairs. Any value (both objects and
4866 /// primitive values) maybe used as either a key or a value.
4867 ///
4868 /// **Note:** Consider using [`Map::new_typed`] for typing support.
4869 ///
4870 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)
4871 #[cfg(not(js_sys_unstable_apis))]
4872 #[wasm_bindgen(constructor)]
4873 pub fn new() -> Map;
4874
4875 /// The Map object holds key-value pairs. Any value (both objects and
4876 /// primitive values) maybe used as either a key or a value.
4877 ///
4878 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)
4879 #[cfg(js_sys_unstable_apis)]
4880 #[wasm_bindgen(constructor)]
4881 pub fn new<K, V>() -> Map<K, V>;
4882
4883 // Next major: deprecate
4884 /// The Map object holds key-value pairs. Any value (both objects and
4885 /// primitive values) maybe used as either a key or a value.
4886 ///
4887 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)
4888 #[wasm_bindgen(constructor)]
4889 pub fn new_typed<K, V>() -> Map<K, V>;
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 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)
4895 #[wasm_bindgen(constructor, js_name = new)]
4896 pub fn new_from_entries<K, V, I: Iterable<Item = ArrayTuple<(K, V)>>>(entries: &I)
4897 -> Map<K, V>;
4898
4899 /// The `clear()` method removes all elements from a Map object.
4900 ///
4901 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/clear)
4902 #[wasm_bindgen(method)]
4903 pub fn clear<K, V>(this: &Map<K, V>);
4904
4905 /// The `delete()` method removes the specified element from a Map object.
4906 ///
4907 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/delete)
4908 #[wasm_bindgen(method)]
4909 pub fn delete<K, V>(this: &Map<K, V>, key: &K) -> bool;
4910
4911 /// The `forEach()` method executes a provided function once per each
4912 /// key/value pair in the Map object, in insertion order.
4913 /// Note that in Javascript land the `Key` and `Value` are reversed compared to normal expectations:
4914 /// # Examples
4915 /// ```
4916 /// let js_map = Map::new();
4917 /// js_map.for_each(&mut |value, key| {
4918 /// // Do something here...
4919 /// })
4920 /// ```
4921 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/forEach)
4922 #[wasm_bindgen(method, js_name = forEach)]
4923 pub fn for_each<K, V>(this: &Map<K, V>, callback: &mut dyn FnMut(V, K));
4924
4925 /// The `forEach()` method executes a provided function once per each
4926 /// key/value pair in the Map object, in insertion order. _(Fallible variation)_
4927 /// Note that in Javascript land the `Key` and `Value` are reversed compared to normal expectations:
4928 /// # Examples
4929 /// ```
4930 /// let js_map = Map::new();
4931 /// js_map.for_each(&mut |value, key| {
4932 /// // Do something here...
4933 /// })
4934 /// ```
4935 ///
4936 /// **Note:** Consider using [`Map::try_for_each`] if the callback might throw an error.
4937 ///
4938 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/forEach)
4939 #[wasm_bindgen(method, js_name = forEach, catch)]
4940 pub fn try_for_each<'a, K, V>(
4941 this: &Map<K, V>,
4942 callback: ImmediateClosure<'a, dyn FnMut(V, K) -> Result<(), JsError> + 'a>,
4943 ) -> Result<(), JsValue>;
4944
4945 /// The `get()` method returns a specified element from a Map object.
4946 /// Returns `undefined` if the key is not found.
4947 ///
4948 /// **Note:** Consider using [`Map::get_checked`] to get an `Option<V>` instead.
4949 ///
4950 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get)
4951 #[cfg(not(js_sys_unstable_apis))]
4952 #[wasm_bindgen(method)]
4953 pub fn get<K, V>(this: &Map<K, V>, key: &K) -> V;
4954
4955 /// The `get()` method returns a specified element from a Map object.
4956 /// Returns `None` if the key is not found.
4957 ///
4958 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get)
4959 #[cfg(js_sys_unstable_apis)]
4960 #[wasm_bindgen(method)]
4961 pub fn get<K, V>(this: &Map<K, V>, key: &K) -> Option<V>;
4962
4963 /// The `get()` method returns a specified element from a Map object.
4964 /// Returns `None` if the key is not found.
4965 ///
4966 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get)
4967 #[wasm_bindgen(method, js_name = get)]
4968 pub fn get_checked<K, V>(this: &Map<K, V>, key: &K) -> Option<V>;
4969
4970 /// The `has()` method returns a boolean indicating whether an element with
4971 /// the specified key exists or not.
4972 ///
4973 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/has)
4974 #[wasm_bindgen(method)]
4975 pub fn has<K, V>(this: &Map<K, V>, key: &K) -> bool;
4976
4977 /// The `set()` method adds or updates an element with a specified key
4978 /// and value to a Map object.
4979 ///
4980 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/set)
4981 #[wasm_bindgen(method)]
4982 pub fn set<K, V>(this: &Map<K, V>, key: &K, value: &V) -> Map<K, V>;
4983
4984 /// The value of size is an integer representing how many entries
4985 /// the Map object has. A set accessor function for size is undefined;
4986 /// you can not change this property.
4987 ///
4988 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/size)
4989 #[wasm_bindgen(method, getter)]
4990 pub fn size<K, V>(this: &Map<K, V>) -> u32;
4991}
4992
4993impl Default for Map<JsValue, JsValue> {
4994 fn default() -> Self {
4995 Self::new()
4996 }
4997}
4998
4999// Map Iterator
5000#[wasm_bindgen]
5001extern "C" {
5002 /// The `entries()` method returns a new Iterator object that contains
5003 /// the [key, value] pairs for each element in the Map object in
5004 /// insertion order.
5005 ///
5006 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries)
5007 #[cfg(not(js_sys_unstable_apis))]
5008 #[wasm_bindgen(method)]
5009 pub fn entries<K, V: FromWasmAbi>(this: &Map<K, V>) -> Iterator;
5010
5011 /// The `entries()` method returns a new Iterator object that contains
5012 /// the [key, value] pairs for each element in the Map object in
5013 /// insertion order.
5014 ///
5015 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries)
5016 #[cfg(js_sys_unstable_apis)]
5017 #[wasm_bindgen(method, js_name = entries)]
5018 pub fn entries<K: JsGeneric, V: FromWasmAbi + JsGeneric>(
5019 this: &Map<K, V>,
5020 ) -> Iterator<ArrayTuple<(K, V)>>;
5021
5022 // Next major: deprecate
5023 /// The `entries()` method returns a new Iterator object that contains
5024 /// the [key, value] pairs for each element in the Map object in
5025 /// insertion order.
5026 ///
5027 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries)
5028 #[wasm_bindgen(method, js_name = entries)]
5029 pub fn entries_typed<K: JsGeneric, V: FromWasmAbi + JsGeneric>(
5030 this: &Map<K, V>,
5031 ) -> Iterator<ArrayTuple<(K, V)>>;
5032
5033 /// The `keys()` method returns a new Iterator object that contains the
5034 /// keys for each element in the Map object in insertion order.
5035 ///
5036 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/keys)
5037 #[wasm_bindgen(method)]
5038 pub fn keys<K: FromWasmAbi, V: FromWasmAbi>(this: &Map<K, V>) -> Iterator<K>;
5039
5040 /// The `values()` method returns a new Iterator object that contains the
5041 /// values for each element in the Map object in insertion order.
5042 ///
5043 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/values)
5044 #[wasm_bindgen(method)]
5045 pub fn values<K, V: FromWasmAbi>(this: &Map<K, V>) -> Iterator<V>;
5046}
5047
5048impl<K, V> Iterable for Map<K, V> {
5049 type Item = ArrayTuple<(K, V)>;
5050}
5051
5052// Iterator
5053#[wasm_bindgen]
5054extern "C" {
5055 /// Any object that conforms to the JS iterator protocol. For example,
5056 /// something returned by `myArray[Symbol.iterator]()`.
5057 ///
5058 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols)
5059 #[derive(Clone, Debug)]
5060 #[wasm_bindgen(is_type_of = Iterator::looks_like_iterator, typescript_type = "Iterator<any>")]
5061 pub type Iterator<T = JsValue>;
5062
5063 /// The `next()` method always has to return an object with appropriate
5064 /// properties including done and value. If a non-object value gets returned
5065 /// (such as false or undefined), a TypeError ("iterator.next() returned a
5066 /// non-object value") will be thrown.
5067 #[wasm_bindgen(catch, method)]
5068 pub fn next<T: FromWasmAbi>(this: &Iterator<T>) -> Result<IteratorNext<T>, JsValue>;
5069}
5070
5071impl<T> UpcastFrom<Iterator<T>> for Object {}
5072
5073impl Iterator {
5074 fn looks_like_iterator(it: &JsValue) -> bool {
5075 #[wasm_bindgen]
5076 extern "C" {
5077 type MaybeIterator;
5078
5079 #[wasm_bindgen(method, getter)]
5080 fn next(this: &MaybeIterator) -> JsValue;
5081 }
5082
5083 if !it.is_object() {
5084 return false;
5085 }
5086
5087 let it = it.unchecked_ref::<MaybeIterator>();
5088
5089 it.next().is_function()
5090 }
5091}
5092
5093// iterators in JS are themselves iterable
5094impl<T> Iterable for Iterator<T> {
5095 type Item = T;
5096}
5097
5098// Async Iterator
5099#[wasm_bindgen]
5100extern "C" {
5101 /// Any object that conforms to the JS async iterator protocol. For example,
5102 /// something returned by `myObject[Symbol.asyncIterator]()`.
5103 ///
5104 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of)
5105 #[derive(Clone, Debug)]
5106 #[wasm_bindgen(is_type_of = Iterator::looks_like_iterator, typescript_type = "AsyncIterator<any>")]
5107 pub type AsyncIterator<T = JsValue>;
5108
5109 /// The `next()` method always has to return a Promise which resolves to an object
5110 /// with appropriate properties including done and value. If a non-object value
5111 /// gets returned (such as false or undefined), a TypeError ("iterator.next()
5112 /// returned a non-object value") will be thrown.
5113 #[cfg(not(js_sys_unstable_apis))]
5114 #[wasm_bindgen(catch, method)]
5115 pub fn next<T>(this: &AsyncIterator<T>) -> Result<Promise, JsValue>;
5116
5117 /// The `next()` method always has to return a Promise which resolves to an object
5118 /// with appropriate properties including done and value. If a non-object value
5119 /// gets returned (such as false or undefined), a TypeError ("iterator.next()
5120 /// returned a non-object value") will be thrown.
5121 #[cfg(js_sys_unstable_apis)]
5122 #[wasm_bindgen(catch, method, js_name = next)]
5123 pub fn next<T: FromWasmAbi>(
5124 this: &AsyncIterator<T>,
5125 ) -> Result<Promise<IteratorNext<T>>, JsValue>;
5126
5127 // Next major: deprecate
5128 /// The `next()` method always has to return a Promise which resolves to an object
5129 /// with appropriate properties including done and value. If a non-object value
5130 /// gets returned (such as false or undefined), a TypeError ("iterator.next()
5131 /// returned a non-object value") will be thrown.
5132 #[wasm_bindgen(catch, method, js_name = next)]
5133 pub fn next_iterator<T: FromWasmAbi>(
5134 this: &AsyncIterator<T>,
5135 ) -> Result<Promise<IteratorNext<T>>, JsValue>;
5136}
5137
5138impl<T> UpcastFrom<AsyncIterator<T>> for Object {}
5139
5140// iterators in JS are themselves iterable
5141impl<T> AsyncIterable for AsyncIterator<T> {
5142 type Item = T;
5143}
5144
5145/// An iterator over the JS `Symbol.iterator` iteration protocol.
5146///
5147/// Use the `IntoIterator for &js_sys::Iterator` implementation to create this.
5148pub struct Iter<'a, T> {
5149 js: &'a Iterator<T>,
5150 state: IterState,
5151}
5152
5153/// An iterator over the JS `Symbol.iterator` iteration protocol.
5154///
5155/// Use the `IntoIterator for js_sys::Iterator` implementation to create this.
5156pub struct IntoIter<T = JsValue> {
5157 js: Iterator<T>,
5158 state: IterState,
5159}
5160
5161struct IterState {
5162 done: bool,
5163}
5164
5165impl<'a, T: FromWasmAbi + JsGeneric> IntoIterator for &'a Iterator<T> {
5166 type Item = Result<T, JsValue>;
5167 type IntoIter = Iter<'a, T>;
5168
5169 fn into_iter(self) -> Iter<'a, T> {
5170 Iter {
5171 js: self,
5172 state: IterState::new(),
5173 }
5174 }
5175}
5176
5177impl<T: FromWasmAbi + JsGeneric> core::iter::Iterator for Iter<'_, T> {
5178 type Item = Result<T, JsValue>;
5179
5180 fn next(&mut self) -> Option<Self::Item> {
5181 self.state.next(self.js)
5182 }
5183}
5184
5185impl<T: FromWasmAbi + JsGeneric> IntoIterator for Iterator<T> {
5186 type Item = Result<T, JsValue>;
5187 type IntoIter = IntoIter<T>;
5188
5189 fn into_iter(self) -> IntoIter<T> {
5190 IntoIter {
5191 js: self,
5192 state: IterState::new(),
5193 }
5194 }
5195}
5196
5197impl<T: FromWasmAbi + JsGeneric> core::iter::Iterator for IntoIter<T> {
5198 type Item = Result<T, JsValue>;
5199
5200 fn next(&mut self) -> Option<Self::Item> {
5201 self.state.next(&self.js)
5202 }
5203}
5204
5205impl IterState {
5206 fn new() -> IterState {
5207 IterState { done: false }
5208 }
5209
5210 fn next<T: FromWasmAbi + JsGeneric>(&mut self, js: &Iterator<T>) -> Option<Result<T, JsValue>> {
5211 if self.done {
5212 return None;
5213 }
5214 let next = match js.next() {
5215 Ok(val) => val,
5216 Err(e) => {
5217 self.done = true;
5218 return Some(Err(e));
5219 }
5220 };
5221 if next.done() {
5222 self.done = true;
5223 None
5224 } else {
5225 Some(Ok(next.value()))
5226 }
5227 }
5228}
5229
5230/// Create an iterator over `val` using the JS iteration protocol and
5231/// `Symbol.iterator`.
5232// #[cfg(not(js_sys_unstable_apis))]
5233pub fn try_iter(val: &JsValue) -> Result<Option<IntoIter<JsValue>>, JsValue> {
5234 let iter_sym = Symbol::iterator();
5235
5236 let iter_fn = Reflect::get_symbol::<Object>(val.unchecked_ref(), iter_sym.as_ref())?;
5237 let iter_fn: Function = match iter_fn.dyn_into() {
5238 Ok(iter_fn) => iter_fn,
5239 Err(_) => return Ok(None),
5240 };
5241
5242 let it: Iterator = match iter_fn.call0(val)?.dyn_into() {
5243 Ok(it) => it,
5244 Err(_) => return Ok(None),
5245 };
5246
5247 Ok(Some(it.into_iter()))
5248}
5249
5250/// Trait for JavaScript types that implement the iterable protocol via `Symbol.iterator`.
5251///
5252/// Types implementing this trait can be iterated over using JavaScript's iteration
5253/// protocol. The `Item` associated type specifies the type of values yielded.
5254///
5255/// ## Built-in Iterables
5256///
5257/// Many `js-sys` collection types implement `Iterable` out of the box:
5258///
5259/// ```ignore
5260/// use js_sys::{Array, Map, Set};
5261///
5262/// // Array<T> yields T
5263/// let arr: Array<Number> = get_numbers();
5264/// for value in arr.iter() {
5265/// let num: Number = value?;
5266/// }
5267///
5268/// // Map<K, V> yields Array (key-value pairs)
5269/// let map: Map<JsString, Number> = get_map();
5270/// for entry in map.iter() {
5271/// let pair: Array = entry?;
5272/// }
5273///
5274/// // Set<T> yields T
5275/// let set: Set<JsString> = get_set();
5276/// for value in set.iter() {
5277/// let s: JsString = value?;
5278/// }
5279/// ```
5280///
5281/// ## Typing Foreign Iterators
5282///
5283/// If you have a JavaScript value that implements the iterator protocol (has a `next()`
5284/// method) but isn't a built-in type, you can use [`JsCast`] to cast it to [`Iterator<T>`]:
5285///
5286/// ```ignore
5287/// use js_sys::Iterator;
5288/// use wasm_bindgen::JsCast;
5289///
5290/// // For a value you know implements the iterator protocol
5291/// fn process_iterator(js_iter: JsValue) {
5292/// // Checked cast - returns None if not an iterator
5293/// if let Some(iter) = js_iter.dyn_ref::<Iterator<Number>>() {
5294/// for value in iter.into_iter() {
5295/// let num: Number = value.unwrap();
5296/// // ...
5297/// }
5298/// }
5299/// }
5300///
5301/// // Or with unchecked cast when you're certain of the type
5302/// fn process_known_iterator(js_iter: JsValue) {
5303/// let iter: &Iterator<JsString> = js_iter.unchecked_ref();
5304/// for value in iter.into_iter() {
5305/// let s: JsString = value.unwrap();
5306/// // ...
5307/// }
5308/// }
5309/// ```
5310///
5311/// ## Using with `JsValue`
5312///
5313/// For dynamic or unknown iterables, use [`try_iter`] which returns an untyped iterator:
5314///
5315/// ```ignore
5316/// fn iterate_unknown(val: &JsValue) -> Result<(), JsValue> {
5317/// if let Some(iter) = js_sys::try_iter(val)? {
5318/// for item in iter {
5319/// let value: JsValue = item?;
5320/// // Handle dynamically...
5321/// }
5322/// }
5323/// Ok(())
5324/// }
5325/// ```
5326///
5327/// [`JsCast`]: wasm_bindgen::JsCast
5328/// [`Iterator<T>`]: Iterator
5329/// [`try_iter`]: crate::try_iter
5330pub trait Iterable {
5331 /// The type of values yielded by this iterable.
5332 type Item;
5333}
5334
5335impl<T: Iterable> Iterable for &T {
5336 type Item = T::Item;
5337}
5338
5339/// Trait for types known to implement the iterator protocol on Symbol.asyncIterator
5340pub trait AsyncIterable {
5341 type Item;
5342}
5343
5344impl<T: AsyncIterable> AsyncIterable for &T {
5345 type Item = T::Item;
5346}
5347
5348impl AsyncIterable for JsValue {
5349 type Item = JsValue;
5350}
5351
5352// IteratorNext
5353#[wasm_bindgen]
5354extern "C" {
5355 /// The result of calling `next()` on a JS iterator.
5356 ///
5357 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols)
5358 #[wasm_bindgen(extends = Object, typescript_type = "IteratorResult<any>")]
5359 #[derive(Clone, Debug, PartialEq, Eq)]
5360 pub type IteratorNext<T = JsValue>;
5361
5362 /// Has the value `true` if the iterator is past the end of the iterated
5363 /// sequence. In this case value optionally specifies the return value of
5364 /// the iterator.
5365 ///
5366 /// Has the value `false` if the iterator was able to produce the next value
5367 /// in the sequence. This is equivalent of not specifying the done property
5368 /// altogether.
5369 #[wasm_bindgen(method, getter)]
5370 pub fn done<T>(this: &IteratorNext<T>) -> bool;
5371
5372 /// Any JavaScript value returned by the iterator. Can be omitted when done
5373 /// is true.
5374 #[wasm_bindgen(method, getter)]
5375 pub fn value<T>(this: &IteratorNext<T>) -> T;
5376}
5377
5378#[allow(non_snake_case)]
5379pub mod Math {
5380 use super::*;
5381
5382 // Math
5383 #[wasm_bindgen]
5384 extern "C" {
5385 /// The `Math.abs()` function returns the absolute value of a number, that is
5386 /// Math.abs(x) = |x|
5387 ///
5388 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/abs)
5389 #[wasm_bindgen(js_namespace = Math)]
5390 pub fn abs(x: f64) -> f64;
5391
5392 /// The `Math.acos()` function returns the arccosine (in radians) of a
5393 /// number, that is ∀x∊[-1;1]
5394 /// Math.acos(x) = arccos(x) = the unique y∊[0;π] such that cos(y)=x
5395 ///
5396 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/acos)
5397 #[wasm_bindgen(js_namespace = Math)]
5398 pub fn acos(x: f64) -> f64;
5399
5400 /// The `Math.acosh()` function returns the hyperbolic arc-cosine of a
5401 /// number, that is ∀x ≥ 1
5402 /// Math.acosh(x) = arcosh(x) = the unique y ≥ 0 such that cosh(y) = x
5403 ///
5404 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/acosh)
5405 #[wasm_bindgen(js_namespace = Math)]
5406 pub fn acosh(x: f64) -> f64;
5407
5408 /// The `Math.asin()` function returns the arcsine (in radians) of a
5409 /// number, that is ∀x ∊ [-1;1]
5410 /// Math.asin(x) = arcsin(x) = the unique y∊[-π2;π2] such that sin(y) = x
5411 ///
5412 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/asin)
5413 #[wasm_bindgen(js_namespace = Math)]
5414 pub fn asin(x: f64) -> f64;
5415
5416 /// The `Math.asinh()` function returns the hyperbolic arcsine of a
5417 /// number, that is Math.asinh(x) = arsinh(x) = the unique y such that sinh(y) = x
5418 ///
5419 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/asinh)
5420 #[wasm_bindgen(js_namespace = Math)]
5421 pub fn asinh(x: f64) -> f64;
5422
5423 /// The `Math.atan()` function returns the arctangent (in radians) of a
5424 /// number, that is Math.atan(x) = arctan(x) = the unique y ∊ [-π2;π2]such that
5425 /// tan(y) = x
5426 #[wasm_bindgen(js_namespace = Math)]
5427 pub fn atan(x: f64) -> f64;
5428
5429 /// The `Math.atan2()` function returns the arctangent of the quotient of
5430 /// its arguments.
5431 ///
5432 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/atan2)
5433 #[wasm_bindgen(js_namespace = Math)]
5434 pub fn atan2(y: f64, x: f64) -> f64;
5435
5436 /// The `Math.atanh()` function returns the hyperbolic arctangent of a number,
5437 /// that is ∀x ∊ (-1,1), Math.atanh(x) = arctanh(x) = the unique y such that
5438 /// tanh(y) = x
5439 ///
5440 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/atanh)
5441 #[wasm_bindgen(js_namespace = Math)]
5442 pub fn atanh(x: f64) -> f64;
5443
5444 /// The `Math.cbrt() `function returns the cube root of a number, that is
5445 /// Math.cbrt(x) = ∛x = the unique y such that y^3 = x
5446 ///
5447 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/cbrt)
5448 #[wasm_bindgen(js_namespace = Math)]
5449 pub fn cbrt(x: f64) -> f64;
5450
5451 /// The `Math.ceil()` function returns the smallest integer greater than
5452 /// or equal to a given number.
5453 ///
5454 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/ceil)
5455 #[wasm_bindgen(js_namespace = Math)]
5456 pub fn ceil(x: f64) -> f64;
5457
5458 /// The `Math.clz32()` function returns the number of leading zero bits in
5459 /// the 32-bit binary representation of a number.
5460 ///
5461 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/clz32)
5462 #[wasm_bindgen(js_namespace = Math)]
5463 pub fn clz32(x: i32) -> u32;
5464
5465 /// The `Math.cos()` static function returns the cosine of the specified angle,
5466 /// which must be specified in radians. This value is length(adjacent)/length(hypotenuse).
5467 ///
5468 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/cos)
5469 #[wasm_bindgen(js_namespace = Math)]
5470 pub fn cos(x: f64) -> f64;
5471
5472 /// The `Math.cosh()` function returns the hyperbolic cosine of a number,
5473 /// that can be expressed using the constant e.
5474 ///
5475 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/cosh)
5476 #[wasm_bindgen(js_namespace = Math)]
5477 pub fn cosh(x: f64) -> f64;
5478
5479 /// The `Math.exp()` function returns e^x, where x is the argument, and e is Euler's number
5480 /// (also known as Napier's constant), the base of the natural logarithms.
5481 ///
5482 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/exp)
5483 #[wasm_bindgen(js_namespace = Math)]
5484 pub fn exp(x: f64) -> f64;
5485
5486 /// The `Math.expm1()` function returns e^x - 1, where x is the argument, and e the base of the
5487 /// natural logarithms.
5488 ///
5489 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/expm1)
5490 #[wasm_bindgen(js_namespace = Math)]
5491 pub fn expm1(x: f64) -> f64;
5492
5493 /// The `Math.floor()` function returns the largest integer less than or
5494 /// equal to a given number.
5495 ///
5496 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/floor)
5497 #[wasm_bindgen(js_namespace = Math)]
5498 pub fn floor(x: f64) -> f64;
5499
5500 /// The `Math.fround()` function returns the nearest 32-bit single precision float representation
5501 /// of a Number.
5502 ///
5503 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/fround)
5504 #[wasm_bindgen(js_namespace = Math)]
5505 pub fn fround(x: f64) -> f32;
5506
5507 /// The `Math.hypot()` function returns the square root of the sum of squares of its arguments.
5508 ///
5509 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/hypot)
5510 #[wasm_bindgen(js_namespace = Math)]
5511 pub fn hypot(x: f64, y: f64) -> f64;
5512
5513 /// The `Math.imul()` function returns the result of the C-like 32-bit multiplication of the
5514 /// two parameters.
5515 ///
5516 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/imul)
5517 #[wasm_bindgen(js_namespace = Math)]
5518 pub fn imul(x: i32, y: i32) -> i32;
5519
5520 /// The `Math.log()` function returns the natural logarithm (base e) of a number.
5521 /// The JavaScript `Math.log()` function is equivalent to ln(x) in mathematics.
5522 ///
5523 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log)
5524 #[wasm_bindgen(js_namespace = Math)]
5525 pub fn log(x: f64) -> f64;
5526
5527 /// The `Math.log10()` function returns the base 10 logarithm of a number.
5528 ///
5529 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log10)
5530 #[wasm_bindgen(js_namespace = Math)]
5531 pub fn log10(x: f64) -> f64;
5532
5533 /// The `Math.log1p()` function returns the natural logarithm (base e) of 1 + a number.
5534 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log1p)
5535 #[wasm_bindgen(js_namespace = Math)]
5536 pub fn log1p(x: f64) -> f64;
5537
5538 /// The `Math.log2()` function returns the base 2 logarithm of a number.
5539 ///
5540 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log2)
5541 #[wasm_bindgen(js_namespace = Math)]
5542 pub fn log2(x: f64) -> f64;
5543
5544 /// The `Math.max()` function returns the largest of two numbers.
5545 ///
5546 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/max)
5547 #[wasm_bindgen(js_namespace = Math)]
5548 pub fn max(x: f64, y: f64) -> f64;
5549
5550 /// The static function `Math.min()` returns the lowest-valued number passed into it.
5551 ///
5552 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/min)
5553 #[wasm_bindgen(js_namespace = Math)]
5554 pub fn min(x: f64, y: f64) -> f64;
5555
5556 /// The `Math.pow()` function returns the base to the exponent power, that is, base^exponent.
5557 ///
5558 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/pow)
5559 #[wasm_bindgen(js_namespace = Math)]
5560 pub fn pow(base: f64, exponent: f64) -> f64;
5561
5562 /// The `Math.random()` function returns a floating-point, pseudo-random number
5563 /// in the range 0–1 (inclusive of 0, but not 1) with approximately uniform distribution
5564 /// over that range — which you can then scale to your desired range.
5565 /// The implementation selects the initial seed to the random number generation algorithm;
5566 /// it cannot be chosen or reset by the user.
5567 ///
5568 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random)
5569 #[wasm_bindgen(js_namespace = Math)]
5570 pub fn random() -> f64;
5571
5572 /// The `Math.round()` function returns the value of a number rounded to the nearest integer.
5573 ///
5574 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round)
5575 #[wasm_bindgen(js_namespace = Math)]
5576 pub fn round(x: f64) -> f64;
5577
5578 /// The `Math.sign()` function returns the sign of a number, indicating whether the number is
5579 /// positive, negative or zero.
5580 ///
5581 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign)
5582 #[wasm_bindgen(js_namespace = Math)]
5583 pub fn sign(x: f64) -> f64;
5584
5585 /// The `Math.sin()` function returns the sine of a number.
5586 ///
5587 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sin)
5588 #[wasm_bindgen(js_namespace = Math)]
5589 pub fn sin(x: f64) -> f64;
5590
5591 /// The `Math.sinh()` function returns the hyperbolic sine of a number, that can be expressed
5592 /// using the constant e: Math.sinh(x) = (e^x - e^-x)/2
5593 ///
5594 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sinh)
5595 #[wasm_bindgen(js_namespace = Math)]
5596 pub fn sinh(x: f64) -> f64;
5597
5598 /// The `Math.sqrt()` function returns the square root of a number, that is
5599 /// ∀x ≥ 0, Math.sqrt(x) = √x = the unique y ≥ 0 such that y^2 = x
5600 ///
5601 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sqrt)
5602 #[wasm_bindgen(js_namespace = Math)]
5603 pub fn sqrt(x: f64) -> f64;
5604
5605 /// The `Math.tan()` function returns the tangent of a number.
5606 ///
5607 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/tan)
5608 #[wasm_bindgen(js_namespace = Math)]
5609 pub fn tan(x: f64) -> f64;
5610
5611 /// The `Math.tanh()` function returns the hyperbolic tangent of a number, that is
5612 /// tanh x = sinh x / cosh x = (e^x - e^-x)/(e^x + e^-x) = (e^2x - 1)/(e^2x + 1)
5613 ///
5614 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/tanh)
5615 #[wasm_bindgen(js_namespace = Math)]
5616 pub fn tanh(x: f64) -> f64;
5617
5618 /// The `Math.trunc()` function returns the integer part of a number by removing any fractional
5619 /// digits.
5620 ///
5621 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/trunc)
5622 #[wasm_bindgen(js_namespace = Math)]
5623 pub fn trunc(x: f64) -> f64;
5624
5625 /// The `Math.PI` property represents the ratio of the circumference of a circle to its diameter,
5626 /// approximately 3.14159.
5627 ///
5628 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/PI)
5629 #[wasm_bindgen(thread_local_v2, js_namespace = Math)]
5630 pub static PI: f64;
5631 }
5632}
5633
5634// Number.
5635#[wasm_bindgen]
5636extern "C" {
5637 #[wasm_bindgen(extends = Object, is_type_of = |v| v.as_f64().is_some(), typescript_type = "number")]
5638 #[derive(Clone, PartialEq)]
5639 pub type Number;
5640
5641 /// The `Number.isFinite()` method determines whether the passed value is a finite number.
5642 ///
5643 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isFinite)
5644 #[wasm_bindgen(static_method_of = Number, js_name = isFinite)]
5645 pub fn is_finite(value: &JsValue) -> bool;
5646
5647 /// The `Number.isInteger()` method determines whether the passed value is an integer.
5648 ///
5649 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isInteger)
5650 #[wasm_bindgen(static_method_of = Number, js_name = isInteger)]
5651 pub fn is_integer(value: &JsValue) -> bool;
5652
5653 /// The `Number.isNaN()` method determines whether the passed value is `NaN` and its type is Number.
5654 /// It is a more robust version of the original, global isNaN().
5655 ///
5656 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isNaN)
5657 #[wasm_bindgen(static_method_of = Number, js_name = isNaN)]
5658 pub fn is_nan(value: &JsValue) -> bool;
5659
5660 /// The `Number.isSafeInteger()` method determines whether the provided value is a number
5661 /// that is a safe integer.
5662 ///
5663 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isSafeInteger)
5664 #[wasm_bindgen(static_method_of = Number, js_name = isSafeInteger)]
5665 pub fn is_safe_integer(value: &JsValue) -> bool;
5666
5667 /// The `Number` JavaScript object is a wrapper object allowing
5668 /// you to work with numerical values. A `Number` object is
5669 /// created using the `Number()` constructor.
5670 ///
5671 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
5672 #[cfg(not(js_sys_unstable_apis))]
5673 #[wasm_bindgen(constructor)]
5674 #[deprecated(note = "recommended to use `Number::from` instead")]
5675 #[allow(deprecated)]
5676 pub fn new(value: &JsValue) -> Number;
5677
5678 #[wasm_bindgen(constructor)]
5679 fn new_from_str(value: &str) -> Number;
5680
5681 /// The `Number.parseInt()` method parses a string argument and returns an
5682 /// integer of the specified radix or base.
5683 ///
5684 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/parseInt)
5685 #[wasm_bindgen(static_method_of = Number, js_name = parseInt)]
5686 pub fn parse_int(text: &str, radix: u8) -> f64;
5687
5688 /// The `Number.parseFloat()` method parses a string argument and returns a
5689 /// floating point number.
5690 ///
5691 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/parseFloat)
5692 #[wasm_bindgen(static_method_of = Number, js_name = parseFloat)]
5693 pub fn parse_float(text: &str) -> f64;
5694
5695 /// The `toLocaleString()` method returns a string with a language sensitive
5696 /// representation of this number.
5697 ///
5698 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString)
5699 #[cfg(not(js_sys_unstable_apis))]
5700 #[wasm_bindgen(method, js_name = toLocaleString)]
5701 pub fn to_locale_string(this: &Number, locale: &str) -> JsString;
5702
5703 /// The `toLocaleString()` method returns a string with a language sensitive
5704 /// representation of this number.
5705 ///
5706 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString)
5707 #[cfg(js_sys_unstable_apis)]
5708 #[wasm_bindgen(method, js_name = toLocaleString)]
5709 pub fn to_locale_string(
5710 this: &Number,
5711 locales: &[JsString],
5712 options: &Intl::NumberFormatOptions,
5713 ) -> JsString;
5714
5715 /// The `toPrecision()` method returns a string representing the Number
5716 /// object to the specified precision.
5717 ///
5718 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision)
5719 #[wasm_bindgen(catch, method, js_name = toPrecision)]
5720 pub fn to_precision(this: &Number, precision: u8) -> Result<JsString, JsValue>;
5721
5722 /// The `toFixed()` method returns a string representing the Number
5723 /// object using fixed-point notation.
5724 ///
5725 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed)
5726 #[wasm_bindgen(catch, method, js_name = toFixed)]
5727 pub fn to_fixed(this: &Number, digits: u8) -> Result<JsString, JsValue>;
5728
5729 /// The `toExponential()` method returns a string representing the Number
5730 /// object in exponential notation.
5731 ///
5732 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toExponential)
5733 #[wasm_bindgen(catch, method, js_name = toExponential)]
5734 pub fn to_exponential(this: &Number, fraction_digits: u8) -> Result<JsString, JsValue>;
5735
5736 /// The `toString()` method returns a string representing the
5737 /// specified Number object.
5738 ///
5739 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString)
5740 #[cfg(not(js_sys_unstable_apis))]
5741 #[deprecated(note = "Use `Number::to_string_with_radix` instead.")]
5742 #[allow(deprecated)]
5743 #[wasm_bindgen(catch, method, js_name = toString)]
5744 pub fn to_string(this: &Number, radix: u8) -> Result<JsString, JsValue>;
5745
5746 /// The `toString()` method returns a string representing the
5747 /// specified Number object.
5748 ///
5749 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString)
5750 #[wasm_bindgen(catch, method, js_name = toString)]
5751 pub fn to_string_with_radix(this: &Number, radix: u8) -> Result<JsString, JsValue>;
5752
5753 /// The `valueOf()` method returns the wrapped primitive value of
5754 /// a Number object.
5755 ///
5756 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/valueOf)
5757 #[wasm_bindgen(method, js_name = valueOf)]
5758 pub fn value_of(this: &Number) -> f64;
5759}
5760
5761impl Number {
5762 /// The smallest interval between two representable numbers.
5763 ///
5764 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/EPSILON)
5765 pub const EPSILON: f64 = f64::EPSILON;
5766 /// The maximum safe integer in JavaScript (2^53 - 1).
5767 ///
5768 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER)
5769 pub const MAX_SAFE_INTEGER: f64 = 9007199254740991.0;
5770 /// The largest positive representable number.
5771 ///
5772 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_VALUE)
5773 pub const MAX_VALUE: f64 = f64::MAX;
5774 /// The minimum safe integer in JavaScript (-(2^53 - 1)).
5775 ///
5776 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MIN_SAFE_INTEGER)
5777 pub const MIN_SAFE_INTEGER: f64 = -9007199254740991.0;
5778 /// The smallest positive representable number—that is, the positive number closest to zero
5779 /// (without actually being zero).
5780 ///
5781 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MIN_VALUE)
5782 // Cannot use f64::MIN_POSITIVE since that is the smallest **normal** positive number.
5783 pub const MIN_VALUE: f64 = 5E-324;
5784 /// Special "Not a Number" value.
5785 ///
5786 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/NaN)
5787 pub const NAN: f64 = f64::NAN;
5788 /// Special value representing negative infinity. Returned on overflow.
5789 ///
5790 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/NEGATIVE_INFINITY)
5791 pub const NEGATIVE_INFINITY: f64 = f64::NEG_INFINITY;
5792 /// Special value representing infinity. Returned on overflow.
5793 ///
5794 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/POSITIVE_INFINITY)
5795 pub const POSITIVE_INFINITY: f64 = f64::INFINITY;
5796
5797 /// Applies the binary `**` JS operator on the two `Number`s.
5798 ///
5799 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Exponentiation)
5800 #[inline]
5801 pub fn pow(&self, rhs: &Self) -> Self {
5802 JsValue::as_ref(self)
5803 .pow(JsValue::as_ref(rhs))
5804 .unchecked_into()
5805 }
5806
5807 /// Applies the binary `>>>` JS operator on the two `Number`s.
5808 ///
5809 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Unsigned_right_shift)
5810 #[inline]
5811 pub fn unsigned_shr(&self, rhs: &Self) -> Self {
5812 Number::from(JsValue::as_ref(self).unsigned_shr(JsValue::as_ref(rhs)))
5813 }
5814}
5815
5816macro_rules! number_from {
5817 ($($x:ident)*) => ($(
5818 impl From<$x> for Number {
5819 #[inline]
5820 fn from(x: $x) -> Number {
5821 Number::unchecked_from_js(JsValue::from(x))
5822 }
5823 }
5824
5825 impl PartialEq<$x> for Number {
5826 #[inline]
5827 fn eq(&self, other: &$x) -> bool {
5828 self.value_of() == f64::from(*other)
5829 }
5830 }
5831
5832 impl UpcastFrom<$x> for Number {}
5833 )*)
5834}
5835number_from!(i8 u8 i16 u16 i32 u32 f32 f64);
5836
5837// The only guarantee for a JS number
5838impl UpcastFrom<Number> for f64 {}
5839
5840/// The error type returned when a checked integral type conversion fails.
5841#[derive(Debug, Copy, Clone, PartialEq, Eq)]
5842pub struct TryFromIntError(());
5843
5844impl fmt::Display for TryFromIntError {
5845 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
5846 fmt.write_str("out of range integral type conversion attempted")
5847 }
5848}
5849
5850#[cfg(feature = "std")]
5851impl std::error::Error for TryFromIntError {}
5852
5853macro_rules! number_try_from {
5854 ($($x:ident)*) => ($(
5855 impl TryFrom<$x> for Number {
5856 type Error = TryFromIntError;
5857
5858 #[inline]
5859 fn try_from(x: $x) -> Result<Number, Self::Error> {
5860 let x_f64 = x as f64;
5861 if (Number::MIN_SAFE_INTEGER..=Number::MAX_SAFE_INTEGER).contains(&x_f64) {
5862 Ok(Number::from(x_f64))
5863 } else {
5864 Err(TryFromIntError(()))
5865 }
5866 }
5867 }
5868 )*)
5869}
5870number_try_from!(i64 u64 i128 u128);
5871
5872impl From<&Number> for f64 {
5873 #[inline]
5874 fn from(n: &Number) -> f64 {
5875 n.value_of()
5876 }
5877}
5878
5879impl From<Number> for f64 {
5880 #[inline]
5881 fn from(n: Number) -> f64 {
5882 <f64 as From<&'_ Number>>::from(&n)
5883 }
5884}
5885
5886impl fmt::Debug for Number {
5887 #[inline]
5888 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5889 fmt::Debug::fmt(&self.value_of(), f)
5890 }
5891}
5892
5893impl fmt::Display for Number {
5894 #[inline]
5895 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5896 fmt::Display::fmt(&self.value_of(), f)
5897 }
5898}
5899
5900impl Default for Number {
5901 fn default() -> Self {
5902 Self::from(f64::default())
5903 }
5904}
5905
5906impl PartialEq<BigInt> for Number {
5907 #[inline]
5908 fn eq(&self, other: &BigInt) -> bool {
5909 JsValue::as_ref(self).loose_eq(JsValue::as_ref(other))
5910 }
5911}
5912
5913impl Not for &Number {
5914 type Output = BigInt;
5915
5916 #[inline]
5917 fn not(self) -> Self::Output {
5918 JsValue::as_ref(self).bit_not().unchecked_into()
5919 }
5920}
5921
5922forward_deref_unop!(impl Not, not for Number);
5923forward_js_unop!(impl Neg, neg for Number);
5924forward_js_binop!(impl BitAnd, bitand for Number);
5925forward_js_binop!(impl BitOr, bitor for Number);
5926forward_js_binop!(impl BitXor, bitxor for Number);
5927forward_js_binop!(impl Shl, shl for Number);
5928forward_js_binop!(impl Shr, shr for Number);
5929forward_js_binop!(impl Add, add for Number);
5930forward_js_binop!(impl Sub, sub for Number);
5931forward_js_binop!(impl Div, div for Number);
5932forward_js_binop!(impl Mul, mul for Number);
5933forward_js_binop!(impl Rem, rem for Number);
5934
5935sum_product!(Number);
5936
5937impl PartialOrd for Number {
5938 #[inline]
5939 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
5940 if Number::is_nan(self) || Number::is_nan(other) {
5941 None
5942 } else if self == other {
5943 Some(Ordering::Equal)
5944 } else if self.lt(other) {
5945 Some(Ordering::Less)
5946 } else {
5947 Some(Ordering::Greater)
5948 }
5949 }
5950
5951 #[inline]
5952 fn lt(&self, other: &Self) -> bool {
5953 JsValue::as_ref(self).lt(JsValue::as_ref(other))
5954 }
5955
5956 #[inline]
5957 fn le(&self, other: &Self) -> bool {
5958 JsValue::as_ref(self).le(JsValue::as_ref(other))
5959 }
5960
5961 #[inline]
5962 fn ge(&self, other: &Self) -> bool {
5963 JsValue::as_ref(self).ge(JsValue::as_ref(other))
5964 }
5965
5966 #[inline]
5967 fn gt(&self, other: &Self) -> bool {
5968 JsValue::as_ref(self).gt(JsValue::as_ref(other))
5969 }
5970}
5971
5972#[cfg(not(js_sys_unstable_apis))]
5973impl FromStr for Number {
5974 type Err = Infallible;
5975
5976 #[allow(deprecated)]
5977 #[inline]
5978 fn from_str(s: &str) -> Result<Self, Self::Err> {
5979 Ok(Number::new_from_str(s))
5980 }
5981}
5982
5983// Date.
5984#[wasm_bindgen]
5985extern "C" {
5986 #[wasm_bindgen(extends = Object, typescript_type = "Date")]
5987 #[derive(Clone, Debug, PartialEq, Eq)]
5988 pub type Date;
5989
5990 /// The `getDate()` method returns the day of the month for the
5991 /// specified date according to local time.
5992 ///
5993 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getDate)
5994 #[wasm_bindgen(method, js_name = getDate)]
5995 pub fn get_date(this: &Date) -> u32;
5996
5997 /// The `getDay()` method returns the day of the week for the specified date according to local time,
5998 /// where 0 represents Sunday. For the day of the month see getDate().
5999 ///
6000 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getDay)
6001 #[wasm_bindgen(method, js_name = getDay)]
6002 pub fn get_day(this: &Date) -> u32;
6003
6004 /// The `getFullYear()` method returns the year of the specified date according to local time.
6005 ///
6006 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getFullYear)
6007 #[wasm_bindgen(method, js_name = getFullYear)]
6008 pub fn get_full_year(this: &Date) -> u32;
6009
6010 /// The `getHours()` method returns the hour for the specified date, according to local time.
6011 ///
6012 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getHours)
6013 #[wasm_bindgen(method, js_name = getHours)]
6014 pub fn get_hours(this: &Date) -> u32;
6015
6016 /// The `getMilliseconds()` method returns the milliseconds in the specified date according to local time.
6017 ///
6018 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMilliseconds)
6019 #[wasm_bindgen(method, js_name = getMilliseconds)]
6020 pub fn get_milliseconds(this: &Date) -> u32;
6021
6022 /// The `getMinutes()` method returns the minutes in the specified date according to local time.
6023 ///
6024 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMinutes)
6025 #[wasm_bindgen(method, js_name = getMinutes)]
6026 pub fn get_minutes(this: &Date) -> u32;
6027
6028 /// The `getMonth()` method returns the month in the specified date according to local time,
6029 /// as a zero-based value (where zero indicates the first month of the year).
6030 ///
6031 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMonth)
6032 #[wasm_bindgen(method, js_name = getMonth)]
6033 pub fn get_month(this: &Date) -> u32;
6034
6035 /// The `getSeconds()` method returns the seconds in the specified date according to local time.
6036 ///
6037 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getSeconds)
6038 #[wasm_bindgen(method, js_name = getSeconds)]
6039 pub fn get_seconds(this: &Date) -> u32;
6040
6041 /// The `getTime()` method returns the numeric value corresponding to the time for the specified date
6042 /// according to universal time.
6043 ///
6044 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTime)
6045 #[wasm_bindgen(method, js_name = getTime)]
6046 pub fn get_time(this: &Date) -> f64;
6047
6048 /// The `getTimezoneOffset()` method returns the time zone difference, in minutes,
6049 /// from current locale (host system settings) to UTC.
6050 ///
6051 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTimezoneOffset)
6052 #[wasm_bindgen(method, js_name = getTimezoneOffset)]
6053 pub fn get_timezone_offset(this: &Date) -> f64;
6054
6055 /// The `getUTCDate()` method returns the day (date) of the month in the specified date
6056 /// according to universal time.
6057 ///
6058 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCDate)
6059 #[wasm_bindgen(method, js_name = getUTCDate)]
6060 pub fn get_utc_date(this: &Date) -> u32;
6061
6062 /// The `getUTCDay()` method returns the day of the week in the specified date according to universal time,
6063 /// where 0 represents Sunday.
6064 ///
6065 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCDay)
6066 #[wasm_bindgen(method, js_name = getUTCDay)]
6067 pub fn get_utc_day(this: &Date) -> u32;
6068
6069 /// The `getUTCFullYear()` method returns the year in the specified date according to universal time.
6070 ///
6071 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCFullYear)
6072 #[wasm_bindgen(method, js_name = getUTCFullYear)]
6073 pub fn get_utc_full_year(this: &Date) -> u32;
6074
6075 /// The `getUTCHours()` method returns the hours in the specified date according to universal time.
6076 ///
6077 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCHours)
6078 #[wasm_bindgen(method, js_name = getUTCHours)]
6079 pub fn get_utc_hours(this: &Date) -> u32;
6080
6081 /// The `getUTCMilliseconds()` method returns the milliseconds 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/getUTCMilliseconds)
6085 #[wasm_bindgen(method, js_name = getUTCMilliseconds)]
6086 pub fn get_utc_milliseconds(this: &Date) -> u32;
6087
6088 /// The `getUTCMinutes()` method returns the minutes in the specified date according to universal time.
6089 ///
6090 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCMinutes)
6091 #[wasm_bindgen(method, js_name = getUTCMinutes)]
6092 pub fn get_utc_minutes(this: &Date) -> u32;
6093
6094 /// The `getUTCMonth()` returns the month of the specified date according to universal time,
6095 /// as a zero-based value (where zero indicates the first month of the year).
6096 ///
6097 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCMonth)
6098 #[wasm_bindgen(method, js_name = getUTCMonth)]
6099 pub fn get_utc_month(this: &Date) -> u32;
6100
6101 /// The `getUTCSeconds()` method returns the seconds 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/getUTCSeconds)
6104 #[wasm_bindgen(method, js_name = getUTCSeconds)]
6105 pub fn get_utc_seconds(this: &Date) -> u32;
6106
6107 /// Creates a JavaScript `Date` instance that represents
6108 /// a single moment in time. `Date` objects are based on a time value that is
6109 /// the number of milliseconds since 1 January 1970 UTC.
6110 ///
6111 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6112 #[wasm_bindgen(constructor)]
6113 pub fn new(init: &JsValue) -> Date;
6114
6115 /// Creates a JavaScript `Date` instance that represents the current moment in
6116 /// time.
6117 ///
6118 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6119 #[wasm_bindgen(constructor)]
6120 pub fn new_0() -> Date;
6121
6122 /// Creates a JavaScript `Date` instance that represents
6123 /// a single moment in time. `Date` objects are based on a time value that is
6124 /// the number of milliseconds since 1 January 1970 UTC.
6125 ///
6126 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6127 #[wasm_bindgen(constructor)]
6128 pub fn new_with_year_month(year: u32, month: i32) -> Date;
6129
6130 /// Creates a JavaScript `Date` instance that represents
6131 /// a single moment in time. `Date` objects are based on a time value that is
6132 /// the number of milliseconds since 1 January 1970 UTC.
6133 ///
6134 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6135 #[wasm_bindgen(constructor)]
6136 pub fn new_with_year_month_day(year: u32, month: i32, day: i32) -> Date;
6137
6138 /// Creates a JavaScript `Date` instance that represents
6139 /// a single moment in time. `Date` objects are based on a time value that is
6140 /// the number of milliseconds since 1 January 1970 UTC.
6141 ///
6142 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6143 #[wasm_bindgen(constructor)]
6144 pub fn new_with_year_month_day_hr(year: u32, month: i32, day: i32, hr: i32) -> Date;
6145
6146 /// Creates a JavaScript `Date` instance that represents
6147 /// a single moment in time. `Date` objects are based on a time value that is
6148 /// the number of milliseconds since 1 January 1970 UTC.
6149 ///
6150 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6151 #[wasm_bindgen(constructor)]
6152 pub fn new_with_year_month_day_hr_min(
6153 year: u32,
6154 month: i32,
6155 day: i32,
6156 hr: i32,
6157 min: i32,
6158 ) -> Date;
6159
6160 /// Creates a JavaScript `Date` instance that represents
6161 /// a single moment in time. `Date` objects are based on a time value that is
6162 /// the number of milliseconds since 1 January 1970 UTC.
6163 ///
6164 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6165 #[wasm_bindgen(constructor)]
6166 pub fn new_with_year_month_day_hr_min_sec(
6167 year: u32,
6168 month: i32,
6169 day: i32,
6170 hr: i32,
6171 min: i32,
6172 sec: i32,
6173 ) -> Date;
6174
6175 /// Creates a JavaScript `Date` instance that represents
6176 /// a single moment in time. `Date` objects are based on a time value that is
6177 /// the number of milliseconds since 1 January 1970 UTC.
6178 ///
6179 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6180 #[wasm_bindgen(constructor)]
6181 pub fn new_with_year_month_day_hr_min_sec_milli(
6182 year: u32,
6183 month: i32,
6184 day: i32,
6185 hr: i32,
6186 min: i32,
6187 sec: i32,
6188 milli: i32,
6189 ) -> Date;
6190
6191 /// The `Date.now()` method returns the number of milliseconds
6192 /// elapsed since January 1, 1970 00:00:00 UTC.
6193 ///
6194 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/now)
6195 #[wasm_bindgen(static_method_of = Date)]
6196 pub fn now() -> f64;
6197
6198 /// The `Date.parse()` method parses a string representation of a date, and returns the number of milliseconds
6199 /// since January 1, 1970, 00:00:00 UTC or `NaN` if the string is unrecognized or, in some cases,
6200 /// contains illegal date values (e.g. 2015-02-31).
6201 ///
6202 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse)
6203 #[wasm_bindgen(static_method_of = Date)]
6204 pub fn parse(date: &str) -> f64;
6205
6206 /// The `setDate()` method sets the day of the Date object relative to the beginning of the currently set month.
6207 ///
6208 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setDate)
6209 #[wasm_bindgen(method, js_name = setDate)]
6210 pub fn set_date(this: &Date, day: u32) -> f64;
6211
6212 /// The `setFullYear()` method sets the full year for a specified date according to local time.
6213 /// Returns new timestamp.
6214 ///
6215 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setFullYear)
6216 #[wasm_bindgen(method, js_name = setFullYear)]
6217 pub fn set_full_year(this: &Date, year: u32) -> f64;
6218
6219 /// The `setFullYear()` method sets the full year for a specified date according to local time.
6220 /// Returns new timestamp.
6221 ///
6222 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setFullYear)
6223 #[wasm_bindgen(method, js_name = setFullYear)]
6224 pub fn set_full_year_with_month(this: &Date, year: u32, month: i32) -> f64;
6225
6226 /// The `setFullYear()` method sets the full year for a specified date according to local time.
6227 /// Returns new timestamp.
6228 ///
6229 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setFullYear)
6230 #[wasm_bindgen(method, js_name = setFullYear)]
6231 pub fn set_full_year_with_month_date(this: &Date, year: u32, month: i32, date: i32) -> f64;
6232
6233 /// The `setHours()` method sets the hours for a specified date according to local time,
6234 /// and returns the number of milliseconds since January 1, 1970 00:00:00 UTC until the time represented
6235 /// by the updated Date instance.
6236 ///
6237 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setHours)
6238 #[wasm_bindgen(method, js_name = setHours)]
6239 pub fn set_hours(this: &Date, hours: u32) -> f64;
6240
6241 /// The `setMilliseconds()` method sets the milliseconds for a specified date according to local time.
6242 ///
6243 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setMilliseconds)
6244 #[wasm_bindgen(method, js_name = setMilliseconds)]
6245 pub fn set_milliseconds(this: &Date, milliseconds: u32) -> f64;
6246
6247 /// The `setMinutes()` method sets the minutes for a specified date according to local time.
6248 ///
6249 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setMinutes)
6250 #[wasm_bindgen(method, js_name = setMinutes)]
6251 pub fn set_minutes(this: &Date, minutes: u32) -> f64;
6252
6253 /// The `setMonth()` method sets the month for a specified date according to the currently set year.
6254 ///
6255 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setMonth)
6256 #[wasm_bindgen(method, js_name = setMonth)]
6257 pub fn set_month(this: &Date, month: u32) -> f64;
6258
6259 /// The `setSeconds()` method sets the seconds for a specified date according to local time.
6260 ///
6261 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setSeconds)
6262 #[wasm_bindgen(method, js_name = setSeconds)]
6263 pub fn set_seconds(this: &Date, seconds: u32) -> f64;
6264
6265 /// The `setTime()` method sets the Date object to the time represented by a number of milliseconds
6266 /// since January 1, 1970, 00:00:00 UTC.
6267 ///
6268 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setTime)
6269 #[wasm_bindgen(method, js_name = setTime)]
6270 pub fn set_time(this: &Date, time: f64) -> f64;
6271
6272 /// The `setUTCDate()` method sets the day of the month for a specified date
6273 /// according to universal time.
6274 ///
6275 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCDate)
6276 #[wasm_bindgen(method, js_name = setUTCDate)]
6277 pub fn set_utc_date(this: &Date, day: u32) -> f64;
6278
6279 /// The `setUTCFullYear()` method sets the full year for a specified date according to universal time.
6280 ///
6281 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCFullYear)
6282 #[wasm_bindgen(method, js_name = setUTCFullYear)]
6283 pub fn set_utc_full_year(this: &Date, year: u32) -> f64;
6284
6285 /// The `setUTCFullYear()` method sets the full year for a specified date according to universal time.
6286 ///
6287 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCFullYear)
6288 #[wasm_bindgen(method, js_name = setUTCFullYear)]
6289 pub fn set_utc_full_year_with_month(this: &Date, year: u32, month: i32) -> f64;
6290
6291 /// The `setUTCFullYear()` method sets the full year for a specified date according to universal time.
6292 ///
6293 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCFullYear)
6294 #[wasm_bindgen(method, js_name = setUTCFullYear)]
6295 pub fn set_utc_full_year_with_month_date(this: &Date, year: u32, month: i32, date: i32) -> f64;
6296
6297 /// The `setUTCHours()` method sets the hour for a specified date according to universal time,
6298 /// and returns the number of milliseconds since January 1, 1970 00:00:00 UTC until the time
6299 /// represented by the updated Date instance.
6300 ///
6301 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCHours)
6302 #[wasm_bindgen(method, js_name = setUTCHours)]
6303 pub fn set_utc_hours(this: &Date, hours: u32) -> f64;
6304
6305 /// The `setUTCMilliseconds()` method sets the milliseconds for a specified date
6306 /// according to universal time.
6307 ///
6308 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCMilliseconds)
6309 #[wasm_bindgen(method, js_name = setUTCMilliseconds)]
6310 pub fn set_utc_milliseconds(this: &Date, milliseconds: u32) -> f64;
6311
6312 /// The `setUTCMinutes()` method sets the minutes for a specified date according to universal time.
6313 ///
6314 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCMinutes)
6315 #[wasm_bindgen(method, js_name = setUTCMinutes)]
6316 pub fn set_utc_minutes(this: &Date, minutes: u32) -> f64;
6317
6318 /// The `setUTCMonth()` method sets the month for a specified date according to universal time.
6319 ///
6320 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCMonth)
6321 #[wasm_bindgen(method, js_name = setUTCMonth)]
6322 pub fn set_utc_month(this: &Date, month: u32) -> f64;
6323
6324 /// The `setUTCSeconds()` method sets the seconds for a specified date according to universal time.
6325 ///
6326 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCSeconds)
6327 #[wasm_bindgen(method, js_name = setUTCSeconds)]
6328 pub fn set_utc_seconds(this: &Date, seconds: u32) -> f64;
6329
6330 /// The `toDateString()` method returns the date portion of a Date object
6331 /// in human readable form in American English.
6332 ///
6333 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toDateString)
6334 #[wasm_bindgen(method, js_name = toDateString)]
6335 pub fn to_date_string(this: &Date) -> JsString;
6336
6337 /// The `toISOString()` method returns a string in simplified extended ISO format (ISO
6338 /// 8601), which is always 24 or 27 characters long (YYYY-MM-DDTHH:mm:ss.sssZ or
6339 /// ±YYYYYY-MM-DDTHH:mm:ss.sssZ, respectively). The timezone is always zero UTC offset,
6340 /// as denoted by the suffix "Z"
6341 ///
6342 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString)
6343 #[wasm_bindgen(method, js_name = toISOString)]
6344 pub fn to_iso_string(this: &Date) -> JsString;
6345
6346 /// The `toJSON()` method returns a string representation of the Date object.
6347 ///
6348 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toJSON)
6349 #[wasm_bindgen(method, js_name = toJSON)]
6350 pub fn to_json(this: &Date) -> JsString;
6351
6352 /// The `toLocaleDateString()` method returns a string with a language sensitive
6353 /// representation of the date portion of this date. The new locales and options
6354 /// arguments let applications specify the language whose formatting conventions
6355 /// should be used and allow to customize the behavior of the function.
6356 /// In older implementations, which ignore the locales and options arguments,
6357 /// the locale used and the form of the string
6358 /// returned are entirely implementation dependent.
6359 ///
6360 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString)
6361 #[cfg(not(js_sys_unstable_apis))]
6362 #[wasm_bindgen(method, js_name = toLocaleDateString)]
6363 pub fn to_locale_date_string(this: &Date, locale: &str, options: &JsValue) -> JsString;
6364
6365 /// The `toLocaleDateString()` method returns a string with a language sensitive
6366 /// representation of the date portion of this date.
6367 ///
6368 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString)
6369 #[cfg(js_sys_unstable_apis)]
6370 #[wasm_bindgen(method, js_name = toLocaleDateString)]
6371 pub fn to_locale_date_string(
6372 this: &Date,
6373 locales: &[JsString],
6374 options: &Intl::DateTimeFormatOptions,
6375 ) -> JsString;
6376
6377 /// The `toLocaleString()` method returns a string with a language sensitive
6378 /// representation of this date. The new locales and options arguments
6379 /// let applications specify the language whose formatting conventions
6380 /// should be used and customize the behavior of the function.
6381 /// In older implementations, which ignore the locales
6382 /// and options arguments, the locale used and the form of the string
6383 /// returned are entirely implementation dependent.
6384 ///
6385 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString)
6386 #[cfg(not(js_sys_unstable_apis))]
6387 #[wasm_bindgen(method, js_name = toLocaleString)]
6388 pub fn to_locale_string(this: &Date, locale: &str, options: &JsValue) -> JsString;
6389
6390 /// The `toLocaleString()` method returns a string with a language sensitive
6391 /// representation of this date.
6392 ///
6393 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString)
6394 #[cfg(js_sys_unstable_apis)]
6395 #[wasm_bindgen(method, js_name = toLocaleString)]
6396 pub fn to_locale_string(
6397 this: &Date,
6398 locales: &[JsString],
6399 options: &Intl::DateTimeFormatOptions,
6400 ) -> JsString;
6401
6402 /// The `toLocaleTimeString()` method returns a string with a language sensitive
6403 /// representation of the time portion of this date. The new locales and options
6404 /// arguments let applications specify the language whose formatting conventions should be
6405 /// used and customize the behavior of the function. In older implementations, which ignore
6406 /// the locales and options arguments, the locale used and the form of the string
6407 /// returned are entirely implementation dependent.
6408 ///
6409 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleTimeString)
6410 #[cfg(not(js_sys_unstable_apis))]
6411 #[wasm_bindgen(method, js_name = toLocaleTimeString)]
6412 pub fn to_locale_time_string(this: &Date, locale: &str) -> JsString;
6413
6414 /// The `toLocaleTimeString()` method returns a string with a language sensitive
6415 /// representation of the time portion of this date.
6416 ///
6417 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleTimeString)
6418 #[cfg(js_sys_unstable_apis)]
6419 #[wasm_bindgen(method, js_name = toLocaleTimeString)]
6420 pub fn to_locale_time_string(
6421 this: &Date,
6422 locales: &[JsString],
6423 options: &Intl::DateTimeFormatOptions,
6424 ) -> JsString;
6425
6426 #[cfg(not(js_sys_unstable_apis))]
6427 #[wasm_bindgen(method, js_name = toLocaleTimeString)]
6428 pub fn to_locale_time_string_with_options(
6429 this: &Date,
6430 locale: &str,
6431 options: &JsValue,
6432 ) -> JsString;
6433
6434 /// The `toString()` method returns a string representing
6435 /// the specified Date object.
6436 ///
6437 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toString)
6438 #[cfg(not(js_sys_unstable_apis))]
6439 #[wasm_bindgen(method, js_name = toString)]
6440 pub fn to_string(this: &Date) -> JsString;
6441
6442 /// The `toTimeString()` method returns the time portion of a Date object in human
6443 /// readable form in American English.
6444 ///
6445 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toTimeString)
6446 #[wasm_bindgen(method, js_name = toTimeString)]
6447 pub fn to_time_string(this: &Date) -> JsString;
6448
6449 /// The `toUTCString()` method converts a date to a string,
6450 /// using the UTC time zone.
6451 ///
6452 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toUTCString)
6453 #[wasm_bindgen(method, js_name = toUTCString)]
6454 pub fn to_utc_string(this: &Date) -> JsString;
6455
6456 /// The `Date.UTC()` method accepts the same parameters as the
6457 /// longest form of the constructor, and returns the number of
6458 /// milliseconds in a `Date` object since January 1, 1970,
6459 /// 00:00:00, universal time.
6460 ///
6461 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/UTC)
6462 #[wasm_bindgen(static_method_of = Date, js_name = UTC)]
6463 pub fn utc(year: f64, month: f64) -> f64;
6464
6465 /// The `valueOf()` method returns the primitive value of
6466 /// a Date object.
6467 ///
6468 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/valueOf)
6469 #[wasm_bindgen(method, js_name = valueOf)]
6470 pub fn value_of(this: &Date) -> f64;
6471
6472 /// The `toTemporalInstant()` method converts a legacy `Date` object to a
6473 /// `Temporal.Instant` object representing the same moment in time.
6474 ///
6475 /// This method is added by the Temporal proposal to facilitate migration
6476 /// from legacy `Date` to the new Temporal API.
6477 ///
6478 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toTemporalInstant)
6479 #[cfg(js_sys_unstable_apis)]
6480 #[wasm_bindgen(method, js_name = toTemporalInstant)]
6481 pub fn to_temporal_instant(this: &Date) -> Temporal::Instant;
6482}
6483
6484// Property Descriptor.
6485#[wasm_bindgen]
6486extern "C" {
6487 #[wasm_bindgen(extends = Object)]
6488 #[derive(Clone, Debug)]
6489 pub type PropertyDescriptor<T = JsValue>;
6490
6491 #[wasm_bindgen(method, getter = writable)]
6492 pub fn get_writable<T>(this: &PropertyDescriptor<T>) -> Option<bool>;
6493
6494 #[wasm_bindgen(method, setter = writable)]
6495 pub fn set_writable<T>(this: &PropertyDescriptor<T>, writable: bool);
6496
6497 #[wasm_bindgen(method, getter = enumerable)]
6498 pub fn get_enumerable<T>(this: &PropertyDescriptor<T>) -> Option<bool>;
6499
6500 #[wasm_bindgen(method, setter = enumerable)]
6501 pub fn set_enumerable<T>(this: &PropertyDescriptor<T>, enumerable: bool);
6502
6503 #[wasm_bindgen(method, getter = configurable)]
6504 pub fn get_configurable<T>(this: &PropertyDescriptor<T>) -> Option<bool>;
6505
6506 #[wasm_bindgen(method, setter = configurable)]
6507 pub fn set_configurable<T>(this: &PropertyDescriptor<T>, configurable: bool);
6508
6509 #[wasm_bindgen(method, getter = get)]
6510 pub fn get_get<T: JsGeneric>(this: &PropertyDescriptor<T>) -> Option<Function<fn() -> T>>;
6511
6512 #[wasm_bindgen(method, setter = get)]
6513 pub fn set_get<T: JsGeneric>(this: &PropertyDescriptor<T>, get: Function<fn() -> T>);
6514
6515 #[wasm_bindgen(method, getter = set)]
6516 pub fn get_set<T: JsGeneric>(
6517 this: &PropertyDescriptor<T>,
6518 ) -> Option<Function<fn(T) -> JsValue>>;
6519
6520 #[wasm_bindgen(method, setter = set)]
6521 pub fn set_set<T: JsGeneric>(this: &PropertyDescriptor<T>, set: Function<fn(T) -> JsValue>);
6522
6523 #[wasm_bindgen(method, getter = value)]
6524 pub fn get_value<T>(this: &PropertyDescriptor<T>) -> Option<T>;
6525
6526 #[wasm_bindgen(method, setter = value)]
6527 pub fn set_value<T>(this: &PropertyDescriptor<T>, value: &T);
6528}
6529
6530impl PropertyDescriptor {
6531 #[cfg(not(js_sys_unstable_apis))]
6532 pub fn new<T>() -> PropertyDescriptor<T> {
6533 JsCast::unchecked_into(Object::new())
6534 }
6535
6536 #[cfg(js_sys_unstable_apis)]
6537 pub fn new<T>() -> PropertyDescriptor<T> {
6538 JsCast::unchecked_into(Object::<JsValue>::new())
6539 }
6540
6541 #[cfg(not(js_sys_unstable_apis))]
6542 pub fn new_value<T: JsGeneric>(value: &T) -> PropertyDescriptor<T> {
6543 let desc: PropertyDescriptor<T> = JsCast::unchecked_into(Object::new());
6544 desc.set_value(value);
6545 desc
6546 }
6547
6548 #[cfg(js_sys_unstable_apis)]
6549 pub fn new_value<T: JsGeneric>(value: &T) -> PropertyDescriptor<T> {
6550 let desc: PropertyDescriptor<T> = JsCast::unchecked_into(Object::<JsValue>::new());
6551 desc.set_value(value);
6552 desc
6553 }
6554}
6555
6556impl Default for PropertyDescriptor {
6557 fn default() -> Self {
6558 PropertyDescriptor::new()
6559 }
6560}
6561
6562// Object.
6563#[wasm_bindgen]
6564extern "C" {
6565 #[wasm_bindgen(typescript_type = "object")]
6566 #[derive(Clone, Debug)]
6567 pub type Object<T = JsValue>;
6568
6569 // Next major: deprecate
6570 /// The `Object.assign()` method is used to copy the values of all enumerable
6571 /// own properties from one or more source objects to a target object. It
6572 /// will return the target object.
6573 ///
6574 /// **Note:** Consider using [`Object::try_assign`] to support error handling.
6575 ///
6576 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
6577 #[wasm_bindgen(static_method_of = Object)]
6578 pub fn assign<T>(target: &Object<T>, source: &Object<T>) -> Object<T>;
6579
6580 // Next major: deprecate
6581 /// The `Object.assign()` method is used to copy the values of all enumerable
6582 /// own properties from one or more source objects to a target object. It
6583 /// will return the target object.
6584 ///
6585 /// **Note:** Consider using [`Object::try_assign`] to support error handling.
6586 ///
6587 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
6588 #[wasm_bindgen(static_method_of = Object, js_name = assign, catch)]
6589 pub fn try_assign<T>(target: &Object<T>, source: &Object<T>) -> Result<Object<T>, JsValue>;
6590
6591 /// The `Object.assign()` method is used to copy the values of all enumerable
6592 /// own properties from one or more source objects to a target object. It
6593 /// will return the target object.
6594 ///
6595 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
6596 #[cfg(not(js_sys_unstable_apis))]
6597 #[wasm_bindgen(static_method_of = Object, js_name = assign)]
6598 #[deprecated(note = "use `assign_many` for arbitrary assign arguments instead")]
6599 #[allow(deprecated)]
6600 pub fn assign2<T>(target: &Object<T>, source1: &Object<T>, source2: &Object<T>) -> Object<T>;
6601
6602 /// The `Object.assign()` method is used to copy the values of all enumerable
6603 /// own properties from one or more source objects to a target object. It
6604 /// will return the target object.
6605 ///
6606 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
6607 #[cfg(not(js_sys_unstable_apis))]
6608 #[wasm_bindgen(static_method_of = Object, js_name = assign)]
6609 #[deprecated(note = "use `assign_many` for arbitrary assign arguments instead")]
6610 #[allow(deprecated)]
6611 pub fn assign3<T>(
6612 target: &Object<T>,
6613 source1: &Object<T>,
6614 source2: &Object<T>,
6615 source3: &Object<T>,
6616 ) -> Object<T>;
6617
6618 /// The `Object.assign()` method is used to copy the values of all enumerable
6619 /// own properties from one or more source objects to a target object. It
6620 /// will return the target object.
6621 ///
6622 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
6623 #[wasm_bindgen(static_method_of = Object, js_name = assign, catch, variadic)]
6624 pub fn assign_many<T>(target: &Object<T>, sources: &[Object<T>]) -> Result<Object<T>, JsValue>;
6625
6626 /// The constructor property returns a reference to the `Object` constructor
6627 /// function that created the instance object.
6628 ///
6629 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/constructor)
6630 #[wasm_bindgen(method, getter)]
6631 pub fn constructor<T>(this: &Object<T>) -> Function;
6632
6633 /// The `Object.create()` method creates a new object, using an existing
6634 /// object to provide the newly created object's prototype.
6635 ///
6636 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/create)
6637 #[wasm_bindgen(static_method_of = Object)]
6638 pub fn create<T>(prototype: &Object<T>) -> Object<T>;
6639
6640 /// The static method `Object.defineProperty()` defines a new
6641 /// property directly on an object, or modifies an existing
6642 /// property on an object, and returns the object.
6643 ///
6644 /// **Note:** Consider using [`Object::define_property_str`] to support typing and error handling.
6645 ///
6646 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty)
6647 #[cfg(not(js_sys_unstable_apis))]
6648 #[wasm_bindgen(static_method_of = Object, js_name = defineProperty)]
6649 pub fn define_property<T>(obj: &Object<T>, prop: &JsValue, descriptor: &Object) -> Object<T>;
6650
6651 /// The static method `Object.defineProperty()` defines a new
6652 /// property directly on an object, or modifies an existing
6653 /// property on an object, and returns the object.
6654 ///
6655 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty)
6656 #[cfg(js_sys_unstable_apis)]
6657 #[wasm_bindgen(static_method_of = Object, js_name = defineProperty, catch)]
6658 pub fn define_property<T>(
6659 obj: &Object<T>,
6660 prop: &JsString,
6661 descriptor: &PropertyDescriptor<T>,
6662 ) -> Result<Object<T>, JsValue>;
6663
6664 // Next major: deprecate
6665 /// The static method `Object.defineProperty()` defines a new
6666 /// property directly on an object, or modifies an existing
6667 /// property on an object, and returns the object.
6668 ///
6669 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty)
6670 #[wasm_bindgen(static_method_of = Object, js_name = defineProperty, catch)]
6671 pub fn define_property_str<T>(
6672 obj: &Object<T>,
6673 prop: &JsString,
6674 descriptor: &PropertyDescriptor<T>,
6675 ) -> Result<Object<T>, JsValue>;
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 #[wasm_bindgen(static_method_of = Object, js_name = defineProperty, catch)]
6683 pub fn define_property_symbol<T>(
6684 obj: &Object<T>,
6685 prop: &Symbol,
6686 descriptor: &PropertyDescriptor<JsValue>,
6687 ) -> Result<Object<T>, JsValue>;
6688
6689 /// The `Object.defineProperties()` method defines new or modifies
6690 /// existing properties directly on an object, returning the
6691 /// object.
6692 ///
6693 /// **Note:** Consider using [`Object::try_define_properties`] to support typing and error handling.
6694 ///
6695 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperties)
6696 #[wasm_bindgen(static_method_of = Object, js_name = defineProperties)]
6697 pub fn define_properties<T>(obj: &Object<T>, props: &Object) -> Object<T>;
6698
6699 /// The `Object.defineProperties()` method defines new or modifies
6700 /// existing properties directly on an object, returning the
6701 /// object.
6702 ///
6703 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperties)
6704 #[cfg(js_sys_unstable_apis)]
6705 #[wasm_bindgen(static_method_of = Object, js_name = defineProperties, catch)]
6706 pub fn try_define_properties<T>(
6707 obj: &Object<T>,
6708 props: &Object<PropertyDescriptor<T>>,
6709 ) -> Result<Object<T>, JsValue>;
6710
6711 /// The `Object.entries()` method returns an array of a given
6712 /// object's own enumerable property [key, value] pairs, in the
6713 /// same order as that provided by a for...in loop (the difference
6714 /// being that a for-in loop enumerates properties in the
6715 /// prototype chain as well).
6716 ///
6717 /// **Note:** Consider using [`Object::entries_typed`] to support typing and error handling.
6718 ///
6719 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries)
6720 #[cfg(not(js_sys_unstable_apis))]
6721 #[wasm_bindgen(static_method_of = Object)]
6722 pub fn entries(object: &Object) -> Array;
6723
6724 /// The `Object.entries()` method returns an array of a given
6725 /// object's own enumerable property [key, value] pairs, in the
6726 /// same order as that provided by a for...in loop (the difference
6727 /// being that a for-in loop enumerates properties in the
6728 /// prototype chain as well).
6729 ///
6730 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries)
6731 #[cfg(js_sys_unstable_apis)]
6732 #[wasm_bindgen(static_method_of = Object, js_name = entries, catch)]
6733 pub fn entries<T: JsGeneric>(
6734 object: &Object<T>,
6735 ) -> Result<Array<ArrayTuple<(JsString, T)>>, JsValue>;
6736
6737 // Next major: deprecate
6738 /// The `Object.entries()` method returns an array of a given
6739 /// object's own enumerable property [key, value] pairs, in the
6740 /// same order as that provided by a for...in loop (the difference
6741 /// being that a for-in loop enumerates properties in the
6742 /// prototype chain as well).
6743 ///
6744 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries)
6745 #[wasm_bindgen(static_method_of = Object, js_name = entries, catch)]
6746 pub fn entries_typed<T: JsGeneric>(
6747 object: &Object<T>,
6748 ) -> Result<Array<ArrayTuple<(JsString, T)>>, JsValue>;
6749
6750 /// The `Object.freeze()` method freezes an object: that is, prevents new
6751 /// properties from being added to it; prevents existing properties from
6752 /// being removed; and prevents existing properties, or their enumerability,
6753 /// configurability, or writability, from being changed, it also prevents
6754 /// the prototype from being changed. The method returns the passed object.
6755 ///
6756 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze)
6757 #[wasm_bindgen(static_method_of = Object)]
6758 pub fn freeze<T>(value: &Object<T>) -> Object<T>;
6759
6760 /// The `Object.fromEntries()` method transforms a list of key-value pairs
6761 /// into an object.
6762 ///
6763 /// **Note:** Consider using [`Object::from_entries_typed`] to support typing and error handling.
6764 ///
6765 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/fromEntries)
6766 #[cfg(not(js_sys_unstable_apis))]
6767 #[wasm_bindgen(static_method_of = Object, catch, js_name = fromEntries)]
6768 pub fn from_entries(entries: &JsValue) -> Result<Object, JsValue>;
6769
6770 /// The `Object.fromEntries()` method transforms a list of key-value pairs
6771 /// into an object.
6772 ///
6773 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/fromEntries)
6774 #[cfg(js_sys_unstable_apis)]
6775 #[wasm_bindgen(static_method_of = Object, catch, js_name = fromEntries)]
6776 pub fn from_entries<T: JsGeneric, I: Iterable<Item = ArrayTuple<(JsString, T)>>>(
6777 entries: &I,
6778 ) -> Result<Object<T>, JsValue>;
6779
6780 // Next major: deprecate
6781 /// The `Object.fromEntries()` method transforms a list of key-value pairs
6782 /// into an object.
6783 ///
6784 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/fromEntries)
6785 #[wasm_bindgen(static_method_of = Object, catch, js_name = fromEntries)]
6786 pub fn from_entries_typed<T: JsGeneric, I: Iterable<Item = ArrayTuple<(JsString, T)>>>(
6787 entries: &I,
6788 ) -> Result<Object<T>, JsValue>;
6789
6790 /// The `Object.getOwnPropertyDescriptor()` method returns a
6791 /// property descriptor for an own property (that is, one directly
6792 /// present on an object and not in the object's prototype chain)
6793 /// of a given object.
6794 ///
6795 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor)
6796 #[cfg(not(js_sys_unstable_apis))]
6797 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptor)]
6798 pub fn get_own_property_descriptor<T>(obj: &Object<T>, prop: &JsValue) -> JsValue;
6799
6800 /// The `Object.getOwnPropertyDescriptor()` method returns a
6801 /// property descriptor for an own property (that is, one directly
6802 /// present on an object and not in the object's prototype chain)
6803 /// of a given object.
6804 ///
6805 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor)
6806 #[cfg(js_sys_unstable_apis)]
6807 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptor, catch)]
6808 pub fn get_own_property_descriptor<T>(
6809 obj: &Object<T>,
6810 prop: &JsString,
6811 ) -> Result<PropertyDescriptor<T>, JsValue>;
6812
6813 // Next major: deprecate
6814 /// The `Object.getOwnPropertyDescriptor()` method returns a
6815 /// property descriptor for an own property (that is, one directly
6816 /// present on an object and not in the object's prototype chain)
6817 /// of a given object.
6818 ///
6819 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor)
6820 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptor, catch)]
6821 pub fn get_own_property_descriptor_str<T>(
6822 obj: &Object<T>,
6823 prop: &JsString,
6824 ) -> Result<PropertyDescriptor<T>, 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 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptor, catch)]
6833 pub fn get_own_property_descriptor_symbol<T>(
6834 obj: &Object<T>,
6835 prop: &Symbol,
6836 ) -> Result<PropertyDescriptor<JsValue>, JsValue>;
6837
6838 /// The `Object.getOwnPropertyDescriptors()` method returns all own
6839 /// property descriptors of a given object.
6840 ///
6841 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptors)
6842 #[cfg(not(js_sys_unstable_apis))]
6843 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptors)]
6844 pub fn get_own_property_descriptors<T>(obj: &Object<T>) -> JsValue;
6845
6846 /// The `Object.getOwnPropertyDescriptors()` method returns all own
6847 /// property descriptors of a given object.
6848 ///
6849 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptors)
6850 #[cfg(js_sys_unstable_apis)]
6851 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptors, catch)]
6852 pub fn get_own_property_descriptors<T>(
6853 obj: &Object<T>,
6854 ) -> Result<Object<PropertyDescriptor<T>>, JsValue>;
6855
6856 /// The `Object.getOwnPropertyNames()` method returns an array of
6857 /// all properties (including non-enumerable properties except for
6858 /// those which use Symbol) found directly upon a given object.
6859 ///
6860 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyNames)
6861 #[cfg(not(js_sys_unstable_apis))]
6862 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyNames)]
6863 pub fn get_own_property_names<T>(obj: &Object<T>) -> Array;
6864
6865 /// The `Object.getOwnPropertyNames()` method returns an array of
6866 /// all properties (including non-enumerable properties except for
6867 /// those which use Symbol) found directly upon a given object.
6868 ///
6869 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyNames)
6870 #[cfg(js_sys_unstable_apis)]
6871 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyNames, catch)]
6872 pub fn get_own_property_names<T>(obj: &Object<T>) -> Result<Array<JsString>, JsValue>;
6873
6874 /// The `Object.getOwnPropertySymbols()` method returns an array of
6875 /// all symbol properties found directly upon a given object.
6876 ///
6877 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertySymbols)
6878 #[cfg(not(js_sys_unstable_apis))]
6879 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertySymbols)]
6880 pub fn get_own_property_symbols<T>(obj: &Object<T>) -> Array;
6881
6882 /// The `Object.getOwnPropertySymbols()` method returns an array of
6883 /// all symbol properties found directly upon a given object.
6884 ///
6885 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertySymbols)
6886 #[cfg(js_sys_unstable_apis)]
6887 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertySymbols, catch)]
6888 pub fn get_own_property_symbols<T>(obj: &Object<T>) -> Result<Array<Symbol>, JsValue>;
6889
6890 /// The `Object.getPrototypeOf()` method returns the prototype
6891 /// (i.e. the value of the internal [[Prototype]] property) of the
6892 /// specified object.
6893 ///
6894 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getPrototypeOf)
6895 #[wasm_bindgen(static_method_of = Object, js_name = getPrototypeOf)]
6896 pub fn get_prototype_of(obj: &JsValue) -> Object;
6897
6898 /// The `hasOwnProperty()` method returns a boolean indicating whether the
6899 /// object has the specified property as its own property (as opposed to
6900 /// inheriting it).
6901 ///
6902 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty)
6903 #[deprecated(note = "Use `Object::hasOwn` instead.")]
6904 #[allow(deprecated)]
6905 #[wasm_bindgen(method, js_name = hasOwnProperty)]
6906 pub fn has_own_property<T>(this: &Object<T>, property: &JsValue) -> bool;
6907
6908 /// The `Object.hasOwn()` method returns a boolean indicating whether the
6909 /// object passed in has the specified property as its own property (as
6910 /// opposed to inheriting it).
6911 ///
6912 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn)
6913 #[cfg(not(js_sys_unstable_apis))]
6914 #[wasm_bindgen(static_method_of = Object, js_name = hasOwn)]
6915 pub fn has_own<T>(instance: &Object<T>, property: &JsValue) -> bool;
6916
6917 /// The `Object.hasOwn()` method returns a boolean indicating whether the
6918 /// object passed in has the specified property as its own property (as
6919 /// opposed to inheriting it).
6920 ///
6921 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn)
6922 #[cfg(js_sys_unstable_apis)]
6923 #[wasm_bindgen(static_method_of = Object, js_name = hasOwn, catch)]
6924 pub fn has_own<T>(instance: &Object<T>, property: &JsString) -> Result<bool, JsValue>;
6925
6926 // Next major: deprecate
6927 /// The `Object.hasOwn()` method returns a boolean indicating whether the
6928 /// object passed in has the specified property as its own property (as
6929 /// opposed to inheriting it).
6930 ///
6931 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn)
6932 #[wasm_bindgen(static_method_of = Object, js_name = hasOwn, catch)]
6933 pub fn has_own_str<T>(instance: &Object<T>, property: &JsString) -> Result<bool, JsValue>;
6934
6935 /// The `Object.hasOwn()` method returns a boolean indicating whether the
6936 /// object passed in has the specified property as its own property (as
6937 /// opposed to inheriting it).
6938 ///
6939 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn)
6940 #[wasm_bindgen(static_method_of = Object, js_name = hasOwn, catch)]
6941 pub fn has_own_symbol<T>(instance: &Object<T>, property: &Symbol) -> Result<bool, JsValue>;
6942
6943 /// The `Object.is()` method determines whether two values are the same value.
6944 ///
6945 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is)
6946 #[wasm_bindgen(static_method_of = Object)]
6947 pub fn is(value1: &JsValue, value_2: &JsValue) -> bool;
6948
6949 /// The `Object.isExtensible()` method determines if an object is extensible
6950 /// (whether it can have new properties added to it).
6951 ///
6952 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isExtensible)
6953 #[wasm_bindgen(static_method_of = Object, js_name = isExtensible)]
6954 pub fn is_extensible<T>(object: &Object<T>) -> bool;
6955
6956 /// The `Object.isFrozen()` determines if an object is frozen.
6957 ///
6958 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isFrozen)
6959 #[wasm_bindgen(static_method_of = Object, js_name = isFrozen)]
6960 pub fn is_frozen<T>(object: &Object<T>) -> bool;
6961
6962 /// The `Object.isSealed()` method determines if an object is sealed.
6963 ///
6964 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isSealed)
6965 #[wasm_bindgen(static_method_of = Object, js_name = isSealed)]
6966 pub fn is_sealed<T>(object: &Object<T>) -> bool;
6967
6968 /// The `isPrototypeOf()` method checks if an object exists in another
6969 /// object's prototype chain.
6970 ///
6971 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isPrototypeOf)
6972 #[wasm_bindgen(method, js_name = isPrototypeOf)]
6973 pub fn is_prototype_of<T>(this: &Object<T>, value: &JsValue) -> bool;
6974
6975 /// The `Object.keys()` method returns an array of a given object's property
6976 /// names, in the same order as we get with a normal loop.
6977 ///
6978 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys)
6979 #[cfg(not(js_sys_unstable_apis))]
6980 #[wasm_bindgen(static_method_of = Object)]
6981 pub fn keys<T>(object: &Object<T>) -> Array;
6982
6983 /// The `Object.keys()` method returns an array of a given object's property
6984 /// names, in the same order as we get with a normal loop.
6985 ///
6986 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys)
6987 #[cfg(js_sys_unstable_apis)]
6988 #[wasm_bindgen(static_method_of = Object)]
6989 pub fn keys<T>(object: &Object<T>) -> Array<JsString>;
6990
6991 /// The [`Object`] constructor creates an object wrapper.
6992 ///
6993 /// **Note:** Consider using [`Object::new_typed`] for typed object records.
6994 ///
6995 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)
6996 #[wasm_bindgen(constructor)]
6997 pub fn new() -> Object;
6998
6999 // Next major: deprecate
7000 /// The [`Object`] constructor creates an object wrapper.
7001 ///
7002 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)
7003 #[wasm_bindgen(constructor)]
7004 pub fn new_typed<T>() -> Object<T>;
7005
7006 /// The `Object.preventExtensions()` method prevents new properties from
7007 /// ever being added to an object (i.e. prevents future extensions to the
7008 /// object).
7009 ///
7010 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/preventExtensions)
7011 #[wasm_bindgen(static_method_of = Object, js_name = preventExtensions)]
7012 pub fn prevent_extensions<T>(object: &Object<T>);
7013
7014 /// The `propertyIsEnumerable()` method returns a Boolean indicating
7015 /// whether the specified property is enumerable.
7016 ///
7017 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/propertyIsEnumerable)
7018 #[wasm_bindgen(method, js_name = propertyIsEnumerable)]
7019 pub fn property_is_enumerable<T>(this: &Object<T>, property: &JsValue) -> bool;
7020
7021 /// The `Object.seal()` method seals an object, preventing new properties
7022 /// from being added to it and marking all existing properties as
7023 /// non-configurable. Values of present properties can still be changed as
7024 /// long as they are writable.
7025 ///
7026 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/seal)
7027 #[wasm_bindgen(static_method_of = Object)]
7028 pub fn seal<T>(value: &Object<T>) -> Object<T>;
7029
7030 /// The `Object.setPrototypeOf()` method sets the prototype (i.e., the
7031 /// internal `[[Prototype]]` property) of a specified object to another
7032 /// object or `null`.
7033 ///
7034 /// **Note:** Consider using [`Object::try_set_prototype_of`] to support errors.
7035 ///
7036 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/setPrototypeOf)
7037 #[wasm_bindgen(static_method_of = Object, js_name = setPrototypeOf)]
7038 pub fn set_prototype_of<T>(object: &Object<T>, prototype: &Object) -> Object<T>;
7039
7040 /// The `Object.setPrototypeOf()` method sets the prototype (i.e., the
7041 /// internal `[[Prototype]]` property) of a specified object to another
7042 /// object or `null`.
7043 ///
7044 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/setPrototypeOf)
7045 #[wasm_bindgen(static_method_of = Object, js_name = setPrototypeOf, catch)]
7046 pub fn try_set_prototype_of<T>(
7047 object: &Object<T>,
7048 prototype: &Object,
7049 ) -> Result<Object<T>, JsValue>;
7050
7051 /// The `toLocaleString()` method returns a string representing the object.
7052 /// This method is meant to be overridden by derived objects for
7053 /// locale-specific purposes.
7054 ///
7055 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toLocaleString)
7056 #[wasm_bindgen(method, js_name = toLocaleString)]
7057 pub fn to_locale_string<T>(this: &Object<T>) -> JsString;
7058
7059 // Next major: deprecate
7060 /// The `toString()` method returns a string representing the object.
7061 ///
7062 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString)
7063 #[wasm_bindgen(method, js_name = toString)]
7064 pub fn to_string<T>(this: &Object<T>) -> JsString;
7065
7066 /// The `toString()` method returns a string representing the object.
7067 ///
7068 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString)
7069 #[wasm_bindgen(method, js_name = toString)]
7070 pub fn to_js_string<T>(this: &Object<T>) -> JsString;
7071
7072 /// The `valueOf()` method returns the primitive value of the
7073 /// specified object.
7074 ///
7075 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf)
7076 #[wasm_bindgen(method, js_name = valueOf)]
7077 pub fn value_of<T>(this: &Object<T>) -> Object;
7078
7079 /// The `Object.values()` method returns an array of a given object's own
7080 /// enumerable property values, in the same order as that provided by a
7081 /// `for...in` loop (the difference being that a for-in loop enumerates
7082 /// properties in the prototype chain as well).
7083 ///
7084 /// **Note:** Consider using [`Object::try_values`] to support errors.
7085 ///
7086 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values)
7087 #[cfg(not(js_sys_unstable_apis))]
7088 #[wasm_bindgen(static_method_of = Object)]
7089 pub fn values<T>(object: &Object<T>) -> Array<T>;
7090
7091 /// The `Object.values()` method returns an array of a given object's own
7092 /// enumerable property values, in the same order as that provided by a
7093 /// `for...in` loop (the difference being that a for-in loop enumerates
7094 /// properties in the prototype chain as well).
7095 ///
7096 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values)
7097 #[cfg(js_sys_unstable_apis)]
7098 #[wasm_bindgen(static_method_of = Object, catch, js_name = values)]
7099 pub fn values<T>(object: &Object<T>) -> Result<Array<T>, JsValue>;
7100
7101 // Next major: deprecate
7102 /// The `Object.values()` method returns an array of a given object's own
7103 /// enumerable property values, in the same order as that provided by a
7104 /// `for...in` loop (the difference being that a for-in loop enumerates
7105 /// properties in the prototype chain as well).
7106 ///
7107 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values)
7108 #[cfg(not(js_sys_unstable_apis))]
7109 #[wasm_bindgen(static_method_of = Object, catch, js_name = values)]
7110 pub fn try_values<T>(object: &Object<T>) -> Result<Array<T>, JsValue>;
7111}
7112
7113impl Object {
7114 /// Returns the `Object` value of this JS value if it's an instance of an
7115 /// object.
7116 ///
7117 /// If this JS value is not an instance of an object then this returns
7118 /// `None`.
7119 pub fn try_from(val: &JsValue) -> Option<&Object> {
7120 if val.is_object() {
7121 Some(val.unchecked_ref())
7122 } else {
7123 None
7124 }
7125 }
7126}
7127
7128impl PartialEq for Object {
7129 #[inline]
7130 fn eq(&self, other: &Object) -> bool {
7131 Object::is(self.as_ref(), other.as_ref())
7132 }
7133}
7134
7135impl Eq for Object {}
7136
7137impl Default for Object<JsValue> {
7138 fn default() -> Self {
7139 Self::new()
7140 }
7141}
7142
7143// Proxy
7144#[wasm_bindgen]
7145extern "C" {
7146 #[wasm_bindgen(typescript_type = "ProxyConstructor")]
7147 #[derive(Clone, Debug)]
7148 pub type Proxy;
7149
7150 /// The [`Proxy`] object is used to define custom behavior for fundamental
7151 /// operations (e.g. property lookup, assignment, enumeration, function
7152 /// invocation, etc).
7153 ///
7154 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy)
7155 #[wasm_bindgen(constructor)]
7156 pub fn new(target: &JsValue, handler: &Object) -> Proxy;
7157
7158 /// The `Proxy.revocable()` method is used to create a revocable [`Proxy`]
7159 /// object.
7160 ///
7161 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy/revocable)
7162 #[wasm_bindgen(static_method_of = Proxy)]
7163 pub fn revocable(target: &JsValue, handler: &Object) -> Object;
7164}
7165
7166// RangeError
7167#[wasm_bindgen]
7168extern "C" {
7169 /// The `RangeError` object indicates an error when a value is not in the set
7170 /// or range of allowed values.
7171 ///
7172 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError)
7173 #[wasm_bindgen(extends = Error, extends = Object, typescript_type = "RangeError")]
7174 #[derive(Clone, Debug, PartialEq, Eq)]
7175 pub type RangeError;
7176
7177 /// The `RangeError` object indicates an error when a value is not in the set
7178 /// or range of allowed values.
7179 ///
7180 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError)
7181 #[wasm_bindgen(constructor)]
7182 pub fn new(message: &str) -> RangeError;
7183}
7184
7185// ReferenceError
7186#[wasm_bindgen]
7187extern "C" {
7188 /// The `ReferenceError` object represents an error when a non-existent
7189 /// variable is referenced.
7190 ///
7191 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError)
7192 #[wasm_bindgen(extends = Error, extends = Object, typescript_type = "ReferenceError")]
7193 #[derive(Clone, Debug, PartialEq, Eq)]
7194 pub type ReferenceError;
7195
7196 /// The `ReferenceError` object represents an error when a non-existent
7197 /// variable is referenced.
7198 ///
7199 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError)
7200 #[wasm_bindgen(constructor)]
7201 pub fn new(message: &str) -> ReferenceError;
7202}
7203
7204#[allow(non_snake_case)]
7205pub mod Reflect {
7206 use super::*;
7207
7208 // Reflect
7209 #[wasm_bindgen]
7210 extern "C" {
7211 /// The static `Reflect.apply()` method calls a target function with
7212 /// arguments as specified.
7213 ///
7214 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/apply)
7215 #[wasm_bindgen(js_namespace = Reflect, catch)]
7216 pub fn apply<T: JsFunction = fn() -> JsValue>(
7217 target: &Function<T>,
7218 this_argument: &JsValue,
7219 arguments_list: &Array,
7220 ) -> Result<<T as JsFunction>::Ret, JsValue>;
7221
7222 /// The static `Reflect.construct()` method acts like the new operator, but
7223 /// as a function. It is equivalent to calling `new target(...args)`. It
7224 /// gives also the added option to specify a different prototype.
7225 ///
7226 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/construct)
7227 #[cfg(not(js_sys_unstable_apis))]
7228 #[wasm_bindgen(js_namespace = Reflect, catch)]
7229 pub fn construct<T: JsFunction = fn() -> JsValue>(
7230 target: &Function<T>,
7231 arguments_list: &Array,
7232 ) -> Result<JsValue, JsValue>;
7233
7234 /// The static `Reflect.construct()` method acts like the new operator, but
7235 /// as a function. It is equivalent to calling `new target(...args)`. It
7236 /// gives also the added option to specify a different prototype.
7237 ///
7238 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/construct)
7239 #[cfg(js_sys_unstable_apis)]
7240 #[wasm_bindgen(js_namespace = Reflect, catch)]
7241 pub fn construct<T: JsFunction = fn() -> JsValue>(
7242 target: &Function<T>,
7243 arguments_list: &ArrayTuple, // DOTO: <A1, A2, A3, A4, A5, A6, A7, A8>,
7244 ) -> Result<JsValue, JsValue>;
7245
7246 /// The static `Reflect.construct()` method acts like the new operator, but
7247 /// as a function. It is equivalent to calling `new target(...args)`. It
7248 /// gives also the added option to specify a different prototype.
7249 ///
7250 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/construct)
7251 #[wasm_bindgen(js_namespace = Reflect, js_name = construct, catch)]
7252 pub fn construct_with_new_target(
7253 target: &Function,
7254 arguments_list: &Array,
7255 new_target: &Function,
7256 ) -> Result<JsValue, JsValue>;
7257
7258 /// The static `Reflect.defineProperty()` method is like
7259 /// `Object.defineProperty()` but returns a `Boolean`.
7260 ///
7261 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/defineProperty)
7262 #[cfg(not(js_sys_unstable_apis))]
7263 #[wasm_bindgen(js_namespace = Reflect, js_name = defineProperty, catch)]
7264 pub fn define_property<T>(
7265 target: &Object<T>,
7266 property_key: &JsValue,
7267 attributes: &Object,
7268 ) -> Result<bool, JsValue>;
7269
7270 /// The static `Reflect.defineProperty()` method is like
7271 /// `Object.defineProperty()` but returns a `Boolean`.
7272 ///
7273 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/defineProperty)
7274 #[cfg(js_sys_unstable_apis)]
7275 #[wasm_bindgen(js_namespace = Reflect, js_name = defineProperty, catch)]
7276 pub fn define_property<T>(
7277 target: &Object<T>,
7278 property_key: &JsValue,
7279 attributes: &PropertyDescriptor<T>,
7280 ) -> Result<bool, JsValue>;
7281
7282 /// The static `Reflect.defineProperty()` method is like
7283 /// `Object.defineProperty()` but returns a `Boolean`.
7284 ///
7285 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/defineProperty)
7286 #[wasm_bindgen(js_namespace = Reflect, js_name = defineProperty, catch)]
7287 pub fn define_property_str<T>(
7288 target: &Object<T>,
7289 property_key: &JsString,
7290 attributes: &PropertyDescriptor<T>,
7291 ) -> Result<bool, JsValue>;
7292
7293 /// The static `Reflect.deleteProperty()` method allows to delete
7294 /// properties. It is like the `delete` operator as a function.
7295 ///
7296 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/deleteProperty)
7297 #[wasm_bindgen(js_namespace = Reflect, js_name = deleteProperty, catch)]
7298 pub fn delete_property<T>(target: &Object<T>, key: &JsValue) -> Result<bool, JsValue>;
7299
7300 /// The static `Reflect.deleteProperty()` method allows to delete
7301 /// properties. It is like the `delete` operator as a function.
7302 ///
7303 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/deleteProperty)
7304 #[wasm_bindgen(js_namespace = Reflect, js_name = deleteProperty, catch)]
7305 pub fn delete_property_str<T>(target: &Object<T>, key: &JsString) -> Result<bool, JsValue>;
7306
7307 /// The static `Reflect.get()` method works like getting a property from
7308 /// an object (`target[propertyKey]`) as a function.
7309 ///
7310 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/get)
7311 #[cfg(not(js_sys_unstable_apis))]
7312 #[wasm_bindgen(js_namespace = Reflect, catch)]
7313 pub fn get(target: &JsValue, key: &JsValue) -> Result<JsValue, JsValue>;
7314
7315 /// The static `Reflect.get()` method works like getting a property from
7316 /// an object (`target[propertyKey]`) as a function.
7317 ///
7318 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/get)
7319 #[cfg(js_sys_unstable_apis)]
7320 #[wasm_bindgen(js_namespace = Reflect, catch)]
7321 pub fn get<T>(target: &Object<T>, key: &JsString) -> Result<Option<T>, JsValue>;
7322
7323 /// The static `Reflect.get()` method works like getting a property from
7324 /// an object (`target[propertyKey]`) as a function.
7325 ///
7326 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/get)
7327 #[wasm_bindgen(js_namespace = Reflect, js_name = get, catch)]
7328 pub fn get_str<T>(target: &Object<T>, key: &JsString) -> Result<Option<T>, JsValue>;
7329
7330 /// The static `Reflect.get()` method works like getting a property from
7331 /// an object (`target[propertyKey]`) as a function.
7332 ///
7333 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/get)
7334 #[wasm_bindgen(js_namespace = Reflect, js_name = get, catch)]
7335 pub fn get_symbol<T>(target: &Object<T>, key: &Symbol) -> Result<JsValue, JsValue>;
7336
7337 /// The same as [`get`](fn.get.html)
7338 /// except the key is an `f64`, which is slightly faster.
7339 #[wasm_bindgen(js_namespace = Reflect, js_name = get, catch)]
7340 pub fn get_f64(target: &JsValue, key: f64) -> Result<JsValue, JsValue>;
7341
7342 /// The same as [`get`](fn.get.html)
7343 /// except the key is a `u32`, which is slightly faster.
7344 #[wasm_bindgen(js_namespace = Reflect, js_name = get, catch)]
7345 pub fn get_u32(target: &JsValue, key: u32) -> Result<JsValue, JsValue>;
7346
7347 /// The static `Reflect.getOwnPropertyDescriptor()` method is similar to
7348 /// `Object.getOwnPropertyDescriptor()`. It returns a property descriptor
7349 /// of the given property if it exists on the object, `undefined` otherwise.
7350 ///
7351 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getOwnPropertyDescriptor)
7352 #[wasm_bindgen(js_namespace = Reflect, js_name = getOwnPropertyDescriptor, catch)]
7353 pub fn get_own_property_descriptor<T>(
7354 target: &Object<T>,
7355 property_key: &JsValue,
7356 ) -> Result<JsValue, JsValue>;
7357
7358 /// The static `Reflect.getOwnPropertyDescriptor()` method is similar to
7359 /// `Object.getOwnPropertyDescriptor()`. It returns a property descriptor
7360 /// of the given property if it exists on the object, `undefined` otherwise.
7361 ///
7362 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getOwnPropertyDescriptor)
7363 #[wasm_bindgen(js_namespace = Reflect, js_name = getOwnPropertyDescriptor, catch)]
7364 pub fn get_own_property_descriptor_str<T>(
7365 target: &Object<T>,
7366 property_key: &JsString,
7367 ) -> Result<PropertyDescriptor<T>, JsValue>;
7368
7369 /// The static `Reflect.getPrototypeOf()` method is almost the same
7370 /// method as `Object.getPrototypeOf()`. It returns the prototype
7371 /// (i.e. the value of the internal `[[Prototype]]` property) of
7372 /// the specified object.
7373 ///
7374 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getPrototypeOf)
7375 #[cfg(not(js_sys_unstable_apis))]
7376 #[wasm_bindgen(js_namespace = Reflect, js_name = getPrototypeOf, catch)]
7377 pub fn get_prototype_of(target: &JsValue) -> Result<Object, JsValue>;
7378
7379 /// The static `Reflect.getPrototypeOf()` method is almost the same
7380 /// method as `Object.getPrototypeOf()`. It returns the prototype
7381 /// (i.e. the value of the internal `[[Prototype]]` property) of
7382 /// the specified object.
7383 ///
7384 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getPrototypeOf)
7385 #[cfg(js_sys_unstable_apis)]
7386 #[wasm_bindgen(js_namespace = Reflect, js_name = getPrototypeOf, catch)]
7387 pub fn get_prototype_of(target: &Object) -> Result<Object, JsValue>;
7388
7389 /// The static `Reflect.has()` method works like the in operator as a
7390 /// function.
7391 ///
7392 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/has)
7393 #[cfg(not(js_sys_unstable_apis))]
7394 #[wasm_bindgen(js_namespace = Reflect, catch)]
7395 pub fn has(target: &JsValue, property_key: &JsValue) -> Result<bool, JsValue>;
7396
7397 /// The static `Reflect.has()` method works like the in operator as a
7398 /// function.
7399 ///
7400 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/has)
7401 #[cfg(js_sys_unstable_apis)]
7402 #[wasm_bindgen(js_namespace = Reflect, catch)]
7403 pub fn has(target: &JsValue, property_key: &Symbol) -> Result<bool, JsValue>;
7404
7405 // Next major: deprecate
7406 /// The static `Reflect.has()` method works like the in operator as a
7407 /// function.
7408 ///
7409 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/has)
7410 #[wasm_bindgen(js_namespace = Reflect, js_name = has, catch)]
7411 pub fn has_str<T>(target: &Object<T>, property_key: &JsString) -> Result<bool, JsValue>;
7412
7413 /// The static `Reflect.has()` method works like the in operator as a
7414 /// function.
7415 ///
7416 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/has)
7417 #[wasm_bindgen(js_namespace = Reflect, js_name = has, catch)]
7418 pub fn has_symbol<T>(target: &Object<T>, property_key: &Symbol) -> Result<bool, JsValue>;
7419
7420 /// The static `Reflect.isExtensible()` method determines if an object is
7421 /// extensible (whether it can have new properties added to it). It is
7422 /// similar to `Object.isExtensible()`, but with some differences.
7423 ///
7424 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/isExtensible)
7425 #[wasm_bindgen(js_namespace = Reflect, js_name = isExtensible, catch)]
7426 pub fn is_extensible<T>(target: &Object<T>) -> Result<bool, JsValue>;
7427
7428 /// The static `Reflect.ownKeys()` method returns an array of the
7429 /// target object's own property keys.
7430 ///
7431 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/ownKeys)
7432 #[wasm_bindgen(js_namespace = Reflect, js_name = ownKeys, catch)]
7433 pub fn own_keys(target: &JsValue) -> Result<Array, JsValue>;
7434
7435 /// The static `Reflect.preventExtensions()` method prevents new
7436 /// properties from ever being added to an object (i.e. prevents
7437 /// future extensions to the object). It is similar to
7438 /// `Object.preventExtensions()`, but with some differences.
7439 ///
7440 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/preventExtensions)
7441 #[wasm_bindgen(js_namespace = Reflect, js_name = preventExtensions, catch)]
7442 pub fn prevent_extensions<T>(target: &Object<T>) -> Result<bool, JsValue>;
7443
7444 /// The static `Reflect.set()` method works like setting a
7445 /// property on an object.
7446 ///
7447 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
7448 #[cfg(not(js_sys_unstable_apis))]
7449 #[wasm_bindgen(js_namespace = Reflect, catch)]
7450 pub fn set(
7451 target: &JsValue,
7452 property_key: &JsValue,
7453 value: &JsValue,
7454 ) -> Result<bool, JsValue>;
7455
7456 /// The static `Reflect.set()` method works like setting a
7457 /// property on an object.
7458 ///
7459 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
7460 #[cfg(js_sys_unstable_apis)]
7461 #[wasm_bindgen(js_namespace = Reflect, catch)]
7462 pub fn set<T>(
7463 target: &Object<T>,
7464 property_key: &JsString,
7465 value: &T,
7466 ) -> Result<bool, JsValue>;
7467
7468 /// The static `Reflect.set()` method works like setting a
7469 /// property on an object.
7470 ///
7471 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
7472 #[cfg(js_sys_unstable_apis)]
7473 #[wasm_bindgen(js_namespace = Reflect, catch)]
7474 pub fn set_symbol<T>(
7475 target: &Object<T>,
7476 property_key: &Symbol,
7477 value: &JsValue,
7478 ) -> Result<bool, JsValue>;
7479
7480 // Next major: deprecate
7481 /// The static `Reflect.set()` method works like setting a
7482 /// property on an object.
7483 ///
7484 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
7485 #[wasm_bindgen(js_namespace = Reflect, js_name = set, catch)]
7486 pub fn set_str<T>(
7487 target: &Object<T>,
7488 property_key: &JsString,
7489 value: &T,
7490 ) -> Result<bool, JsValue>;
7491
7492 /// The same as [`set`](fn.set.html)
7493 /// except the key is an `f64`, which is slightly faster.
7494 #[wasm_bindgen(js_namespace = Reflect, js_name = set, catch)]
7495 pub fn set_f64(
7496 target: &JsValue,
7497 property_key: f64,
7498 value: &JsValue,
7499 ) -> Result<bool, JsValue>;
7500
7501 /// The same as [`set`](fn.set.html)
7502 /// except the key is a `u32`, which is slightly faster.
7503 #[wasm_bindgen(js_namespace = Reflect, js_name = set, catch)]
7504 pub fn set_u32(
7505 target: &JsValue,
7506 property_key: u32,
7507 value: &JsValue,
7508 ) -> Result<bool, JsValue>;
7509
7510 /// The static `Reflect.set()` method works like setting a
7511 /// property on an object.
7512 ///
7513 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
7514 #[wasm_bindgen(js_namespace = Reflect, js_name = set, catch)]
7515 pub fn set_with_receiver(
7516 target: &JsValue,
7517 property_key: &JsValue,
7518 value: &JsValue,
7519 receiver: &JsValue,
7520 ) -> Result<bool, JsValue>;
7521
7522 /// The static `Reflect.setPrototypeOf()` method is the same
7523 /// method as `Object.setPrototypeOf()`. It sets the prototype
7524 /// (i.e., the internal `[[Prototype]]` property) of a specified
7525 /// object to another object or to null.
7526 ///
7527 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/setPrototypeOf)
7528 #[wasm_bindgen(js_namespace = Reflect, js_name = setPrototypeOf, catch)]
7529 pub fn set_prototype_of<T>(
7530 target: &Object<T>,
7531 prototype: &JsValue,
7532 ) -> Result<bool, JsValue>;
7533 }
7534}
7535
7536// RegExp
7537#[wasm_bindgen]
7538extern "C" {
7539 #[wasm_bindgen(extends = Object, typescript_type = "RegExp")]
7540 #[derive(Clone, Debug, PartialEq, Eq)]
7541 pub type RegExp;
7542
7543 /// The `exec()` method executes a search for a match in a specified
7544 /// string. Returns a result array, or null.
7545 ///
7546 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec)
7547 #[cfg(not(js_sys_unstable_apis))]
7548 #[wasm_bindgen(method)]
7549 pub fn exec(this: &RegExp, text: &str) -> Option<Array<JsString>>;
7550
7551 /// The `exec()` method executes a search for a match in a specified
7552 /// string. Returns a result array, or null.
7553 ///
7554 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec)
7555 #[cfg(js_sys_unstable_apis)]
7556 #[wasm_bindgen(method)]
7557 pub fn exec(this: &RegExp, text: &str) -> Option<RegExpMatchArray>;
7558
7559 /// The flags property returns a string consisting of the flags of
7560 /// the current regular expression object.
7561 ///
7562 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/flags)
7563 #[wasm_bindgen(method, getter)]
7564 pub fn flags(this: &RegExp) -> JsString;
7565
7566 /// The global property indicates whether or not the "g" flag is
7567 /// used with the regular expression. global is a read-only
7568 /// property of an individual regular expression instance.
7569 ///
7570 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/global)
7571 #[wasm_bindgen(method, getter)]
7572 pub fn global(this: &RegExp) -> bool;
7573
7574 /// The ignoreCase property indicates whether or not the "i" flag
7575 /// is used with the regular expression. ignoreCase is a read-only
7576 /// property of an individual regular expression instance.
7577 ///
7578 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/ignoreCase)
7579 #[wasm_bindgen(method, getter, js_name = ignoreCase)]
7580 pub fn ignore_case(this: &RegExp) -> bool;
7581
7582 /// The non-standard input property is a static property of
7583 /// regular expressions that contains the string against which a
7584 /// regular expression is matched. RegExp.$_ is an alias for this
7585 /// property.
7586 ///
7587 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/input)
7588 #[wasm_bindgen(static_method_of = RegExp, getter)]
7589 pub fn input() -> JsString;
7590
7591 /// The lastIndex is a read/write integer property of regular expression
7592 /// instances that specifies the index at which to start the next match.
7593 ///
7594 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex)
7595 #[wasm_bindgen(structural, getter = lastIndex, method)]
7596 pub fn last_index(this: &RegExp) -> u32;
7597
7598 /// The lastIndex is a read/write integer property of regular expression
7599 /// instances that specifies the index at which to start the next match.
7600 ///
7601 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex)
7602 #[wasm_bindgen(structural, setter = lastIndex, method)]
7603 pub fn set_last_index(this: &RegExp, index: u32);
7604
7605 /// The non-standard lastMatch property is a static and read-only
7606 /// property of regular expressions that contains the last matched
7607 /// characters. `RegExp.$&` is an alias for this property.
7608 ///
7609 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastMatch)
7610 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = lastMatch)]
7611 pub fn last_match() -> JsString;
7612
7613 /// The non-standard lastParen property is a static and read-only
7614 /// property of regular expressions that contains the last
7615 /// parenthesized substring match, if any. `RegExp.$+` is an alias
7616 /// for this property.
7617 ///
7618 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastParen)
7619 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = lastParen)]
7620 pub fn last_paren() -> JsString;
7621
7622 /// The non-standard leftContext property is a static and
7623 /// read-only property of regular expressions that contains the
7624 /// substring preceding the most recent match. `RegExp.$`` is an
7625 /// alias for this property.
7626 ///
7627 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/leftContext)
7628 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = leftContext)]
7629 pub fn left_context() -> JsString;
7630
7631 /// The multiline property indicates whether or not the "m" flag
7632 /// is used with the regular expression. multiline is a read-only
7633 /// property of an individual regular expression instance.
7634 ///
7635 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/multiline)
7636 #[wasm_bindgen(method, getter)]
7637 pub fn multiline(this: &RegExp) -> bool;
7638
7639 /// The non-standard $1, $2, $3, $4, $5, $6, $7, $8, $9 properties
7640 /// are static and read-only properties of regular expressions
7641 /// that contain parenthesized substring matches.
7642 ///
7643 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/n)
7644 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$1")]
7645 pub fn n1() -> JsString;
7646 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$2")]
7647 pub fn n2() -> JsString;
7648 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$3")]
7649 pub fn n3() -> JsString;
7650 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$4")]
7651 pub fn n4() -> JsString;
7652 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$5")]
7653 pub fn n5() -> JsString;
7654 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$6")]
7655 pub fn n6() -> JsString;
7656 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$7")]
7657 pub fn n7() -> JsString;
7658 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$8")]
7659 pub fn n8() -> JsString;
7660 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$9")]
7661 pub fn n9() -> JsString;
7662
7663 /// The `RegExp` constructor creates a regular expression object for matching text with a pattern.
7664 ///
7665 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp)
7666 #[wasm_bindgen(constructor)]
7667 pub fn new(pattern: &str, flags: &str) -> RegExp;
7668 #[wasm_bindgen(constructor)]
7669 pub fn new_regexp(pattern: &RegExp, flags: &str) -> RegExp;
7670
7671 /// The non-standard rightContext property is a static and
7672 /// read-only property of regular expressions that contains the
7673 /// substring following the most recent match. `RegExp.$'` is an
7674 /// alias for this property.
7675 ///
7676 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/rightContext)
7677 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = rightContext)]
7678 pub fn right_context() -> JsString;
7679
7680 /// The source property returns a String containing the source
7681 /// text of the regexp object, and it doesn't contain the two
7682 /// forward slashes on both sides and any flags.
7683 ///
7684 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/source)
7685 #[wasm_bindgen(method, getter)]
7686 pub fn source(this: &RegExp) -> JsString;
7687
7688 /// The sticky property reflects whether or not the search is
7689 /// sticky (searches in strings only from the index indicated by
7690 /// the lastIndex property of this regular expression). sticky is
7691 /// a read-only property of an individual regular expression
7692 /// object.
7693 ///
7694 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/sticky)
7695 #[wasm_bindgen(method, getter)]
7696 pub fn sticky(this: &RegExp) -> bool;
7697
7698 /// The `test()` method executes a search for a match between a
7699 /// regular expression and a specified string. Returns true or
7700 /// false.
7701 ///
7702 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/test)
7703 #[wasm_bindgen(method)]
7704 pub fn test(this: &RegExp, text: &str) -> bool;
7705
7706 /// The `toString()` method returns a string representing the
7707 /// regular expression.
7708 ///
7709 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/toString)
7710 #[cfg(not(js_sys_unstable_apis))]
7711 #[wasm_bindgen(method, js_name = toString)]
7712 pub fn to_string(this: &RegExp) -> JsString;
7713
7714 /// The unicode property indicates whether or not the "u" flag is
7715 /// used with a regular expression. unicode is a read-only
7716 /// property of an individual regular expression instance.
7717 ///
7718 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/unicode)
7719 #[wasm_bindgen(method, getter)]
7720 pub fn unicode(this: &RegExp) -> bool;
7721}
7722
7723// RegExpMatchArray
7724#[wasm_bindgen]
7725extern "C" {
7726 /// The result array from `RegExp.exec()` or `String.matchAll()`.
7727 ///
7728 /// This is an array of strings with additional properties `index`, `input`, and `groups`.
7729 ///
7730 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec#return_value)
7731 #[wasm_bindgen(extends = Object, extends = Array, typescript_type = "RegExpMatchArray")]
7732 #[derive(Clone, Debug, PartialEq, Eq)]
7733 pub type RegExpMatchArray;
7734
7735 /// The 0-based index of the match in the string.
7736 #[wasm_bindgen(method, getter)]
7737 pub fn index(this: &RegExpMatchArray) -> u32;
7738
7739 /// The original string that was matched against.
7740 #[wasm_bindgen(method, getter)]
7741 pub fn input(this: &RegExpMatchArray) -> JsString;
7742
7743 /// An object of named capturing groups whose keys are the names and valuestype Array
7744 /// are the capturing groups, or `undefined` if no named capturing groups were defined.
7745 #[wasm_bindgen(method, getter)]
7746 pub fn groups(this: &RegExpMatchArray) -> Option<Object>;
7747
7748 /// The number of elements in the match array (full match + capture groups).
7749 #[wasm_bindgen(method, getter)]
7750 pub fn length(this: &RegExpMatchArray) -> u32;
7751
7752 /// Gets the matched string or capture group at the given index.
7753 /// Index 0 is the full match, indices 1+ are capture groups.
7754 #[wasm_bindgen(method, indexing_getter)]
7755 pub fn get(this: &RegExpMatchArray, index: u32) -> Option<JsString>;
7756}
7757
7758// Set
7759#[wasm_bindgen]
7760extern "C" {
7761 #[wasm_bindgen(extends = Object, typescript_type = "Set<any>")]
7762 #[derive(Clone, Debug, PartialEq, Eq)]
7763 pub type Set<T = JsValue>;
7764
7765 /// The [`Set`] object lets you store unique values of any type, whether
7766 /// primitive values or object references.
7767 ///
7768 /// **Note:** Consider using [`Set::new_typed`] to support typing.
7769 ///
7770 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
7771 #[cfg(not(js_sys_unstable_apis))]
7772 #[wasm_bindgen(constructor)]
7773 pub fn new(init: &JsValue) -> Set;
7774
7775 /// The [`Set`] object lets you store unique values of any type, whether
7776 /// primitive values or object references.
7777 ///
7778 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
7779 #[cfg(js_sys_unstable_apis)]
7780 #[wasm_bindgen(constructor)]
7781 pub fn new<T>() -> Set<T>;
7782
7783 // Next major: deprecate
7784 /// The [`Set`] object lets you store unique values of any type, whether
7785 /// primitive values or object references.
7786 ///
7787 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
7788 #[wasm_bindgen(constructor)]
7789 pub fn new_typed<T>() -> Set<T>;
7790
7791 /// The [`Set`] object lets you store unique values of any type, whether
7792 /// primitive values or object references.
7793 ///
7794 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
7795 #[wasm_bindgen(constructor, js_name = new)]
7796 pub fn new_empty<T>() -> Set<T>;
7797
7798 /// The [`Set`] object lets you store unique values of any type, whether
7799 /// primitive values or object references.
7800 ///
7801 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
7802 #[wasm_bindgen(constructor, js_name = new)]
7803 pub fn new_from_items<T>(items: &[T]) -> Set<T>;
7804
7805 /// The [`Set`] object lets you store unique values of any type, whether
7806 /// primitive values or object references.
7807 ///
7808 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
7809 #[wasm_bindgen(constructor, js_name = new, catch)]
7810 pub fn new_from_iterable<T, I: Iterable<Item = T>>(iterable: I) -> Result<Set<T>, JsValue>;
7811
7812 /// The `add()` method appends a new element with a specified value to the
7813 /// end of a [`Set`] object.
7814 ///
7815 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/add)
7816 #[wasm_bindgen(method)]
7817 pub fn add<T>(this: &Set<T>, value: &T) -> Set<T>;
7818
7819 /// The `clear()` method removes all elements from a [`Set`] object.
7820 ///
7821 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/clear)
7822 #[wasm_bindgen(method)]
7823 pub fn clear<T>(this: &Set<T>);
7824
7825 /// The `delete()` method removes the specified element from a [`Set`]
7826 /// object.
7827 ///
7828 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/delete)
7829 #[wasm_bindgen(method)]
7830 pub fn delete<T>(this: &Set<T>, value: &T) -> bool;
7831
7832 /// The `forEach()` method executes a provided function once for each value
7833 /// in the Set object, in insertion order.
7834 ///
7835 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/forEach)
7836 #[cfg(not(js_sys_unstable_apis))]
7837 #[wasm_bindgen(method, js_name = forEach)]
7838 pub fn for_each<T>(this: &Set<T>, callback: &mut dyn FnMut(T, T, Set<T>));
7839
7840 /// The `forEach()` method executes a provided function once for each value
7841 /// in the Set object, in insertion order.
7842 ///
7843 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/forEach)
7844 #[cfg(js_sys_unstable_apis)]
7845 #[wasm_bindgen(method, js_name = forEach)]
7846 pub fn for_each<'a, T>(this: &Set<T>, callback: ImmediateClosure<'a, dyn FnMut(T) + 'a>);
7847
7848 /// The `forEach()` method executes a provided function once for each value
7849 /// in the Set object, in insertion order.
7850 ///
7851 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/forEach)
7852 #[wasm_bindgen(method, js_name = forEach, catch)]
7853 pub fn try_for_each<'a, T>(
7854 this: &Set<T>,
7855 callback: ImmediateClosure<'a, dyn FnMut(T) -> Result<(), JsError> + 'a>,
7856 ) -> Result<(), JsValue>;
7857
7858 /// The `has()` method returns a boolean indicating whether an element with
7859 /// the specified value exists in a [`Set`] object or not.
7860 ///
7861 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/has)
7862 #[wasm_bindgen(method)]
7863 pub fn has<T>(this: &Set<T>, value: &T) -> bool;
7864
7865 /// The size accessor property returns the number of elements in a [`Set`]
7866 /// object.
7867 ///
7868 /// [MDN documentation](https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Set/size)
7869 #[wasm_bindgen(method, getter)]
7870 pub fn size<T>(this: &Set<T>) -> u32;
7871
7872 /// The `union()` method returns a new set containing elements which are in
7873 /// either or both of this set and the given set.
7874 ///
7875 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/union)
7876 #[wasm_bindgen(method)]
7877 pub fn union<T>(this: &Set<T>, other: &Set<T>) -> Set<T>;
7878
7879 /// The `intersection()` method returns a new set containing elements which are
7880 /// in both this set and the given set.
7881 ///
7882 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/intersection)
7883 #[wasm_bindgen(method)]
7884 pub fn intersection<T>(this: &Set<T>, other: &Set<T>) -> Set<T>;
7885
7886 /// The `difference()` method returns a new set containing elements which are
7887 /// in this set but not in the given set.
7888 ///
7889 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/difference)
7890 #[wasm_bindgen(method)]
7891 pub fn difference<T>(this: &Set<T>, other: &Set<T>) -> Set<T>;
7892
7893 /// The `symmetricDifference()` method returns a new set containing elements
7894 /// which are in either this set or the given set, but not in both.
7895 ///
7896 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/symmetricDifference)
7897 #[wasm_bindgen(method, js_name = symmetricDifference)]
7898 pub fn symmetric_difference<T>(this: &Set<T>, other: &Set<T>) -> Set<T>;
7899
7900 /// The `isSubsetOf()` method returns a boolean indicating whether all elements
7901 /// of this set are in the given set.
7902 ///
7903 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/isSubsetOf)
7904 #[wasm_bindgen(method, js_name = isSubsetOf)]
7905 pub fn is_subset_of<T>(this: &Set<T>, other: &Set<T>) -> bool;
7906
7907 /// The `isSupersetOf()` method returns a boolean indicating whether all elements
7908 /// of the given set are in this set.
7909 ///
7910 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/isSupersetOf)
7911 #[wasm_bindgen(method, js_name = isSupersetOf)]
7912 pub fn is_superset_of<T>(this: &Set<T>, other: &Set<T>) -> bool;
7913
7914 /// The `isDisjointFrom()` method returns a boolean indicating whether this set
7915 /// has no elements in common with the given set.
7916 ///
7917 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/isDisjointFrom)
7918 #[wasm_bindgen(method, js_name = isDisjointFrom)]
7919 pub fn is_disjoint_from<T>(this: &Set<T>, other: &Set<T>) -> bool;
7920}
7921
7922impl Default for Set<JsValue> {
7923 fn default() -> Self {
7924 Self::new_typed()
7925 }
7926}
7927
7928impl<T> Iterable for Set<T> {
7929 type Item = T;
7930}
7931
7932// SetIterator
7933#[wasm_bindgen]
7934extern "C" {
7935 /// The `entries()` method returns a new Iterator object that contains an
7936 /// array of [value, value] for each element in the Set object, in insertion
7937 /// order. For Set objects there is no key like in Map objects. However, to
7938 /// keep the API similar to the Map object, each entry has the same value
7939 /// for its key and value here, so that an array [value, value] is returned.
7940 ///
7941 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/entries)
7942 #[cfg(not(js_sys_unstable_apis))]
7943 #[wasm_bindgen(method)]
7944 pub fn entries<T>(set: &Set<T>) -> Iterator;
7945
7946 /// The `entries()` method returns a new Iterator object that contains an
7947 /// array of [value, value] for each element in the Set object, in insertion
7948 /// order. For Set objects there is no key like in Map objects. However, to
7949 /// keep the API similar to the Map object, each entry has the same value
7950 /// for its key and value here, so that an array [value, value] is returned.
7951 ///
7952 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/entries)
7953 #[cfg(js_sys_unstable_apis)]
7954 #[wasm_bindgen(method, js_name = entries)]
7955 pub fn entries<T: JsGeneric>(set: &Set<T>) -> Iterator<ArrayTuple<(T, T)>>;
7956
7957 // Next major: deprecate
7958 /// The `entries()` method returns a new Iterator object that contains an
7959 /// array of [value, value] for each element in the Set object, in insertion
7960 /// order. For Set objects there is no key like in Map objects. However, to
7961 /// keep the API similar to the Map object, each entry has the same value
7962 /// for its key and value here, so that an array [value, value] is returned.
7963 ///
7964 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/entries)
7965 #[wasm_bindgen(method, js_name = entries)]
7966 pub fn entries_typed<T: JsGeneric>(set: &Set<T>) -> Iterator<ArrayTuple<(T, T)>>;
7967
7968 /// The `keys()` method is an alias for this method (for similarity with
7969 /// Map objects); it behaves exactly the same and returns values
7970 /// of Set elements.
7971 ///
7972 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/values)
7973 #[wasm_bindgen(method)]
7974 pub fn keys<T>(set: &Set<T>) -> Iterator<T>;
7975
7976 /// The `values()` method returns a new Iterator object that contains the
7977 /// values for each element in the Set object in insertion order.
7978 ///
7979 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/values)
7980 #[wasm_bindgen(method)]
7981 pub fn values<T>(set: &Set<T>) -> Iterator<T>;
7982}
7983
7984// SyntaxError
7985#[wasm_bindgen]
7986extern "C" {
7987 /// A `SyntaxError` is thrown when the JavaScript engine encounters tokens or
7988 /// token order that does not conform to the syntax of the language when
7989 /// parsing code.
7990 ///
7991 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError)
7992 #[wasm_bindgen(extends = Error, extends = Object, typescript_type = "SyntaxError")]
7993 #[derive(Clone, Debug, PartialEq, Eq)]
7994 pub type SyntaxError;
7995
7996 /// A `SyntaxError` is thrown when the JavaScript engine encounters tokens or
7997 /// token order that does not conform to the syntax of the language when
7998 /// parsing code.
7999 ///
8000 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError)
8001 #[wasm_bindgen(constructor)]
8002 pub fn new(message: &str) -> SyntaxError;
8003}
8004
8005// TypeError
8006#[wasm_bindgen]
8007extern "C" {
8008 /// The `TypeError` object represents an error when a value is not of the
8009 /// expected type.
8010 ///
8011 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError)
8012 #[wasm_bindgen(extends = Error, extends = Object, typescript_type = "TypeError")]
8013 #[derive(Clone, Debug, PartialEq, Eq)]
8014 pub type TypeError;
8015
8016 /// The `TypeError` object represents an error when a value is not of the
8017 /// expected type.
8018 ///
8019 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError)
8020 #[wasm_bindgen(constructor)]
8021 pub fn new(message: &str) -> TypeError;
8022}
8023
8024// URIError
8025#[wasm_bindgen]
8026extern "C" {
8027 /// The `URIError` object represents an error when a global URI handling
8028 /// function was used in a wrong way.
8029 ///
8030 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError)
8031 #[wasm_bindgen(extends = Error, extends = Object, js_name = URIError, typescript_type = "URIError")]
8032 #[derive(Clone, Debug, PartialEq, Eq)]
8033 pub type UriError;
8034
8035 /// The `URIError` object represents an error when a global URI handling
8036 /// function was used in a wrong way.
8037 ///
8038 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError)
8039 #[wasm_bindgen(constructor, js_class = "URIError")]
8040 pub fn new(message: &str) -> UriError;
8041}
8042
8043// WeakMap
8044#[wasm_bindgen]
8045extern "C" {
8046 #[wasm_bindgen(extends = Object, typescript_type = "WeakMap<object, any>")]
8047 #[derive(Clone, Debug, PartialEq, Eq)]
8048 pub type WeakMap<K = Object, V = JsValue>;
8049
8050 /// The [`WeakMap`] object is a collection of key/value pairs in which the
8051 /// keys are weakly referenced. The keys must be objects and the values can
8052 /// be arbitrary values.
8053 ///
8054 /// **Note:** Consider using [`WeakMap::new_typed`] to support typing.
8055 ///
8056 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap)
8057 #[cfg(not(js_sys_unstable_apis))]
8058 #[wasm_bindgen(constructor)]
8059 pub fn new() -> WeakMap;
8060
8061 /// The [`WeakMap`] object is a collection of key/value pairs in which the
8062 /// keys are weakly referenced. The keys must be objects and the values can
8063 /// be arbitrary values.
8064 ///
8065 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap)
8066 #[cfg(js_sys_unstable_apis)]
8067 #[wasm_bindgen(constructor)]
8068 pub fn new<K: JsGeneric = Object, V: JsGeneric = Object>() -> WeakMap<K, V>;
8069
8070 // Next major: deprecate
8071 /// The [`WeakMap`] object is a collection of key/value pairs in which the
8072 /// keys are weakly referenced. The keys must be objects and the values can
8073 /// be arbitrary values.
8074 ///
8075 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap)
8076 #[wasm_bindgen(constructor)]
8077 pub fn new_typed<K: JsGeneric = Object, V: JsGeneric = Object>() -> WeakMap<K, V>;
8078
8079 /// The `set()` method sets the value for the key in the [`WeakMap`] object.
8080 /// Returns the [`WeakMap`] object.
8081 ///
8082 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/set)
8083 #[wasm_bindgen(method, js_class = "WeakMap")]
8084 pub fn set<K, V>(this: &WeakMap<K, V>, key: &K, value: &V) -> WeakMap<K, V>;
8085
8086 /// The `get()` method returns a specified by key element
8087 /// from a [`WeakMap`] object. Returns `undefined` if the key is not found.
8088 ///
8089 /// **Note:** Consider using [`WeakMap::get_checked`] to get an `Option<V>` instead.
8090 ///
8091 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/get)
8092 #[cfg(not(js_sys_unstable_apis))]
8093 #[wasm_bindgen(method)]
8094 pub fn get<K, V>(this: &WeakMap<K, V>, key: &K) -> V;
8095
8096 /// The `get()` method returns a specified by key element
8097 /// from a [`WeakMap`] object. Returns `None` if the key is not found.
8098 ///
8099 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/get)
8100 #[cfg(js_sys_unstable_apis)]
8101 #[wasm_bindgen(method)]
8102 pub fn get<K, V>(this: &WeakMap<K, V>, key: &K) -> Option<V>;
8103
8104 /// The `get()` method returns a specified by key element
8105 /// from a [`WeakMap`] object. Returns `None` if the key is not found.
8106 ///
8107 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/get)
8108 #[wasm_bindgen(method, js_name = get)]
8109 pub fn get_checked<K, V>(this: &WeakMap<K, V>, key: &K) -> Option<V>;
8110
8111 /// The `has()` method returns a boolean indicating whether an element with
8112 /// the specified key exists in the [`WeakMap`] object or not.
8113 ///
8114 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/has)
8115 #[wasm_bindgen(method)]
8116 pub fn has<K, V>(this: &WeakMap<K, V>, key: &K) -> bool;
8117
8118 /// The `delete()` method removes the specified element from a [`WeakMap`]
8119 /// object.
8120 ///
8121 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/delete)
8122 #[wasm_bindgen(method)]
8123 pub fn delete<K, V>(this: &WeakMap<K, V>, key: &K) -> bool;
8124}
8125
8126impl Default for WeakMap {
8127 fn default() -> Self {
8128 Self::new()
8129 }
8130}
8131
8132// WeakSet
8133#[wasm_bindgen]
8134extern "C" {
8135 #[wasm_bindgen(extends = Object, typescript_type = "WeakSet<object>")]
8136 #[derive(Clone, Debug, PartialEq, Eq)]
8137 pub type WeakSet<T = Object>;
8138
8139 /// The `WeakSet` object lets you store weakly held objects in a collection.
8140 ///
8141 /// **Note:** Consider using [`WeakSet::new_typed`] for typed sets.
8142 ///
8143 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet)
8144 #[cfg(not(js_sys_unstable_apis))]
8145 #[wasm_bindgen(constructor)]
8146 pub fn new() -> WeakSet;
8147
8148 /// The `WeakSet` object lets you store weakly held objects in a collection.
8149 ///
8150 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet)
8151 #[cfg(js_sys_unstable_apis)]
8152 #[wasm_bindgen(constructor)]
8153 pub fn new<T = Object>() -> WeakSet<T>;
8154
8155 // Next major: deprecate
8156 /// The `WeakSet` object lets you store weakly held objects in a collection.
8157 ///
8158 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet)
8159 #[wasm_bindgen(constructor)]
8160 pub fn new_typed<T = Object>() -> WeakSet<T>;
8161
8162 /// The `has()` method returns a boolean indicating whether an object exists
8163 /// in a WeakSet or not.
8164 ///
8165 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet/has)
8166 #[wasm_bindgen(method)]
8167 pub fn has<T>(this: &WeakSet<T>, value: &T) -> bool;
8168
8169 /// The `add()` method appends a new object to the end of a WeakSet object.
8170 ///
8171 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet/add)
8172 #[wasm_bindgen(method)]
8173 pub fn add<T>(this: &WeakSet<T>, value: &T) -> WeakSet<T>;
8174
8175 /// The `delete()` method removes the specified element from a WeakSet
8176 /// object.
8177 ///
8178 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet/delete)
8179 #[wasm_bindgen(method)]
8180 pub fn delete<T>(this: &WeakSet<T>, value: &T) -> bool;
8181}
8182
8183impl Default for WeakSet {
8184 fn default() -> Self {
8185 Self::new()
8186 }
8187}
8188
8189// WeakRef
8190#[wasm_bindgen]
8191extern "C" {
8192 #[wasm_bindgen(extends = Object, typescript_type = "WeakRef<object>")]
8193 #[derive(Clone, Debug, PartialEq, Eq)]
8194 pub type WeakRef<T = Object>;
8195
8196 /// The `WeakRef` object contains a weak reference to an object. A weak
8197 /// reference to an object is a reference that does not prevent the object
8198 /// from being reclaimed by the garbage collector.
8199 ///
8200 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef)
8201 #[wasm_bindgen(constructor)]
8202 pub fn new<T = Object>(target: &T) -> WeakRef<T>;
8203
8204 /// Returns the `Object` this `WeakRef` points to, or `None` if the
8205 /// object has been garbage collected.
8206 ///
8207 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef/deref)
8208 #[wasm_bindgen(method)]
8209 pub fn deref<T>(this: &WeakRef<T>) -> Option<T>;
8210}
8211
8212#[cfg(js_sys_unstable_apis)]
8213#[allow(non_snake_case)]
8214pub mod Temporal;
8215
8216#[allow(non_snake_case)]
8217pub mod WebAssembly {
8218 use super::*;
8219
8220 // WebAssembly
8221 #[wasm_bindgen]
8222 extern "C" {
8223 /// The `WebAssembly.compile()` function compiles a `WebAssembly.Module`
8224 /// from WebAssembly binary code. This function is useful if it is
8225 /// necessary to a compile a module before it can be instantiated
8226 /// (otherwise, the `WebAssembly.instantiate()` function should be used).
8227 ///
8228 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compile)
8229 #[cfg(not(js_sys_unstable_apis))]
8230 #[wasm_bindgen(js_namespace = WebAssembly)]
8231 pub fn compile(buffer_source: &JsValue) -> Promise<JsValue>;
8232
8233 /// The `WebAssembly.compile()` function compiles a `WebAssembly.Module`
8234 /// from WebAssembly binary code. This function is useful if it is
8235 /// necessary to a compile a module before it can be instantiated
8236 /// (otherwise, the `WebAssembly.instantiate()` function should be used).
8237 ///
8238 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compile)
8239 #[cfg(js_sys_unstable_apis)]
8240 #[wasm_bindgen(js_namespace = WebAssembly)]
8241 pub fn compile(buffer_source: &JsValue) -> Promise<Module>;
8242
8243 /// The `WebAssembly.compileStreaming()` function compiles a
8244 /// `WebAssembly.Module` module directly from a streamed underlying
8245 /// source. This function is useful if it is necessary to a compile a
8246 /// module before it can be instantiated (otherwise, the
8247 /// `WebAssembly.instantiateStreaming()` function should be used).
8248 ///
8249 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compileStreaming)
8250 #[cfg(not(js_sys_unstable_apis))]
8251 #[wasm_bindgen(js_namespace = WebAssembly, js_name = compileStreaming)]
8252 pub fn compile_streaming(response: &Promise) -> Promise<JsValue>;
8253
8254 /// The `WebAssembly.compileStreaming()` function compiles a
8255 /// `WebAssembly.Module` module directly from a streamed underlying
8256 /// source. This function is useful if it is necessary to a compile a
8257 /// module before it can be instantiated (otherwise, the
8258 /// `WebAssembly.instantiateStreaming()` function should be used).
8259 ///
8260 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compileStreaming)
8261 #[cfg(js_sys_unstable_apis)]
8262 #[wasm_bindgen(js_namespace = WebAssembly, js_name = compileStreaming)]
8263 pub fn compile_streaming(response: &Promise) -> Promise<Module>;
8264
8265 /// The `WebAssembly.instantiate()` function allows you to compile and
8266 /// instantiate WebAssembly code.
8267 ///
8268 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate)
8269 #[cfg(not(js_sys_unstable_apis))]
8270 #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiate)]
8271 pub fn instantiate_buffer(buffer: &[u8], imports: &Object) -> Promise<JsValue>;
8272
8273 /// The `WebAssembly.instantiate()` function allows you to compile and
8274 /// instantiate WebAssembly code.
8275 ///
8276 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate)
8277 #[cfg(js_sys_unstable_apis)]
8278 #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiate)]
8279 pub fn instantiate_buffer(buffer: &[u8], imports: &Object) -> Promise<Instance>;
8280
8281 /// The `WebAssembly.instantiate()` function allows you to compile and
8282 /// instantiate WebAssembly code.
8283 ///
8284 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate)
8285 #[cfg(not(js_sys_unstable_apis))]
8286 #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiate)]
8287 pub fn instantiate_module(module: &Module, imports: &Object) -> Promise<JsValue>;
8288
8289 /// The `WebAssembly.instantiate()` function allows you to compile and
8290 /// instantiate WebAssembly code.
8291 ///
8292 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate)
8293 #[cfg(js_sys_unstable_apis)]
8294 #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiate)]
8295 pub fn instantiate_module(module: &Module, imports: &Object) -> Promise<Instance>;
8296
8297 /// The `WebAssembly.instantiateStreaming()` function compiles and
8298 /// instantiates a WebAssembly module directly from a streamed
8299 /// underlying source. This is the most efficient, optimized way to load
8300 /// Wasm code.
8301 ///
8302 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiateStreaming)
8303 #[cfg(not(js_sys_unstable_apis))]
8304 #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiateStreaming)]
8305 pub fn instantiate_streaming(response: &JsValue, imports: &Object) -> Promise<JsValue>;
8306
8307 /// The `WebAssembly.instantiateStreaming()` function compiles and
8308 /// instantiates a WebAssembly module directly from a streamed
8309 /// underlying source. This is the most efficient, optimized way to load
8310 /// Wasm code.
8311 ///
8312 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiateStreaming)
8313 #[cfg(js_sys_unstable_apis)]
8314 #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiateStreaming)]
8315 pub fn instantiate_streaming(response: &JsValue, imports: &Object) -> Promise<Instance>;
8316
8317 /// The `WebAssembly.validate()` function validates a given typed
8318 /// array of WebAssembly binary code, returning whether the bytes
8319 /// form a valid Wasm module (`true`) or not (`false`).
8320 ///
8321 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/validate)
8322 #[wasm_bindgen(js_namespace = WebAssembly, catch)]
8323 pub fn validate(buffer_source: &JsValue) -> Result<bool, JsValue>;
8324 }
8325
8326 // WebAssembly.CompileError
8327 #[wasm_bindgen]
8328 extern "C" {
8329 /// The `WebAssembly.CompileError()` constructor creates a new
8330 /// WebAssembly `CompileError` object, which indicates an error during
8331 /// WebAssembly decoding or validation.
8332 ///
8333 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/CompileError)
8334 #[wasm_bindgen(extends = Error, js_namespace = WebAssembly, typescript_type = "WebAssembly.CompileError")]
8335 #[derive(Clone, Debug, PartialEq, Eq)]
8336 pub type CompileError;
8337
8338 /// The `WebAssembly.CompileError()` constructor creates a new
8339 /// WebAssembly `CompileError` object, which indicates an error during
8340 /// WebAssembly decoding or validation.
8341 ///
8342 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/CompileError)
8343 #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
8344 pub fn new(message: &str) -> CompileError;
8345 }
8346
8347 // WebAssembly.Instance
8348 #[wasm_bindgen]
8349 extern "C" {
8350 /// A `WebAssembly.Instance` object is a stateful, executable instance
8351 /// of a `WebAssembly.Module`. Instance objects contain all the exported
8352 /// WebAssembly functions that allow calling into WebAssembly code from
8353 /// JavaScript.
8354 ///
8355 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance)
8356 #[wasm_bindgen(extends = Object, js_namespace = WebAssembly, typescript_type = "WebAssembly.Instance")]
8357 #[derive(Clone, Debug, PartialEq, Eq)]
8358 pub type Instance;
8359
8360 /// The `WebAssembly.Instance()` constructor function can be called to
8361 /// synchronously instantiate a given `WebAssembly.Module`
8362 /// object. However, the primary way to get an `Instance` is through the
8363 /// asynchronous `WebAssembly.instantiateStreaming()` function.
8364 ///
8365 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance)
8366 #[wasm_bindgen(catch, constructor, js_namespace = WebAssembly)]
8367 pub fn new(module: &Module, imports: &Object) -> Result<Instance, JsValue>;
8368
8369 /// The `exports` readonly property of the `WebAssembly.Instance` object
8370 /// prototype returns an object containing as its members all the
8371 /// functions exported from the WebAssembly module instance, to allow
8372 /// them to be accessed and used by JavaScript.
8373 ///
8374 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance/exports)
8375 #[wasm_bindgen(getter, method, js_namespace = WebAssembly)]
8376 pub fn exports(this: &Instance) -> Object;
8377 }
8378
8379 // WebAssembly.LinkError
8380 #[wasm_bindgen]
8381 extern "C" {
8382 /// The `WebAssembly.LinkError()` constructor creates a new WebAssembly
8383 /// LinkError object, which indicates an error during module
8384 /// instantiation (besides traps from the start function).
8385 ///
8386 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/LinkError)
8387 #[wasm_bindgen(extends = Error, js_namespace = WebAssembly, typescript_type = "WebAssembly.LinkError")]
8388 #[derive(Clone, Debug, PartialEq, Eq)]
8389 pub type LinkError;
8390
8391 /// The `WebAssembly.LinkError()` constructor creates a new WebAssembly
8392 /// LinkError object, which indicates an error during module
8393 /// instantiation (besides traps from the start function).
8394 ///
8395 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/LinkError)
8396 #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
8397 pub fn new(message: &str) -> LinkError;
8398 }
8399
8400 // WebAssembly.RuntimeError
8401 #[wasm_bindgen]
8402 extern "C" {
8403 /// The `WebAssembly.RuntimeError()` constructor creates a new WebAssembly
8404 /// `RuntimeError` object — the type that is thrown whenever WebAssembly
8405 /// specifies a trap.
8406 ///
8407 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/RuntimeError)
8408 #[wasm_bindgen(extends = Error, js_namespace = WebAssembly, typescript_type = "WebAssembly.RuntimeError")]
8409 #[derive(Clone, Debug, PartialEq, Eq)]
8410 pub type RuntimeError;
8411
8412 /// The `WebAssembly.RuntimeError()` constructor creates a new WebAssembly
8413 /// `RuntimeError` object — the type that is thrown whenever WebAssembly
8414 /// specifies a trap.
8415 ///
8416 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/RuntimeError)
8417 #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
8418 pub fn new(message: &str) -> RuntimeError;
8419 }
8420
8421 // WebAssembly.Module
8422 #[wasm_bindgen]
8423 extern "C" {
8424 /// A `WebAssembly.Module` object contains stateless WebAssembly code
8425 /// that has already been compiled by the browser and can be
8426 /// efficiently shared with Workers, and instantiated multiple times.
8427 ///
8428 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module)
8429 #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Module")]
8430 #[derive(Clone, Debug, PartialEq, Eq)]
8431 pub type Module;
8432
8433 /// A `WebAssembly.Module` object contains stateless WebAssembly code
8434 /// that has already been compiled by the browser and can be
8435 /// efficiently shared with Workers, and instantiated multiple times.
8436 ///
8437 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module)
8438 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
8439 pub fn new(buffer_source: &JsValue) -> Result<Module, JsValue>;
8440
8441 /// The `WebAssembly.customSections()` function returns a copy of the
8442 /// contents of all custom sections in the given module with the given
8443 /// string name.
8444 ///
8445 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/customSections)
8446 #[wasm_bindgen(static_method_of = Module, js_namespace = WebAssembly, js_name = customSections)]
8447 pub fn custom_sections(module: &Module, sectionName: &str) -> Array;
8448
8449 /// The `WebAssembly.exports()` function returns an array containing
8450 /// descriptions of all the declared exports of the given `Module`.
8451 ///
8452 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/exports)
8453 #[wasm_bindgen(static_method_of = Module, js_namespace = WebAssembly)]
8454 pub fn exports(module: &Module) -> Array;
8455
8456 /// The `WebAssembly.imports()` function returns an array containing
8457 /// descriptions of all the declared imports of the given `Module`.
8458 ///
8459 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/imports)
8460 #[wasm_bindgen(static_method_of = Module, js_namespace = WebAssembly)]
8461 pub fn imports(module: &Module) -> Array;
8462 }
8463
8464 // WebAssembly.Table
8465 #[wasm_bindgen]
8466 extern "C" {
8467 /// The `WebAssembly.Table()` constructor creates a new `Table` object
8468 /// of the given size and element type.
8469 ///
8470 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table)
8471 #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Table")]
8472 #[derive(Clone, Debug, PartialEq, Eq)]
8473 pub type Table;
8474
8475 /// The `WebAssembly.Table()` constructor creates a new `Table` object
8476 /// of the given size and element type.
8477 ///
8478 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table)
8479 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
8480 pub fn new(table_descriptor: &Object) -> Result<Table, JsValue>;
8481
8482 /// The `WebAssembly.Table()` constructor creates a new `Table` object
8483 /// of the given size and element type.
8484 ///
8485 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table)
8486 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
8487 pub fn new_with_value(table_descriptor: &Object, value: JsValue) -> Result<Table, JsValue>;
8488
8489 /// The length prototype property of the `WebAssembly.Table` object
8490 /// returns the length of the table, i.e. the number of elements in the
8491 /// table.
8492 ///
8493 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/length)
8494 #[wasm_bindgen(method, getter, js_namespace = WebAssembly)]
8495 pub fn length(this: &Table) -> u32;
8496
8497 /// The `get()` prototype method of the `WebAssembly.Table()` object
8498 /// retrieves a function reference stored at a given index.
8499 ///
8500 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/get)
8501 #[wasm_bindgen(method, catch, js_namespace = WebAssembly)]
8502 pub fn get(this: &Table, index: u32) -> Result<Function, JsValue>;
8503
8504 /// The `get()` prototype method of the `WebAssembly.Table()` object
8505 /// retrieves a function reference stored at a given index.
8506 ///
8507 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/get)
8508 #[wasm_bindgen(method, catch, js_namespace = WebAssembly, js_name = get)]
8509 pub fn get_raw(this: &Table, index: u32) -> Result<JsValue, JsValue>;
8510
8511 /// The `grow()` prototype method of the `WebAssembly.Table` object
8512 /// increases the size of the `Table` instance by a specified number of
8513 /// elements.
8514 ///
8515 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/grow)
8516 #[wasm_bindgen(method, catch, js_namespace = WebAssembly)]
8517 pub fn grow(this: &Table, additional_capacity: u32) -> Result<u32, JsValue>;
8518
8519 /// The `grow()` prototype method of the `WebAssembly.Table` object
8520 /// increases the size of the `Table` instance by a specified number of
8521 /// elements.
8522 ///
8523 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/grow)
8524 #[wasm_bindgen(method, catch, js_namespace = WebAssembly, js_name = grow)]
8525 pub fn grow_with_value(
8526 this: &Table,
8527 additional_capacity: u32,
8528 value: JsValue,
8529 ) -> Result<u32, JsValue>;
8530
8531 /// The `set()` prototype method of the `WebAssembly.Table` object mutates a
8532 /// reference stored at a given index to a different value.
8533 ///
8534 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/set)
8535 #[wasm_bindgen(method, catch, js_namespace = WebAssembly)]
8536 pub fn set(this: &Table, index: u32, function: &Function) -> Result<(), JsValue>;
8537
8538 /// The `set()` prototype method of the `WebAssembly.Table` object mutates a
8539 /// reference stored at a given index to a different value.
8540 ///
8541 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/set)
8542 #[wasm_bindgen(method, catch, js_namespace = WebAssembly, js_name = set)]
8543 pub fn set_raw(this: &Table, index: u32, value: &JsValue) -> Result<(), JsValue>;
8544 }
8545
8546 // WebAssembly.Tag
8547 #[wasm_bindgen]
8548 extern "C" {
8549 /// The `WebAssembly.Tag()` constructor creates a new `Tag` object
8550 ///
8551 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Tag)
8552 #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Tag")]
8553 #[derive(Clone, Debug, PartialEq, Eq)]
8554 pub type Tag;
8555
8556 /// The `WebAssembly.Tag()` constructor creates a new `Tag` object
8557 ///
8558 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Tag)
8559 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
8560 pub fn new(tag_descriptor: &Object) -> Result<Tag, JsValue>;
8561 }
8562
8563 // WebAssembly.Exception
8564 #[wasm_bindgen]
8565 extern "C" {
8566 /// The `WebAssembly.Exception()` constructor creates a new `Exception` object
8567 ///
8568 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception)
8569 #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Exception")]
8570 #[derive(Clone, Debug, PartialEq, Eq)]
8571 pub type Exception;
8572
8573 /// The `WebAssembly.Exception()` constructor creates a new `Exception` object
8574 ///
8575 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception)
8576 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
8577 pub fn new(tag: &Tag, payload: &Array) -> Result<Exception, JsValue>;
8578
8579 /// The `WebAssembly.Exception()` constructor creates a new `Exception` object
8580 ///
8581 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception)
8582 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
8583 pub fn new_with_options(
8584 tag: &Tag,
8585 payload: &Array,
8586 options: &Object,
8587 ) -> Result<Exception, JsValue>;
8588
8589 /// The `is()` prototype method of the `WebAssembly.Exception` can be used to
8590 /// test if the Exception matches a given tag.
8591 ///
8592 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception/is)
8593 #[wasm_bindgen(method, js_namespace = WebAssembly)]
8594 pub fn is(this: &Exception, tag: &Tag) -> bool;
8595
8596 /// The `getArg()` prototype method of the `WebAssembly.Exception` can be used
8597 /// to get the value of a specified item in the exception's data arguments
8598 ///
8599 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception/getArg)
8600 #[wasm_bindgen(method, js_namespace = WebAssembly, js_name = getArg, catch)]
8601 pub fn get_arg(this: &Exception, tag: &Tag, index: u32) -> Result<JsValue, JsValue>;
8602 }
8603
8604 // WebAssembly.Global
8605 #[wasm_bindgen]
8606 extern "C" {
8607 /// The `WebAssembly.Global()` constructor creates a new `Global` object
8608 /// of the given type and value.
8609 ///
8610 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global)
8611 #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Global")]
8612 #[derive(Clone, Debug, PartialEq, Eq)]
8613 pub type Global;
8614
8615 /// The `WebAssembly.Global()` constructor creates a new `Global` object
8616 /// of the given type and value.
8617 ///
8618 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global)
8619 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
8620 pub fn new(global_descriptor: &Object, value: &JsValue) -> Result<Global, JsValue>;
8621
8622 /// The value prototype property of the `WebAssembly.Global` object
8623 /// returns the value of the global.
8624 ///
8625 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global)
8626 #[wasm_bindgen(method, getter, js_namespace = WebAssembly)]
8627 pub fn value(this: &Global) -> JsValue;
8628 #[wasm_bindgen(method, setter = value, js_namespace = WebAssembly)]
8629 pub fn set_value(this: &Global, value: &JsValue);
8630 }
8631
8632 // WebAssembly.Memory
8633 #[wasm_bindgen]
8634 extern "C" {
8635 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory)
8636 #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Memory")]
8637 #[derive(Clone, Debug, PartialEq, Eq)]
8638 pub type Memory;
8639
8640 /// The `WebAssembly.Memory()` constructor creates a new `Memory` object
8641 /// which is a resizable `ArrayBuffer` that holds the raw bytes of
8642 /// memory accessed by a WebAssembly `Instance`.
8643 ///
8644 /// A memory created by JavaScript or in WebAssembly code will be
8645 /// accessible and mutable from both JavaScript and WebAssembly.
8646 ///
8647 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory)
8648 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
8649 pub fn new(descriptor: &Object) -> Result<Memory, JsValue>;
8650
8651 /// An accessor property that returns the buffer contained in the
8652 /// memory.
8653 ///
8654 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory/buffer)
8655 #[wasm_bindgen(method, getter, js_namespace = WebAssembly)]
8656 pub fn buffer(this: &Memory) -> JsValue;
8657
8658 /// The `grow()` prototype method of the `Memory` object increases the
8659 /// size of the memory instance by a specified number of WebAssembly
8660 /// pages.
8661 ///
8662 /// Takes the number of pages to grow (64KiB in size) and returns the
8663 /// previous size of memory, in pages.
8664 ///
8665 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory/grow)
8666 #[wasm_bindgen(method, js_namespace = WebAssembly)]
8667 pub fn grow(this: &Memory, pages: u32) -> u32;
8668 }
8669}
8670
8671/// The `JSON` object contains methods for parsing [JavaScript Object
8672/// Notation (JSON)](https://json.org/) and converting values to JSON. It
8673/// can't be called or constructed, and aside from its two method
8674/// properties, it has no interesting functionality of its own.
8675#[allow(non_snake_case)]
8676pub mod JSON {
8677 use super::*;
8678
8679 // JSON
8680 #[wasm_bindgen]
8681 extern "C" {
8682 /// The `JSON.parse()` method parses a JSON string, constructing the
8683 /// JavaScript value or object described by the string.
8684 ///
8685 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse)
8686 #[wasm_bindgen(catch, js_namespace = JSON)]
8687 pub fn parse(text: &str) -> Result<JsValue, JsValue>;
8688
8689 /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
8690 ///
8691 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
8692 #[wasm_bindgen(catch, js_namespace = JSON)]
8693 pub fn stringify(obj: &JsValue) -> Result<JsString, JsValue>;
8694
8695 /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
8696 ///
8697 /// The `replacer` argument is a function that alters the behavior of the stringification
8698 /// process, or an array of String and Number objects that serve as a whitelist
8699 /// for selecting/filtering the properties of the value object to be included
8700 /// in the JSON string. If this value is null or not provided, all properties
8701 /// of the object are included in the resulting JSON string.
8702 ///
8703 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
8704 #[cfg(not(js_sys_unstable_apis))]
8705 #[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
8706 pub fn stringify_with_replacer(
8707 obj: &JsValue,
8708 replacer: &JsValue,
8709 ) -> Result<JsString, JsValue>;
8710
8711 /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
8712 ///
8713 /// The `replacer` argument is a function that alters the behavior of the stringification
8714 /// process, or an array of String and Number objects that serve as a whitelist
8715 /// for selecting/filtering the properties of the value object to be included
8716 /// in the JSON string. If this value is null or not provided, all properties
8717 /// of the object are included in the resulting JSON string.
8718 ///
8719 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
8720 #[cfg(js_sys_unstable_apis)]
8721 #[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
8722 pub fn stringify_with_replacer<'a>(
8723 obj: &JsValue,
8724 replacer: ImmediateClosure<
8725 'a,
8726 dyn FnMut(JsString, JsValue) -> Result<Option<JsValue>, JsError> + 'a,
8727 >,
8728 space: Option<u32>,
8729 ) -> Result<JsString, JsValue>;
8730
8731 // Next major: deprecate
8732 /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
8733 ///
8734 /// The `replacer` argument is a function that alters the behavior of the stringification
8735 /// process, or an array of String and Number objects that serve as a whitelist
8736 /// for selecting/filtering the properties of the value object to be included
8737 /// in the JSON string. If this value is null or not provided, all properties
8738 /// of the object are included in the resulting JSON string.
8739 ///
8740 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
8741 #[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
8742 pub fn stringify_with_replacer_func<'a>(
8743 obj: &JsValue,
8744 replacer: ImmediateClosure<
8745 'a,
8746 dyn FnMut(JsString, JsValue) -> Result<Option<JsValue>, JsError> + 'a,
8747 >,
8748 space: Option<u32>,
8749 ) -> Result<JsString, JsValue>;
8750
8751 /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
8752 ///
8753 /// The `replacer` argument is a function that alters the behavior of the stringification
8754 /// process, or an array of String and Number objects that serve as a whitelist
8755 /// for selecting/filtering the properties of the value object to be included
8756 /// in the JSON string. If this value is null or not provided, all properties
8757 /// of the object are included in the resulting JSON string.
8758 ///
8759 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
8760 #[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
8761 pub fn stringify_with_replacer_list(
8762 obj: &JsValue,
8763 replacer: Vec<String>,
8764 space: Option<u32>,
8765 ) -> Result<JsString, JsValue>;
8766
8767 // Next major: deprecate
8768 /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
8769 ///
8770 /// The `replacer` argument is a function that alters the behavior of the stringification
8771 /// process, or an array of String and Number objects that serve as a whitelist
8772 /// for selecting/filtering the properties of the value object to be included
8773 /// in the JSON string. If this value is null or not provided, all properties
8774 /// of the object are included in the resulting JSON string.
8775 ///
8776 /// The `space` argument is a String or Number object that's used to insert white space into
8777 /// the output JSON string for readability purposes. If this is a Number, it
8778 /// indicates the number of space characters to use as white space; this number
8779 /// is capped at 10 (if it is greater, the value is just 10). Values less than
8780 /// 1 indicate that no space should be used. If this is a String, the string
8781 /// (or the first 10 characters of the string, if it's longer than that) is
8782 /// used as white space. If this parameter is not provided (or is null), no
8783 /// white space is used.
8784 ///
8785 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
8786 #[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
8787 pub fn stringify_with_replacer_and_space(
8788 obj: &JsValue,
8789 replacer: &JsValue,
8790 space: &JsValue,
8791 ) -> Result<JsString, JsValue>;
8792 }
8793}
8794// JsString
8795#[wasm_bindgen]
8796extern "C" {
8797 #[wasm_bindgen(js_name = String, extends = Object, is_type_of = JsValue::is_string, typescript_type = "string")]
8798 #[derive(Clone, PartialEq, Eq)]
8799 pub type JsString;
8800
8801 /// The length property of a String object indicates the length of a string,
8802 /// in UTF-16 code units.
8803 ///
8804 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/length)
8805 #[wasm_bindgen(method, getter)]
8806 pub fn length(this: &JsString) -> u32;
8807
8808 /// The 'at()' method returns a new string consisting of the single UTF-16
8809 /// code unit located at the specified offset into the string, counting from
8810 /// the end if it's negative.
8811 ///
8812 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/at)
8813 #[wasm_bindgen(method, js_class = "String")]
8814 pub fn at(this: &JsString, index: i32) -> Option<JsString>;
8815
8816 /// The String object's `charAt()` method returns a new string consisting of
8817 /// the single UTF-16 code unit located at the specified offset into the
8818 /// string.
8819 ///
8820 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charAt)
8821 #[wasm_bindgen(method, js_class = "String", js_name = charAt)]
8822 pub fn char_at(this: &JsString, index: u32) -> JsString;
8823
8824 /// The `charCodeAt()` method returns an integer between 0 and 65535
8825 /// representing the UTF-16 code unit at the given index (the UTF-16 code
8826 /// unit matches the Unicode code point for code points representable in a
8827 /// single UTF-16 code unit, but might also be the first code unit of a
8828 /// surrogate pair for code points not representable in a single UTF-16 code
8829 /// unit, e.g. Unicode code points > 0x10000). If you want the entire code
8830 /// point value, use `codePointAt()`.
8831 ///
8832 /// Returns `NaN` if index is out of range.
8833 ///
8834 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charCodeAt)
8835 #[wasm_bindgen(method, js_class = "String", js_name = charCodeAt)]
8836 pub fn char_code_at(this: &JsString, index: u32) -> f64;
8837
8838 /// The `codePointAt()` method returns a non-negative integer that is the
8839 /// Unicode code point value.
8840 ///
8841 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/codePointAt)
8842 #[cfg(not(js_sys_unstable_apis))]
8843 #[wasm_bindgen(method, js_class = "String", js_name = codePointAt)]
8844 pub fn code_point_at(this: &JsString, pos: u32) -> JsValue;
8845
8846 /// The `codePointAt()` method returns a non-negative integer that is the
8847 /// Unicode code point value.
8848 ///
8849 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/codePointAt)
8850 #[cfg(js_sys_unstable_apis)]
8851 #[wasm_bindgen(method, js_class = "String", js_name = codePointAt)]
8852 pub fn code_point_at(this: &JsString, pos: u32) -> Option<u32>;
8853
8854 // Next major: deprecate
8855 /// The `codePointAt()` method returns a non-negative integer that is the
8856 /// Unicode code point value.
8857 ///
8858 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/codePointAt)
8859 #[wasm_bindgen(method, js_class = "String", js_name = codePointAt)]
8860 pub fn try_code_point_at(this: &JsString, pos: u32) -> Option<u16>;
8861
8862 /// The `concat()` method concatenates the string arguments to the calling
8863 /// string and returns a new string.
8864 ///
8865 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/concat)
8866 #[cfg(not(js_sys_unstable_apis))]
8867 #[wasm_bindgen(method, js_class = "String")]
8868 pub fn concat(this: &JsString, string_2: &JsValue) -> JsString;
8869
8870 /// The `concat()` method concatenates the string arguments to the calling
8871 /// string and returns a new string.
8872 ///
8873 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/concat)
8874 #[cfg(js_sys_unstable_apis)]
8875 #[wasm_bindgen(method, js_class = "String")]
8876 pub fn concat(this: &JsString, string: &JsString) -> JsString;
8877
8878 /// The `concat()` method concatenates the string arguments to the calling
8879 /// string and returns a new string.
8880 ///
8881 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/concat)
8882 #[wasm_bindgen(method, js_class = "String")]
8883 pub fn concat_many(this: &JsString, strings: &[JsString]) -> JsString;
8884
8885 /// The `endsWith()` method determines whether a string ends with the characters of a
8886 /// specified string, returning true or false as appropriate.
8887 ///
8888 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith)
8889 #[cfg(not(js_sys_unstable_apis))]
8890 #[wasm_bindgen(method, js_class = "String", js_name = endsWith)]
8891 pub fn ends_with(this: &JsString, search_string: &str, length: i32) -> bool;
8892
8893 /// The `endsWith()` method determines whether a string ends with the characters of a
8894 /// specified string, returning true or false as appropriate.
8895 ///
8896 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith)
8897 #[cfg(js_sys_unstable_apis)]
8898 #[wasm_bindgen(method, js_class = "String", js_name = endsWith)]
8899 pub fn ends_with(this: &JsString, search_string: &str) -> bool;
8900
8901 /// The static `String.fromCharCode()` method returns a string created from
8902 /// the specified sequence of UTF-16 code units.
8903 ///
8904 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
8905 ///
8906 /// # Notes
8907 ///
8908 /// There are a few bindings to `from_char_code` in `js-sys`: `from_char_code1`, `from_char_code2`, etc...
8909 /// with different arities.
8910 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode, variadic)]
8911 pub fn from_char_code(char_codes: &[u16]) -> JsString;
8912
8913 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
8914 #[cfg(not(js_sys_unstable_apis))]
8915 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
8916 pub fn from_char_code1(a: u32) -> JsString;
8917
8918 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
8919 #[cfg(js_sys_unstable_apis)]
8920 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
8921 pub fn from_char_code1(a: u16) -> JsString;
8922
8923 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
8924 #[cfg(not(js_sys_unstable_apis))]
8925 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
8926 pub fn from_char_code2(a: u32, b: u32) -> JsString;
8927
8928 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
8929 #[cfg(js_sys_unstable_apis)]
8930 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
8931 pub fn from_char_code2(a: u16, b: 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_code3(a: u32, b: u32, c: 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_code3(a: u16, b: u16, c: 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_code4(a: u32, b: u32, c: u32, d: 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_code4(a: u16, b: u16, c: u16, d: 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_code5(a: u32, b: u32, c: u32, d: u32, e: 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_code5(a: u16, b: u16, c: u16, d: u16, e: u16) -> JsString;
8962
8963 /// The static `String.fromCodePoint()` method returns a string created by
8964 /// using the specified sequence of code points.
8965 ///
8966 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
8967 ///
8968 /// # Exceptions
8969 ///
8970 /// A RangeError is thrown if an invalid Unicode code point is given
8971 ///
8972 /// # Notes
8973 ///
8974 /// There are a few bindings to `from_code_point` in `js-sys`: `from_code_point1`, `from_code_point2`, etc...
8975 /// with different arities.
8976 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint, variadic)]
8977 pub fn from_code_point(code_points: &[u32]) -> Result<JsString, JsValue>;
8978
8979 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
8980 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
8981 pub fn from_code_point1(a: u32) -> Result<JsString, JsValue>;
8982
8983 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
8984 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
8985 pub fn from_code_point2(a: u32, b: u32) -> Result<JsString, JsValue>;
8986
8987 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
8988 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
8989 pub fn from_code_point3(a: u32, b: u32, c: u32) -> Result<JsString, JsValue>;
8990
8991 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
8992 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
8993 pub fn from_code_point4(a: u32, b: u32, c: u32, d: u32) -> Result<JsString, JsValue>;
8994
8995 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
8996 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
8997 pub fn from_code_point5(a: u32, b: u32, c: u32, d: u32, e: u32) -> Result<JsString, JsValue>;
8998
8999 /// The `includes()` method determines whether one string may be found
9000 /// within another string, returning true or false as appropriate.
9001 ///
9002 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes)
9003 #[wasm_bindgen(method, js_class = "String")]
9004 pub fn includes(this: &JsString, search_string: &str, position: i32) -> bool;
9005
9006 /// The `indexOf()` method returns the index within the calling String
9007 /// object of the first occurrence of the specified value, starting the
9008 /// search at fromIndex. Returns -1 if the value is not found.
9009 ///
9010 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf)
9011 #[wasm_bindgen(method, js_class = "String", js_name = indexOf)]
9012 pub fn index_of(this: &JsString, search_value: &str, from_index: i32) -> i32;
9013
9014 /// The `lastIndexOf()` method returns the index within the calling String
9015 /// object of the last occurrence of the specified value, searching
9016 /// backwards from fromIndex. Returns -1 if the value is not found.
9017 ///
9018 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/lastIndexOf)
9019 #[wasm_bindgen(method, js_class = "String", js_name = lastIndexOf)]
9020 pub fn last_index_of(this: &JsString, search_value: &str, from_index: i32) -> i32;
9021
9022 /// The `localeCompare()` method returns a number indicating whether
9023 /// a reference string comes before or after or is the same as
9024 /// the given string in sort order.
9025 ///
9026 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare)
9027 #[cfg(not(js_sys_unstable_apis))]
9028 #[wasm_bindgen(method, js_class = "String", js_name = localeCompare)]
9029 pub fn locale_compare(
9030 this: &JsString,
9031 compare_string: &str,
9032 locales: &Array,
9033 options: &Object,
9034 ) -> i32;
9035
9036 /// The `localeCompare()` method returns a number indicating whether
9037 /// a reference string comes before or after or is the same as
9038 /// the given string in sort order.
9039 ///
9040 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare)
9041 #[cfg(js_sys_unstable_apis)]
9042 #[wasm_bindgen(method, js_class = "String", js_name = localeCompare)]
9043 pub fn locale_compare(
9044 this: &JsString,
9045 compare_string: &str,
9046 locales: &[JsString],
9047 options: &Intl::CollatorOptions,
9048 ) -> i32;
9049
9050 /// The `match()` method retrieves the matches when matching a string against a regular expression.
9051 ///
9052 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match)
9053 #[wasm_bindgen(method, js_class = "String", js_name = match)]
9054 pub fn match_(this: &JsString, pattern: &RegExp) -> Option<Object>;
9055
9056 /// The `match_all()` method is similar to `match()`, but gives an iterator of `exec()` arrays, which preserve capture groups.
9057 ///
9058 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/matchAll)
9059 #[cfg(not(js_sys_unstable_apis))]
9060 #[wasm_bindgen(method, js_class = "String", js_name = matchAll)]
9061 pub fn match_all(this: &JsString, pattern: &RegExp) -> Iterator;
9062
9063 /// The `match_all()` method is similar to `match()`, but gives an iterator of `exec()` arrays, which preserve capture groups.
9064 ///
9065 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/matchAll)
9066 #[cfg(js_sys_unstable_apis)]
9067 #[wasm_bindgen(method, js_class = "String", js_name = matchAll)]
9068 pub fn match_all(this: &JsString, pattern: &RegExp) -> Iterator<RegExpMatchArray>;
9069
9070 /// The `normalize()` method returns the Unicode Normalization Form
9071 /// of a given string (if the value isn't a string, it will be converted to one first).
9072 ///
9073 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize)
9074 #[wasm_bindgen(method, js_class = "String")]
9075 pub fn normalize(this: &JsString, form: &str) -> JsString;
9076
9077 /// The `padEnd()` method pads the current string with a given string
9078 /// (repeated, if needed) so that the resulting string reaches a given
9079 /// length. The padding is applied from the end (right) of the current
9080 /// string.
9081 ///
9082 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padEnd)
9083 #[wasm_bindgen(method, js_class = "String", js_name = padEnd)]
9084 pub fn pad_end(this: &JsString, target_length: u32, pad_string: &str) -> JsString;
9085
9086 /// The `padStart()` method pads the current string with another string
9087 /// (repeated, if needed) so that the resulting string reaches the given
9088 /// length. The padding is applied from the start (left) of the current
9089 /// string.
9090 ///
9091 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padStart)
9092 #[wasm_bindgen(method, js_class = "String", js_name = padStart)]
9093 pub fn pad_start(this: &JsString, target_length: u32, pad_string: &str) -> JsString;
9094
9095 /// The `repeat()` method constructs and returns a new string which contains the specified
9096 /// number of copies of the string on which it was called, concatenated together.
9097 ///
9098 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat)
9099 #[wasm_bindgen(method, js_class = "String")]
9100 pub fn repeat(this: &JsString, count: i32) -> JsString;
9101
9102 /// The `replace()` method returns a new string with some or all matches of a pattern
9103 /// replaced by a replacement. The pattern can be a string or a RegExp, and
9104 /// the replacement can be a string or a function to be called for each match.
9105 ///
9106 /// Note: The original string will remain unchanged.
9107 ///
9108 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
9109 #[wasm_bindgen(method, js_class = "String")]
9110 pub fn replace(this: &JsString, pattern: &str, replacement: &str) -> JsString;
9111
9112 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
9113 #[cfg(not(js_sys_unstable_apis))]
9114 #[wasm_bindgen(method, js_class = "String", js_name = replace)]
9115 pub fn replace_with_function(
9116 this: &JsString,
9117 pattern: &str,
9118 replacement: &Function,
9119 ) -> JsString;
9120
9121 /// The replacer function signature is `(match, offset, string) -> replacement`
9122 /// for patterns without capture groups, or `(match, p1, p2, ..., pN, offset, string, groups) -> replacement`
9123 /// when capture groups are present.
9124 ///
9125 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
9126 #[cfg(js_sys_unstable_apis)]
9127 #[wasm_bindgen(method, js_class = "String", js_name = replace)]
9128 pub fn replace_with_function(
9129 this: &JsString,
9130 pattern: &str,
9131 replacement: &Function<fn(JsString) -> JsString>,
9132 ) -> JsString;
9133
9134 #[wasm_bindgen(method, js_class = "String", js_name = replace)]
9135 pub fn replace_by_pattern(this: &JsString, pattern: &RegExp, replacement: &str) -> JsString;
9136
9137 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
9138 #[cfg(not(js_sys_unstable_apis))]
9139 #[wasm_bindgen(method, js_class = "String", js_name = replace)]
9140 pub fn replace_by_pattern_with_function(
9141 this: &JsString,
9142 pattern: &RegExp,
9143 replacement: &Function,
9144 ) -> JsString;
9145
9146 /// The replacer function signature is `(match, offset, string) -> replacement`
9147 /// for patterns without capture groups, or `(match, p1, p2, ..., pN, offset, string, groups) -> replacement`
9148 /// when capture groups are present.
9149 ///
9150 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
9151 #[cfg(js_sys_unstable_apis)]
9152 #[wasm_bindgen(method, js_class = "String", js_name = replace)]
9153 pub fn replace_by_pattern_with_function(
9154 this: &JsString,
9155 pattern: &RegExp,
9156 replacement: &Function<fn(JsString) -> JsString>,
9157 ) -> JsString;
9158
9159 /// The `replace_all()` method returns a new string with all matches of a pattern
9160 /// replaced by a replacement. The pattern can be a string or a global RegExp, and
9161 /// the replacement can be a string or a function to be called for each match.
9162 ///
9163 /// Note: The original string will remain unchanged.
9164 ///
9165 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)
9166 #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
9167 pub fn replace_all(this: &JsString, pattern: &str, replacement: &str) -> JsString;
9168
9169 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)
9170 #[cfg(not(js_sys_unstable_apis))]
9171 #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
9172 pub fn replace_all_with_function(
9173 this: &JsString,
9174 pattern: &str,
9175 replacement: &Function,
9176 ) -> JsString;
9177
9178 /// The replacer function signature is `(match, offset, string) -> replacement`
9179 /// for patterns without capture groups, or `(match, p1, p2, ..., pN, offset, string, groups) -> replacement`
9180 /// when capture groups are present.
9181 ///
9182 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)
9183 #[cfg(js_sys_unstable_apis)]
9184 #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
9185 pub fn replace_all_with_function(
9186 this: &JsString,
9187 pattern: &str,
9188 replacement: &Function<fn(JsString) -> JsString>,
9189 ) -> JsString;
9190
9191 #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
9192 pub fn replace_all_by_pattern(this: &JsString, pattern: &RegExp, replacement: &str)
9193 -> JsString;
9194
9195 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)
9196 #[cfg(not(js_sys_unstable_apis))]
9197 #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
9198 pub fn replace_all_by_pattern_with_function(
9199 this: &JsString,
9200 pattern: &RegExp,
9201 replacement: &Function,
9202 ) -> JsString;
9203
9204 /// The replacer function signature is `(match, offset, string) -> replacement`
9205 /// for patterns without capture groups, or `(match, p1, p2, ..., pN, offset, string, groups) -> replacement`
9206 /// when capture groups are present.
9207 ///
9208 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)
9209 #[cfg(js_sys_unstable_apis)]
9210 #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
9211 pub fn replace_all_by_pattern_with_function(
9212 this: &JsString,
9213 pattern: &RegExp,
9214 replacement: &Function<fn(JsString) -> JsString>,
9215 ) -> JsString;
9216
9217 /// The `search()` method executes a search for a match between
9218 /// a regular expression and this String object.
9219 ///
9220 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/search)
9221 #[wasm_bindgen(method, js_class = "String")]
9222 pub fn search(this: &JsString, pattern: &RegExp) -> i32;
9223
9224 /// The `slice()` method extracts a section of a string and returns it as a
9225 /// new string, without modifying the original string.
9226 ///
9227 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice)
9228 #[wasm_bindgen(method, js_class = "String")]
9229 pub fn slice(this: &JsString, start: u32, end: u32) -> JsString;
9230
9231 /// The `split()` method splits a String object into an array of strings by separating the string
9232 /// into substrings, using a specified separator string to determine where to make each split.
9233 ///
9234 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)
9235 #[wasm_bindgen(method, js_class = "String")]
9236 pub fn split(this: &JsString, separator: &str) -> Array;
9237
9238 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)
9239 #[wasm_bindgen(method, js_class = "String", js_name = split)]
9240 pub fn split_limit(this: &JsString, separator: &str, limit: u32) -> Array;
9241
9242 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)
9243 #[wasm_bindgen(method, js_class = "String", js_name = split)]
9244 pub fn split_by_pattern(this: &JsString, pattern: &RegExp) -> Array;
9245
9246 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)
9247 #[wasm_bindgen(method, js_class = "String", js_name = split)]
9248 pub fn split_by_pattern_limit(this: &JsString, pattern: &RegExp, limit: u32) -> Array;
9249
9250 /// The `startsWith()` method determines whether a string begins with the
9251 /// characters of a specified string, returning true or false as
9252 /// appropriate.
9253 ///
9254 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith)
9255 #[wasm_bindgen(method, js_class = "String", js_name = startsWith)]
9256 pub fn starts_with(this: &JsString, search_string: &str, position: u32) -> bool;
9257
9258 /// The `substring()` method returns the part of the string between the
9259 /// start and end indexes, or to the end of the string.
9260 ///
9261 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring)
9262 #[wasm_bindgen(method, js_class = "String")]
9263 pub fn substring(this: &JsString, index_start: u32, index_end: u32) -> JsString;
9264
9265 /// The `substr()` method returns the part of a string between
9266 /// the start index and a number of characters after it.
9267 ///
9268 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr)
9269 #[wasm_bindgen(method, js_class = "String")]
9270 pub fn substr(this: &JsString, start: i32, length: i32) -> JsString;
9271
9272 /// The `toLocaleLowerCase()` method returns the calling string value converted to lower case,
9273 /// according to any locale-specific case mappings.
9274 ///
9275 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLocaleLowerCase)
9276 #[wasm_bindgen(method, js_class = "String", js_name = toLocaleLowerCase)]
9277 pub fn to_locale_lower_case(this: &JsString, locale: Option<&str>) -> JsString;
9278
9279 /// The `toLocaleUpperCase()` method returns the calling string value converted to upper case,
9280 /// according to any locale-specific case mappings.
9281 ///
9282 /// [MDN documentation](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/String/toLocaleUpperCase)
9283 #[wasm_bindgen(method, js_class = "String", js_name = toLocaleUpperCase)]
9284 pub fn to_locale_upper_case(this: &JsString, locale: Option<&str>) -> JsString;
9285
9286 /// The `toLowerCase()` method returns the calling string value
9287 /// converted to lower case.
9288 ///
9289 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLowerCase)
9290 #[wasm_bindgen(method, js_class = "String", js_name = toLowerCase)]
9291 pub fn to_lower_case(this: &JsString) -> JsString;
9292
9293 /// The `toString()` method returns a string representing the specified
9294 /// object.
9295 ///
9296 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toString)
9297 #[cfg(not(js_sys_unstable_apis))]
9298 #[wasm_bindgen(method, js_class = "String", js_name = toString)]
9299 pub fn to_string(this: &JsString) -> JsString;
9300
9301 /// The `toUpperCase()` method returns the calling string value converted to
9302 /// uppercase (the value will be converted to a string if it isn't one).
9303 ///
9304 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase)
9305 #[wasm_bindgen(method, js_class = "String", js_name = toUpperCase)]
9306 pub fn to_upper_case(this: &JsString) -> JsString;
9307
9308 /// The `trim()` method removes whitespace from both ends of a string.
9309 /// Whitespace in this context is all the whitespace characters (space, tab,
9310 /// no-break space, etc.) and all the line terminator characters (LF, CR,
9311 /// etc.).
9312 ///
9313 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trim)
9314 #[wasm_bindgen(method, js_class = "String")]
9315 pub fn trim(this: &JsString) -> JsString;
9316
9317 /// The `trimEnd()` method removes whitespace from the end of a string.
9318 /// `trimRight()` is an alias of this method.
9319 ///
9320 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimEnd)
9321 #[wasm_bindgen(method, js_class = "String", js_name = trimEnd)]
9322 pub fn trim_end(this: &JsString) -> JsString;
9323
9324 /// The `trimEnd()` method removes whitespace from the end of a string.
9325 /// `trimRight()` is an alias of this method.
9326 ///
9327 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimEnd)
9328 #[wasm_bindgen(method, js_class = "String", js_name = trimRight)]
9329 pub fn trim_right(this: &JsString) -> JsString;
9330
9331 /// The `trimStart()` method removes whitespace from the beginning of a
9332 /// string. `trimLeft()` is an alias of this method.
9333 ///
9334 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimStart)
9335 #[wasm_bindgen(method, js_class = "String", js_name = trimStart)]
9336 pub fn trim_start(this: &JsString) -> JsString;
9337
9338 /// The `trimStart()` method removes whitespace from the beginning of a
9339 /// string. `trimLeft()` is an alias of this method.
9340 ///
9341 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimStart)
9342 #[wasm_bindgen(method, js_class = "String", js_name = trimLeft)]
9343 pub fn trim_left(this: &JsString) -> JsString;
9344
9345 /// The `valueOf()` method returns the primitive value of a `String` object.
9346 ///
9347 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/valueOf)
9348 #[wasm_bindgen(method, js_class = "String", js_name = valueOf)]
9349 pub fn value_of(this: &JsString) -> JsString;
9350
9351 /// The static `raw()` method is a tag function of template literals,
9352 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9353 ///
9354 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9355 #[wasm_bindgen(catch, variadic, static_method_of = JsString, js_class = "String")]
9356 pub fn raw(call_site: &Object, substitutions: &Array) -> Result<JsString, JsValue>;
9357
9358 /// The static `raw()` method is a tag function of template literals,
9359 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9360 ///
9361 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9362 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9363 pub fn raw_0(call_site: &Object) -> Result<JsString, JsValue>;
9364
9365 /// The static `raw()` method is a tag function of template literals,
9366 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9367 ///
9368 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9369 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9370 pub fn raw_1(call_site: &Object, substitutions_1: &str) -> Result<JsString, JsValue>;
9371
9372 /// The static `raw()` method is a tag function of template literals,
9373 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9374 ///
9375 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9376 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9377 pub fn raw_2(
9378 call_site: &Object,
9379 substitutions1: &str,
9380 substitutions2: &str,
9381 ) -> Result<JsString, JsValue>;
9382
9383 /// The static `raw()` method is a tag function of template literals,
9384 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9385 ///
9386 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9387 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9388 pub fn raw_3(
9389 call_site: &Object,
9390 substitutions1: &str,
9391 substitutions2: &str,
9392 substitutions3: &str,
9393 ) -> Result<JsString, JsValue>;
9394
9395 /// The static `raw()` method is a tag function of template literals,
9396 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9397 ///
9398 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9399 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9400 pub fn raw_4(
9401 call_site: &Object,
9402 substitutions1: &str,
9403 substitutions2: &str,
9404 substitutions3: &str,
9405 substitutions4: &str,
9406 ) -> Result<JsString, JsValue>;
9407
9408 /// The static `raw()` method is a tag function of template literals,
9409 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9410 ///
9411 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9412 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9413 pub fn raw_5(
9414 call_site: &Object,
9415 substitutions1: &str,
9416 substitutions2: &str,
9417 substitutions3: &str,
9418 substitutions4: &str,
9419 substitutions5: &str,
9420 ) -> Result<JsString, JsValue>;
9421
9422 /// The static `raw()` method is a tag function of template literals,
9423 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9424 ///
9425 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9426 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9427 pub fn raw_6(
9428 call_site: &Object,
9429 substitutions1: &str,
9430 substitutions2: &str,
9431 substitutions3: &str,
9432 substitutions4: &str,
9433 substitutions5: &str,
9434 substitutions6: &str,
9435 ) -> Result<JsString, JsValue>;
9436
9437 /// The static `raw()` method is a tag function of template literals,
9438 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9439 ///
9440 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9441 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9442 pub fn raw_7(
9443 call_site: &Object,
9444 substitutions1: &str,
9445 substitutions2: &str,
9446 substitutions3: &str,
9447 substitutions4: &str,
9448 substitutions5: &str,
9449 substitutions6: &str,
9450 substitutions7: &str,
9451 ) -> Result<JsString, JsValue>;
9452}
9453
9454// These upcasts are non-castable due to the constraints on the function
9455// but the UpcastFrom covariance must still extend through closure types.
9456// (impl UpcastFrom really just means CovariantGeneric relation)
9457impl UpcastFrom<String> for JsString {}
9458impl UpcastFrom<JsString> for String {}
9459
9460impl UpcastFrom<&str> for JsString {}
9461impl UpcastFrom<JsString> for &str {}
9462
9463impl UpcastFrom<char> for JsString {}
9464impl UpcastFrom<JsString> for char {}
9465
9466impl JsString {
9467 /// Returns the `JsString` value of this JS value if it's an instance of a
9468 /// string.
9469 ///
9470 /// If this JS value is not an instance of a string then this returns
9471 /// `None`.
9472 #[cfg(not(js_sys_unstable_apis))]
9473 #[deprecated(note = "recommended to use dyn_ref instead which is now equivalent")]
9474 pub fn try_from(val: &JsValue) -> Option<&JsString> {
9475 val.dyn_ref()
9476 }
9477
9478 /// Returns whether this string is a valid UTF-16 string.
9479 ///
9480 /// This is useful for learning whether `String::from(..)` will return a
9481 /// lossless representation of the JS string. If this string contains
9482 /// unpaired surrogates then `String::from` will succeed but it will be a
9483 /// lossy representation of the JS string because unpaired surrogates will
9484 /// become replacement characters.
9485 ///
9486 /// If this function returns `false` then to get a lossless representation
9487 /// of the string you'll need to manually use the `iter` method (or the
9488 /// `char_code_at` accessor) to view the raw character codes.
9489 ///
9490 /// For more information, see the documentation on [JS strings vs Rust
9491 /// strings][docs]
9492 ///
9493 /// [docs]: https://wasm-bindgen.github.io/wasm-bindgen/reference/types/str.html
9494 pub fn is_valid_utf16(&self) -> bool {
9495 core::char::decode_utf16(self.iter()).all(|i| i.is_ok())
9496 }
9497
9498 /// Returns an iterator over the `u16` character codes that make up this JS
9499 /// string.
9500 ///
9501 /// This method will call `char_code_at` for each code in this JS string,
9502 /// returning an iterator of the codes in sequence.
9503 pub fn iter(
9504 &self,
9505 ) -> impl ExactSizeIterator<Item = u16> + DoubleEndedIterator<Item = u16> + '_ {
9506 (0..self.length()).map(move |i| self.char_code_at(i) as u16)
9507 }
9508
9509 /// If this string consists of a single Unicode code point, then this method
9510 /// converts it into a Rust `char` without doing any allocations.
9511 ///
9512 /// If this JS value is not a valid UTF-8 or consists of more than a single
9513 /// codepoint, then this returns `None`.
9514 ///
9515 /// Note that a single Unicode code point might be represented as more than
9516 /// one code unit on the JavaScript side. For example, a JavaScript string
9517 /// `"\uD801\uDC37"` is actually a single Unicode code point U+10437 which
9518 /// corresponds to a character '𐐷'.
9519 pub fn as_char(&self) -> Option<char> {
9520 let len = self.length();
9521
9522 if len == 0 || len > 2 {
9523 return None;
9524 }
9525
9526 #[cfg(not(js_sys_unstable_apis))]
9527 let cp = self.code_point_at(0).as_f64().unwrap_throw() as u32;
9528 #[cfg(js_sys_unstable_apis)]
9529 let cp = self.code_point_at(0)?;
9530
9531 let c = core::char::from_u32(cp)?;
9532
9533 if c.len_utf16() as u32 == len {
9534 Some(c)
9535 } else {
9536 None
9537 }
9538 }
9539}
9540
9541impl PartialEq<str> for JsString {
9542 #[allow(clippy::cmp_owned)] // prevent infinite recursion
9543 fn eq(&self, other: &str) -> bool {
9544 String::from(self) == other
9545 }
9546}
9547
9548impl<'a> PartialEq<&'a str> for JsString {
9549 fn eq(&self, other: &&'a str) -> bool {
9550 <JsString as PartialEq<str>>::eq(self, other)
9551 }
9552}
9553
9554impl PartialEq<String> for JsString {
9555 fn eq(&self, other: &String) -> bool {
9556 <JsString as PartialEq<str>>::eq(self, other)
9557 }
9558}
9559
9560impl<'a> PartialEq<&'a String> for JsString {
9561 fn eq(&self, other: &&'a String) -> bool {
9562 <JsString as PartialEq<str>>::eq(self, other)
9563 }
9564}
9565
9566impl Default for JsString {
9567 fn default() -> Self {
9568 Self::from("")
9569 }
9570}
9571
9572impl<'a> From<&'a str> for JsString {
9573 fn from(s: &'a str) -> Self {
9574 JsString::unchecked_from_js(JsValue::from_str(s))
9575 }
9576}
9577
9578impl From<String> for JsString {
9579 fn from(s: String) -> Self {
9580 From::from(&*s)
9581 }
9582}
9583
9584impl From<char> for JsString {
9585 #[inline]
9586 fn from(c: char) -> Self {
9587 JsString::from_code_point1(c as u32).unwrap_throw()
9588 }
9589}
9590
9591impl<'a> From<&'a JsString> for String {
9592 fn from(s: &'a JsString) -> Self {
9593 s.obj.as_string().unwrap_throw()
9594 }
9595}
9596
9597impl From<JsString> for String {
9598 fn from(s: JsString) -> Self {
9599 From::from(&s)
9600 }
9601}
9602
9603impl fmt::Debug for JsString {
9604 #[inline]
9605 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9606 fmt::Debug::fmt(&String::from(self), f)
9607 }
9608}
9609
9610impl fmt::Display for JsString {
9611 #[inline]
9612 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9613 fmt::Display::fmt(&String::from(self), f)
9614 }
9615}
9616
9617impl str::FromStr for JsString {
9618 type Err = convert::Infallible;
9619 fn from_str(s: &str) -> Result<Self, Self::Err> {
9620 Ok(JsString::from(s))
9621 }
9622}
9623
9624// Symbol
9625#[wasm_bindgen]
9626extern "C" {
9627 #[wasm_bindgen(is_type_of = JsValue::is_symbol, typescript_type = "Symbol")]
9628 #[derive(Clone, Debug)]
9629 pub type Symbol;
9630
9631 /// The `Symbol.hasInstance` well-known symbol is used to determine
9632 /// if a constructor object recognizes an object as its instance.
9633 /// The `instanceof` operator's behavior can be customized by this symbol.
9634 ///
9635 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/hasInstance)
9636 #[wasm_bindgen(static_method_of = Symbol, getter, js_name = hasInstance)]
9637 pub fn has_instance() -> Symbol;
9638
9639 /// The `Symbol.isConcatSpreadable` well-known symbol is used to configure
9640 /// if an object should be flattened to its array elements when using the
9641 /// `Array.prototype.concat()` method.
9642 ///
9643 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/isConcatSpreadable)
9644 #[wasm_bindgen(static_method_of = Symbol, getter, js_name = isConcatSpreadable)]
9645 pub fn is_concat_spreadable() -> Symbol;
9646
9647 /// The `Symbol.asyncIterator` well-known symbol specifies the default AsyncIterator for an object.
9648 /// If this property is set on an object, it is an async iterable and can be used in a `for await...of` loop.
9649 ///
9650 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/asyncIterator)
9651 #[wasm_bindgen(static_method_of = Symbol, getter, js_name = asyncIterator)]
9652 pub fn async_iterator() -> Symbol;
9653
9654 /// The `Symbol.iterator` well-known symbol specifies the default iterator
9655 /// for an object. Used by `for...of`.
9656 ///
9657 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/iterator)
9658 #[wasm_bindgen(static_method_of = Symbol, getter)]
9659 pub fn iterator() -> Symbol;
9660
9661 /// The `Symbol.match` well-known symbol specifies the matching of a regular
9662 /// expression against a string. This function is called by the
9663 /// `String.prototype.match()` method.
9664 ///
9665 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/match)
9666 #[wasm_bindgen(static_method_of = Symbol, getter, js_name = match)]
9667 pub fn match_() -> Symbol;
9668
9669 /// The `Symbol.replace` well-known symbol specifies the method that
9670 /// replaces matched substrings of a string. This function is called by the
9671 /// `String.prototype.replace()` method.
9672 ///
9673 /// For more information, see `RegExp.prototype[@@replace]()` and
9674 /// `String.prototype.replace()`.
9675 ///
9676 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/replace)
9677 #[wasm_bindgen(static_method_of = Symbol, getter)]
9678 pub fn replace() -> Symbol;
9679
9680 /// The `Symbol.search` well-known symbol specifies the method that returns
9681 /// the index within a string that matches the regular expression. This
9682 /// function is called by the `String.prototype.search()` method.
9683 ///
9684 /// For more information, see `RegExp.prototype[@@search]()` and
9685 /// `String.prototype.search()`.
9686 ///
9687 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/search)
9688 #[wasm_bindgen(static_method_of = Symbol, getter)]
9689 pub fn search() -> Symbol;
9690
9691 /// The well-known symbol `Symbol.species` specifies a function-valued
9692 /// property that the constructor function uses to create derived objects.
9693 ///
9694 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/species)
9695 #[wasm_bindgen(static_method_of = Symbol, getter)]
9696 pub fn species() -> Symbol;
9697
9698 /// The `Symbol.split` well-known symbol specifies the method that splits a
9699 /// string at the indices that match a regular expression. This function is
9700 /// called by the `String.prototype.split()` method.
9701 ///
9702 /// For more information, see `RegExp.prototype[@@split]()` and
9703 /// `String.prototype.split()`.
9704 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/split)
9705 #[wasm_bindgen(static_method_of = Symbol, getter)]
9706 pub fn split() -> Symbol;
9707
9708 /// The `Symbol.toPrimitive` is a symbol that specifies a function valued
9709 /// property that is called to convert an object to a corresponding
9710 /// primitive value.
9711 ///
9712 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toPrimitive)
9713 #[wasm_bindgen(static_method_of = Symbol, getter, js_name = toPrimitive)]
9714 pub fn to_primitive() -> Symbol;
9715
9716 /// The `Symbol.toStringTag` well-known symbol is a string valued property
9717 /// that is used in the creation of the default string description of an
9718 /// object. It is accessed internally by the `Object.prototype.toString()`
9719 /// method.
9720 ///
9721 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toString)
9722 #[wasm_bindgen(static_method_of = Symbol, getter, js_name = toStringTag)]
9723 pub fn to_string_tag() -> Symbol;
9724
9725 /// The `Symbol.for(key)` method searches for existing symbols in a runtime-wide symbol registry with
9726 /// the given key and returns it if found.
9727 /// Otherwise a new symbol gets created in the global symbol registry with this key.
9728 ///
9729 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/for)
9730 #[wasm_bindgen(static_method_of = Symbol, js_name = for)]
9731 pub fn for_(key: &str) -> Symbol;
9732
9733 /// The `Symbol.keyFor(sym)` method retrieves a shared symbol key from the global symbol registry for the given symbol.
9734 ///
9735 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/keyFor)
9736 #[wasm_bindgen(static_method_of = Symbol, js_name = keyFor)]
9737 pub fn key_for(sym: &Symbol) -> JsValue;
9738
9739 // Next major: deprecate
9740 /// The `toString()` method returns a string representing the specified Symbol object.
9741 ///
9742 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toString)
9743 #[wasm_bindgen(method, js_name = toString)]
9744 pub fn to_string(this: &Symbol) -> JsString;
9745
9746 /// The `toString()` method returns a string representing the specified Symbol object.
9747 ///
9748 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toString)
9749 #[wasm_bindgen(method, js_name = toString)]
9750 pub fn to_js_string(this: &Symbol) -> JsString;
9751
9752 /// The `Symbol.unscopables` well-known symbol is used to specify an object
9753 /// value of whose own and inherited property names are excluded from the
9754 /// with environment bindings of the associated object.
9755 ///
9756 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/unscopables)
9757 #[wasm_bindgen(static_method_of = Symbol, getter)]
9758 pub fn unscopables() -> Symbol;
9759
9760 /// The `valueOf()` method returns the primitive value of a Symbol object.
9761 ///
9762 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/valueOf)
9763 #[wasm_bindgen(method, js_name = valueOf)]
9764 pub fn value_of(this: &Symbol) -> Symbol;
9765}
9766
9767#[allow(non_snake_case)]
9768pub mod Intl {
9769 use super::*;
9770
9771 // Intl
9772 #[wasm_bindgen]
9773 extern "C" {
9774 /// The `Intl.getCanonicalLocales()` method returns an array containing
9775 /// the canonical locale names. Duplicates will be omitted and elements
9776 /// will be validated as structurally valid language tags.
9777 ///
9778 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/getCanonicalLocales)
9779 #[cfg(not(js_sys_unstable_apis))]
9780 #[wasm_bindgen(js_name = getCanonicalLocales, js_namespace = Intl)]
9781 pub fn get_canonical_locales(s: &JsValue) -> Array;
9782
9783 /// The `Intl.getCanonicalLocales()` method returns an array containing
9784 /// the canonical locale names. Duplicates will be omitted and elements
9785 /// will be validated as structurally valid language tags.
9786 ///
9787 /// Throws a `RangeError` if any of the strings are not valid locale identifiers.
9788 ///
9789 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/getCanonicalLocales)
9790 #[cfg(js_sys_unstable_apis)]
9791 #[wasm_bindgen(js_name = getCanonicalLocales, js_namespace = Intl, catch)]
9792 pub fn get_canonical_locales(s: &[JsString]) -> Result<Array<JsString>, JsValue>;
9793
9794 /// The `Intl.supportedValuesOf()` method returns an array containing the
9795 /// supported calendar, collation, currency, numbering system, or unit values
9796 /// supported by the implementation.
9797 ///
9798 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/supportedValuesOf)
9799 #[wasm_bindgen(js_name = supportedValuesOf, js_namespace = Intl)]
9800 pub fn supported_values_of(key: SupportedValuesKey) -> Array<JsString>;
9801 }
9802
9803 // Intl string enums
9804
9805 /// Key for `Intl.supportedValuesOf()`.
9806 #[wasm_bindgen]
9807 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9808 pub enum SupportedValuesKey {
9809 Calendar = "calendar",
9810 Collation = "collation",
9811 Currency = "currency",
9812 NumberingSystem = "numberingSystem",
9813 TimeZone = "timeZone",
9814 Unit = "unit",
9815 }
9816
9817 /// Locale matching algorithm for Intl constructors.
9818 #[wasm_bindgen]
9819 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9820 pub enum LocaleMatcher {
9821 Lookup = "lookup",
9822 BestFit = "best fit",
9823 }
9824
9825 /// Usage for `Intl.Collator`.
9826 #[wasm_bindgen]
9827 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9828 pub enum CollatorUsage {
9829 Sort = "sort",
9830 Search = "search",
9831 }
9832
9833 /// Sensitivity for `Intl.Collator`.
9834 #[wasm_bindgen]
9835 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9836 pub enum CollatorSensitivity {
9837 Base = "base",
9838 Accent = "accent",
9839 Case = "case",
9840 Variant = "variant",
9841 }
9842
9843 /// Case first option for `Intl.Collator`.
9844 #[wasm_bindgen]
9845 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9846 pub enum CollatorCaseFirst {
9847 Upper = "upper",
9848 Lower = "lower",
9849 False = "false",
9850 }
9851
9852 /// Style for `Intl.NumberFormat`.
9853 #[wasm_bindgen]
9854 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9855 pub enum NumberFormatStyle {
9856 Decimal = "decimal",
9857 Currency = "currency",
9858 Percent = "percent",
9859 Unit = "unit",
9860 }
9861
9862 /// Currency display for `Intl.NumberFormat`.
9863 #[wasm_bindgen]
9864 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9865 pub enum CurrencyDisplay {
9866 Code = "code",
9867 Symbol = "symbol",
9868 NarrowSymbol = "narrowSymbol",
9869 Name = "name",
9870 }
9871
9872 /// Currency sign for `Intl.NumberFormat`.
9873 #[wasm_bindgen]
9874 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9875 pub enum CurrencySign {
9876 Standard = "standard",
9877 Accounting = "accounting",
9878 }
9879
9880 /// Unit display for `Intl.NumberFormat`.
9881 #[wasm_bindgen]
9882 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9883 pub enum UnitDisplay {
9884 Short = "short",
9885 Narrow = "narrow",
9886 Long = "long",
9887 }
9888
9889 /// Notation for `Intl.NumberFormat`.
9890 #[wasm_bindgen]
9891 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9892 pub enum NumberFormatNotation {
9893 Standard = "standard",
9894 Scientific = "scientific",
9895 Engineering = "engineering",
9896 Compact = "compact",
9897 }
9898
9899 /// Compact display for `Intl.NumberFormat`.
9900 #[wasm_bindgen]
9901 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9902 pub enum CompactDisplay {
9903 Short = "short",
9904 Long = "long",
9905 }
9906
9907 /// Sign display for `Intl.NumberFormat`.
9908 #[wasm_bindgen]
9909 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9910 pub enum SignDisplay {
9911 Auto = "auto",
9912 Never = "never",
9913 Always = "always",
9914 ExceptZero = "exceptZero",
9915 }
9916
9917 /// Rounding mode for `Intl.NumberFormat`.
9918 #[wasm_bindgen]
9919 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9920 pub enum RoundingMode {
9921 Ceil = "ceil",
9922 Floor = "floor",
9923 Expand = "expand",
9924 Trunc = "trunc",
9925 HalfCeil = "halfCeil",
9926 HalfFloor = "halfFloor",
9927 HalfExpand = "halfExpand",
9928 HalfTrunc = "halfTrunc",
9929 HalfEven = "halfEven",
9930 }
9931
9932 /// Rounding priority for `Intl.NumberFormat`.
9933 #[wasm_bindgen]
9934 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9935 pub enum RoundingPriority {
9936 Auto = "auto",
9937 MorePrecision = "morePrecision",
9938 LessPrecision = "lessPrecision",
9939 }
9940
9941 /// Trailing zero display for `Intl.NumberFormat`.
9942 #[wasm_bindgen]
9943 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9944 pub enum TrailingZeroDisplay {
9945 Auto = "auto",
9946 StripIfInteger = "stripIfInteger",
9947 }
9948
9949 /// Use grouping option for `Intl.NumberFormat`.
9950 ///
9951 /// Determines whether to use grouping separators, such as thousands
9952 /// separators or thousand/lakh/crore separators.
9953 ///
9954 /// The default is `Min2` if notation is "compact", and `Auto` otherwise.
9955 ///
9956 /// Note: The string values `"true"` and `"false"` are accepted by JavaScript
9957 /// but are always converted to the default value. Use `True` and `False`
9958 /// variants for the boolean behavior.
9959 ///
9960 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#usegrouping)
9961 #[wasm_bindgen]
9962 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9963 pub enum UseGrouping {
9964 /// Display grouping separators even if the locale prefers otherwise.
9965 Always = "always",
9966 /// Display grouping separators based on the locale preference,
9967 /// which may also be dependent on the currency.
9968 Auto = "auto",
9969 /// Display grouping separators when there are at least 2 digits in a group.
9970 Min2 = "min2",
9971 /// Same as `Always`. Display grouping separators even if the locale prefers otherwise.
9972 True = "true",
9973 /// Display no grouping separators.
9974 False = "false",
9975 }
9976
9977 /// Date/time style for `Intl.DateTimeFormat`.
9978 #[wasm_bindgen]
9979 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9980 pub enum DateTimeStyle {
9981 Full = "full",
9982 Long = "long",
9983 Medium = "medium",
9984 Short = "short",
9985 }
9986
9987 /// Hour cycle for `Intl.DateTimeFormat`.
9988 #[wasm_bindgen]
9989 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9990 pub enum HourCycle {
9991 H11 = "h11",
9992 H12 = "h12",
9993 H23 = "h23",
9994 H24 = "h24",
9995 }
9996
9997 /// Weekday format for `Intl.DateTimeFormat`.
9998 #[wasm_bindgen]
9999 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10000 pub enum WeekdayFormat {
10001 Narrow = "narrow",
10002 Short = "short",
10003 Long = "long",
10004 }
10005
10006 /// Era format for `Intl.DateTimeFormat`.
10007 #[wasm_bindgen]
10008 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10009 pub enum EraFormat {
10010 Narrow = "narrow",
10011 Short = "short",
10012 Long = "long",
10013 }
10014
10015 /// Year format for `Intl.DateTimeFormat`.
10016 #[wasm_bindgen]
10017 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10018 pub enum YearFormat {
10019 Numeric = "numeric",
10020 TwoDigit = "2-digit",
10021 }
10022
10023 /// Month format for `Intl.DateTimeFormat`.
10024 #[wasm_bindgen]
10025 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10026 pub enum MonthFormat {
10027 #[wasm_bindgen]
10028 Numeric = "numeric",
10029 #[wasm_bindgen]
10030 TwoDigit = "2-digit",
10031 #[wasm_bindgen]
10032 Narrow = "narrow",
10033 #[wasm_bindgen]
10034 Short = "short",
10035 #[wasm_bindgen]
10036 Long = "long",
10037 }
10038
10039 /// Day format for `Intl.DateTimeFormat`.
10040 #[wasm_bindgen]
10041 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10042 pub enum DayFormat {
10043 #[wasm_bindgen]
10044 Numeric = "numeric",
10045 #[wasm_bindgen]
10046 TwoDigit = "2-digit",
10047 }
10048
10049 /// Hour/minute/second format for `Intl.DateTimeFormat`.
10050 #[wasm_bindgen]
10051 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10052 pub enum NumericFormat {
10053 #[wasm_bindgen]
10054 Numeric = "numeric",
10055 #[wasm_bindgen]
10056 TwoDigit = "2-digit",
10057 }
10058
10059 /// Time zone name format for `Intl.DateTimeFormat`.
10060 #[wasm_bindgen]
10061 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10062 pub enum TimeZoneNameFormat {
10063 Short = "short",
10064 Long = "long",
10065 ShortOffset = "shortOffset",
10066 LongOffset = "longOffset",
10067 ShortGeneric = "shortGeneric",
10068 LongGeneric = "longGeneric",
10069 }
10070
10071 /// Day period format for `Intl.DateTimeFormat`.
10072 #[wasm_bindgen]
10073 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10074 pub enum DayPeriodFormat {
10075 Narrow = "narrow",
10076 Short = "short",
10077 Long = "long",
10078 }
10079
10080 /// Part type for `DateTimeFormat.formatToParts()`.
10081 #[wasm_bindgen]
10082 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10083 pub enum DateTimeFormatPartType {
10084 Day = "day",
10085 DayPeriod = "dayPeriod",
10086 Era = "era",
10087 FractionalSecond = "fractionalSecond",
10088 Hour = "hour",
10089 Literal = "literal",
10090 Minute = "minute",
10091 Month = "month",
10092 RelatedYear = "relatedYear",
10093 Second = "second",
10094 TimeZoneName = "timeZoneName",
10095 Weekday = "weekday",
10096 Year = "year",
10097 YearName = "yearName",
10098 }
10099
10100 /// Part type for `NumberFormat.formatToParts()`.
10101 #[wasm_bindgen]
10102 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10103 pub enum NumberFormatPartType {
10104 Compact = "compact",
10105 Currency = "currency",
10106 Decimal = "decimal",
10107 ExponentInteger = "exponentInteger",
10108 ExponentMinusSign = "exponentMinusSign",
10109 ExponentSeparator = "exponentSeparator",
10110 Fraction = "fraction",
10111 Group = "group",
10112 Infinity = "infinity",
10113 Integer = "integer",
10114 Literal = "literal",
10115 MinusSign = "minusSign",
10116 Nan = "nan",
10117 PercentSign = "percentSign",
10118 PlusSign = "plusSign",
10119 Unit = "unit",
10120 Unknown = "unknown",
10121 }
10122
10123 /// Type for `Intl.PluralRules` (cardinal or ordinal).
10124 #[wasm_bindgen]
10125 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10126 pub enum PluralRulesType {
10127 Cardinal = "cardinal",
10128 Ordinal = "ordinal",
10129 }
10130
10131 /// Plural category returned by `PluralRules.select()`.
10132 #[wasm_bindgen]
10133 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10134 pub enum PluralCategory {
10135 Zero = "zero",
10136 One = "one",
10137 Two = "two",
10138 Few = "few",
10139 Many = "many",
10140 Other = "other",
10141 }
10142
10143 /// Numeric option for `Intl.RelativeTimeFormat`.
10144 #[wasm_bindgen]
10145 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10146 pub enum RelativeTimeFormatNumeric {
10147 Always = "always",
10148 Auto = "auto",
10149 }
10150
10151 /// Style for `Intl.RelativeTimeFormat`.
10152 #[wasm_bindgen]
10153 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10154 pub enum RelativeTimeFormatStyle {
10155 Long = "long",
10156 Short = "short",
10157 Narrow = "narrow",
10158 }
10159
10160 /// Unit for `RelativeTimeFormat.format()`.
10161 #[wasm_bindgen]
10162 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10163 pub enum RelativeTimeFormatUnit {
10164 Year = "year",
10165 Years = "years",
10166 Quarter = "quarter",
10167 Quarters = "quarters",
10168 Month = "month",
10169 Months = "months",
10170 Week = "week",
10171 Weeks = "weeks",
10172 Day = "day",
10173 Days = "days",
10174 Hour = "hour",
10175 Hours = "hours",
10176 Minute = "minute",
10177 Minutes = "minutes",
10178 Second = "second",
10179 Seconds = "seconds",
10180 }
10181
10182 /// Part type for `RelativeTimeFormat.formatToParts()`.
10183 #[wasm_bindgen]
10184 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10185 pub enum RelativeTimeFormatPartType {
10186 Literal = "literal",
10187 Integer = "integer",
10188 Decimal = "decimal",
10189 Fraction = "fraction",
10190 }
10191
10192 /// Source indicator for range format parts.
10193 ///
10194 /// Indicates which part of the range (start, end, or shared) a formatted
10195 /// part belongs to when using `formatRangeToParts()`.
10196 ///
10197 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatRangeToParts#description)
10198 #[wasm_bindgen]
10199 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10200 pub enum RangeSource {
10201 /// The part is from the start of the range.
10202 StartRange = "startRange",
10203 /// The part is from the end of the range.
10204 EndRange = "endRange",
10205 /// The part is shared between start and end (e.g., a separator or common element).
10206 Shared = "shared",
10207 }
10208
10209 /// Type for `Intl.ListFormat`.
10210 #[wasm_bindgen]
10211 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10212 pub enum ListFormatType {
10213 /// For lists of standalone items (default).
10214 Conjunction = "conjunction",
10215 /// For lists representing alternatives.
10216 Disjunction = "disjunction",
10217 /// For lists of values with units.
10218 Unit = "unit",
10219 }
10220
10221 /// Style for `Intl.ListFormat`.
10222 #[wasm_bindgen]
10223 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10224 pub enum ListFormatStyle {
10225 /// "A, B, and C" (default).
10226 Long = "long",
10227 /// "A, B, C".
10228 Short = "short",
10229 /// "A B C".
10230 Narrow = "narrow",
10231 }
10232
10233 /// Part type for `Intl.ListFormat.formatToParts()`.
10234 #[wasm_bindgen]
10235 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10236 pub enum ListFormatPartType {
10237 /// A value from the list.
10238 Element = "element",
10239 /// A linguistic construct (e.g., ", ", " and ").
10240 Literal = "literal",
10241 }
10242
10243 /// Type for `Intl.Segmenter`.
10244 #[wasm_bindgen]
10245 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10246 pub enum SegmenterGranularity {
10247 /// Segment by grapheme clusters (user-perceived characters).
10248 Grapheme = "grapheme",
10249 /// Segment by words.
10250 Word = "word",
10251 /// Segment by sentences.
10252 Sentence = "sentence",
10253 }
10254
10255 /// Type for `Intl.DisplayNames`.
10256 #[wasm_bindgen]
10257 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10258 pub enum DisplayNamesType {
10259 /// Language display names.
10260 Language = "language",
10261 /// Region display names.
10262 Region = "region",
10263 /// Script display names.
10264 Script = "script",
10265 /// Currency display names.
10266 Currency = "currency",
10267 /// Calendar display names.
10268 Calendar = "calendar",
10269 /// Date/time field display names.
10270 DateTimeField = "dateTimeField",
10271 }
10272
10273 /// Style for `Intl.DisplayNames`.
10274 #[wasm_bindgen]
10275 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10276 pub enum DisplayNamesStyle {
10277 /// Full display name (default).
10278 Long = "long",
10279 /// Abbreviated display name.
10280 Short = "short",
10281 /// Minimal display name.
10282 Narrow = "narrow",
10283 }
10284
10285 /// Fallback for `Intl.DisplayNames`.
10286 #[wasm_bindgen]
10287 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10288 pub enum DisplayNamesFallback {
10289 /// Return the input code if no display name is available (default).
10290 Code = "code",
10291 /// Return undefined if no display name is available.
10292 None = "none",
10293 }
10294
10295 /// Language display for `Intl.DisplayNames`.
10296 #[wasm_bindgen]
10297 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10298 pub enum DisplayNamesLanguageDisplay {
10299 /// Use dialect names (e.g., "British English").
10300 Dialect = "dialect",
10301 /// Use standard names (e.g., "English (United Kingdom)").
10302 Standard = "standard",
10303 }
10304
10305 // Intl.RelativeTimeFormatOptions
10306 #[wasm_bindgen]
10307 extern "C" {
10308 /// Options for `Intl.RelativeTimeFormat` constructor.
10309 ///
10310 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/RelativeTimeFormat#options)
10311 #[wasm_bindgen(extends = Object)]
10312 #[derive(Clone, Debug)]
10313 pub type RelativeTimeFormatOptions;
10314
10315 #[wasm_bindgen(method, getter = localeMatcher)]
10316 pub fn get_locale_matcher(this: &RelativeTimeFormatOptions) -> Option<LocaleMatcher>;
10317 #[wasm_bindgen(method, setter = localeMatcher)]
10318 pub fn set_locale_matcher(this: &RelativeTimeFormatOptions, value: LocaleMatcher);
10319
10320 #[wasm_bindgen(method, getter = numeric)]
10321 pub fn get_numeric(this: &RelativeTimeFormatOptions) -> Option<RelativeTimeFormatNumeric>;
10322 #[wasm_bindgen(method, setter = numeric)]
10323 pub fn set_numeric(this: &RelativeTimeFormatOptions, value: RelativeTimeFormatNumeric);
10324
10325 #[wasm_bindgen(method, getter = style)]
10326 pub fn get_style(this: &RelativeTimeFormatOptions) -> Option<RelativeTimeFormatStyle>;
10327 #[wasm_bindgen(method, setter = style)]
10328 pub fn set_style(this: &RelativeTimeFormatOptions, value: RelativeTimeFormatStyle);
10329 }
10330
10331 impl RelativeTimeFormatOptions {
10332 pub fn new() -> RelativeTimeFormatOptions {
10333 JsCast::unchecked_into(Object::new())
10334 }
10335 }
10336
10337 impl Default for RelativeTimeFormatOptions {
10338 fn default() -> Self {
10339 RelativeTimeFormatOptions::new()
10340 }
10341 }
10342
10343 // Intl.ResolvedRelativeTimeFormatOptions
10344 #[wasm_bindgen]
10345 extern "C" {
10346 /// Resolved options returned by `Intl.RelativeTimeFormat.prototype.resolvedOptions()`.
10347 ///
10348 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/resolvedOptions)
10349 #[wasm_bindgen(extends = RelativeTimeFormatOptions)]
10350 #[derive(Clone, Debug)]
10351 pub type ResolvedRelativeTimeFormatOptions;
10352
10353 /// The resolved locale string.
10354 #[wasm_bindgen(method, getter = locale)]
10355 pub fn get_locale(this: &ResolvedRelativeTimeFormatOptions) -> JsString;
10356
10357 /// The numbering system used.
10358 #[wasm_bindgen(method, getter = numberingSystem)]
10359 pub fn get_numbering_system(this: &ResolvedRelativeTimeFormatOptions) -> JsString;
10360 }
10361
10362 // Intl.RelativeTimeFormatPart
10363 #[wasm_bindgen]
10364 extern "C" {
10365 /// A part of the formatted relative time returned by `formatToParts()`.
10366 ///
10367 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/formatToParts)
10368 #[wasm_bindgen(extends = Object)]
10369 #[derive(Clone, Debug)]
10370 pub type RelativeTimeFormatPart;
10371
10372 /// The type of this part.
10373 #[wasm_bindgen(method, getter = type)]
10374 pub fn type_(this: &RelativeTimeFormatPart) -> RelativeTimeFormatPartType;
10375
10376 /// The string value of this part.
10377 #[wasm_bindgen(method, getter = value)]
10378 pub fn value(this: &RelativeTimeFormatPart) -> JsString;
10379
10380 /// The unit used in this part (only for integer parts).
10381 #[wasm_bindgen(method, getter = unit)]
10382 pub fn unit(this: &RelativeTimeFormatPart) -> Option<JsString>;
10383 }
10384
10385 // Intl.LocaleMatcherOptions
10386 #[wasm_bindgen]
10387 extern "C" {
10388 /// Options for `supportedLocalesOf` methods.
10389 #[wasm_bindgen(extends = Object)]
10390 #[derive(Clone, Debug)]
10391 pub type LocaleMatcherOptions;
10392
10393 #[wasm_bindgen(method, getter = localeMatcher)]
10394 pub fn get_locale_matcher(this: &LocaleMatcherOptions) -> Option<LocaleMatcher>;
10395
10396 #[wasm_bindgen(method, setter = localeMatcher)]
10397 pub fn set_locale_matcher(this: &LocaleMatcherOptions, value: LocaleMatcher);
10398 }
10399
10400 impl LocaleMatcherOptions {
10401 pub fn new() -> LocaleMatcherOptions {
10402 JsCast::unchecked_into(Object::new())
10403 }
10404 }
10405
10406 impl Default for LocaleMatcherOptions {
10407 fn default() -> Self {
10408 LocaleMatcherOptions::new()
10409 }
10410 }
10411
10412 // Intl.Collator Options
10413 #[wasm_bindgen]
10414 extern "C" {
10415 /// Options for `Intl.Collator` and `String.prototype.localeCompare`.
10416 ///
10417 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Collator/Collator#options)
10418 #[wasm_bindgen(extends = Object)]
10419 #[derive(Clone, Debug)]
10420 pub type CollatorOptions;
10421
10422 #[wasm_bindgen(method, getter = localeMatcher)]
10423 pub fn get_locale_matcher(this: &CollatorOptions) -> Option<LocaleMatcher>;
10424 #[wasm_bindgen(method, setter = localeMatcher)]
10425 pub fn set_locale_matcher(this: &CollatorOptions, value: LocaleMatcher);
10426
10427 #[wasm_bindgen(method, getter = usage)]
10428 pub fn get_usage(this: &CollatorOptions) -> Option<CollatorUsage>;
10429 #[wasm_bindgen(method, setter = usage)]
10430 pub fn set_usage(this: &CollatorOptions, value: CollatorUsage);
10431
10432 #[wasm_bindgen(method, getter = sensitivity)]
10433 pub fn get_sensitivity(this: &CollatorOptions) -> Option<CollatorSensitivity>;
10434 #[wasm_bindgen(method, setter = sensitivity)]
10435 pub fn set_sensitivity(this: &CollatorOptions, value: CollatorSensitivity);
10436
10437 #[wasm_bindgen(method, getter = ignorePunctuation)]
10438 pub fn get_ignore_punctuation(this: &CollatorOptions) -> Option<bool>;
10439 #[wasm_bindgen(method, setter = ignorePunctuation)]
10440 pub fn set_ignore_punctuation(this: &CollatorOptions, value: bool);
10441
10442 #[wasm_bindgen(method, getter = numeric)]
10443 pub fn get_numeric(this: &CollatorOptions) -> Option<bool>;
10444 #[wasm_bindgen(method, setter = numeric)]
10445 pub fn set_numeric(this: &CollatorOptions, value: bool);
10446
10447 #[wasm_bindgen(method, getter = caseFirst)]
10448 pub fn get_case_first(this: &CollatorOptions) -> Option<CollatorCaseFirst>;
10449 #[wasm_bindgen(method, setter = caseFirst)]
10450 pub fn set_case_first(this: &CollatorOptions, value: CollatorCaseFirst);
10451 }
10452 impl CollatorOptions {
10453 pub fn new() -> CollatorOptions {
10454 JsCast::unchecked_into(Object::new())
10455 }
10456 }
10457 impl Default for CollatorOptions {
10458 fn default() -> Self {
10459 CollatorOptions::new()
10460 }
10461 }
10462
10463 // Intl.Collator ResolvedCollatorOptions
10464 #[wasm_bindgen]
10465 extern "C" {
10466 #[wasm_bindgen(extends = CollatorOptions)]
10467 pub type ResolvedCollatorOptions;
10468
10469 #[wasm_bindgen(method, getter = locale)]
10470 pub fn get_locale(this: &ResolvedCollatorOptions) -> JsString; // not Option, always present
10471 #[wasm_bindgen(method, getter = collation)]
10472 pub fn get_collation(this: &ResolvedCollatorOptions) -> JsString;
10473 }
10474
10475 // Intl.Collator
10476 #[wasm_bindgen]
10477 extern "C" {
10478 /// The `Intl.Collator` object is a constructor for collators, objects
10479 /// that enable language sensitive string comparison.
10480 ///
10481 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator)
10482 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.Collator")]
10483 #[derive(Clone, Debug)]
10484 pub type Collator;
10485
10486 /// The `Intl.Collator` object is a constructor for collators, objects
10487 /// that enable language sensitive string comparison.
10488 ///
10489 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator)
10490 #[cfg(not(js_sys_unstable_apis))]
10491 #[wasm_bindgen(constructor, js_namespace = Intl)]
10492 pub fn new(locales: &Array, options: &Object) -> Collator;
10493
10494 /// The `Intl.Collator` object is a constructor for collators, objects
10495 /// that enable language sensitive string comparison.
10496 ///
10497 /// Throws a `RangeError` if locales contain invalid values.
10498 ///
10499 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator)
10500 #[cfg(js_sys_unstable_apis)]
10501 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
10502 pub fn new(locales: &[JsString], options: &CollatorOptions) -> Result<Collator, JsValue>;
10503
10504 /// The Intl.Collator.prototype.compare property returns a function that
10505 /// compares two strings according to the sort order of this Collator
10506 /// object.
10507 ///
10508 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/compare)
10509 #[cfg(not(js_sys_unstable_apis))]
10510 #[wasm_bindgen(method, getter, js_class = "Intl.Collator")]
10511 pub fn compare(this: &Collator) -> Function;
10512
10513 /// Compares two strings according to the sort order of this Collator.
10514 ///
10515 /// Returns a negative value if `a` comes before `b`, positive if `a` comes
10516 /// after `b`, and zero if they are equal.
10517 ///
10518 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Collator/compare)
10519 #[cfg(js_sys_unstable_apis)]
10520 #[wasm_bindgen(method, js_class = "Intl.Collator")]
10521 pub fn compare(this: &Collator, a: &str, b: &str) -> i32;
10522
10523 /// The `Intl.Collator.prototype.resolvedOptions()` method returns a new
10524 /// object with properties reflecting the locale and collation options
10525 /// computed during initialization of this Collator object.
10526 ///
10527 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/resolvedOptions)
10528 #[cfg(not(js_sys_unstable_apis))]
10529 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
10530 pub fn resolved_options(this: &Collator) -> Object;
10531
10532 /// The `Intl.Collator.prototype.resolvedOptions()` method returns a new
10533 /// object with properties reflecting the locale and collation options
10534 /// computed during initialization of this Collator object.
10535 ///
10536 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/resolvedOptions)
10537 #[cfg(js_sys_unstable_apis)]
10538 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
10539 pub fn resolved_options(this: &Collator) -> ResolvedCollatorOptions;
10540
10541 /// The `Intl.Collator.supportedLocalesOf()` method returns an array
10542 /// containing those of the provided locales that are supported in
10543 /// collation without having to fall back to the runtime's default
10544 /// locale.
10545 ///
10546 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/supportedLocalesOf)
10547 #[cfg(not(js_sys_unstable_apis))]
10548 #[wasm_bindgen(static_method_of = Collator, js_namespace = Intl, js_name = supportedLocalesOf)]
10549 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
10550
10551 /// The `Intl.Collator.supportedLocalesOf()` method returns an array
10552 /// containing those of the provided locales that are supported in
10553 /// collation without having to fall back to the runtime's default
10554 /// locale.
10555 ///
10556 /// Throws a `RangeError` if locales contain invalid values.
10557 ///
10558 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/supportedLocalesOf)
10559 #[cfg(js_sys_unstable_apis)]
10560 #[wasm_bindgen(static_method_of = Collator, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
10561 pub fn supported_locales_of(
10562 locales: &[JsString],
10563 options: &LocaleMatcherOptions,
10564 ) -> Result<Array<JsString>, JsValue>;
10565 }
10566
10567 #[cfg(not(js_sys_unstable_apis))]
10568 impl Default for Collator {
10569 fn default() -> Self {
10570 Self::new(
10571 &JsValue::UNDEFINED.unchecked_into(),
10572 &JsValue::UNDEFINED.unchecked_into(),
10573 )
10574 }
10575 }
10576
10577 #[cfg(js_sys_unstable_apis)]
10578 impl Default for Collator {
10579 fn default() -> Self {
10580 Self::new(&[], &Default::default()).unwrap()
10581 }
10582 }
10583
10584 // Intl.DateTimeFormatOptions
10585 #[wasm_bindgen]
10586 extern "C" {
10587 /// Options for `Intl.DateTimeFormat` constructor.
10588 ///
10589 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat#options)
10590 #[wasm_bindgen(extends = Object)]
10591 #[derive(Clone, Debug)]
10592 pub type DateTimeFormatOptions;
10593
10594 // Locale matching
10595 #[wasm_bindgen(method, getter = localeMatcher)]
10596 pub fn get_locale_matcher(this: &DateTimeFormatOptions) -> Option<LocaleMatcher>;
10597 #[wasm_bindgen(method, setter = localeMatcher)]
10598 pub fn set_locale_matcher(this: &DateTimeFormatOptions, value: LocaleMatcher);
10599
10600 // Calendar/numbering (free-form strings, no enum)
10601 #[wasm_bindgen(method, getter = calendar)]
10602 pub fn get_calendar(this: &DateTimeFormatOptions) -> Option<JsString>;
10603 #[wasm_bindgen(method, setter = calendar)]
10604 pub fn set_calendar(this: &DateTimeFormatOptions, value: &str);
10605
10606 #[wasm_bindgen(method, getter = numberingSystem)]
10607 pub fn get_numbering_system(this: &DateTimeFormatOptions) -> Option<JsString>;
10608 #[wasm_bindgen(method, setter = numberingSystem)]
10609 pub fn set_numbering_system(this: &DateTimeFormatOptions, value: &str);
10610
10611 // Timezone (free-form string)
10612 #[wasm_bindgen(method, getter = timeZone)]
10613 pub fn get_time_zone(this: &DateTimeFormatOptions) -> Option<JsString>;
10614 #[wasm_bindgen(method, setter = timeZone)]
10615 pub fn set_time_zone(this: &DateTimeFormatOptions, value: &str);
10616
10617 // Hour cycle
10618 #[wasm_bindgen(method, getter = hour12)]
10619 pub fn get_hour12(this: &DateTimeFormatOptions) -> Option<bool>;
10620 #[wasm_bindgen(method, setter = hour12)]
10621 pub fn set_hour12(this: &DateTimeFormatOptions, value: bool);
10622
10623 #[wasm_bindgen(method, getter = hourCycle)]
10624 pub fn get_hour_cycle(this: &DateTimeFormatOptions) -> Option<HourCycle>;
10625 #[wasm_bindgen(method, setter = hourCycle)]
10626 pub fn set_hour_cycle(this: &DateTimeFormatOptions, value: HourCycle);
10627
10628 // Style shortcuts
10629 #[wasm_bindgen(method, getter = dateStyle)]
10630 pub fn get_date_style(this: &DateTimeFormatOptions) -> Option<DateTimeStyle>;
10631 #[wasm_bindgen(method, setter = dateStyle)]
10632 pub fn set_date_style(this: &DateTimeFormatOptions, value: DateTimeStyle);
10633
10634 #[wasm_bindgen(method, getter = timeStyle)]
10635 pub fn get_time_style(this: &DateTimeFormatOptions) -> Option<DateTimeStyle>;
10636 #[wasm_bindgen(method, setter = timeStyle)]
10637 pub fn set_time_style(this: &DateTimeFormatOptions, value: DateTimeStyle);
10638
10639 // Component options
10640 #[wasm_bindgen(method, getter = weekday)]
10641 pub fn get_weekday(this: &DateTimeFormatOptions) -> Option<WeekdayFormat>;
10642 #[wasm_bindgen(method, setter = weekday)]
10643 pub fn set_weekday(this: &DateTimeFormatOptions, value: WeekdayFormat);
10644
10645 #[wasm_bindgen(method, getter = era)]
10646 pub fn get_era(this: &DateTimeFormatOptions) -> Option<EraFormat>;
10647 #[wasm_bindgen(method, setter = era)]
10648 pub fn set_era(this: &DateTimeFormatOptions, value: EraFormat);
10649
10650 #[wasm_bindgen(method, getter = year)]
10651 pub fn get_year(this: &DateTimeFormatOptions) -> Option<YearFormat>;
10652 #[wasm_bindgen(method, setter = year)]
10653 pub fn set_year(this: &DateTimeFormatOptions, value: YearFormat);
10654
10655 #[wasm_bindgen(method, getter = month)]
10656 pub fn get_month(this: &DateTimeFormatOptions) -> Option<MonthFormat>;
10657 #[wasm_bindgen(method, setter = month)]
10658 pub fn set_month(this: &DateTimeFormatOptions, value: MonthFormat);
10659
10660 #[wasm_bindgen(method, getter = day)]
10661 pub fn get_day(this: &DateTimeFormatOptions) -> Option<DayFormat>;
10662 #[wasm_bindgen(method, setter = day)]
10663 pub fn set_day(this: &DateTimeFormatOptions, value: DayFormat);
10664
10665 #[wasm_bindgen(method, getter = hour)]
10666 pub fn get_hour(this: &DateTimeFormatOptions) -> Option<NumericFormat>;
10667 #[wasm_bindgen(method, setter = hour)]
10668 pub fn set_hour(this: &DateTimeFormatOptions, value: NumericFormat);
10669
10670 #[wasm_bindgen(method, getter = minute)]
10671 pub fn get_minute(this: &DateTimeFormatOptions) -> Option<NumericFormat>;
10672 #[wasm_bindgen(method, setter = minute)]
10673 pub fn set_minute(this: &DateTimeFormatOptions, value: NumericFormat);
10674
10675 #[wasm_bindgen(method, getter = second)]
10676 pub fn get_second(this: &DateTimeFormatOptions) -> Option<NumericFormat>;
10677 #[wasm_bindgen(method, setter = second)]
10678 pub fn set_second(this: &DateTimeFormatOptions, value: NumericFormat);
10679
10680 #[wasm_bindgen(method, getter = fractionalSecondDigits)]
10681 pub fn get_fractional_second_digits(this: &DateTimeFormatOptions) -> Option<u8>;
10682 #[wasm_bindgen(method, setter = fractionalSecondDigits)]
10683 pub fn set_fractional_second_digits(this: &DateTimeFormatOptions, value: u8);
10684
10685 #[wasm_bindgen(method, getter = timeZoneName)]
10686 pub fn get_time_zone_name(this: &DateTimeFormatOptions) -> Option<TimeZoneNameFormat>;
10687 #[wasm_bindgen(method, setter = timeZoneName)]
10688 pub fn set_time_zone_name(this: &DateTimeFormatOptions, value: TimeZoneNameFormat);
10689
10690 #[wasm_bindgen(method, getter = dayPeriod)]
10691 pub fn get_day_period(this: &DateTimeFormatOptions) -> Option<DayPeriodFormat>;
10692 #[wasm_bindgen(method, setter = dayPeriod)]
10693 pub fn set_day_period(this: &DateTimeFormatOptions, value: DayPeriodFormat);
10694 }
10695
10696 impl DateTimeFormatOptions {
10697 pub fn new() -> DateTimeFormatOptions {
10698 JsCast::unchecked_into(Object::new())
10699 }
10700 }
10701
10702 impl Default for DateTimeFormatOptions {
10703 fn default() -> Self {
10704 DateTimeFormatOptions::new()
10705 }
10706 }
10707
10708 // Intl.ResolvedDateTimeFormatOptions
10709 #[wasm_bindgen]
10710 extern "C" {
10711 /// Resolved options returned by `Intl.DateTimeFormat.prototype.resolvedOptions()`.
10712 ///
10713 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/resolvedOptions)
10714 #[wasm_bindgen(extends = DateTimeFormatOptions)]
10715 #[derive(Clone, Debug)]
10716 pub type ResolvedDateTimeFormatOptions;
10717
10718 /// The resolved locale string.
10719 #[wasm_bindgen(method, getter = locale)]
10720 pub fn get_locale(this: &ResolvedDateTimeFormatOptions) -> JsString;
10721 }
10722
10723 // Intl.DateTimeFormatPart
10724 #[wasm_bindgen]
10725 extern "C" {
10726 /// A part of the formatted date returned by `formatToParts()`.
10727 ///
10728 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatToParts)
10729 #[wasm_bindgen(extends = Object)]
10730 #[derive(Clone, Debug)]
10731 pub type DateTimeFormatPart;
10732
10733 /// The type of the part (e.g., "day", "month", "year", "literal", etc.)
10734 #[wasm_bindgen(method, getter = type)]
10735 pub fn type_(this: &DateTimeFormatPart) -> DateTimeFormatPartType;
10736
10737 /// The value of the part.
10738 #[wasm_bindgen(method, getter)]
10739 pub fn value(this: &DateTimeFormatPart) -> JsString;
10740 }
10741
10742 // Intl.DateTimeRangeFormatPart
10743 #[wasm_bindgen]
10744 extern "C" {
10745 /// A part of the formatted date range returned by `formatRangeToParts()`.
10746 ///
10747 /// Extends `DateTimeFormatPart` with a `source` property indicating whether
10748 /// the part is from the start date, end date, or shared between them.
10749 ///
10750 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatRangeToParts)
10751 #[wasm_bindgen(extends = DateTimeFormatPart)]
10752 #[derive(Clone, Debug)]
10753 pub type DateTimeRangeFormatPart;
10754
10755 /// The source of the part: "startRange", "endRange", or "shared".
10756 #[wasm_bindgen(method, getter)]
10757 pub fn source(this: &DateTimeRangeFormatPart) -> RangeSource;
10758 }
10759
10760 // Intl.DateTimeFormat
10761 #[wasm_bindgen]
10762 extern "C" {
10763 /// The `Intl.DateTimeFormat` object is a constructor for objects
10764 /// that enable language-sensitive date and time formatting.
10765 ///
10766 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat)
10767 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.DateTimeFormat")]
10768 #[derive(Clone, Debug)]
10769 pub type DateTimeFormat;
10770
10771 /// The `Intl.DateTimeFormat` object is a constructor for objects
10772 /// that enable language-sensitive date and time formatting.
10773 ///
10774 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat)
10775 #[cfg(not(js_sys_unstable_apis))]
10776 #[wasm_bindgen(constructor, js_namespace = Intl)]
10777 pub fn new(locales: &Array, options: &Object) -> DateTimeFormat;
10778
10779 /// The `Intl.DateTimeFormat` object is a constructor for objects
10780 /// that enable language-sensitive date and time formatting.
10781 ///
10782 /// Throws a `RangeError` if locales contain invalid values.
10783 ///
10784 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat)
10785 #[cfg(js_sys_unstable_apis)]
10786 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
10787 pub fn new(
10788 locales: &[JsString],
10789 options: &DateTimeFormatOptions,
10790 ) -> Result<DateTimeFormat, JsValue>;
10791
10792 /// The Intl.DateTimeFormat.prototype.format property returns a getter function that
10793 /// formats a date according to the locale and formatting options of this
10794 /// Intl.DateTimeFormat object.
10795 ///
10796 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/format)
10797 #[cfg(not(js_sys_unstable_apis))]
10798 #[wasm_bindgen(method, getter, js_class = "Intl.DateTimeFormat")]
10799 pub fn format(this: &DateTimeFormat) -> Function;
10800
10801 /// Formats a date according to the locale and formatting options of this
10802 /// `Intl.DateTimeFormat` object.
10803 ///
10804 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/format)
10805 #[cfg(js_sys_unstable_apis)]
10806 #[wasm_bindgen(method, js_class = "Intl.DateTimeFormat")]
10807 pub fn format(this: &DateTimeFormat, date: &Date) -> JsString;
10808
10809 /// The `Intl.DateTimeFormat.prototype.formatToParts()` method allows locale-aware
10810 /// formatting of strings produced by DateTimeFormat formatters.
10811 ///
10812 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/formatToParts)
10813 #[cfg(not(js_sys_unstable_apis))]
10814 #[wasm_bindgen(method, js_class = "Intl.DateTimeFormat", js_name = formatToParts)]
10815 pub fn format_to_parts(this: &DateTimeFormat, date: &Date) -> Array;
10816
10817 /// The `Intl.DateTimeFormat.prototype.formatToParts()` method allows locale-aware
10818 /// formatting of strings produced by DateTimeFormat formatters.
10819 ///
10820 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/formatToParts)
10821 #[cfg(js_sys_unstable_apis)]
10822 #[wasm_bindgen(method, js_class = "Intl.DateTimeFormat", js_name = formatToParts)]
10823 pub fn format_to_parts(this: &DateTimeFormat, date: &Date) -> Array<DateTimeFormatPart>;
10824
10825 /// The `Intl.DateTimeFormat.prototype.formatRange()` method formats a date range
10826 /// in the most concise way based on the locales and options provided when
10827 /// instantiating this `Intl.DateTimeFormat` object.
10828 ///
10829 /// Throws a `TypeError` if the dates are invalid.
10830 ///
10831 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatRange)
10832 #[wasm_bindgen(method, js_class = "Intl.DateTimeFormat", js_name = formatRange, catch)]
10833 pub fn format_range(
10834 this: &DateTimeFormat,
10835 start_date: &Date,
10836 end_date: &Date,
10837 ) -> Result<JsString, JsValue>;
10838
10839 /// The `Intl.DateTimeFormat.prototype.formatRangeToParts()` method returns an array
10840 /// of locale-specific tokens representing each part of the formatted date range
10841 /// produced by `Intl.DateTimeFormat` formatters.
10842 ///
10843 /// Throws a `TypeError` if the dates are invalid.
10844 ///
10845 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatRangeToParts)
10846 #[wasm_bindgen(method, js_class = "Intl.DateTimeFormat", js_name = formatRangeToParts, catch)]
10847 pub fn format_range_to_parts(
10848 this: &DateTimeFormat,
10849 start_date: &Date,
10850 end_date: &Date,
10851 ) -> Result<Array<DateTimeRangeFormatPart>, JsValue>;
10852
10853 /// The `Intl.DateTimeFormat.prototype.resolvedOptions()` method returns a new
10854 /// object with properties reflecting the locale and date and time formatting
10855 /// options computed during initialization of this DateTimeFormat object.
10856 ///
10857 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/resolvedOptions)
10858 #[cfg(not(js_sys_unstable_apis))]
10859 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
10860 pub fn resolved_options(this: &DateTimeFormat) -> Object;
10861
10862 /// The `Intl.DateTimeFormat.prototype.resolvedOptions()` method returns a new
10863 /// object with properties reflecting the locale and date and time formatting
10864 /// options computed during initialization of this DateTimeFormat object.
10865 ///
10866 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/resolvedOptions)
10867 #[cfg(js_sys_unstable_apis)]
10868 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
10869 pub fn resolved_options(this: &DateTimeFormat) -> ResolvedDateTimeFormatOptions;
10870
10871 /// The `Intl.DateTimeFormat.supportedLocalesOf()` method returns an array
10872 /// containing those of the provided locales that are supported in date
10873 /// and time formatting without having to fall back to the runtime's default
10874 /// locale.
10875 ///
10876 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/supportedLocalesOf)
10877 #[cfg(not(js_sys_unstable_apis))]
10878 #[wasm_bindgen(static_method_of = DateTimeFormat, js_namespace = Intl, js_name = supportedLocalesOf)]
10879 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
10880
10881 /// The `Intl.DateTimeFormat.supportedLocalesOf()` method returns an array
10882 /// containing those of the provided locales that are supported in date
10883 /// and time formatting without having to fall back to the runtime's default
10884 /// locale.
10885 ///
10886 /// Throws a `RangeError` if locales contain invalid values.
10887 ///
10888 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/supportedLocalesOf)
10889 #[cfg(js_sys_unstable_apis)]
10890 #[wasm_bindgen(static_method_of = DateTimeFormat, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
10891 pub fn supported_locales_of(
10892 locales: &[JsString],
10893 options: &LocaleMatcherOptions,
10894 ) -> Result<Array<JsString>, JsValue>;
10895 }
10896
10897 #[cfg(not(js_sys_unstable_apis))]
10898 impl Default for DateTimeFormat {
10899 fn default() -> Self {
10900 Self::new(
10901 &JsValue::UNDEFINED.unchecked_into(),
10902 &JsValue::UNDEFINED.unchecked_into(),
10903 )
10904 }
10905 }
10906
10907 #[cfg(js_sys_unstable_apis)]
10908 impl Default for DateTimeFormat {
10909 fn default() -> Self {
10910 Self::new(&[], &Default::default()).unwrap()
10911 }
10912 }
10913
10914 // Intl.NumberFormatOptions
10915 #[wasm_bindgen]
10916 extern "C" {
10917 /// Options for `Intl.NumberFormat` constructor.
10918 ///
10919 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#options)
10920 #[wasm_bindgen(extends = Object)]
10921 #[derive(Clone, Debug)]
10922 pub type NumberFormatOptions;
10923
10924 // Locale matching
10925 #[wasm_bindgen(method, getter = localeMatcher)]
10926 pub fn get_locale_matcher(this: &NumberFormatOptions) -> Option<LocaleMatcher>;
10927 #[wasm_bindgen(method, setter = localeMatcher)]
10928 pub fn set_locale_matcher(this: &NumberFormatOptions, value: LocaleMatcher);
10929
10930 // Numbering system (free-form string)
10931 #[wasm_bindgen(method, getter = numberingSystem)]
10932 pub fn get_numbering_system(this: &NumberFormatOptions) -> Option<JsString>;
10933 #[wasm_bindgen(method, setter = numberingSystem)]
10934 pub fn set_numbering_system(this: &NumberFormatOptions, value: &str);
10935
10936 // Style
10937 #[wasm_bindgen(method, getter = style)]
10938 pub fn get_style(this: &NumberFormatOptions) -> Option<NumberFormatStyle>;
10939 #[wasm_bindgen(method, setter = style)]
10940 pub fn set_style(this: &NumberFormatOptions, value: NumberFormatStyle);
10941
10942 // Currency options (currency code is free-form ISO 4217 string)
10943 #[wasm_bindgen(method, getter = currency)]
10944 pub fn get_currency(this: &NumberFormatOptions) -> Option<JsString>;
10945 #[wasm_bindgen(method, setter = currency)]
10946 pub fn set_currency(this: &NumberFormatOptions, value: &str);
10947
10948 #[wasm_bindgen(method, getter = currencyDisplay)]
10949 pub fn get_currency_display(this: &NumberFormatOptions) -> Option<CurrencyDisplay>;
10950 #[wasm_bindgen(method, setter = currencyDisplay)]
10951 pub fn set_currency_display(this: &NumberFormatOptions, value: CurrencyDisplay);
10952
10953 #[wasm_bindgen(method, getter = currencySign)]
10954 pub fn get_currency_sign(this: &NumberFormatOptions) -> Option<CurrencySign>;
10955 #[wasm_bindgen(method, setter = currencySign)]
10956 pub fn set_currency_sign(this: &NumberFormatOptions, value: CurrencySign);
10957
10958 // Unit options (unit name is free-form string)
10959 #[wasm_bindgen(method, getter = unit)]
10960 pub fn get_unit(this: &NumberFormatOptions) -> Option<JsString>;
10961 #[wasm_bindgen(method, setter = unit)]
10962 pub fn set_unit(this: &NumberFormatOptions, value: &str);
10963
10964 #[wasm_bindgen(method, getter = unitDisplay)]
10965 pub fn get_unit_display(this: &NumberFormatOptions) -> Option<UnitDisplay>;
10966 #[wasm_bindgen(method, setter = unitDisplay)]
10967 pub fn set_unit_display(this: &NumberFormatOptions, value: UnitDisplay);
10968
10969 // Notation
10970 #[wasm_bindgen(method, getter = notation)]
10971 pub fn get_notation(this: &NumberFormatOptions) -> Option<NumberFormatNotation>;
10972 #[wasm_bindgen(method, setter = notation)]
10973 pub fn set_notation(this: &NumberFormatOptions, value: NumberFormatNotation);
10974
10975 #[wasm_bindgen(method, getter = compactDisplay)]
10976 pub fn get_compact_display(this: &NumberFormatOptions) -> Option<CompactDisplay>;
10977 #[wasm_bindgen(method, setter = compactDisplay)]
10978 pub fn set_compact_display(this: &NumberFormatOptions, value: CompactDisplay);
10979
10980 // Sign display
10981 #[wasm_bindgen(method, getter = signDisplay)]
10982 pub fn get_sign_display(this: &NumberFormatOptions) -> Option<SignDisplay>;
10983 #[wasm_bindgen(method, setter = signDisplay)]
10984 pub fn set_sign_display(this: &NumberFormatOptions, value: SignDisplay);
10985
10986 // Digit options
10987 #[wasm_bindgen(method, getter = minimumIntegerDigits)]
10988 pub fn get_minimum_integer_digits(this: &NumberFormatOptions) -> Option<u8>;
10989 #[wasm_bindgen(method, setter = minimumIntegerDigits)]
10990 pub fn set_minimum_integer_digits(this: &NumberFormatOptions, value: u8);
10991
10992 #[wasm_bindgen(method, getter = minimumFractionDigits)]
10993 pub fn get_minimum_fraction_digits(this: &NumberFormatOptions) -> Option<u8>;
10994 #[wasm_bindgen(method, setter = minimumFractionDigits)]
10995 pub fn set_minimum_fraction_digits(this: &NumberFormatOptions, value: u8);
10996
10997 #[wasm_bindgen(method, getter = maximumFractionDigits)]
10998 pub fn get_maximum_fraction_digits(this: &NumberFormatOptions) -> Option<u8>;
10999 #[wasm_bindgen(method, setter = maximumFractionDigits)]
11000 pub fn set_maximum_fraction_digits(this: &NumberFormatOptions, value: u8);
11001
11002 #[wasm_bindgen(method, getter = minimumSignificantDigits)]
11003 pub fn get_minimum_significant_digits(this: &NumberFormatOptions) -> Option<u8>;
11004 #[wasm_bindgen(method, setter = minimumSignificantDigits)]
11005 pub fn set_minimum_significant_digits(this: &NumberFormatOptions, value: u8);
11006
11007 #[wasm_bindgen(method, getter = maximumSignificantDigits)]
11008 pub fn get_maximum_significant_digits(this: &NumberFormatOptions) -> Option<u8>;
11009 #[wasm_bindgen(method, setter = maximumSignificantDigits)]
11010 pub fn set_maximum_significant_digits(this: &NumberFormatOptions, value: u8);
11011
11012 // Grouping
11013 #[wasm_bindgen(method, getter = useGrouping)]
11014 pub fn get_use_grouping(this: &NumberFormatOptions) -> Option<UseGrouping>;
11015 #[wasm_bindgen(method, setter = useGrouping)]
11016 pub fn set_use_grouping(this: &NumberFormatOptions, value: UseGrouping);
11017
11018 // Rounding
11019 #[wasm_bindgen(method, getter = roundingMode)]
11020 pub fn get_rounding_mode(this: &NumberFormatOptions) -> Option<RoundingMode>;
11021 #[wasm_bindgen(method, setter = roundingMode)]
11022 pub fn set_rounding_mode(this: &NumberFormatOptions, value: RoundingMode);
11023
11024 #[wasm_bindgen(method, getter = roundingPriority)]
11025 pub fn get_rounding_priority(this: &NumberFormatOptions) -> Option<RoundingPriority>;
11026 #[wasm_bindgen(method, setter = roundingPriority)]
11027 pub fn set_rounding_priority(this: &NumberFormatOptions, value: RoundingPriority);
11028
11029 #[wasm_bindgen(method, getter = roundingIncrement)]
11030 pub fn get_rounding_increment(this: &NumberFormatOptions) -> Option<u32>;
11031 #[wasm_bindgen(method, setter = roundingIncrement)]
11032 pub fn set_rounding_increment(this: &NumberFormatOptions, value: u32);
11033
11034 #[wasm_bindgen(method, getter = trailingZeroDisplay)]
11035 pub fn get_trailing_zero_display(this: &NumberFormatOptions)
11036 -> Option<TrailingZeroDisplay>;
11037 #[wasm_bindgen(method, setter = trailingZeroDisplay)]
11038 pub fn set_trailing_zero_display(this: &NumberFormatOptions, value: TrailingZeroDisplay);
11039 }
11040
11041 impl NumberFormatOptions {
11042 pub fn new() -> NumberFormatOptions {
11043 JsCast::unchecked_into(Object::new())
11044 }
11045 }
11046
11047 impl Default for NumberFormatOptions {
11048 fn default() -> Self {
11049 NumberFormatOptions::new()
11050 }
11051 }
11052
11053 // Intl.ResolvedNumberFormatOptions
11054 #[wasm_bindgen]
11055 extern "C" {
11056 /// Resolved options returned by `Intl.NumberFormat.prototype.resolvedOptions()`.
11057 ///
11058 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/resolvedOptions)
11059 #[wasm_bindgen(extends = NumberFormatOptions)]
11060 #[derive(Clone, Debug)]
11061 pub type ResolvedNumberFormatOptions;
11062
11063 /// The resolved locale string.
11064 #[wasm_bindgen(method, getter = locale)]
11065 pub fn get_locale(this: &ResolvedNumberFormatOptions) -> JsString;
11066 }
11067
11068 // Intl.NumberFormatPart
11069 #[wasm_bindgen]
11070 extern "C" {
11071 /// A part of the formatted number returned by `formatToParts()`.
11072 ///
11073 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatToParts)
11074 #[wasm_bindgen(extends = Object)]
11075 #[derive(Clone, Debug)]
11076 pub type NumberFormatPart;
11077
11078 /// The type of the part (e.g., "integer", "decimal", "fraction", "currency", etc.)
11079 #[wasm_bindgen(method, getter = type)]
11080 pub fn type_(this: &NumberFormatPart) -> NumberFormatPartType;
11081
11082 /// The value of the part.
11083 #[wasm_bindgen(method, getter)]
11084 pub fn value(this: &NumberFormatPart) -> JsString;
11085 }
11086
11087 // Intl.NumberRangeFormatPart
11088 #[wasm_bindgen]
11089 extern "C" {
11090 /// A part of the formatted number range returned by `formatRangeToParts()`.
11091 ///
11092 /// Extends `NumberFormatPart` with a `source` property indicating whether
11093 /// the part is from the start number, end number, or shared between them.
11094 ///
11095 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatRangeToParts)
11096 #[wasm_bindgen(extends = NumberFormatPart)]
11097 #[derive(Clone, Debug)]
11098 pub type NumberRangeFormatPart;
11099
11100 /// The source of the part: "startRange", "endRange", or "shared".
11101 #[wasm_bindgen(method, getter)]
11102 pub fn source(this: &NumberRangeFormatPart) -> RangeSource;
11103 }
11104
11105 // Intl.NumberFormat
11106 #[wasm_bindgen]
11107 extern "C" {
11108 /// The `Intl.NumberFormat` object is a constructor for objects
11109 /// that enable language sensitive number formatting.
11110 ///
11111 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat)
11112 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.NumberFormat")]
11113 #[derive(Clone, Debug)]
11114 pub type NumberFormat;
11115
11116 /// The `Intl.NumberFormat` object is a constructor for objects
11117 /// that enable language sensitive number formatting.
11118 ///
11119 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat)
11120 #[cfg(not(js_sys_unstable_apis))]
11121 #[wasm_bindgen(constructor, js_namespace = Intl)]
11122 pub fn new(locales: &Array, options: &Object) -> NumberFormat;
11123
11124 /// The `Intl.NumberFormat` object is a constructor for objects
11125 /// that enable language sensitive number formatting.
11126 ///
11127 /// Throws a `RangeError` if locales contain invalid values.
11128 ///
11129 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat)
11130 #[cfg(js_sys_unstable_apis)]
11131 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
11132 pub fn new(
11133 locales: &[JsString],
11134 options: &NumberFormatOptions,
11135 ) -> Result<NumberFormat, JsValue>;
11136
11137 /// The Intl.NumberFormat.prototype.format property returns a getter function that
11138 /// formats a number according to the locale and formatting options of this
11139 /// NumberFormat object.
11140 ///
11141 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/format)
11142 #[cfg(not(js_sys_unstable_apis))]
11143 #[wasm_bindgen(method, getter, js_class = "Intl.NumberFormat")]
11144 pub fn format(this: &NumberFormat) -> Function;
11145
11146 /// Formats a number according to the locale and formatting options of this
11147 /// `Intl.NumberFormat` object.
11148 ///
11149 /// Accepts numeric strings for BigInt/arbitrary precision (e.g., `"123n"` → `"123"`,
11150 /// or use E notation: `"1000000E-6"` → `"1"`).
11151 ///
11152 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/format)
11153 #[cfg(js_sys_unstable_apis)]
11154 #[wasm_bindgen(method, js_class = "Intl.NumberFormat")]
11155 pub fn format(this: &NumberFormat, value: &JsString) -> JsString;
11156
11157 /// The `Intl.Numberformat.prototype.formatToParts()` method allows locale-aware
11158 /// formatting of strings produced by NumberTimeFormat formatters.
11159 ///
11160 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/formatToParts)
11161 #[cfg(not(js_sys_unstable_apis))]
11162 #[wasm_bindgen(method, js_class = "Intl.NumberFormat", js_name = formatToParts)]
11163 pub fn format_to_parts(this: &NumberFormat, number: f64) -> Array;
11164
11165 /// The `Intl.NumberFormat.prototype.formatToParts()` method allows locale-aware
11166 /// formatting of strings produced by `Intl.NumberFormat` formatters.
11167 ///
11168 /// Accepts numeric strings for BigInt/arbitrary precision (e.g., `"123n"` → `"123"`,
11169 /// or use E notation: `"1000000E-6"` → `"1"`).
11170 ///
11171 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatToParts)
11172 #[cfg(js_sys_unstable_apis)]
11173 #[wasm_bindgen(method, js_class = "Intl.NumberFormat", js_name = formatToParts)]
11174 pub fn format_to_parts(this: &NumberFormat, value: &JsString) -> Array<NumberFormatPart>;
11175
11176 /// Formats a range of numbers according to the locale and formatting options
11177 /// of this `Intl.NumberFormat` object.
11178 ///
11179 /// Accepts numeric strings for BigInt/arbitrary precision (e.g., `"123n"` → `"123"`,
11180 /// or use E notation: `"1000000E-6"` → `"1"`).
11181 ///
11182 /// Throws a `TypeError` if the values are invalid.
11183 ///
11184 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatRange)
11185 #[wasm_bindgen(method, js_class = "Intl.NumberFormat", js_name = formatRange, catch)]
11186 pub fn format_range(
11187 this: &NumberFormat,
11188 start: &JsString,
11189 end: &JsString,
11190 ) -> Result<JsString, JsValue>;
11191
11192 /// Returns an array of locale-specific tokens representing each part of
11193 /// the formatted number range.
11194 ///
11195 /// Accepts numeric strings for BigInt/arbitrary precision (e.g., `"123n"` → `"123"`,
11196 /// or use E notation: `"1000000E-6"` → `"1"`).
11197 ///
11198 /// Throws a `TypeError` if the values are invalid.
11199 ///
11200 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatRangeToParts)
11201 #[wasm_bindgen(method, js_class = "Intl.NumberFormat", js_name = formatRangeToParts, catch)]
11202 pub fn format_range_to_parts(
11203 this: &NumberFormat,
11204 start: &JsString,
11205 end: &JsString,
11206 ) -> Result<Array<NumberRangeFormatPart>, JsValue>;
11207
11208 /// The `Intl.NumberFormat.prototype.resolvedOptions()` method returns a new
11209 /// object with properties reflecting the locale and number formatting
11210 /// options computed during initialization of this NumberFormat object.
11211 ///
11212 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/resolvedOptions)
11213 #[cfg(not(js_sys_unstable_apis))]
11214 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11215 pub fn resolved_options(this: &NumberFormat) -> Object;
11216
11217 /// The `Intl.NumberFormat.prototype.resolvedOptions()` method returns a new
11218 /// object with properties reflecting the locale and number formatting
11219 /// options computed during initialization of this NumberFormat object.
11220 ///
11221 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/resolvedOptions)
11222 #[cfg(js_sys_unstable_apis)]
11223 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11224 pub fn resolved_options(this: &NumberFormat) -> ResolvedNumberFormatOptions;
11225
11226 /// The `Intl.NumberFormat.supportedLocalesOf()` method returns an array
11227 /// containing those of the provided locales that are supported in number
11228 /// formatting without having to fall back to the runtime's default locale.
11229 ///
11230 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/supportedLocalesOf)
11231 #[cfg(not(js_sys_unstable_apis))]
11232 #[wasm_bindgen(static_method_of = NumberFormat, js_namespace = Intl, js_name = supportedLocalesOf)]
11233 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
11234
11235 /// The `Intl.NumberFormat.supportedLocalesOf()` method returns an array
11236 /// containing those of the provided locales that are supported in number
11237 /// formatting without having to fall back to the runtime's default locale.
11238 ///
11239 /// Throws a `RangeError` if locales contain invalid values.
11240 ///
11241 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/supportedLocalesOf)
11242 #[cfg(js_sys_unstable_apis)]
11243 #[wasm_bindgen(static_method_of = NumberFormat, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
11244 pub fn supported_locales_of(
11245 locales: &[JsString],
11246 options: &LocaleMatcherOptions,
11247 ) -> Result<Array<JsString>, JsValue>;
11248 }
11249
11250 #[cfg(not(js_sys_unstable_apis))]
11251 impl Default for NumberFormat {
11252 fn default() -> Self {
11253 Self::new(
11254 &JsValue::UNDEFINED.unchecked_into(),
11255 &JsValue::UNDEFINED.unchecked_into(),
11256 )
11257 }
11258 }
11259
11260 #[cfg(js_sys_unstable_apis)]
11261 impl Default for NumberFormat {
11262 fn default() -> Self {
11263 Self::new(&[], &Default::default()).unwrap()
11264 }
11265 }
11266
11267 // Intl.PluralRulesOptions
11268 #[wasm_bindgen]
11269 extern "C" {
11270 /// Options for `Intl.PluralRules` constructor.
11271 ///
11272 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules/PluralRules#options)
11273 #[wasm_bindgen(extends = Object)]
11274 #[derive(Clone, Debug)]
11275 pub type PluralRulesOptions;
11276
11277 #[wasm_bindgen(method, getter = localeMatcher)]
11278 pub fn get_locale_matcher(this: &PluralRulesOptions) -> Option<LocaleMatcher>;
11279 #[wasm_bindgen(method, setter = localeMatcher)]
11280 pub fn set_locale_matcher(this: &PluralRulesOptions, value: LocaleMatcher);
11281
11282 #[wasm_bindgen(method, getter = type)]
11283 pub fn get_type(this: &PluralRulesOptions) -> Option<PluralRulesType>;
11284 #[wasm_bindgen(method, setter = type)]
11285 pub fn set_type(this: &PluralRulesOptions, value: PluralRulesType);
11286
11287 #[wasm_bindgen(method, getter = minimumIntegerDigits)]
11288 pub fn get_minimum_integer_digits(this: &PluralRulesOptions) -> Option<u8>;
11289 #[wasm_bindgen(method, setter = minimumIntegerDigits)]
11290 pub fn set_minimum_integer_digits(this: &PluralRulesOptions, value: u8);
11291
11292 #[wasm_bindgen(method, getter = minimumFractionDigits)]
11293 pub fn get_minimum_fraction_digits(this: &PluralRulesOptions) -> Option<u8>;
11294 #[wasm_bindgen(method, setter = minimumFractionDigits)]
11295 pub fn set_minimum_fraction_digits(this: &PluralRulesOptions, value: u8);
11296
11297 #[wasm_bindgen(method, getter = maximumFractionDigits)]
11298 pub fn get_maximum_fraction_digits(this: &PluralRulesOptions) -> Option<u8>;
11299 #[wasm_bindgen(method, setter = maximumFractionDigits)]
11300 pub fn set_maximum_fraction_digits(this: &PluralRulesOptions, value: u8);
11301
11302 #[wasm_bindgen(method, getter = minimumSignificantDigits)]
11303 pub fn get_minimum_significant_digits(this: &PluralRulesOptions) -> Option<u8>;
11304 #[wasm_bindgen(method, setter = minimumSignificantDigits)]
11305 pub fn set_minimum_significant_digits(this: &PluralRulesOptions, value: u8);
11306
11307 #[wasm_bindgen(method, getter = maximumSignificantDigits)]
11308 pub fn get_maximum_significant_digits(this: &PluralRulesOptions) -> Option<u8>;
11309 #[wasm_bindgen(method, setter = maximumSignificantDigits)]
11310 pub fn set_maximum_significant_digits(this: &PluralRulesOptions, value: u8);
11311
11312 #[wasm_bindgen(method, getter = roundingPriority)]
11313 pub fn get_rounding_priority(this: &PluralRulesOptions) -> Option<RoundingPriority>;
11314 #[wasm_bindgen(method, setter = roundingPriority)]
11315 pub fn set_rounding_priority(this: &PluralRulesOptions, value: RoundingPriority);
11316
11317 #[wasm_bindgen(method, getter = roundingIncrement)]
11318 pub fn get_rounding_increment(this: &PluralRulesOptions) -> Option<u32>;
11319 #[wasm_bindgen(method, setter = roundingIncrement)]
11320 pub fn set_rounding_increment(this: &PluralRulesOptions, value: u32);
11321
11322 #[wasm_bindgen(method, getter = roundingMode)]
11323 pub fn get_rounding_mode(this: &PluralRulesOptions) -> Option<RoundingMode>;
11324 #[wasm_bindgen(method, setter = roundingMode)]
11325 pub fn set_rounding_mode(this: &PluralRulesOptions, value: RoundingMode);
11326
11327 #[wasm_bindgen(method, getter = trailingZeroDisplay)]
11328 pub fn get_trailing_zero_display(this: &PluralRulesOptions) -> Option<TrailingZeroDisplay>;
11329 #[wasm_bindgen(method, setter = trailingZeroDisplay)]
11330 pub fn set_trailing_zero_display(this: &PluralRulesOptions, value: TrailingZeroDisplay);
11331 }
11332
11333 impl PluralRulesOptions {
11334 pub fn new() -> PluralRulesOptions {
11335 JsCast::unchecked_into(Object::new())
11336 }
11337 }
11338
11339 impl Default for PluralRulesOptions {
11340 fn default() -> Self {
11341 PluralRulesOptions::new()
11342 }
11343 }
11344
11345 // Intl.ResolvedPluralRulesOptions
11346 #[wasm_bindgen]
11347 extern "C" {
11348 /// Resolved options returned by `Intl.PluralRules.prototype.resolvedOptions()`.
11349 ///
11350 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules/resolvedOptions)
11351 #[wasm_bindgen(extends = PluralRulesOptions)]
11352 #[derive(Clone, Debug)]
11353 pub type ResolvedPluralRulesOptions;
11354
11355 /// The resolved locale string.
11356 #[wasm_bindgen(method, getter = locale)]
11357 pub fn get_locale(this: &ResolvedPluralRulesOptions) -> JsString;
11358
11359 /// The plural categories used by the locale.
11360 #[wasm_bindgen(method, getter = pluralCategories)]
11361 pub fn get_plural_categories(this: &ResolvedPluralRulesOptions) -> Array<JsString>;
11362 }
11363
11364 // Intl.PluralRules
11365 #[wasm_bindgen]
11366 extern "C" {
11367 /// The `Intl.PluralRules` object is a constructor for objects
11368 /// that enable plural sensitive formatting and plural language rules.
11369 ///
11370 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules)
11371 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.PluralRules")]
11372 #[derive(Clone, Debug)]
11373 pub type PluralRules;
11374
11375 /// The `Intl.PluralRules` object is a constructor for objects
11376 /// that enable plural sensitive formatting and plural language rules.
11377 ///
11378 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules)
11379 #[cfg(not(js_sys_unstable_apis))]
11380 #[wasm_bindgen(constructor, js_namespace = Intl)]
11381 pub fn new(locales: &Array, options: &Object) -> PluralRules;
11382
11383 /// The `Intl.PluralRules` object is a constructor for objects
11384 /// that enable plural sensitive formatting and plural language rules.
11385 ///
11386 /// Throws a `RangeError` if locales contain invalid values.
11387 ///
11388 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules)
11389 #[cfg(js_sys_unstable_apis)]
11390 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
11391 pub fn new(
11392 locales: &[JsString],
11393 options: &PluralRulesOptions,
11394 ) -> Result<PluralRules, JsValue>;
11395
11396 /// The `Intl.PluralRules.prototype.resolvedOptions()` method returns a new
11397 /// object with properties reflecting the locale and plural formatting
11398 /// options computed during initialization of this PluralRules object.
11399 ///
11400 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/resolvedOptions)
11401 #[cfg(not(js_sys_unstable_apis))]
11402 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11403 pub fn resolved_options(this: &PluralRules) -> Object;
11404
11405 /// The `Intl.PluralRules.prototype.resolvedOptions()` method returns a new
11406 /// object with properties reflecting the locale and plural formatting
11407 /// options computed during initialization of this PluralRules object.
11408 ///
11409 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/resolvedOptions)
11410 #[cfg(js_sys_unstable_apis)]
11411 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11412 pub fn resolved_options(this: &PluralRules) -> ResolvedPluralRulesOptions;
11413
11414 /// The `Intl.PluralRules.prototype.select()` method returns a String indicating
11415 /// which plural rule to use for locale-aware formatting.
11416 ///
11417 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/select)
11418 #[cfg(not(js_sys_unstable_apis))]
11419 #[wasm_bindgen(method, js_namespace = Intl)]
11420 pub fn select(this: &PluralRules, number: f64) -> JsString;
11421
11422 /// The `Intl.PluralRules.prototype.select()` method returns a String indicating
11423 /// which plural rule to use for locale-aware formatting.
11424 ///
11425 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/select)
11426 #[cfg(js_sys_unstable_apis)]
11427 #[wasm_bindgen(method, js_namespace = Intl)]
11428 pub fn select(this: &PluralRules, number: f64) -> PluralCategory;
11429
11430 /// The `Intl.PluralRules.prototype.selectRange()` method returns a string indicating
11431 /// which plural rule to use for locale-aware formatting of a range of numbers.
11432 ///
11433 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules/selectRange)
11434 #[cfg(not(js_sys_unstable_apis))]
11435 #[wasm_bindgen(method, js_namespace = Intl, js_name = selectRange)]
11436 pub fn select_range(this: &PluralRules, start: f64, end: f64) -> JsString;
11437
11438 /// The `Intl.PluralRules.prototype.selectRange()` method returns a string indicating
11439 /// which plural rule to use for locale-aware formatting of a range of numbers.
11440 ///
11441 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules/selectRange)
11442 #[cfg(js_sys_unstable_apis)]
11443 #[wasm_bindgen(method, js_namespace = Intl, js_name = selectRange)]
11444 pub fn select_range(this: &PluralRules, start: f64, end: f64) -> PluralCategory;
11445
11446 /// The `Intl.PluralRules.supportedLocalesOf()` method returns an array
11447 /// containing those of the provided locales that are supported in plural
11448 /// formatting without having to fall back to the runtime's default locale.
11449 ///
11450 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/supportedLocalesOf)
11451 #[cfg(not(js_sys_unstable_apis))]
11452 #[wasm_bindgen(static_method_of = PluralRules, js_namespace = Intl, js_name = supportedLocalesOf)]
11453 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
11454
11455 /// The `Intl.PluralRules.supportedLocalesOf()` method returns an array
11456 /// containing those of the provided locales that are supported in plural
11457 /// formatting without having to fall back to the runtime's default locale.
11458 ///
11459 /// Throws a `RangeError` if locales contain invalid values.
11460 ///
11461 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/supportedLocalesOf)
11462 #[cfg(js_sys_unstable_apis)]
11463 #[wasm_bindgen(static_method_of = PluralRules, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
11464 pub fn supported_locales_of(
11465 locales: &[JsString],
11466 options: &LocaleMatcherOptions,
11467 ) -> Result<Array<JsString>, JsValue>;
11468 }
11469
11470 #[cfg(not(js_sys_unstable_apis))]
11471 impl Default for PluralRules {
11472 fn default() -> Self {
11473 Self::new(
11474 &JsValue::UNDEFINED.unchecked_into(),
11475 &JsValue::UNDEFINED.unchecked_into(),
11476 )
11477 }
11478 }
11479
11480 #[cfg(js_sys_unstable_apis)]
11481 impl Default for PluralRules {
11482 fn default() -> Self {
11483 Self::new(&[], &Default::default()).unwrap()
11484 }
11485 }
11486
11487 // Intl.RelativeTimeFormat
11488 #[wasm_bindgen]
11489 extern "C" {
11490 /// The `Intl.RelativeTimeFormat` object is a constructor for objects
11491 /// that enable language-sensitive relative time formatting.
11492 ///
11493 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat)
11494 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.RelativeTimeFormat")]
11495 #[derive(Clone, Debug)]
11496 pub type RelativeTimeFormat;
11497
11498 /// The `Intl.RelativeTimeFormat` object is a constructor for objects
11499 /// that enable language-sensitive relative time formatting.
11500 ///
11501 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat)
11502 #[cfg(not(js_sys_unstable_apis))]
11503 #[wasm_bindgen(constructor, js_namespace = Intl)]
11504 pub fn new(locales: &Array, options: &Object) -> RelativeTimeFormat;
11505
11506 /// The `Intl.RelativeTimeFormat` object is a constructor for objects
11507 /// that enable language-sensitive relative time formatting.
11508 ///
11509 /// Throws a `RangeError` if locales contain invalid values.
11510 ///
11511 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat)
11512 #[cfg(js_sys_unstable_apis)]
11513 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
11514 pub fn new(locales: &[JsString]) -> Result<RelativeTimeFormat, JsValue>;
11515
11516 /// The `Intl.RelativeTimeFormat` object is a constructor for objects
11517 /// that enable language-sensitive relative time formatting.
11518 ///
11519 /// Throws a `RangeError` if locales or options contain invalid values.
11520 ///
11521 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat)
11522 #[cfg(js_sys_unstable_apis)]
11523 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
11524 pub fn new_with_options(
11525 locales: &[JsString],
11526 options: &RelativeTimeFormatOptions,
11527 ) -> Result<RelativeTimeFormat, JsValue>;
11528
11529 /// The `Intl.RelativeTimeFormat.prototype.format` method formats a `value` and `unit`
11530 /// according to the locale and formatting options of this Intl.RelativeTimeFormat object.
11531 ///
11532 /// Throws a `RangeError` if unit is invalid.
11533 ///
11534 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/format)
11535 #[cfg(not(js_sys_unstable_apis))]
11536 #[wasm_bindgen(method, js_class = "Intl.RelativeTimeFormat")]
11537 pub fn format(this: &RelativeTimeFormat, value: f64, unit: &str) -> JsString;
11538
11539 /// The `Intl.RelativeTimeFormat.prototype.format` method formats a `value` and `unit`
11540 /// according to the locale and formatting options of this Intl.RelativeTimeFormat object.
11541 ///
11542 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/format)
11543 #[cfg(js_sys_unstable_apis)]
11544 #[wasm_bindgen(method, js_class = "Intl.RelativeTimeFormat")]
11545 pub fn format(
11546 this: &RelativeTimeFormat,
11547 value: f64,
11548 unit: RelativeTimeFormatUnit,
11549 ) -> JsString;
11550
11551 /// The `Intl.RelativeTimeFormat.prototype.formatToParts()` method returns an array of
11552 /// objects representing the relative time format in parts that can be used for custom locale-aware formatting.
11553 ///
11554 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/formatToParts)
11555 #[cfg(not(js_sys_unstable_apis))]
11556 #[wasm_bindgen(method, js_class = "Intl.RelativeTimeFormat", js_name = formatToParts)]
11557 pub fn format_to_parts(this: &RelativeTimeFormat, value: f64, unit: &str) -> Array;
11558
11559 /// The `Intl.RelativeTimeFormat.prototype.formatToParts()` method returns an array of
11560 /// objects representing the relative time format in parts that can be used for custom locale-aware formatting.
11561 ///
11562 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/formatToParts)
11563 #[cfg(js_sys_unstable_apis)]
11564 #[wasm_bindgen(method, js_class = "Intl.RelativeTimeFormat", js_name = formatToParts)]
11565 pub fn format_to_parts(
11566 this: &RelativeTimeFormat,
11567 value: f64,
11568 unit: RelativeTimeFormatUnit,
11569 ) -> Array<RelativeTimeFormatPart>;
11570
11571 /// The `Intl.RelativeTimeFormat.prototype.resolvedOptions()` method returns a new
11572 /// object with properties reflecting the locale and relative time formatting
11573 /// options computed during initialization of this RelativeTimeFormat object.
11574 ///
11575 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/resolvedOptions)
11576 #[cfg(not(js_sys_unstable_apis))]
11577 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11578 pub fn resolved_options(this: &RelativeTimeFormat) -> Object;
11579
11580 /// The `Intl.RelativeTimeFormat.prototype.resolvedOptions()` method returns a new
11581 /// object with properties reflecting the locale and relative time formatting
11582 /// options computed during initialization of this RelativeTimeFormat object.
11583 ///
11584 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/resolvedOptions)
11585 #[cfg(js_sys_unstable_apis)]
11586 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11587 pub fn resolved_options(this: &RelativeTimeFormat) -> ResolvedRelativeTimeFormatOptions;
11588
11589 /// The `Intl.RelativeTimeFormat.supportedLocalesOf()` method returns an array
11590 /// containing those of the provided locales that are supported in date and time
11591 /// formatting without having to fall back to the runtime's default locale.
11592 ///
11593 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RelativeTimeFormat/supportedLocalesOf)
11594 #[cfg(not(js_sys_unstable_apis))]
11595 #[wasm_bindgen(static_method_of = RelativeTimeFormat, js_namespace = Intl, js_name = supportedLocalesOf)]
11596 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
11597
11598 /// The `Intl.RelativeTimeFormat.supportedLocalesOf()` method returns an array
11599 /// containing those of the provided locales that are supported in date and time
11600 /// formatting without having to fall back to the runtime's default locale.
11601 ///
11602 /// Throws a `RangeError` if locales contain invalid values.
11603 ///
11604 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RelativeTimeFormat/supportedLocalesOf)
11605 #[cfg(js_sys_unstable_apis)]
11606 #[wasm_bindgen(static_method_of = RelativeTimeFormat, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
11607 pub fn supported_locales_of(
11608 locales: &[JsString],
11609 options: &LocaleMatcherOptions,
11610 ) -> Result<Array<JsString>, JsValue>;
11611 }
11612
11613 #[cfg(not(js_sys_unstable_apis))]
11614 impl Default for RelativeTimeFormat {
11615 fn default() -> Self {
11616 Self::new(
11617 &JsValue::UNDEFINED.unchecked_into(),
11618 &JsValue::UNDEFINED.unchecked_into(),
11619 )
11620 }
11621 }
11622
11623 #[cfg(js_sys_unstable_apis)]
11624 impl Default for RelativeTimeFormat {
11625 fn default() -> Self {
11626 Self::new(&[]).unwrap()
11627 }
11628 }
11629
11630 // Intl.ListFormatOptions
11631 #[wasm_bindgen]
11632 extern "C" {
11633 /// Options for `Intl.ListFormat` constructor.
11634 ///
11635 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/ListFormat#options)
11636 #[wasm_bindgen(extends = Object)]
11637 #[derive(Clone, Debug)]
11638 pub type ListFormatOptions;
11639
11640 #[wasm_bindgen(method, getter = localeMatcher)]
11641 pub fn get_locale_matcher(this: &ListFormatOptions) -> Option<LocaleMatcher>;
11642 #[wasm_bindgen(method, setter = localeMatcher)]
11643 pub fn set_locale_matcher(this: &ListFormatOptions, value: LocaleMatcher);
11644
11645 #[wasm_bindgen(method, getter = type)]
11646 pub fn get_type(this: &ListFormatOptions) -> Option<ListFormatType>;
11647 #[wasm_bindgen(method, setter = type)]
11648 pub fn set_type(this: &ListFormatOptions, value: ListFormatType);
11649
11650 #[wasm_bindgen(method, getter = style)]
11651 pub fn get_style(this: &ListFormatOptions) -> Option<ListFormatStyle>;
11652 #[wasm_bindgen(method, setter = style)]
11653 pub fn set_style(this: &ListFormatOptions, value: ListFormatStyle);
11654 }
11655
11656 impl ListFormatOptions {
11657 pub fn new() -> ListFormatOptions {
11658 JsCast::unchecked_into(Object::new())
11659 }
11660 }
11661
11662 impl Default for ListFormatOptions {
11663 fn default() -> Self {
11664 ListFormatOptions::new()
11665 }
11666 }
11667
11668 // Intl.ResolvedListFormatOptions
11669 #[wasm_bindgen]
11670 extern "C" {
11671 /// Resolved options returned by `Intl.ListFormat.prototype.resolvedOptions()`.
11672 ///
11673 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/resolvedOptions)
11674 #[wasm_bindgen(extends = ListFormatOptions)]
11675 #[derive(Clone, Debug)]
11676 pub type ResolvedListFormatOptions;
11677
11678 /// The resolved locale string.
11679 #[wasm_bindgen(method, getter = locale)]
11680 pub fn get_locale(this: &ResolvedListFormatOptions) -> JsString;
11681 }
11682
11683 // Intl.ListFormatPart
11684 #[wasm_bindgen]
11685 extern "C" {
11686 /// A part of the formatted list returned by `formatToParts()`.
11687 ///
11688 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/formatToParts)
11689 #[wasm_bindgen(extends = Object)]
11690 #[derive(Clone, Debug)]
11691 pub type ListFormatPart;
11692
11693 /// The type of the part ("element" or "literal").
11694 #[wasm_bindgen(method, getter = type)]
11695 pub fn type_(this: &ListFormatPart) -> ListFormatPartType;
11696
11697 /// The value of the part.
11698 #[wasm_bindgen(method, getter)]
11699 pub fn value(this: &ListFormatPart) -> JsString;
11700 }
11701
11702 // Intl.ListFormat
11703 #[wasm_bindgen]
11704 extern "C" {
11705 /// The `Intl.ListFormat` object enables language-sensitive list formatting.
11706 ///
11707 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat)
11708 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.ListFormat")]
11709 #[derive(Clone, Debug)]
11710 pub type ListFormat;
11711
11712 /// Creates a new `Intl.ListFormat` object.
11713 ///
11714 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/ListFormat)
11715 #[cfg(not(js_sys_unstable_apis))]
11716 #[wasm_bindgen(constructor, js_namespace = Intl)]
11717 pub fn new(locales: &Array, options: &Object) -> ListFormat;
11718
11719 /// Creates a new `Intl.ListFormat` object.
11720 ///
11721 /// Throws a `RangeError` if locales or options contain invalid values.
11722 ///
11723 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/ListFormat)
11724 #[cfg(js_sys_unstable_apis)]
11725 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
11726 pub fn new(
11727 locales: &[JsString],
11728 options: &ListFormatOptions,
11729 ) -> Result<ListFormat, JsValue>;
11730
11731 /// Formats a list of strings according to the locale and options.
11732 ///
11733 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/format)
11734 #[cfg(not(js_sys_unstable_apis))]
11735 #[wasm_bindgen(method, js_class = "Intl.ListFormat")]
11736 pub fn format(this: &ListFormat, list: &Array) -> JsString;
11737
11738 /// Formats a list of strings according to the locale and options.
11739 ///
11740 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/format)
11741 #[cfg(js_sys_unstable_apis)]
11742 #[wasm_bindgen(method, js_class = "Intl.ListFormat")]
11743 pub fn format(this: &ListFormat, list: &[JsString]) -> JsString;
11744
11745 /// Returns an array of objects representing the list in parts.
11746 ///
11747 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/formatToParts)
11748 #[cfg(not(js_sys_unstable_apis))]
11749 #[wasm_bindgen(method, js_class = "Intl.ListFormat", js_name = formatToParts)]
11750 pub fn format_to_parts(this: &ListFormat, list: &Array) -> Array;
11751
11752 /// Returns an array of objects representing the list in parts.
11753 ///
11754 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/formatToParts)
11755 #[cfg(js_sys_unstable_apis)]
11756 #[wasm_bindgen(method, js_class = "Intl.ListFormat", js_name = formatToParts)]
11757 pub fn format_to_parts(this: &ListFormat, list: &[JsString]) -> Array<ListFormatPart>;
11758
11759 /// Returns an object with properties reflecting the options used.
11760 ///
11761 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/resolvedOptions)
11762 #[cfg(not(js_sys_unstable_apis))]
11763 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11764 pub fn resolved_options(this: &ListFormat) -> Object;
11765
11766 /// Returns an object with properties reflecting the options used.
11767 ///
11768 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/resolvedOptions)
11769 #[cfg(js_sys_unstable_apis)]
11770 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11771 pub fn resolved_options(this: &ListFormat) -> ResolvedListFormatOptions;
11772
11773 /// Returns an array of supported locales.
11774 ///
11775 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/supportedLocalesOf)
11776 #[cfg(not(js_sys_unstable_apis))]
11777 #[wasm_bindgen(static_method_of = ListFormat, js_namespace = Intl, js_name = supportedLocalesOf)]
11778 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
11779
11780 /// Returns an array of supported locales.
11781 ///
11782 /// Throws a `RangeError` if locales contain invalid values.
11783 ///
11784 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/supportedLocalesOf)
11785 #[cfg(js_sys_unstable_apis)]
11786 #[wasm_bindgen(static_method_of = ListFormat, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
11787 pub fn supported_locales_of(
11788 locales: &[JsString],
11789 options: &LocaleMatcherOptions,
11790 ) -> Result<Array<JsString>, JsValue>;
11791 }
11792
11793 #[cfg(not(js_sys_unstable_apis))]
11794 impl Default for ListFormat {
11795 fn default() -> Self {
11796 Self::new(
11797 &JsValue::UNDEFINED.unchecked_into(),
11798 &JsValue::UNDEFINED.unchecked_into(),
11799 )
11800 }
11801 }
11802
11803 #[cfg(js_sys_unstable_apis)]
11804 impl Default for ListFormat {
11805 fn default() -> Self {
11806 Self::new(&[], &Default::default()).unwrap()
11807 }
11808 }
11809
11810 // Intl.SegmenterOptions
11811 #[wasm_bindgen]
11812 extern "C" {
11813 /// Options for `Intl.Segmenter` constructor.
11814 ///
11815 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/Segmenter#options)
11816 #[wasm_bindgen(extends = Object)]
11817 #[derive(Clone, Debug)]
11818 pub type SegmenterOptions;
11819
11820 #[wasm_bindgen(method, getter = localeMatcher)]
11821 pub fn get_locale_matcher(this: &SegmenterOptions) -> Option<LocaleMatcher>;
11822 #[wasm_bindgen(method, setter = localeMatcher)]
11823 pub fn set_locale_matcher(this: &SegmenterOptions, value: LocaleMatcher);
11824
11825 #[wasm_bindgen(method, getter = granularity)]
11826 pub fn get_granularity(this: &SegmenterOptions) -> Option<SegmenterGranularity>;
11827 #[wasm_bindgen(method, setter = granularity)]
11828 pub fn set_granularity(this: &SegmenterOptions, value: SegmenterGranularity);
11829 }
11830
11831 impl SegmenterOptions {
11832 pub fn new() -> SegmenterOptions {
11833 JsCast::unchecked_into(Object::new())
11834 }
11835 }
11836
11837 impl Default for SegmenterOptions {
11838 fn default() -> Self {
11839 SegmenterOptions::new()
11840 }
11841 }
11842
11843 // Intl.ResolvedSegmenterOptions
11844 #[wasm_bindgen]
11845 extern "C" {
11846 /// Resolved options returned by `Intl.Segmenter.prototype.resolvedOptions()`.
11847 ///
11848 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/resolvedOptions)
11849 #[wasm_bindgen(extends = SegmenterOptions)]
11850 #[derive(Clone, Debug)]
11851 pub type ResolvedSegmenterOptions;
11852
11853 /// The resolved locale string.
11854 #[wasm_bindgen(method, getter = locale)]
11855 pub fn get_locale(this: &ResolvedSegmenterOptions) -> JsString;
11856 }
11857
11858 // Intl.SegmentData
11859 #[wasm_bindgen]
11860 extern "C" {
11861 /// Data about a segment returned by the Segments iterator.
11862 ///
11863 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/segment/Segments#segment_data)
11864 #[wasm_bindgen(extends = Object)]
11865 #[derive(Clone, Debug)]
11866 pub type SegmentData;
11867
11868 /// The segment string.
11869 #[wasm_bindgen(method, getter)]
11870 pub fn segment(this: &SegmentData) -> JsString;
11871
11872 /// The index of the segment in the original string.
11873 #[wasm_bindgen(method, getter)]
11874 pub fn index(this: &SegmentData) -> u32;
11875
11876 /// The original input string.
11877 #[wasm_bindgen(method, getter)]
11878 pub fn input(this: &SegmentData) -> JsString;
11879
11880 /// Whether the segment is word-like (only for word granularity).
11881 #[wasm_bindgen(method, getter = isWordLike)]
11882 pub fn is_word_like(this: &SegmentData) -> Option<bool>;
11883 }
11884
11885 // Intl.Segments
11886 #[wasm_bindgen]
11887 extern "C" {
11888 /// The Segments object is an iterable collection of segments of a string.
11889 ///
11890 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/segment/Segments)
11891 #[wasm_bindgen(extends = Object)]
11892 #[derive(Clone, Debug)]
11893 pub type Segments;
11894
11895 /// Returns segment data for the segment containing the character at the given index.
11896 ///
11897 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/segment/Segments/containing)
11898 #[wasm_bindgen(method)]
11899 pub fn containing(this: &Segments, index: u32) -> Option<SegmentData>;
11900 }
11901
11902 // Intl.Segmenter
11903 #[wasm_bindgen]
11904 extern "C" {
11905 /// The `Intl.Segmenter` object enables locale-sensitive text segmentation.
11906 ///
11907 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter)
11908 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.Segmenter")]
11909 #[derive(Clone, Debug)]
11910 pub type Segmenter;
11911
11912 /// Creates a new `Intl.Segmenter` object.
11913 ///
11914 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/Segmenter)
11915 #[cfg(not(js_sys_unstable_apis))]
11916 #[wasm_bindgen(constructor, js_namespace = Intl)]
11917 pub fn new(locales: &Array, options: &Object) -> Segmenter;
11918
11919 /// Creates a new `Intl.Segmenter` object.
11920 ///
11921 /// Throws a `RangeError` if locales or options contain invalid values.
11922 ///
11923 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/Segmenter)
11924 #[cfg(js_sys_unstable_apis)]
11925 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
11926 pub fn new(locales: &[JsString], options: &SegmenterOptions) -> Result<Segmenter, JsValue>;
11927
11928 /// Returns a Segments object containing the segments of the input string.
11929 ///
11930 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/segment)
11931 #[wasm_bindgen(method, js_class = "Intl.Segmenter")]
11932 pub fn segment(this: &Segmenter, input: &str) -> Segments;
11933
11934 /// Returns an object with properties reflecting the options used.
11935 ///
11936 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/resolvedOptions)
11937 #[cfg(not(js_sys_unstable_apis))]
11938 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11939 pub fn resolved_options(this: &Segmenter) -> Object;
11940
11941 /// Returns an object with properties reflecting the options used.
11942 ///
11943 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/resolvedOptions)
11944 #[cfg(js_sys_unstable_apis)]
11945 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11946 pub fn resolved_options(this: &Segmenter) -> ResolvedSegmenterOptions;
11947
11948 /// Returns an array of supported locales.
11949 ///
11950 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/supportedLocalesOf)
11951 #[cfg(not(js_sys_unstable_apis))]
11952 #[wasm_bindgen(static_method_of = Segmenter, js_namespace = Intl, js_name = supportedLocalesOf)]
11953 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
11954
11955 /// Returns an array of supported locales.
11956 ///
11957 /// Throws a `RangeError` if locales contain invalid values.
11958 ///
11959 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/supportedLocalesOf)
11960 #[cfg(js_sys_unstable_apis)]
11961 #[wasm_bindgen(static_method_of = Segmenter, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
11962 pub fn supported_locales_of(
11963 locales: &[JsString],
11964 options: &LocaleMatcherOptions,
11965 ) -> Result<Array<JsString>, JsValue>;
11966 }
11967
11968 #[cfg(not(js_sys_unstable_apis))]
11969 impl Default for Segmenter {
11970 fn default() -> Self {
11971 Self::new(
11972 &JsValue::UNDEFINED.unchecked_into(),
11973 &JsValue::UNDEFINED.unchecked_into(),
11974 )
11975 }
11976 }
11977
11978 #[cfg(js_sys_unstable_apis)]
11979 impl Default for Segmenter {
11980 fn default() -> Self {
11981 Self::new(&[], &Default::default()).unwrap()
11982 }
11983 }
11984
11985 // Intl.DisplayNamesOptions
11986 #[wasm_bindgen]
11987 extern "C" {
11988 /// Options for `Intl.DisplayNames` constructor.
11989 ///
11990 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/DisplayNames#options)
11991 #[wasm_bindgen(extends = Object)]
11992 #[derive(Clone, Debug)]
11993 pub type DisplayNamesOptions;
11994
11995 #[wasm_bindgen(method, getter = localeMatcher)]
11996 pub fn get_locale_matcher(this: &DisplayNamesOptions) -> Option<LocaleMatcher>;
11997 #[wasm_bindgen(method, setter = localeMatcher)]
11998 pub fn set_locale_matcher(this: &DisplayNamesOptions, value: LocaleMatcher);
11999
12000 #[wasm_bindgen(method, getter = type)]
12001 pub fn get_type(this: &DisplayNamesOptions) -> Option<DisplayNamesType>;
12002 #[wasm_bindgen(method, setter = type)]
12003 pub fn set_type(this: &DisplayNamesOptions, value: DisplayNamesType);
12004
12005 #[wasm_bindgen(method, getter = style)]
12006 pub fn get_style(this: &DisplayNamesOptions) -> Option<DisplayNamesStyle>;
12007 #[wasm_bindgen(method, setter = style)]
12008 pub fn set_style(this: &DisplayNamesOptions, value: DisplayNamesStyle);
12009
12010 #[wasm_bindgen(method, getter = fallback)]
12011 pub fn get_fallback(this: &DisplayNamesOptions) -> Option<DisplayNamesFallback>;
12012 #[wasm_bindgen(method, setter = fallback)]
12013 pub fn set_fallback(this: &DisplayNamesOptions, value: DisplayNamesFallback);
12014
12015 #[wasm_bindgen(method, getter = languageDisplay)]
12016 pub fn get_language_display(
12017 this: &DisplayNamesOptions,
12018 ) -> Option<DisplayNamesLanguageDisplay>;
12019 #[wasm_bindgen(method, setter = languageDisplay)]
12020 pub fn set_language_display(this: &DisplayNamesOptions, value: DisplayNamesLanguageDisplay);
12021 }
12022
12023 impl DisplayNamesOptions {
12024 pub fn new() -> DisplayNamesOptions {
12025 JsCast::unchecked_into(Object::new())
12026 }
12027 }
12028
12029 impl Default for DisplayNamesOptions {
12030 fn default() -> Self {
12031 DisplayNamesOptions::new()
12032 }
12033 }
12034
12035 // Intl.ResolvedDisplayNamesOptions
12036 #[wasm_bindgen]
12037 extern "C" {
12038 /// Resolved options returned by `Intl.DisplayNames.prototype.resolvedOptions()`.
12039 ///
12040 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/resolvedOptions)
12041 #[wasm_bindgen(extends = DisplayNamesOptions)]
12042 #[derive(Clone, Debug)]
12043 pub type ResolvedDisplayNamesOptions;
12044
12045 /// The resolved locale string.
12046 #[wasm_bindgen(method, getter = locale)]
12047 pub fn get_locale(this: &ResolvedDisplayNamesOptions) -> JsString;
12048 }
12049
12050 // Intl.DisplayNames
12051 #[wasm_bindgen]
12052 extern "C" {
12053 /// The `Intl.DisplayNames` object enables the consistent translation of
12054 /// language, region, and script display names.
12055 ///
12056 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames)
12057 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.DisplayNames")]
12058 #[derive(Clone, Debug)]
12059 pub type DisplayNames;
12060
12061 /// Creates a new `Intl.DisplayNames` object.
12062 ///
12063 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/DisplayNames)
12064 #[cfg(not(js_sys_unstable_apis))]
12065 #[wasm_bindgen(constructor, js_namespace = Intl)]
12066 pub fn new(locales: &Array, options: &Object) -> DisplayNames;
12067
12068 /// Creates a new `Intl.DisplayNames` object.
12069 ///
12070 /// Throws a `RangeError` if locales or options contain invalid values.
12071 ///
12072 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/DisplayNames)
12073 #[cfg(js_sys_unstable_apis)]
12074 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
12075 pub fn new(
12076 locales: &[JsString],
12077 options: &DisplayNamesOptions,
12078 ) -> Result<DisplayNames, JsValue>;
12079
12080 /// Returns the display name for the given code.
12081 ///
12082 /// Returns `undefined` if fallback is "none" and no name is available.
12083 ///
12084 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/of)
12085 #[wasm_bindgen(method, js_class = "Intl.DisplayNames")]
12086 pub fn of(this: &DisplayNames, code: &str) -> Option<JsString>;
12087
12088 /// Returns an object with properties reflecting the options used.
12089 ///
12090 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/resolvedOptions)
12091 #[cfg(not(js_sys_unstable_apis))]
12092 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
12093 pub fn resolved_options(this: &DisplayNames) -> Object;
12094
12095 /// Returns an object with properties reflecting the options used.
12096 ///
12097 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/resolvedOptions)
12098 #[cfg(js_sys_unstable_apis)]
12099 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
12100 pub fn resolved_options(this: &DisplayNames) -> ResolvedDisplayNamesOptions;
12101
12102 /// Returns an array of supported locales.
12103 ///
12104 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/supportedLocalesOf)
12105 #[cfg(not(js_sys_unstable_apis))]
12106 #[wasm_bindgen(static_method_of = DisplayNames, js_namespace = Intl, js_name = supportedLocalesOf)]
12107 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
12108
12109 /// Returns an array of supported locales.
12110 ///
12111 /// Throws a `RangeError` if locales contain invalid values.
12112 ///
12113 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/supportedLocalesOf)
12114 #[cfg(js_sys_unstable_apis)]
12115 #[wasm_bindgen(static_method_of = DisplayNames, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
12116 pub fn supported_locales_of(
12117 locales: &[JsString],
12118 options: &LocaleMatcherOptions,
12119 ) -> Result<Array<JsString>, JsValue>;
12120 }
12121
12122 // Intl.Locale
12123 #[wasm_bindgen]
12124 extern "C" {
12125 /// The `Intl.Locale` object is a standard built-in property of the Intl object
12126 /// that represents a Unicode locale identifier.
12127 ///
12128 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale)
12129 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.Locale")]
12130 #[derive(Clone, Debug)]
12131 pub type Locale;
12132
12133 /// Creates a new `Intl.Locale` object.
12134 ///
12135 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/Locale)
12136 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
12137 pub fn new(tag: &str) -> Result<Locale, JsValue>;
12138
12139 /// Creates a new `Intl.Locale` object with options.
12140 ///
12141 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/Locale)
12142 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
12143 pub fn new_with_options(tag: &str, options: &Object) -> Result<Locale, JsValue>;
12144
12145 /// The base name of the locale (language + region + script).
12146 ///
12147 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/baseName)
12148 #[wasm_bindgen(method, getter = baseName)]
12149 pub fn base_name(this: &Locale) -> JsString;
12150
12151 /// The calendar type for the locale.
12152 ///
12153 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/calendar)
12154 #[wasm_bindgen(method, getter)]
12155 pub fn calendar(this: &Locale) -> Option<JsString>;
12156
12157 /// The case first sorting option.
12158 ///
12159 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/caseFirst)
12160 #[wasm_bindgen(method, getter = caseFirst)]
12161 pub fn case_first(this: &Locale) -> Option<JsString>;
12162
12163 /// The collation type for the locale.
12164 ///
12165 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/collation)
12166 #[wasm_bindgen(method, getter)]
12167 pub fn collation(this: &Locale) -> Option<JsString>;
12168
12169 /// The hour cycle for the locale.
12170 ///
12171 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/hourCycle)
12172 #[wasm_bindgen(method, getter = hourCycle)]
12173 pub fn hour_cycle(this: &Locale) -> Option<JsString>;
12174
12175 /// The language code for the locale.
12176 ///
12177 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/language)
12178 #[wasm_bindgen(method, getter)]
12179 pub fn language(this: &Locale) -> JsString;
12180
12181 /// The numbering system for the locale.
12182 ///
12183 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/numberingSystem)
12184 #[wasm_bindgen(method, getter = numberingSystem)]
12185 pub fn numbering_system(this: &Locale) -> Option<JsString>;
12186
12187 /// Whether the locale uses numeric collation.
12188 ///
12189 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/numeric)
12190 #[wasm_bindgen(method, getter)]
12191 pub fn numeric(this: &Locale) -> bool;
12192
12193 /// The region code for the locale.
12194 ///
12195 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/region)
12196 #[wasm_bindgen(method, getter)]
12197 pub fn region(this: &Locale) -> Option<JsString>;
12198
12199 /// The script code for the locale.
12200 ///
12201 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/script)
12202 #[wasm_bindgen(method, getter)]
12203 pub fn script(this: &Locale) -> Option<JsString>;
12204
12205 /// Returns an array of available calendars for the locale.
12206 ///
12207 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getCalendars)
12208 #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getCalendars)]
12209 pub fn get_calendars(this: &Locale) -> Array<JsString>;
12210
12211 /// Returns an array of available collations for the locale.
12212 ///
12213 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getCollations)
12214 #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getCollations)]
12215 pub fn get_collations(this: &Locale) -> Array<JsString>;
12216
12217 /// Returns an array of available hour cycles for the locale.
12218 ///
12219 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getHourCycles)
12220 #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getHourCycles)]
12221 pub fn get_hour_cycles(this: &Locale) -> Array<JsString>;
12222
12223 /// Returns an array of available numbering systems for the locale.
12224 ///
12225 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getNumberingSystems)
12226 #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getNumberingSystems)]
12227 pub fn get_numbering_systems(this: &Locale) -> Array<JsString>;
12228
12229 /// Returns an array of available time zones for the locale's region.
12230 ///
12231 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getTimeZones)
12232 #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getTimeZones)]
12233 pub fn get_time_zones(this: &Locale) -> Option<Array<JsString>>;
12234
12235 /// Returns week information for the locale.
12236 ///
12237 /// May not be available in all environments.
12238 ///
12239 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getWeekInfo)
12240 #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getWeekInfo, catch)]
12241 pub fn get_week_info(this: &Locale) -> Result<WeekInfo, JsValue>;
12242
12243 /// Returns text layout information for the locale.
12244 ///
12245 /// May not be available in all environments.
12246 ///
12247 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getTextInfo)
12248 #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getTextInfo, catch)]
12249 pub fn get_text_info(this: &Locale) -> Result<TextInfo, JsValue>;
12250
12251 /// Returns a new Locale with the specified calendar.
12252 ///
12253 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/maximize)
12254 #[wasm_bindgen(method, js_class = "Intl.Locale")]
12255 pub fn maximize(this: &Locale) -> Locale;
12256
12257 /// Returns a new Locale with the minimal subtags.
12258 ///
12259 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/minimize)
12260 #[wasm_bindgen(method, js_class = "Intl.Locale")]
12261 pub fn minimize(this: &Locale) -> Locale;
12262 }
12263
12264 // Intl.Locale WeekInfo
12265 #[wasm_bindgen]
12266 extern "C" {
12267 /// Week information for a locale.
12268 ///
12269 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getWeekInfo)
12270 #[wasm_bindgen(extends = Object)]
12271 #[derive(Clone, Debug)]
12272 pub type WeekInfo;
12273
12274 /// The first day of the week (1 = Monday, 7 = Sunday).
12275 #[wasm_bindgen(method, getter = firstDay)]
12276 pub fn first_day(this: &WeekInfo) -> u8;
12277
12278 /// Array of weekend days.
12279 #[wasm_bindgen(method, getter)]
12280 pub fn weekend(this: &WeekInfo) -> Array<Number>;
12281
12282 /// Minimal days in the first week of the year.
12283 #[wasm_bindgen(method, getter = minimalDays)]
12284 pub fn minimal_days(this: &WeekInfo) -> u8;
12285 }
12286
12287 // Intl.Locale TextInfo
12288 #[wasm_bindgen]
12289 extern "C" {
12290 /// Text layout information for a locale.
12291 ///
12292 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getTextInfo)
12293 #[wasm_bindgen(extends = Object)]
12294 #[derive(Clone, Debug)]
12295 pub type TextInfo;
12296
12297 /// The text direction ("ltr" or "rtl").
12298 #[wasm_bindgen(method, getter)]
12299 pub fn direction(this: &TextInfo) -> JsString;
12300 }
12301
12302 // Intl.DurationFormat enums
12303
12304 /// The style for duration formatting.
12305 ///
12306 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat#style)
12307 #[wasm_bindgen]
12308 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
12309 pub enum DurationFormatStyle {
12310 Long = "long",
12311 Short = "short",
12312 Narrow = "narrow",
12313 Digital = "digital",
12314 }
12315
12316 /// The display style for individual duration units.
12317 ///
12318 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat#years)
12319 #[wasm_bindgen]
12320 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
12321 pub enum DurationUnitStyle {
12322 Long = "long",
12323 Short = "short",
12324 Narrow = "narrow",
12325 }
12326
12327 /// The display style for time duration units (hours, minutes, seconds).
12328 ///
12329 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat#hours)
12330 #[wasm_bindgen]
12331 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
12332 pub enum DurationTimeUnitStyle {
12333 Long = "long",
12334 Short = "short",
12335 Narrow = "narrow",
12336 Numeric = "numeric",
12337 #[wasm_bindgen(js_name = "2-digit")]
12338 TwoDigit = "2-digit",
12339 }
12340
12341 /// The display option for duration units.
12342 ///
12343 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat#yearsdisplay)
12344 #[wasm_bindgen]
12345 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
12346 pub enum DurationUnitDisplay {
12347 Auto = "auto",
12348 Always = "always",
12349 }
12350
12351 /// The type of a duration format part.
12352 ///
12353 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/formatToParts#type)
12354 #[wasm_bindgen]
12355 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
12356 pub enum DurationFormatPartType {
12357 Years = "years",
12358 Months = "months",
12359 Weeks = "weeks",
12360 Days = "days",
12361 Hours = "hours",
12362 Minutes = "minutes",
12363 Seconds = "seconds",
12364 Milliseconds = "milliseconds",
12365 Microseconds = "microseconds",
12366 Nanoseconds = "nanoseconds",
12367 Literal = "literal",
12368 Integer = "integer",
12369 Decimal = "decimal",
12370 Fraction = "fraction",
12371 }
12372
12373 // Intl.DurationFormatOptions
12374 #[wasm_bindgen]
12375 extern "C" {
12376 /// Options for `Intl.DurationFormat` constructor.
12377 ///
12378 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat#options)
12379 #[wasm_bindgen(extends = Object)]
12380 #[derive(Clone, Debug)]
12381 pub type DurationFormatOptions;
12382
12383 #[wasm_bindgen(method, getter = localeMatcher)]
12384 pub fn get_locale_matcher(this: &DurationFormatOptions) -> Option<LocaleMatcher>;
12385 #[wasm_bindgen(method, setter = localeMatcher)]
12386 pub fn set_locale_matcher(this: &DurationFormatOptions, value: LocaleMatcher);
12387
12388 #[wasm_bindgen(method, getter = style)]
12389 pub fn get_style(this: &DurationFormatOptions) -> Option<DurationFormatStyle>;
12390 #[wasm_bindgen(method, setter = style)]
12391 pub fn set_style(this: &DurationFormatOptions, value: DurationFormatStyle);
12392
12393 #[wasm_bindgen(method, getter = years)]
12394 pub fn get_years(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
12395 #[wasm_bindgen(method, setter = years)]
12396 pub fn set_years(this: &DurationFormatOptions, value: DurationUnitStyle);
12397
12398 #[wasm_bindgen(method, getter = yearsDisplay)]
12399 pub fn get_years_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
12400 #[wasm_bindgen(method, setter = yearsDisplay)]
12401 pub fn set_years_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12402
12403 #[wasm_bindgen(method, getter = months)]
12404 pub fn get_months(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
12405 #[wasm_bindgen(method, setter = months)]
12406 pub fn set_months(this: &DurationFormatOptions, value: DurationUnitStyle);
12407
12408 #[wasm_bindgen(method, getter = monthsDisplay)]
12409 pub fn get_months_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
12410 #[wasm_bindgen(method, setter = monthsDisplay)]
12411 pub fn set_months_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12412
12413 #[wasm_bindgen(method, getter = weeks)]
12414 pub fn get_weeks(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
12415 #[wasm_bindgen(method, setter = weeks)]
12416 pub fn set_weeks(this: &DurationFormatOptions, value: DurationUnitStyle);
12417
12418 #[wasm_bindgen(method, getter = weeksDisplay)]
12419 pub fn get_weeks_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
12420 #[wasm_bindgen(method, setter = weeksDisplay)]
12421 pub fn set_weeks_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12422
12423 #[wasm_bindgen(method, getter = days)]
12424 pub fn get_days(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
12425 #[wasm_bindgen(method, setter = days)]
12426 pub fn set_days(this: &DurationFormatOptions, value: DurationUnitStyle);
12427
12428 #[wasm_bindgen(method, getter = daysDisplay)]
12429 pub fn get_days_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
12430 #[wasm_bindgen(method, setter = daysDisplay)]
12431 pub fn set_days_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12432
12433 #[wasm_bindgen(method, getter = hours)]
12434 pub fn get_hours(this: &DurationFormatOptions) -> Option<DurationTimeUnitStyle>;
12435 #[wasm_bindgen(method, setter = hours)]
12436 pub fn set_hours(this: &DurationFormatOptions, value: DurationTimeUnitStyle);
12437
12438 #[wasm_bindgen(method, getter = hoursDisplay)]
12439 pub fn get_hours_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
12440 #[wasm_bindgen(method, setter = hoursDisplay)]
12441 pub fn set_hours_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12442
12443 #[wasm_bindgen(method, getter = minutes)]
12444 pub fn get_minutes(this: &DurationFormatOptions) -> Option<DurationTimeUnitStyle>;
12445 #[wasm_bindgen(method, setter = minutes)]
12446 pub fn set_minutes(this: &DurationFormatOptions, value: DurationTimeUnitStyle);
12447
12448 #[wasm_bindgen(method, getter = minutesDisplay)]
12449 pub fn get_minutes_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
12450 #[wasm_bindgen(method, setter = minutesDisplay)]
12451 pub fn set_minutes_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12452
12453 #[wasm_bindgen(method, getter = seconds)]
12454 pub fn get_seconds(this: &DurationFormatOptions) -> Option<DurationTimeUnitStyle>;
12455 #[wasm_bindgen(method, setter = seconds)]
12456 pub fn set_seconds(this: &DurationFormatOptions, value: DurationTimeUnitStyle);
12457
12458 #[wasm_bindgen(method, getter = secondsDisplay)]
12459 pub fn get_seconds_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
12460 #[wasm_bindgen(method, setter = secondsDisplay)]
12461 pub fn set_seconds_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12462
12463 #[wasm_bindgen(method, getter = milliseconds)]
12464 pub fn get_milliseconds(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
12465 #[wasm_bindgen(method, setter = milliseconds)]
12466 pub fn set_milliseconds(this: &DurationFormatOptions, value: DurationUnitStyle);
12467
12468 #[wasm_bindgen(method, getter = millisecondsDisplay)]
12469 pub fn get_milliseconds_display(
12470 this: &DurationFormatOptions,
12471 ) -> Option<DurationUnitDisplay>;
12472 #[wasm_bindgen(method, setter = millisecondsDisplay)]
12473 pub fn set_milliseconds_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12474
12475 #[wasm_bindgen(method, getter = microseconds)]
12476 pub fn get_microseconds(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
12477 #[wasm_bindgen(method, setter = microseconds)]
12478 pub fn set_microseconds(this: &DurationFormatOptions, value: DurationUnitStyle);
12479
12480 #[wasm_bindgen(method, getter = microsecondsDisplay)]
12481 pub fn get_microseconds_display(
12482 this: &DurationFormatOptions,
12483 ) -> Option<DurationUnitDisplay>;
12484 #[wasm_bindgen(method, setter = microsecondsDisplay)]
12485 pub fn set_microseconds_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12486
12487 #[wasm_bindgen(method, getter = nanoseconds)]
12488 pub fn get_nanoseconds(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
12489 #[wasm_bindgen(method, setter = nanoseconds)]
12490 pub fn set_nanoseconds(this: &DurationFormatOptions, value: DurationUnitStyle);
12491
12492 #[wasm_bindgen(method, getter = nanosecondsDisplay)]
12493 pub fn get_nanoseconds_display(this: &DurationFormatOptions)
12494 -> Option<DurationUnitDisplay>;
12495 #[wasm_bindgen(method, setter = nanosecondsDisplay)]
12496 pub fn set_nanoseconds_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12497
12498 #[wasm_bindgen(method, getter = fractionalDigits)]
12499 pub fn get_fractional_digits(this: &DurationFormatOptions) -> Option<u8>;
12500 #[wasm_bindgen(method, setter = fractionalDigits)]
12501 pub fn set_fractional_digits(this: &DurationFormatOptions, value: u8);
12502 }
12503
12504 impl DurationFormatOptions {
12505 pub fn new() -> DurationFormatOptions {
12506 JsCast::unchecked_into(Object::new())
12507 }
12508 }
12509
12510 impl Default for DurationFormatOptions {
12511 fn default() -> Self {
12512 DurationFormatOptions::new()
12513 }
12514 }
12515
12516 // Intl.ResolvedDurationFormatOptions
12517 #[wasm_bindgen]
12518 extern "C" {
12519 /// Resolved options returned by `Intl.DurationFormat.prototype.resolvedOptions()`.
12520 ///
12521 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/resolvedOptions)
12522 #[wasm_bindgen(extends = DurationFormatOptions)]
12523 #[derive(Clone, Debug)]
12524 pub type ResolvedDurationFormatOptions;
12525
12526 /// The resolved locale string.
12527 #[wasm_bindgen(method, getter = locale)]
12528 pub fn get_locale(this: &ResolvedDurationFormatOptions) -> JsString;
12529
12530 /// The resolved numbering system.
12531 #[wasm_bindgen(method, getter = numberingSystem)]
12532 pub fn get_numbering_system(this: &ResolvedDurationFormatOptions) -> JsString;
12533 }
12534
12535 // Intl.Duration (input object for DurationFormat)
12536 #[wasm_bindgen]
12537 extern "C" {
12538 /// A duration object used as input to `Intl.DurationFormat.format()`.
12539 ///
12540 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/format#duration)
12541 #[wasm_bindgen(extends = Object)]
12542 #[derive(Clone, Debug)]
12543 pub type Duration;
12544
12545 #[wasm_bindgen(method, getter)]
12546 pub fn years(this: &Duration) -> Option<f64>;
12547 #[wasm_bindgen(method, setter)]
12548 pub fn set_years(this: &Duration, value: f64);
12549
12550 #[wasm_bindgen(method, getter)]
12551 pub fn months(this: &Duration) -> Option<f64>;
12552 #[wasm_bindgen(method, setter)]
12553 pub fn set_months(this: &Duration, value: f64);
12554
12555 #[wasm_bindgen(method, getter)]
12556 pub fn weeks(this: &Duration) -> Option<f64>;
12557 #[wasm_bindgen(method, setter)]
12558 pub fn set_weeks(this: &Duration, value: f64);
12559
12560 #[wasm_bindgen(method, getter)]
12561 pub fn days(this: &Duration) -> Option<f64>;
12562 #[wasm_bindgen(method, setter)]
12563 pub fn set_days(this: &Duration, value: f64);
12564
12565 #[wasm_bindgen(method, getter)]
12566 pub fn hours(this: &Duration) -> Option<f64>;
12567 #[wasm_bindgen(method, setter)]
12568 pub fn set_hours(this: &Duration, value: f64);
12569
12570 #[wasm_bindgen(method, getter)]
12571 pub fn minutes(this: &Duration) -> Option<f64>;
12572 #[wasm_bindgen(method, setter)]
12573 pub fn set_minutes(this: &Duration, value: f64);
12574
12575 #[wasm_bindgen(method, getter)]
12576 pub fn seconds(this: &Duration) -> Option<f64>;
12577 #[wasm_bindgen(method, setter)]
12578 pub fn set_seconds(this: &Duration, value: f64);
12579
12580 #[wasm_bindgen(method, getter)]
12581 pub fn milliseconds(this: &Duration) -> Option<f64>;
12582 #[wasm_bindgen(method, setter)]
12583 pub fn set_milliseconds(this: &Duration, value: f64);
12584
12585 #[wasm_bindgen(method, getter)]
12586 pub fn microseconds(this: &Duration) -> Option<f64>;
12587 #[wasm_bindgen(method, setter)]
12588 pub fn set_microseconds(this: &Duration, value: f64);
12589
12590 #[wasm_bindgen(method, getter)]
12591 pub fn nanoseconds(this: &Duration) -> Option<f64>;
12592 #[wasm_bindgen(method, setter)]
12593 pub fn set_nanoseconds(this: &Duration, value: f64);
12594 }
12595
12596 impl Duration {
12597 pub fn new() -> Duration {
12598 JsCast::unchecked_into(Object::new())
12599 }
12600 }
12601
12602 impl Default for Duration {
12603 fn default() -> Self {
12604 Duration::new()
12605 }
12606 }
12607
12608 // Intl.DurationFormatPart
12609 #[wasm_bindgen]
12610 extern "C" {
12611 /// A part of the formatted duration returned by `formatToParts()`.
12612 ///
12613 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/formatToParts)
12614 #[wasm_bindgen(extends = Object)]
12615 #[derive(Clone, Debug)]
12616 pub type DurationFormatPart;
12617
12618 /// The type of the part.
12619 #[wasm_bindgen(method, getter = type)]
12620 pub fn type_(this: &DurationFormatPart) -> DurationFormatPartType;
12621
12622 /// The value of the part.
12623 #[wasm_bindgen(method, getter)]
12624 pub fn value(this: &DurationFormatPart) -> JsString;
12625
12626 /// The unit this part represents (if applicable).
12627 #[wasm_bindgen(method, getter)]
12628 pub fn unit(this: &DurationFormatPart) -> Option<JsString>;
12629 }
12630
12631 // Intl.DurationFormat
12632 #[wasm_bindgen]
12633 extern "C" {
12634 /// The `Intl.DurationFormat` object enables language-sensitive duration formatting.
12635 ///
12636 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat)
12637 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.DurationFormat")]
12638 #[derive(Clone, Debug)]
12639 pub type DurationFormat;
12640
12641 /// Creates a new `Intl.DurationFormat` object.
12642 ///
12643 /// Throws a `RangeError` if locales or options contain invalid values.
12644 ///
12645 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat)
12646 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
12647 pub fn new(
12648 locales: &[JsString],
12649 options: &DurationFormatOptions,
12650 ) -> Result<DurationFormat, JsValue>;
12651
12652 /// Formats a duration according to the locale and formatting options.
12653 ///
12654 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/format)
12655 #[wasm_bindgen(method, js_class = "Intl.DurationFormat")]
12656 pub fn format(this: &DurationFormat, duration: &Duration) -> JsString;
12657
12658 /// Returns an array of objects representing the formatted duration in parts.
12659 ///
12660 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/formatToParts)
12661 #[wasm_bindgen(method, js_class = "Intl.DurationFormat", js_name = formatToParts)]
12662 pub fn format_to_parts(
12663 this: &DurationFormat,
12664 duration: &Duration,
12665 ) -> Array<DurationFormatPart>;
12666
12667 /// Returns an object with properties reflecting the options used.
12668 ///
12669 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/resolvedOptions)
12670 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
12671 pub fn resolved_options(this: &DurationFormat) -> ResolvedDurationFormatOptions;
12672
12673 /// Returns an array of supported locales.
12674 ///
12675 /// Throws a `RangeError` if locales contain invalid values.
12676 ///
12677 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/supportedLocalesOf)
12678 #[wasm_bindgen(static_method_of = DurationFormat, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
12679 pub fn supported_locales_of(
12680 locales: &[JsString],
12681 options: &LocaleMatcherOptions,
12682 ) -> Result<Array<JsString>, JsValue>;
12683 }
12684
12685 impl Default for DurationFormat {
12686 fn default() -> Self {
12687 Self::new(&[], &Default::default()).unwrap()
12688 }
12689 }
12690}
12691
12692#[wasm_bindgen]
12693extern "C" {
12694 /// The `PromiseState` object represents the the status of the promise,
12695 /// as used in `allSettled`.
12696 ///
12697 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled)
12698 #[must_use]
12699 #[wasm_bindgen(extends = Object, typescript_type = "any")]
12700 #[derive(Clone, Debug)]
12701 pub type PromiseState<T = JsValue>;
12702
12703 /// A string, either "fulfilled" or "rejected", indicating the eventual state of the promise.
12704 #[wasm_bindgen(method, getter = status)]
12705 pub fn get_status<T>(this: &PromiseState<T>) -> String;
12706
12707 /// Only present if status is "fulfilled". The value that the promise was fulfilled with.
12708 #[wasm_bindgen(method, getter = value)]
12709 pub fn get_value<T>(this: &PromiseState<T>) -> Option<T>;
12710
12711 /// Only present if status is "rejected". The reason that the promise was rejected with.
12712 #[wasm_bindgen(method, getter = reason)]
12713 pub fn get_reason<T>(this: &PromiseState<T>) -> Option<JsValue>;
12714}
12715
12716impl<T> PromiseState<T> {
12717 pub fn is_fulfilled(&self) -> bool {
12718 self.get_status() == "fulfilled"
12719 }
12720
12721 pub fn is_rejected(&self) -> bool {
12722 self.get_status() == "rejected"
12723 }
12724}
12725
12726// Promise
12727#[wasm_bindgen]
12728extern "C" {
12729 /// The `Promise` object represents the eventual completion (or failure) of
12730 /// an asynchronous operation, and its resulting value.
12731 ///
12732 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
12733 #[must_use]
12734 #[wasm_bindgen(extends = Object, typescript_type = "Promise<any>", no_promising)]
12735 #[derive(Clone, Debug)]
12736 pub type Promise<T = JsValue>;
12737
12738 /// Creates a new `Promise` with the provided executor `cb`
12739 ///
12740 /// The `cb` is a function that is passed with the arguments `resolve` and
12741 /// `reject`. The `cb` function is executed immediately by the `Promise`
12742 /// implementation, passing `resolve` and `reject` functions (the executor
12743 /// is called before the `Promise` constructor even returns the created
12744 /// object). The `resolve` and `reject` functions, when called, resolve or
12745 /// reject the promise, respectively. The executor normally initiates
12746 /// some asynchronous work, and then, once that completes, either calls
12747 /// the `resolve` function to resolve the promise or else rejects it if an
12748 /// error occurred.
12749 ///
12750 /// If an error is thrown in the executor function, the promise is rejected.
12751 /// The return value of the executor is ignored.
12752 ///
12753 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
12754 #[cfg(not(js_sys_unstable_apis))]
12755 #[wasm_bindgen(constructor)]
12756 pub fn new(cb: &mut dyn FnMut(Function, Function)) -> Promise;
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(js_sys_unstable_apis)]
12775 #[wasm_bindgen(constructor)]
12776 pub fn new<'a, T: JsGeneric>(
12777 cb: ImmediateClosure<
12778 'a,
12779 dyn FnMut(Function<fn(T) -> Undefined>, Function<fn(JsValue) -> Undefined>) + 'a,
12780 >,
12781 ) -> Promise<T>;
12782
12783 // Next major: deprecate
12784 /// Creates a new `Promise` with the provided executor `cb`
12785 ///
12786 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
12787 #[wasm_bindgen(constructor)]
12788 pub fn new_typed<'a, T: JsGeneric>(
12789 cb: ImmediateClosure<
12790 'a,
12791 dyn FnMut(Function<fn(T) -> Undefined>, Function<fn(JsValue) -> Undefined>) + 'a,
12792 >,
12793 ) -> Promise<T>;
12794
12795 /// The `Promise.all(iterable)` method returns a single `Promise` that
12796 /// resolves when all of the promises in the iterable argument have resolved
12797 /// or when the iterable argument contains no promises. It rejects with the
12798 /// reason of the first promise that rejects.
12799 ///
12800 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all)
12801 #[cfg(not(js_sys_unstable_apis))]
12802 #[wasm_bindgen(static_method_of = Promise)]
12803 pub fn all(obj: &JsValue) -> Promise;
12804
12805 /// The `Promise.all(iterable)` method returns a single `Promise` that
12806 /// resolves when all of the promises in the iterable argument have resolved
12807 /// or when the iterable argument contains no promises. It rejects with the
12808 /// reason of the first promise that rejects.
12809 ///
12810 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all)
12811 #[cfg(js_sys_unstable_apis)]
12812 #[wasm_bindgen(static_method_of = Promise, js_name = all)]
12813 pub fn all<I: Iterable>(obj: &I) -> Promise<Array<<I::Item as Promising>::Resolution>>
12814 where
12815 I::Item: Promising;
12816
12817 // Next major: deprecate
12818 /// The `Promise.all(iterable)` method returns a single `Promise` that
12819 /// resolves when all of the promises in the iterable argument have resolved
12820 /// or when the iterable argument contains no promises. It rejects with the
12821 /// reason of the first promise that rejects.
12822 ///
12823 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all)
12824 #[wasm_bindgen(static_method_of = Promise, js_name = all)]
12825 pub fn all_iterable<I: Iterable>(obj: &I) -> Promise<Array<<I::Item as Promising>::Resolution>>
12826 where
12827 I::Item: Promising;
12828
12829 /// The `Promise.allSettled(iterable)` method returns a single `Promise` that
12830 /// resolves when all of the promises in the iterable argument have either
12831 /// fulfilled or rejected or when the iterable argument contains no promises.
12832 ///
12833 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled)
12834 #[cfg(not(js_sys_unstable_apis))]
12835 #[wasm_bindgen(static_method_of = Promise, js_name = allSettled)]
12836 pub fn all_settled(obj: Object) -> Promise;
12837
12838 /// The `Promise.allSettled(iterable)` method returns a single `Promise` that
12839 /// resolves when all of the promises in the iterable argument have either
12840 /// fulfilled or rejected or when the iterable argument contains no promises.
12841 ///
12842 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled)
12843 #[cfg(js_sys_unstable_apis)]
12844 #[wasm_bindgen(static_method_of = Promise, js_name = allSettled)]
12845 pub fn all_settled<I: Iterable>(
12846 obj: &I,
12847 ) -> Promise<Array<PromiseState<<I::Item as Promising>::Resolution>>>
12848 where
12849 I::Item: Promising;
12850
12851 // Next major: deprecate
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 #[wasm_bindgen(static_method_of = Promise, js_name = allSettled)]
12858 pub fn all_settled_iterable<I: Iterable>(
12859 obj: &I,
12860 ) -> Promise<Array<PromiseState<<I::Item as Promising>::Resolution>>>
12861 where
12862 I::Item: Promising;
12863
12864 /// The `Promise.any(iterable)` method returns a single `Promise` that
12865 /// resolves when any of the promises in the iterable argument have resolved
12866 /// or when the iterable argument contains no promises. It rejects with an
12867 /// `AggregateError` if all promises in the iterable rejected.
12868 ///
12869 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/any)
12870 #[cfg(not(js_sys_unstable_apis))]
12871 #[wasm_bindgen(static_method_of = Promise)]
12872 pub fn any(obj: &JsValue) -> Promise;
12873
12874 /// The `Promise.any(iterable)` method returns a single `Promise` that
12875 /// resolves when any of the promises in the iterable argument have resolved
12876 /// or when the iterable argument contains no promises. It rejects with an
12877 /// `AggregateError` if all promises in the iterable rejected.
12878 ///
12879 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/any)
12880 #[cfg(js_sys_unstable_apis)]
12881 #[wasm_bindgen(static_method_of = Promise, js_name = any)]
12882 pub fn any<I: Iterable>(obj: &I) -> Promise<<I::Item as Promising>::Resolution>
12883 where
12884 I::Item: Promising;
12885
12886 // Next major: deprecate
12887 /// The `Promise.any(iterable)` method returns a single `Promise` that
12888 /// resolves when any of the promises in the iterable argument have resolved
12889 /// or when the iterable argument contains no promises. It rejects with an
12890 /// `AggregateError` if all promises in the iterable rejected.
12891 ///
12892 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/any)
12893 #[cfg(not(js_sys_unstable_apis))]
12894 #[wasm_bindgen(static_method_of = Promise, js_name = any)]
12895 pub fn any_iterable<I: Iterable>(obj: &I) -> Promise<<I::Item as Promising>::Resolution>
12896 where
12897 I::Item: Promising;
12898
12899 /// The `Promise.race(iterable)` method returns a promise that resolves or
12900 /// rejects as soon as one of the promises in the iterable resolves or
12901 /// rejects, with the value or reason from that promise.
12902 ///
12903 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/race)
12904 #[cfg(not(js_sys_unstable_apis))]
12905 #[wasm_bindgen(static_method_of = Promise)]
12906 pub fn race(obj: &JsValue) -> Promise;
12907
12908 /// The `Promise.race(iterable)` method returns a promise that resolves or
12909 /// rejects as soon as one of the promises in the iterable resolves or
12910 /// rejects, with the value or reason from that promise.
12911 ///
12912 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/race)
12913 #[cfg(js_sys_unstable_apis)]
12914 #[wasm_bindgen(static_method_of = Promise, js_name = race)]
12915 pub fn race<I: Iterable>(obj: &I) -> Promise<<I::Item as Promising>::Resolution>
12916 where
12917 I::Item: Promising;
12918
12919 // Next major: deprecate
12920 /// The `Promise.race(iterable)` method returns a promise that resolves or
12921 /// rejects as soon as one of the promises in the iterable resolves or
12922 /// rejects, with the value or reason from that promise.
12923 ///
12924 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/race)
12925 #[wasm_bindgen(static_method_of = Promise, js_name = race)]
12926 pub fn race_iterable<I: Iterable>(obj: &I) -> Promise<<I::Item as Promising>::Resolution>
12927 where
12928 I::Item: Promising;
12929
12930 /// The `Promise.reject(reason)` method returns a `Promise` object that is
12931 /// rejected with the given reason.
12932 ///
12933 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/reject)
12934 #[cfg(not(js_sys_unstable_apis))]
12935 #[wasm_bindgen(static_method_of = Promise)]
12936 pub fn reject(obj: &JsValue) -> Promise;
12937
12938 /// The `Promise.reject(reason)` method returns a `Promise` object that is
12939 /// rejected with the given reason.
12940 ///
12941 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/reject)
12942 #[cfg(js_sys_unstable_apis)]
12943 #[wasm_bindgen(static_method_of = Promise, js_name = reject)]
12944 pub fn reject<T>(obj: &JsValue) -> Promise<T>;
12945
12946 // Next major: deprecate
12947 /// The `Promise.reject(reason)` method returns a `Promise` object that is
12948 /// rejected with the given reason.
12949 ///
12950 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/reject)
12951 #[wasm_bindgen(static_method_of = Promise, js_name = reject)]
12952 pub fn reject_typed<T>(obj: &JsValue) -> Promise<T>;
12953
12954 /// The `Promise.resolve(value)` method returns a `Promise` object that is
12955 /// resolved with the given value. If the value is a promise, that promise
12956 /// is returned; if the value is a thenable (i.e. has a "then" method), the
12957 /// returned promise will "follow" that thenable, adopting its eventual
12958 /// state; otherwise the returned promise will be fulfilled with the value.
12959 ///
12960 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/resolve)
12961 #[wasm_bindgen(static_method_of = Promise, js_name = resolve)]
12962 pub fn resolve<U: Promising>(obj: &U) -> Promise<U::Resolution>;
12963
12964 /// The `catch()` method returns a `Promise` and deals with rejected cases
12965 /// only. It behaves the same as calling `Promise.prototype.then(undefined,
12966 /// onRejected)` (in fact, calling `obj.catch(onRejected)` internally calls
12967 /// `obj.then(undefined, onRejected)`).
12968 ///
12969 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch)
12970 #[cfg(not(js_sys_unstable_apis))]
12971 #[wasm_bindgen(method)]
12972 pub fn catch<T>(this: &Promise<T>, cb: &ScopedClosure<dyn FnMut(JsValue)>) -> Promise<JsValue>;
12973
12974 /// The `catch()` method returns a `Promise` and deals with rejected cases
12975 /// only. It behaves the same as calling `Promise.prototype.then(undefined,
12976 /// onRejected)` (in fact, calling `obj.catch(onRejected)` internally calls
12977 /// `obj.then(undefined, onRejected)`).
12978 ///
12979 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch)
12980 #[cfg(js_sys_unstable_apis)]
12981 #[wasm_bindgen(method, js_name = catch)]
12982 pub fn catch<'a, T, R: Promising>(
12983 this: &Promise<T>,
12984 cb: &ScopedClosure<'a, dyn FnMut(T) -> Result<R, JsError>>,
12985 ) -> Promise<R::Resolution>;
12986
12987 // Next major: deprecate
12988 /// Same as `catch`, but returning a result to become the new Promise value.
12989 #[wasm_bindgen(method, js_name = catch)]
12990 pub fn catch_map<'a, T, R: Promising>(
12991 this: &Promise<T>,
12992 cb: &ScopedClosure<'a, dyn FnMut(T) -> Result<R, JsError>>,
12993 ) -> Promise<R::Resolution>;
12994
12995 /// The `then()` method returns a `Promise`. It takes up to two arguments:
12996 /// callback functions for the success and failure cases of the `Promise`.
12997 ///
12998 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then)
12999 #[cfg(not(js_sys_unstable_apis))]
13000 #[wasm_bindgen(method)]
13001 pub fn then<'a, T>(this: &Promise<T>, cb: &ScopedClosure<'a, dyn FnMut(T)>)
13002 -> Promise<JsValue>;
13003
13004 /// The `then()` method returns a `Promise`. It takes up to two arguments:
13005 /// callback functions for the success and failure cases of the `Promise`.
13006 ///
13007 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then)
13008 #[cfg(js_sys_unstable_apis)]
13009 #[wasm_bindgen(method, js_name = then)]
13010 pub fn then<'a, T, R: Promising>(
13011 this: &Promise<T>,
13012 cb: &ScopedClosure<'a, dyn FnMut(T) -> Result<R, JsError>>,
13013 ) -> Promise<R::Resolution>;
13014
13015 /// The `then()` method returns a `Promise`. It takes up to two arguments:
13016 /// callback functions for the success and failure cases of the `Promise`.
13017 ///
13018 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then)
13019 #[wasm_bindgen(method, js_name = then)]
13020 pub fn then_with_reject<'a, T, R: Promising>(
13021 this: &Promise<T>,
13022 resolve: &ScopedClosure<'a, dyn FnMut(T) -> Result<R, JsError>>,
13023 reject: &ScopedClosure<'a, dyn FnMut(JsValue) -> Result<R, JsError>>,
13024 ) -> Promise<R::Resolution>;
13025
13026 // Next major: deprecate
13027 /// Alias for `then()` with a return value.
13028 /// The `then()` method returns a `Promise`. It takes up to two arguments:
13029 /// callback functions for the success and failure cases of the `Promise`.
13030 ///
13031 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then)
13032 #[wasm_bindgen(method, js_name = then)]
13033 pub fn then_map<'a, T, R: Promising>(
13034 this: &Promise<T>,
13035 cb: &ScopedClosure<'a, dyn FnMut(T) -> Result<R, JsError>>,
13036 ) -> Promise<R::Resolution>;
13037
13038 /// The `finally()` method returns a `Promise`. When the promise is settled,
13039 /// whether fulfilled or rejected, the specified callback function is
13040 /// executed. This provides a way for code that must be executed once the
13041 /// `Promise` has been dealt with to be run whether the promise was
13042 /// fulfilled successfully or rejected.
13043 ///
13044 /// This lets you avoid duplicating code in both the promise's `then()` and
13045 /// `catch()` handlers.
13046 ///
13047 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/finally)
13048 #[wasm_bindgen(method)]
13049 pub fn finally<T>(this: &Promise<T>, cb: &ScopedClosure<dyn FnMut()>) -> Promise<JsValue>;
13050}
13051
13052impl<T: JsGeneric> Promising for Promise<T> {
13053 type Resolution = T;
13054}
13055
13056/// Returns a handle to the global scope object.
13057///
13058/// This allows access to the global properties and global names by accessing
13059/// the `Object` returned.
13060pub fn global() -> Object {
13061 use once_cell::unsync::Lazy;
13062
13063 struct Wrapper<T>(Lazy<T>);
13064
13065 #[cfg(not(target_feature = "atomics"))]
13066 unsafe impl<T> Sync for Wrapper<T> {}
13067
13068 #[cfg(not(target_feature = "atomics"))]
13069 unsafe impl<T> Send for Wrapper<T> {}
13070
13071 #[cfg_attr(target_feature = "atomics", thread_local)]
13072 static GLOBAL: Wrapper<Object> = Wrapper(Lazy::new(get_global_object));
13073
13074 return GLOBAL.0.clone();
13075
13076 fn get_global_object() -> Object {
13077 // Accessing the global object is not an easy thing to do, and what we
13078 // basically want is `globalThis` but we can't rely on that existing
13079 // everywhere. In the meantime we've got the fallbacks mentioned in:
13080 //
13081 // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis
13082 //
13083 // Note that this is pretty heavy code-size wise but it at least gets
13084 // the job largely done for now and avoids the `Function` constructor at
13085 // the end which triggers CSP errors.
13086 #[wasm_bindgen]
13087 extern "C" {
13088 type Global;
13089
13090 #[wasm_bindgen(thread_local_v2, js_name = globalThis)]
13091 static GLOBAL_THIS: Option<Object>;
13092
13093 #[wasm_bindgen(thread_local_v2, js_name = self)]
13094 static SELF: Option<Object>;
13095
13096 #[wasm_bindgen(thread_local_v2, js_name = window)]
13097 static WINDOW: Option<Object>;
13098
13099 #[wasm_bindgen(thread_local_v2, js_name = global)]
13100 static GLOBAL: Option<Object>;
13101 }
13102
13103 // The order is important: in Firefox Extension Content Scripts `globalThis`
13104 // is a Sandbox (not Window), so `globalThis` must be checked after `window`.
13105 let static_object = SELF
13106 .with(Option::clone)
13107 .or_else(|| WINDOW.with(Option::clone))
13108 .or_else(|| GLOBAL_THIS.with(Option::clone))
13109 .or_else(|| GLOBAL.with(Option::clone));
13110 if let Some(obj) = static_object {
13111 if !obj.is_undefined() {
13112 return obj;
13113 }
13114 }
13115
13116 // Global object not found
13117 JsValue::undefined().unchecked_into()
13118 }
13119}
13120
13121macro_rules! arrays {
13122 ($(#[doc = $ctor:literal] #[doc = $mdn:literal] $name:ident: $ty:ident,)*) => ($(
13123 #[wasm_bindgen]
13124 extern "C" {
13125 #[wasm_bindgen(extends = Object, typescript_type = $name)]
13126 #[derive(Clone, Debug)]
13127 pub type $name;
13128
13129 /// The
13130 #[doc = $ctor]
13131 /// constructor creates a new array.
13132 ///
13133 /// [MDN documentation](
13134 #[doc = $mdn]
13135 /// )
13136 #[wasm_bindgen(constructor)]
13137 pub fn new(constructor_arg: &JsValue) -> $name;
13138
13139 /// An
13140 #[doc = $ctor]
13141 /// which creates an array with an internal buffer large
13142 /// enough for `length` elements.
13143 ///
13144 /// [MDN documentation](
13145 #[doc = $mdn]
13146 /// )
13147 #[wasm_bindgen(constructor)]
13148 pub fn new_with_length(length: u32) -> $name;
13149
13150 /// An
13151 #[doc = $ctor]
13152 /// which creates an array from a Rust slice.
13153 ///
13154 /// [MDN documentation](
13155 #[doc = $mdn]
13156 /// )
13157 #[wasm_bindgen(constructor)]
13158 pub fn new_from_slice(slice: &[$ty]) -> $name;
13159
13160 /// An
13161 #[doc = $ctor]
13162 /// which creates an array with the given buffer but is a
13163 /// view starting at `byte_offset`.
13164 ///
13165 /// [MDN documentation](
13166 #[doc = $mdn]
13167 /// )
13168 #[wasm_bindgen(constructor)]
13169 pub fn new_with_byte_offset(buffer: &JsValue, byte_offset: u32) -> $name;
13170
13171 /// An
13172 #[doc = $ctor]
13173 /// which creates an array with the given buffer but is a
13174 /// view starting at `byte_offset` for `length` elements.
13175 ///
13176 /// [MDN documentation](
13177 #[doc = $mdn]
13178 /// )
13179 #[wasm_bindgen(constructor)]
13180 pub fn new_with_byte_offset_and_length(
13181 buffer: &JsValue,
13182 byte_offset: u32,
13183 length: u32,
13184 ) -> $name;
13185
13186 /// The `fill()` method fills all the elements of an array from a start index
13187 /// to an end index with a static value. The end index is not included.
13188 ///
13189 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/fill)
13190 #[wasm_bindgen(method)]
13191 pub fn fill(this: &$name, value: $ty, start: u32, end: u32) -> $name;
13192
13193 /// The buffer accessor property represents the `ArrayBuffer` referenced
13194 /// by a `TypedArray` at construction time.
13195 #[wasm_bindgen(getter, method)]
13196 pub fn buffer(this: &$name) -> ArrayBuffer;
13197
13198 /// The `subarray()` method returns a new `TypedArray` on the same
13199 /// `ArrayBuffer` store and with the same element types as for this
13200 /// `TypedArray` object.
13201 #[wasm_bindgen(method)]
13202 pub fn subarray(this: &$name, begin: u32, end: u32) -> $name;
13203
13204 /// The `slice()` method returns a shallow copy of a portion of a typed
13205 /// array into a new typed array object. This method has the same algorithm
13206 /// as `Array.prototype.slice()`.
13207 #[wasm_bindgen(method)]
13208 pub fn slice(this: &$name, begin: u32, end: u32) -> $name;
13209
13210 /// The `forEach()` method executes a provided function once per array
13211 /// element. This method has the same algorithm as
13212 /// `Array.prototype.forEach()`. `TypedArray` is one of the typed array
13213 /// types here.
13214 #[wasm_bindgen(method, js_name = forEach)]
13215 pub fn for_each(this: &$name, callback: &mut dyn FnMut($ty, u32, $name));
13216
13217 /// The `forEach()` method executes a provided function once per array
13218 /// element. This method has the same algorithm as
13219 /// `Array.prototype.forEach()`. `TypedArray` is one of the typed array
13220 /// types here.
13221 #[wasm_bindgen(method, js_name = forEach, catch)]
13222 pub fn try_for_each<'a>(this: &$name, callback: ImmediateClosure<'a, dyn FnMut($ty, u32, $name) -> Result<(), JsError> + 'a>) -> Result<(), JsValue>;
13223
13224 /// The length accessor property represents the length (in elements) of a
13225 /// typed array.
13226 #[wasm_bindgen(method, getter)]
13227 pub fn length(this: &$name) -> u32;
13228
13229 /// The byteLength accessor property represents the length (in bytes) of a
13230 /// typed array.
13231 #[wasm_bindgen(method, getter, js_name = byteLength)]
13232 pub fn byte_length(this: &$name) -> u32;
13233
13234 /// The byteOffset accessor property represents the offset (in bytes) of a
13235 /// typed array from the start of its `ArrayBuffer`.
13236 #[wasm_bindgen(method, getter, js_name = byteOffset)]
13237 pub fn byte_offset(this: &$name) -> u32;
13238
13239 /// The `set()` method stores multiple values in the typed array, reading
13240 /// input values from a specified array.
13241 #[wasm_bindgen(method)]
13242 pub fn set(this: &$name, src: &JsValue, offset: u32);
13243
13244 /// Gets the value at `idx`, counting from the end if negative.
13245 #[wasm_bindgen(method)]
13246 pub fn at(this: &$name, idx: i32) -> Option<$ty>;
13247
13248 /// The `copyWithin()` method shallow copies part of a typed array to another
13249 /// location in the same typed array and returns it, without modifying its size.
13250 ///
13251 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin)
13252 #[wasm_bindgen(method, js_name = copyWithin)]
13253 pub fn copy_within(this: &$name, target: i32, start: i32, end: i32) -> $name;
13254
13255 /// Gets the value at `idx`, equivalent to the javascript `my_var = arr[idx]`.
13256 #[wasm_bindgen(method, indexing_getter)]
13257 pub fn get_index(this: &$name, idx: u32) -> $ty;
13258
13259 /// Sets the value at `idx`, equivalent to the javascript `arr[idx] = value`.
13260 #[wasm_bindgen(method, indexing_setter)]
13261 pub fn set_index(this: &$name, idx: u32, value: $ty);
13262
13263 /// Copies the Rust slice's data to self.
13264 ///
13265 /// This method is not expected to be public. It requires the length of the
13266 /// TypedArray to be the same as the slice, use `self.copy_from(slice)` instead.
13267 #[wasm_bindgen(method, js_name = set)]
13268 fn copy_from_slice(this: &$name, slice: &[$ty]);
13269
13270 /// Copies this TypedArray's data to Rust slice;
13271 ///
13272 /// This method is not expected to be public. It requires the length of the
13273 /// TypedArray to be the same as the slice, use `self.copy_to(slice)` instead.
13274 ///
13275 /// # Workaround
13276 ///
13277 /// We actually need `slice.set(typed_array)` here, but since slice cannot be treated as
13278 /// `Uint8Array` on the Rust side, we use `Uint8Array.prototype.set.call`, which allows
13279 /// us to specify the `this` value inside the function.
13280 ///
13281 /// Therefore, `Uint8Array.prototype.set.call(slice, typed_array)` is equivalent to
13282 /// `slice.set(typed_array)`.
13283 #[wasm_bindgen(js_namespace = $name, js_name = "prototype.set.call")]
13284 fn copy_to_slice(slice: &mut [$ty], this: &$name);
13285 }
13286
13287 impl $name {
13288 /// Creates a JS typed array which is a view into wasm's linear
13289 /// memory at the slice specified.
13290 ///
13291 /// This function returns a new typed array which is a view into
13292 /// wasm's memory. This view does not copy the underlying data.
13293 ///
13294 /// # Safety
13295 ///
13296 /// Views into WebAssembly memory are only valid so long as the
13297 /// backing buffer isn't resized in JS. Once this function is called
13298 /// any future calls to `Box::new` (or malloc of any form) may cause
13299 /// the returned value here to be invalidated. Use with caution!
13300 ///
13301 /// Additionally the returned object can be safely mutated but the
13302 /// input slice isn't guaranteed to be mutable.
13303 ///
13304 /// Finally, the returned object is disconnected from the input
13305 /// slice's lifetime, so there's no guarantee that the data is read
13306 /// at the right time.
13307 pub unsafe fn view(rust: &[$ty]) -> $name {
13308 wasm_bindgen::__rt::wbg_cast(rust)
13309 }
13310
13311 /// Creates a JS typed array which is a view into wasm's linear
13312 /// memory at the specified pointer with specified length.
13313 ///
13314 /// This function returns a new typed array which is a view into
13315 /// wasm's memory. This view does not copy the underlying data.
13316 ///
13317 /// # Safety
13318 ///
13319 /// Views into WebAssembly memory are only valid so long as the
13320 /// backing buffer isn't resized in JS. Once this function is called
13321 /// any future calls to `Box::new` (or malloc of any form) may cause
13322 /// the returned value here to be invalidated. Use with caution!
13323 ///
13324 /// Additionally the returned object can be safely mutated,
13325 /// the changes are guaranteed to be reflected in the input array.
13326 pub unsafe fn view_mut_raw(ptr: *mut $ty, length: usize) -> $name {
13327 let slice = core::slice::from_raw_parts_mut(ptr, length);
13328 Self::view(slice)
13329 }
13330
13331 /// Copy the contents of this JS typed array into the destination
13332 /// Rust pointer.
13333 ///
13334 /// This function will efficiently copy the memory from a typed
13335 /// array into this Wasm module's own linear memory, initializing
13336 /// the memory destination provided.
13337 ///
13338 /// # Safety
13339 ///
13340 /// This function requires `dst` to point to a buffer
13341 /// large enough to fit this array's contents.
13342 pub unsafe fn raw_copy_to_ptr(&self, dst: *mut $ty) {
13343 let slice = core::slice::from_raw_parts_mut(dst, self.length() as usize);
13344 self.copy_to(slice);
13345 }
13346
13347 /// Copy the contents of this JS typed array into the destination
13348 /// Rust slice.
13349 ///
13350 /// This function will efficiently copy the memory from a typed
13351 /// array into this Wasm module's own linear memory, initializing
13352 /// the memory destination provided.
13353 ///
13354 /// # Panics
13355 ///
13356 /// This function will panic if this typed array's length is
13357 /// different than the length of the provided `dst` array.
13358 pub fn copy_to(&self, dst: &mut [$ty]) {
13359 core::assert_eq!(self.length() as usize, dst.len());
13360 $name::copy_to_slice(dst, self);
13361 }
13362
13363 /// Copy the contents of this JS typed array into the destination
13364 /// Rust slice.
13365 ///
13366 /// This function will efficiently copy the memory from a typed
13367 /// array into this Wasm module's own linear memory, initializing
13368 /// the memory destination provided.
13369 ///
13370 /// # Panics
13371 ///
13372 /// This function will panic if this typed array's length is
13373 /// different than the length of the provided `dst` array.
13374 pub fn copy_to_uninit<'dst>(&self, dst: &'dst mut [MaybeUninit<$ty>]) -> &'dst mut [$ty] {
13375 core::assert_eq!(self.length() as usize, dst.len());
13376 let dst = unsafe { &mut *(dst as *mut [MaybeUninit<$ty>] as *mut [$ty]) };
13377 self.copy_to(dst);
13378 dst
13379 }
13380
13381 /// Copy the contents of the source Rust slice into this
13382 /// JS typed array.
13383 ///
13384 /// This function will efficiently copy the memory from within
13385 /// the Wasm module's own linear memory to this typed array.
13386 ///
13387 /// # Panics
13388 ///
13389 /// This function will panic if this typed array's length is
13390 /// different than the length of the provided `src` array.
13391 pub fn copy_from(&self, src: &[$ty]) {
13392 core::assert_eq!(self.length() as usize, src.len());
13393 self.copy_from_slice(src);
13394 }
13395
13396 /// Efficiently copies the contents of this JS typed array into a new Vec.
13397 pub fn to_vec(&self) -> Vec<$ty> {
13398 let len = self.length() as usize;
13399 let mut output = Vec::with_capacity(len);
13400 // Safety: the capacity has been set
13401 unsafe {
13402 self.raw_copy_to_ptr(output.as_mut_ptr());
13403 output.set_len(len);
13404 }
13405 output
13406 }
13407 }
13408
13409 impl<'a> From<&'a [$ty]> for $name {
13410 #[inline]
13411 fn from(slice: &'a [$ty]) -> $name {
13412 // This is safe because the `new` function makes a copy if its argument is a TypedArray
13413 $name::new_from_slice(slice)
13414 }
13415 }
13416
13417 impl Default for $name {
13418 fn default() -> Self {
13419 Self::new(&JsValue::UNDEFINED.unchecked_into())
13420 }
13421 }
13422
13423 impl TypedArray for $name {}
13424
13425
13426 )*);
13427}
13428
13429arrays! {
13430 /// `Int8Array()`
13431 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int8Array
13432 Int8Array: i8,
13433
13434 /// `Int16Array()`
13435 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int16Array
13436 Int16Array: i16,
13437
13438 /// `Int32Array()`
13439 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int32Array
13440 Int32Array: i32,
13441
13442 /// `Uint8Array()`
13443 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array
13444 Uint8Array: u8,
13445
13446 /// `Uint8ClampedArray()`
13447 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8ClampedArray
13448 Uint8ClampedArray: u8,
13449
13450 /// `Uint16Array()`
13451 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint16Array
13452 Uint16Array: u16,
13453
13454 /// `Uint32Array()`
13455 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint32Array
13456 Uint32Array: u32,
13457
13458 /// `Float32Array()`
13459 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array
13460 Float32Array: f32,
13461
13462 /// `Float64Array()`
13463 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float64Array
13464 Float64Array: f64,
13465
13466 /// `BigInt64Array()`
13467 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt64Array
13468 BigInt64Array: i64,
13469
13470 /// `BigUint64Array()`
13471 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigUint64Array
13472 BigUint64Array: u64,
13473}