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::marker::PhantomData;
43use core::mem::MaybeUninit;
44use core::ops::{Add, BitAnd, BitOr, BitXor, Div, Mul, Neg, Not, Rem, Shl, Shr, Sub};
45use core::str;
46use core::str::FromStr;
47pub use wasm_bindgen;
48use wasm_bindgen::closure::{ScopedClosure, WasmClosure};
49use wasm_bindgen::convert::{FromWasmAbi, IntoWasmAbi, Upcast, UpcastFrom};
50use wasm_bindgen::prelude::*;
51use wasm_bindgen::JsError;
52
53// Re-export sys types as js-sys types
54pub use wasm_bindgen::sys::{JsOption, Null, Promising, Undefined};
55pub use wasm_bindgen::JsGeneric;
56
57// When adding new imports:
58//
59// * Keep imports in alphabetical order.
60//
61// * Rename imports with `js_name = ...` according to the note about `camelCase`
62// and `snake_case` in the module's documentation above.
63//
64// * Include the one sentence summary of the import from the MDN link in the
65// module's documentation above, and the MDN link itself.
66//
67// * If a function or method can throw an exception, make it catchable by adding
68// `#[wasm_bindgen(catch)]`.
69//
70// * Add a new `#[test]` into the appropriate file in the
71// `crates/js-sys/tests/wasm/` directory. If the imported function or method
72// can throw an exception, make sure to also add test coverage for that case.
73//
74// * Arguments that are `JsValue`s or imported JavaScript types should be taken
75// by reference.
76//
77// * Name JavaScript's `toString()` method as `to_js_string()` to avoid conflict
78// with Rust's `ToString` trait.
79
80macro_rules! forward_deref_unop {
81 (impl $imp:ident, $method:ident for $t:ty) => {
82 impl $imp for $t {
83 type Output = <&'static $t as $imp>::Output;
84
85 #[inline]
86 fn $method(self) -> Self::Output {
87 $imp::$method(&self)
88 }
89 }
90 };
91 (impl<$($gen:ident),+> $imp:ident, $method:ident for $t:ty) => {
92 impl<$($gen),+> $imp for $t {
93 type Output = <&'static $t as $imp>::Output;
94
95 #[inline]
96 fn $method(self) -> Self::Output {
97 $imp::$method(&self)
98 }
99 }
100 };
101}
102
103macro_rules! forward_deref_binop {
104 (impl $imp:ident, $method:ident for $t:ty) => {
105 impl<'a> $imp<$t> for &'a $t {
106 type Output = <&'static $t as $imp<&'static $t>>::Output;
107
108 #[inline]
109 fn $method(self, other: $t) -> Self::Output {
110 $imp::$method(self, &other)
111 }
112 }
113
114 impl $imp<&$t> for $t {
115 type Output = <&'static $t as $imp<&'static $t>>::Output;
116
117 #[inline]
118 fn $method(self, other: &$t) -> Self::Output {
119 $imp::$method(&self, other)
120 }
121 }
122
123 impl $imp<$t> for $t {
124 type Output = <&'static $t as $imp<&'static $t>>::Output;
125
126 #[inline]
127 fn $method(self, other: $t) -> Self::Output {
128 $imp::$method(&self, &other)
129 }
130 }
131 };
132 (impl<$($gen:ident),+> $imp:ident, $method:ident for $t:ty) => {
133 impl<'a, $($gen),+> $imp<$t> for &'a $t {
134 type Output = <&'static $t as $imp<&'static $t>>::Output;
135
136 #[inline]
137 fn $method(self, other: $t) -> Self::Output {
138 $imp::$method(self, &other)
139 }
140 }
141
142 impl<$($gen),+> $imp<&$t> for $t {
143 type Output = <&'static $t as $imp<&'static $t>>::Output;
144
145 #[inline]
146 fn $method(self, other: &$t) -> Self::Output {
147 $imp::$method(&self, other)
148 }
149 }
150
151 impl<$($gen),+> $imp<$t> for $t {
152 type Output = <&'static $t as $imp<&'static $t>>::Output;
153
154 #[inline]
155 fn $method(self, other: $t) -> Self::Output {
156 $imp::$method(&self, &other)
157 }
158 }
159 };
160}
161
162macro_rules! forward_js_unop {
163 (impl $imp:ident, $method:ident for $t:ty) => {
164 impl $imp for &$t {
165 type Output = $t;
166
167 #[inline]
168 fn $method(self) -> Self::Output {
169 $imp::$method(JsValue::as_ref(self)).unchecked_into()
170 }
171 }
172
173 forward_deref_unop!(impl $imp, $method for $t);
174 };
175 (impl<$($gen:ident),+> $imp:ident, $method:ident for $t:ty) => {
176 impl<$($gen),+> $imp for &$t {
177 type Output = $t;
178
179 #[inline]
180 fn $method(self) -> Self::Output {
181 $imp::$method(JsValue::as_ref(self)).unchecked_into()
182 }
183 }
184
185 forward_deref_unop!(impl<$($gen),+> $imp, $method for $t);
186 };
187}
188
189macro_rules! forward_js_binop {
190 (impl $imp:ident, $method:ident for $t:ty) => {
191 impl $imp<&$t> for &$t {
192 type Output = $t;
193
194 #[inline]
195 fn $method(self, other: &$t) -> Self::Output {
196 $imp::$method(JsValue::as_ref(self), JsValue::as_ref(other)).unchecked_into()
197 }
198 }
199
200 forward_deref_binop!(impl $imp, $method for $t);
201 };
202 (impl<$($gen:ident),+> $imp:ident, $method:ident for $t:ty) => {
203 impl<$($gen),+> $imp<&$t> for &$t {
204 type Output = $t;
205
206 #[inline]
207 fn $method(self, other: &$t) -> Self::Output {
208 $imp::$method(JsValue::as_ref(self), JsValue::as_ref(other)).unchecked_into()
209 }
210 }
211
212 forward_deref_binop!(impl<$($gen),+> $imp, $method for $t);
213 };
214}
215
216macro_rules! sum_product {
217 ($($a:ident)*) => ($(
218 impl Sum for $a {
219 #[inline]
220 fn sum<I: iter::Iterator<Item=Self>>(iter: I) -> Self {
221 iter.fold(
222 $a::from(0),
223 |a, b| a + b,
224 )
225 }
226 }
227
228 impl Product for $a {
229 #[inline]
230 fn product<I: iter::Iterator<Item=Self>>(iter: I) -> Self {
231 iter.fold(
232 $a::from(1),
233 |a, b| a * b,
234 )
235 }
236 }
237
238 impl<'a> Sum<&'a $a> for $a {
239 fn sum<I: iter::Iterator<Item=&'a Self>>(iter: I) -> Self {
240 iter.fold(
241 $a::from(0),
242 |a, b| a + b,
243 )
244 }
245 }
246
247 impl<'a> Product<&'a $a> for $a {
248 #[inline]
249 fn product<I: iter::Iterator<Item=&'a Self>>(iter: I) -> Self {
250 iter.fold(
251 $a::from(1),
252 |a, b| a * b,
253 )
254 }
255 }
256 )*);
257 // Generic variant: impl<T> for Type<T>
258 (impl<$gen:ident> $a:ident<$g2:ident>) => {
259 impl<$gen> Sum for $a<$g2>
260 where
261 $a<$g2>: From<$gen>,
262 $g2: From<u32>
263 {
264 #[inline]
265 fn sum<I: iter::Iterator<Item=Self>>(iter: I) -> Self {
266 iter.fold(
267 $a::from($g2::from(0)),
268 |a, b| a + b,
269 )
270 }
271 }
272
273 impl<$gen> Product for $a<$g2>
274 where
275 $a<$g2>: From<$gen>,
276 $g2: From<u32>
277 {
278 #[inline]
279 fn product<I: iter::Iterator<Item=Self>>(iter: I) -> Self {
280 iter.fold(
281 $a::from($g2::from(1)),
282 |a, b| a * b,
283 )
284 }
285 }
286
287 impl<'a, $gen> Sum<&'a $a<$g2>> for $a<$g2>
288 where
289 $a<$g2>: From<$gen>,
290 $g2: From<u32>
291 {
292 fn sum<I: iter::Iterator<Item=&'a Self>>(iter: I) -> Self {
293 iter.fold(
294 $a::from($g2::from(0)),
295 |a, b| a + b,
296 )
297 }
298 }
299
300 impl<'a, $gen> Product<&'a $a<$g2>> for $a<$g2>
301 where
302 $a<$g2>: From<$gen>,
303 $g2: From<u32>
304 {
305 #[inline]
306 fn product<I: iter::Iterator<Item=&'a Self>>(iter: I) -> Self {
307 iter.fold(
308 $a::from($g2::from(1)),
309 |a, b| a * b,
310 )
311 }
312 }
313 };
314}
315
316macro_rules! partialord_ord {
317 ($t:ident) => {
318 impl PartialOrd for $t {
319 #[inline]
320 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
321 Some(self.cmp(other))
322 }
323
324 #[inline]
325 fn lt(&self, other: &Self) -> bool {
326 JsValue::as_ref(self).lt(JsValue::as_ref(other))
327 }
328
329 #[inline]
330 fn le(&self, other: &Self) -> bool {
331 JsValue::as_ref(self).le(JsValue::as_ref(other))
332 }
333
334 #[inline]
335 fn ge(&self, other: &Self) -> bool {
336 JsValue::as_ref(self).ge(JsValue::as_ref(other))
337 }
338
339 #[inline]
340 fn gt(&self, other: &Self) -> bool {
341 JsValue::as_ref(self).gt(JsValue::as_ref(other))
342 }
343 }
344
345 impl Ord for $t {
346 #[inline]
347 fn cmp(&self, other: &Self) -> Ordering {
348 if self == other {
349 Ordering::Equal
350 } else if self.lt(other) {
351 Ordering::Less
352 } else {
353 Ordering::Greater
354 }
355 }
356 }
357 };
358}
359
360#[wasm_bindgen]
361extern "C" {
362 /// The `decodeURI()` function decodes a Uniform Resource Identifier (URI)
363 /// previously created by `encodeURI` or by a similar routine.
364 ///
365 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURI)
366 #[wasm_bindgen(catch, js_name = decodeURI)]
367 pub fn decode_uri(encoded: &str) -> Result<JsString, JsValue>;
368
369 /// The `decodeURIComponent()` function decodes a Uniform Resource Identifier (URI) component
370 /// previously created by `encodeURIComponent` or by a similar routine.
371 ///
372 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURIComponent)
373 #[wasm_bindgen(catch, js_name = decodeURIComponent)]
374 pub fn decode_uri_component(encoded: &str) -> Result<JsString, JsValue>;
375
376 /// The `encodeURI()` function encodes a Uniform Resource Identifier (URI)
377 /// by replacing each instance of certain characters by one, two, three, or
378 /// four escape sequences representing the UTF-8 encoding of the character
379 /// (will only be four escape sequences for characters composed of two
380 /// "surrogate" characters).
381 ///
382 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURI)
383 #[wasm_bindgen(js_name = encodeURI)]
384 pub fn encode_uri(decoded: &str) -> JsString;
385
386 /// The `encodeURIComponent()` function encodes a Uniform Resource Identifier (URI) component
387 /// by replacing each instance of certain characters by one, two, three, or four escape sequences
388 /// representing the UTF-8 encoding of the character
389 /// (will only be four escape sequences for characters composed of two "surrogate" characters).
390 ///
391 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent)
392 #[wasm_bindgen(js_name = encodeURIComponent)]
393 pub fn encode_uri_component(decoded: &str) -> JsString;
394
395 /// The `eval()` function evaluates JavaScript code represented as a string.
396 ///
397 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval)
398 #[cfg(feature = "unsafe-eval")]
399 #[wasm_bindgen(catch)]
400 pub fn eval(js_source_text: &str) -> Result<JsValue, JsValue>;
401
402 /// The global `isFinite()` function determines whether the passed value is a finite number.
403 /// If needed, the parameter is first converted to a number.
404 ///
405 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isFinite)
406 #[wasm_bindgen(js_name = isFinite)]
407 pub fn is_finite(value: &JsValue) -> bool;
408
409 /// The `parseInt()` function parses a string argument and returns an integer
410 /// of the specified radix (the base in mathematical numeral systems), or NaN on error.
411 ///
412 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt)
413 #[wasm_bindgen(js_name = parseInt)]
414 pub fn parse_int(text: &str, radix: u8) -> f64;
415
416 /// The `parseFloat()` function parses an argument and returns a floating point number,
417 /// or NaN on error.
418 ///
419 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseFloat)
420 #[wasm_bindgen(js_name = parseFloat)]
421 pub fn parse_float(text: &str) -> f64;
422
423 /// The `escape()` function computes a new string in which certain characters have been
424 /// replaced by a hexadecimal escape sequence.
425 ///
426 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/escape)
427 #[wasm_bindgen]
428 pub fn escape(string: &str) -> JsString;
429
430 /// The `unescape()` function computes a new string in which hexadecimal escape
431 /// sequences are replaced with the character that it represents. The escape sequences might
432 /// be introduced by a function like `escape`. Usually, `decodeURI` or `decodeURIComponent`
433 /// are preferred over `unescape`.
434 ///
435 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/unescape)
436 #[wasm_bindgen]
437 pub fn unescape(string: &str) -> JsString;
438}
439
440// Array
441#[wasm_bindgen]
442extern "C" {
443 #[wasm_bindgen(extends = Object, is_type_of = Array::is_array, typescript_type = "Array<any>")]
444 #[derive(Clone, Debug, PartialEq, Eq)]
445 pub type Array<T = JsValue>;
446
447 /// Creates a new empty array.
448 ///
449 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Array)
450 #[cfg(not(js_sys_unstable_apis))]
451 #[wasm_bindgen(constructor)]
452 pub fn new() -> Array;
453
454 /// Creates a new empty array.
455 ///
456 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Array)
457 #[cfg(js_sys_unstable_apis)]
458 #[wasm_bindgen(constructor)]
459 pub fn new<T>() -> Array<T>;
460
461 // Next major: deprecate
462 /// Creates a new empty array.
463 ///
464 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Array)
465 #[wasm_bindgen(constructor)]
466 pub fn new_typed<T>() -> Array<T>;
467
468 /// Creates a new array with the specified length (elements are initialized to `undefined`).
469 ///
470 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Array)
471 #[cfg(not(js_sys_unstable_apis))]
472 #[wasm_bindgen(constructor)]
473 pub fn new_with_length(len: u32) -> Array;
474
475 /// Creates a new array with the specified length (elements are initialized to `undefined`).
476 ///
477 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Array)
478 #[cfg(js_sys_unstable_apis)]
479 #[wasm_bindgen(constructor)]
480 pub fn new_with_length<T>(len: u32) -> Array<T>;
481
482 // Next major: deprecate
483 /// Creates a new array with the specified length (elements are initialized to `undefined`).
484 ///
485 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Array)
486 #[wasm_bindgen(constructor)]
487 pub fn new_with_length_typed<T>(len: u32) -> Array<T>;
488
489 /// Retrieves the element at the index, counting from the end if negative
490 /// (returns `undefined` if the index is out of range).
491 ///
492 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at)
493 #[cfg(not(js_sys_unstable_apis))]
494 #[wasm_bindgen(method)]
495 pub fn at<T>(this: &Array<T>, index: i32) -> T;
496
497 /// Retrieves the element at the index, counting from the end if negative
498 /// (returns `None` if the index is out of range).
499 ///
500 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at)
501 #[cfg(js_sys_unstable_apis)]
502 #[wasm_bindgen(method)]
503 pub fn at<T>(this: &Array<T>, index: i32) -> Option<T>;
504
505 /// Retrieves the element at the index (returns `undefined` if the index is out of range).
506 ///
507 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at)
508 #[cfg(not(js_sys_unstable_apis))]
509 #[wasm_bindgen(method, indexing_getter)]
510 pub fn get<T>(this: &Array<T>, index: u32) -> T;
511
512 /// Retrieves the element at the index (returns `None` if the index is out of range).
513 ///
514 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at)
515 #[cfg(js_sys_unstable_apis)]
516 #[wasm_bindgen(method, indexing_getter)]
517 pub fn get<T>(this: &Array<T>, index: u32) -> Option<T>;
518
519 /// Retrieves the element at the index (returns `undefined` if the index is out of range).
520 ///
521 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at)
522 #[wasm_bindgen(method, indexing_getter)]
523 pub fn get_unchecked<T>(this: &Array<T>, index: u32) -> T;
524
525 // Next major: deprecate
526 /// Retrieves the element at the index (returns `None` if the index is out of range,
527 /// or if the element is explicitly `undefined`).
528 #[wasm_bindgen(method, indexing_getter)]
529 pub fn get_checked<T>(this: &Array<T>, index: u32) -> Option<T>;
530
531 /// Sets the element at the index (auto-enlarges the array if the index is out of range).
532 #[cfg(not(js_sys_unstable_apis))]
533 #[wasm_bindgen(method, indexing_setter)]
534 pub fn set<T>(this: &Array<T>, index: u32, value: T);
535
536 /// Sets the element at the index (auto-enlarges the array if the index is out of range).
537 #[cfg(js_sys_unstable_apis)]
538 #[wasm_bindgen(method, indexing_setter)]
539 pub fn set<T>(this: &Array<T>, index: u32, value: &T);
540
541 // Next major: deprecate
542 /// Sets the element at the index (auto-enlarges the array if the index is out of range).
543 #[wasm_bindgen(method, indexing_setter)]
544 pub fn set_ref<T>(this: &Array<T>, index: u32, value: &T);
545
546 /// Deletes the element at the index (does nothing if the index is out of range).
547 ///
548 /// The element at the index is set to `undefined`.
549 ///
550 /// This does not resize the array, the array will still be the same length.
551 #[wasm_bindgen(method, indexing_deleter)]
552 pub fn delete<T>(this: &Array<T>, index: u32);
553
554 /// The `Array.from()` static method creates a new, shallow-copied `Array` instance
555 /// from an array-like or iterable object.
556 ///
557 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from)
558 #[cfg(not(js_sys_unstable_apis))]
559 #[wasm_bindgen(static_method_of = Array)]
560 pub fn from(val: &JsValue) -> Array;
561
562 /// The `Array.from()` static method creates a new, shallow-copied `Array` instance
563 /// from an array-like or iterable object.
564 ///
565 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from)
566 #[cfg(js_sys_unstable_apis)]
567 #[wasm_bindgen(static_method_of = Array, catch, js_name = from)]
568 pub fn from<I: Iterable>(val: &I) -> Result<Array<I::Item>, JsValue>;
569
570 // Next major: deprecate
571 /// The `Array.from()` static method creates a new, shallow-copied `Array` instance
572 /// from an array-like or iterable object.
573 ///
574 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from)
575 #[wasm_bindgen(static_method_of = Array, catch, js_name = from)]
576 pub fn from_iterable<I: Iterable>(val: &I) -> Result<Array<I::Item>, JsValue>;
577
578 /// The `Array.from()` static method with a map function creates a new, shallow-copied
579 /// `Array` instance from an array-like or iterable object, applying the map function
580 /// to each value.
581 ///
582 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from)
583 #[wasm_bindgen(static_method_of = Array, catch, js_name = from)]
584 pub fn from_iterable_map<I: Iterable, U>(
585 val: &I,
586 map: &mut dyn FnMut(I::Item, u32) -> Result<U, JsError>,
587 ) -> Result<Array<U>, JsValue>;
588
589 /// The `Array.fromAsync()` static method creates a new, shallow-copied `Array` instance
590 /// from an async iterable, iterable or array-like object.
591 ///
592 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fromAsync)
593 #[wasm_bindgen(static_method_of = Array, catch, js_name = fromAsync)]
594 pub fn from_async<I: AsyncIterable>(val: &I) -> Result<Promise<Array<I::Item>>, JsValue>;
595
596 /// The `Array.fromAsync()` static method with a map function creates a new, shallow-copied
597 /// `Array` instance from an async iterable, iterable or array-like object, applying the map
598 /// function to each value.
599 ///
600 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fromAsync)
601 #[wasm_bindgen(static_method_of = Array, catch, js_name = fromAsync)]
602 pub fn from_async_map<'a, I: AsyncIterable, R: Promising>(
603 val: &I,
604 map: &ScopedClosure<'a, dyn FnMut(I::Item, u32) -> Result<R, JsError>>,
605 ) -> Result<Promise<Array<R::Resolution>>, JsValue>;
606
607 /// The `copyWithin()` method shallow copies part of an array to another
608 /// location in the same array and returns it, without modifying its size.
609 ///
610 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin)
611 #[wasm_bindgen(method, js_name = copyWithin)]
612 pub fn copy_within<T>(this: &Array<T>, target: i32, start: i32, end: i32) -> Array<T>;
613
614 /// The `concat()` method is used to merge two or more arrays. This method
615 /// does not change the existing arrays, but instead returns a new array.
616 ///
617 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat)
618 #[wasm_bindgen(method)]
619 pub fn concat<T, U: Upcast<T>>(this: &Array<T>, array: &Array<U>) -> Array<T>;
620
621 /// The `concat()` method is used to merge two or more arrays. This method
622 /// does not change the existing arrays, but instead returns a new array.
623 ///
624 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat)
625 #[wasm_bindgen(method)]
626 pub fn concat_many<T, U: Upcast<T>>(this: &Array<T>, array: &[Array<U>]) -> Array<T>;
627
628 /// The `every()` method tests whether all elements in the array pass the test
629 /// implemented by the provided function.
630 ///
631 /// **Note:** Consider using [`Array::try_every`] if the predicate might throw an error.
632 ///
633 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every)
634 #[wasm_bindgen(method)]
635 pub fn every<T>(this: &Array<T>, predicate: &mut dyn FnMut(T, u32, Array<T>) -> bool) -> bool;
636
637 /// The `every()` method tests whether all elements in the array pass the test
638 /// implemented by the provided function. _(Fallible variation)_
639 ///
640 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every)
641 #[wasm_bindgen(method, js_name = every, catch)]
642 pub fn try_every<T>(
643 this: &Array<T>,
644 predicate: &mut dyn FnMut(T, u32) -> Result<bool, JsError>,
645 ) -> Result<bool, JsValue>;
646
647 /// The `fill()` method fills all the elements of an array from a start index
648 /// to an end index with a static value. The end index is not included.
649 ///
650 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill)
651 #[wasm_bindgen(method)]
652 pub fn fill<T>(this: &Array<T>, value: &T, start: u32, end: u32) -> Array<T>;
653
654 /// The `filter()` method creates a new array with all elements that pass the
655 /// test implemented by the provided function.
656 ///
657 /// **Note:** Consider using [`Array::try_filter`] if the predicate might throw an error.
658 ///
659 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter)
660 #[wasm_bindgen(method)]
661 pub fn filter<T>(
662 this: &Array<T>,
663 predicate: &mut dyn FnMut(T, u32, Array<T>) -> bool,
664 ) -> Array<T>;
665
666 /// The `filter()` method creates a new array with all elements that pass the
667 /// test implemented by the provided function. _(Fallible variation)_
668 ///
669 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter)
670 #[wasm_bindgen(method, js_name = filter, catch)]
671 pub fn try_filter<T>(
672 this: &Array<T>,
673 predicate: &mut dyn FnMut(T, u32) -> Result<bool, JsError>,
674 ) -> Result<Array<T>, JsValue>;
675
676 /// The `find()` method returns the value of the first element in the array that satisfies
677 /// the provided testing function. Otherwise `undefined` is returned.
678 ///
679 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)
680 #[cfg(not(js_sys_unstable_apis))]
681 #[wasm_bindgen(method)]
682 pub fn find<T>(this: &Array<T>, predicate: &mut dyn FnMut(T, u32, Array<T>) -> bool) -> T;
683
684 /// The `find()` method returns the value of the first element in the array that satisfies
685 /// the provided testing function. Returns `None` if no element matches.
686 ///
687 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)
688 #[cfg(js_sys_unstable_apis)]
689 #[wasm_bindgen(method)]
690 pub fn find<T>(
691 this: &Array<T>,
692 predicate: &mut dyn FnMut(T, u32, Array<T>) -> bool,
693 ) -> Option<T>;
694
695 /// The `find()` method returns the value of the first element in the array that satisfies
696 /// the provided testing function. Otherwise `undefined` is returned. _(Fallible variation)_
697 ///
698 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)
699 #[wasm_bindgen(method, js_name = find, catch)]
700 pub fn try_find<T>(
701 this: &Array<T>,
702 predicate: &mut dyn FnMut(T, u32) -> Result<bool, JsError>,
703 ) -> Result<Option<T>, JsValue>;
704
705 /// The `findIndex()` method returns the index of the first element in the array that
706 /// satisfies the provided testing function. Otherwise -1 is returned.
707 ///
708 /// **Note:** Consider using [`Array::try_find_index`] if the predicate might throw an error.
709 ///
710 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex)
711 #[wasm_bindgen(method, js_name = findIndex)]
712 pub fn find_index<T>(
713 this: &Array<T>,
714 predicate: &mut dyn FnMut(T, u32, Array<T>) -> bool,
715 ) -> i32;
716
717 /// The `findIndex()` method returns the index of the first element in the array that
718 /// satisfies the provided testing function. Otherwise -1 is returned. _(Fallible variation)_
719 ///
720 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex)
721 #[wasm_bindgen(method, js_name = findIndex, catch)]
722 pub fn try_find_index<T>(
723 this: &Array<T>,
724 predicate: &mut dyn FnMut(T, u32) -> Result<bool, JsError>,
725 ) -> Result<i32, JsValue>;
726
727 /// The `findLast()` method of Array instances iterates the array in reverse order
728 /// and returns the value of the first element that satisfies the provided testing function.
729 /// If no elements satisfy the testing function, undefined is returned.
730 ///
731 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLast)
732 #[cfg(not(js_sys_unstable_apis))]
733 #[wasm_bindgen(method, js_name = findLast)]
734 pub fn find_last<T>(this: &Array<T>, predicate: &mut dyn FnMut(T, u32, Array<T>) -> bool) -> T;
735
736 /// The `findLast()` method of Array instances iterates the array in reverse order
737 /// and returns the value of the first element that satisfies the provided testing function.
738 /// Returns `None` if no element matches.
739 ///
740 /// **Note:** Consider using [`Array::try_find_last`] if the predicate might throw an error.
741 ///
742 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLast)
743 #[cfg(js_sys_unstable_apis)]
744 #[wasm_bindgen(method, js_name = findLast)]
745 pub fn find_last<T>(this: &Array<T>, predicate: &mut dyn FnMut(T, u32) -> bool) -> Option<T>;
746
747 /// The `findLast()` method of Array instances iterates the array in reverse order
748 /// and returns the value of the first element that satisfies the provided testing function.
749 /// If no elements satisfy the testing function, undefined is returned. _(Fallible variation)_
750 ///
751 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLast)
752 #[wasm_bindgen(method, js_name = findLast, catch)]
753 pub fn try_find_last<T>(
754 this: &Array<T>,
755 predicate: &mut dyn FnMut(T, u32) -> Result<bool, JsError>,
756 ) -> Result<Option<T>, JsValue>;
757
758 /// The `findLastIndex()` method of Array instances iterates the array in reverse order
759 /// and returns the index of the first element that satisfies the provided testing function.
760 /// If no elements satisfy the testing function, -1 is returned.
761 ///
762 /// **Note:** Consider using [`Array::try_find_last_index`] if the predicate might throw an error.
763 ///
764 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLastIndex)
765 #[wasm_bindgen(method, js_name = findLastIndex)]
766 pub fn find_last_index<T>(
767 this: &Array<T>,
768 predicate: &mut dyn FnMut(T, u32, Array<T>) -> bool,
769 ) -> i32;
770
771 /// The `findLastIndex()` method of Array instances iterates the array in reverse order
772 /// and returns the index of the first element that satisfies the provided testing function.
773 /// If no elements satisfy the testing function, -1 is returned. _(Fallible variation)_
774 ///
775 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLastIndex)
776 #[wasm_bindgen(method, js_name = findLastIndex, catch)]
777 pub fn try_find_last_index<T>(
778 this: &Array<T>,
779 predicate: &mut dyn FnMut(T, u32) -> Result<bool, JsError>,
780 ) -> Result<i32, JsValue>;
781
782 /// The `flat()` method creates a new array with all sub-array elements concatenated into it
783 /// recursively up to the specified depth.
784 ///
785 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat)
786 #[wasm_bindgen(method)]
787 pub fn flat<T>(this: &Array<T>, depth: i32) -> Array<JsValue>;
788
789 /// The `flatMap()` method first maps each element using a mapping function, then flattens
790 /// the result into a new array.
791 ///
792 /// **Note:** Consider using [`Array::try_flat_map`] for safer fallible handling.
793 ///
794 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap)
795 #[wasm_bindgen(method, js_name = flatMap)]
796 pub fn flat_map<T, U>(
797 this: &Array<T>,
798 callback: &mut dyn FnMut(T, u32, Array<T>) -> Vec<U>,
799 ) -> Array<U>;
800
801 /// The `flatMap()` method first maps each element using a mapping function, then flattens
802 /// the result into a new array.
803 ///
804 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap)
805 #[wasm_bindgen(method, js_name = flatMap, catch)]
806 pub fn try_flat_map<T, U>(
807 this: &Array<T>,
808 callback: &mut dyn FnMut(T, u32) -> Vec<U>,
809 ) -> Result<Array<U>, JsValue>;
810
811 /// The `forEach()` method executes a provided function once for each array element.
812 ///
813 /// **Note:** Consider using [`Array::try_for_each`] if the callback might throw an error.
814 ///
815 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach)
816 #[wasm_bindgen(method, js_name = forEach)]
817 pub fn for_each<T: JsGeneric>(this: &Array<T>, callback: &mut dyn FnMut(T, u32, Array<T>));
818
819 /// The `forEach()` method executes a provided function once for each array element. _(Fallible variation)_
820 ///
821 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach)
822 #[wasm_bindgen(method, js_name = forEach, catch)]
823 pub fn try_for_each<T>(
824 this: &Array<T>,
825 callback: &mut dyn FnMut(T, u32) -> Result<(), JsError>,
826 ) -> Result<(), JsValue>;
827
828 /// The `includes()` method determines whether an array includes a certain
829 /// element, returning true or false as appropriate.
830 ///
831 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes)
832 #[wasm_bindgen(method)]
833 pub fn includes<T>(this: &Array<T>, value: &T, from_index: i32) -> bool;
834
835 /// The `indexOf()` method returns the first index at which a given element
836 /// can be found in the array, or -1 if it is not present.
837 ///
838 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf)
839 #[wasm_bindgen(method, js_name = indexOf)]
840 pub fn index_of<T>(this: &Array<T>, value: &T, from_index: i32) -> i32;
841
842 /// The `Array.isArray()` method determines whether the passed value is an Array.
843 ///
844 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray)
845 #[wasm_bindgen(static_method_of = Array, js_name = isArray)]
846 pub fn is_array(value: &JsValue) -> bool;
847
848 /// The `join()` method joins all elements of an array (or an array-like object)
849 /// into a string and returns this string.
850 ///
851 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join)
852 #[wasm_bindgen(method)]
853 pub fn join<T>(this: &Array<T>, delimiter: &str) -> JsString;
854
855 /// The `lastIndexOf()` method returns the last index at which a given element
856 /// can be found in the array, or -1 if it is not present. The array is
857 /// searched backwards, starting at fromIndex.
858 ///
859 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/lastIndexOf)
860 #[wasm_bindgen(method, js_name = lastIndexOf)]
861 pub fn last_index_of<T>(this: &Array<T>, value: &T, from_index: i32) -> i32;
862
863 /// The length property of an object which is an instance of type Array
864 /// sets or returns the number of elements in that array. The value is an
865 /// unsigned, 32-bit integer that is always numerically greater than the
866 /// highest index in the array.
867 ///
868 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/length)
869 #[wasm_bindgen(method, getter)]
870 pub fn length<T>(this: &Array<T>) -> u32;
871
872 /// Sets the length of the array.
873 ///
874 /// If it is set to less than the current length of the array, it will
875 /// shrink the array.
876 ///
877 /// If it is set to more than the current length of the array, it will
878 /// increase the length of the array, filling the new space with empty
879 /// slots.
880 ///
881 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/length)
882 #[wasm_bindgen(method, setter)]
883 pub fn set_length<T>(this: &Array<T>, value: u32);
884
885 /// `map()` calls a provided callback function once for each element in an array,
886 /// in order, and constructs a new array from the results. callback is invoked
887 /// only for indexes of the array which have assigned values, including undefined.
888 /// It is not called for missing elements of the array (that is, indexes that have
889 /// never been set, which have been deleted or which have never been assigned a value).
890 ///
891 /// **Note:** Consider using [`Array::try_map`] for safer fallible handling.
892 ///
893 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map)
894 #[wasm_bindgen(method)]
895 pub fn map<T, U>(this: &Array<T>, predicate: &mut dyn FnMut(T, u32, Array<T>) -> U)
896 -> Array<U>;
897
898 /// `map()` calls a provided callback function once for each element in an array,
899 /// in order, and constructs a new array from the results. callback is invoked
900 /// only for indexes of the array which have assigned values, including undefined.
901 /// It is not called for missing elements of the array (that is, indexes that have
902 /// never been set, which have been deleted or which have never been assigned a value).
903 /// _(Fallible variation)_
904 ///
905 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map)
906 #[wasm_bindgen(method, js_name = map, catch)]
907 pub fn try_map<T, U>(
908 this: &Array<T>,
909 predicate: &mut dyn FnMut(T, u32) -> Result<U, JsError>,
910 ) -> Result<Array<U>, JsValue>;
911
912 /// The `Array.of()` method creates a new Array instance with a variable
913 /// number of arguments, regardless of number or type of the arguments.
914 ///
915 /// Note: For type inference use `Array::<T>::of(&[T])`.
916 ///
917 /// The difference between `Array.of()` and the `Array` constructor is in the
918 /// handling of integer arguments: `Array.of(7)` creates an array with a single
919 /// element, `7`, whereas `Array(7)` creates an empty array with a `length`
920 /// property of `7` (Note: this implies an array of 7 empty slots, not slots
921 /// with actual undefined values).
922 ///
923 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of)
924 #[wasm_bindgen(static_method_of = Array, js_name = of, variadic)]
925 pub fn of<T>(values: &[T]) -> Array<T>;
926
927 // Next major: deprecate these
928 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of)
929 #[wasm_bindgen(static_method_of = Array, js_name = of)]
930 pub fn of1(a: &JsValue) -> Array;
931
932 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of)
933 #[wasm_bindgen(static_method_of = Array, js_name = of)]
934 pub fn of2(a: &JsValue, b: &JsValue) -> Array;
935
936 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of)
937 #[wasm_bindgen(static_method_of = Array, js_name = of)]
938 pub fn of3(a: &JsValue, b: &JsValue, c: &JsValue) -> Array;
939
940 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of)
941 #[wasm_bindgen(static_method_of = Array, js_name = of)]
942 pub fn of4(a: &JsValue, b: &JsValue, c: &JsValue, d: &JsValue) -> Array;
943
944 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of)
945 #[wasm_bindgen(static_method_of = Array, js_name = of)]
946 pub fn of5(a: &JsValue, b: &JsValue, c: &JsValue, d: &JsValue, e: &JsValue) -> Array;
947
948 /// The `pop()` method removes the last element from an array and returns that
949 /// element. This method changes the length of the array.
950 ///
951 /// **Note:** Consider using [`Array::pop_checked`] for handling empty arrays.
952 ///
953 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pop)
954 #[cfg(not(js_sys_unstable_apis))]
955 #[wasm_bindgen(method)]
956 pub fn pop<T>(this: &Array<T>) -> T;
957
958 /// The `pop()` method removes the last element from an array and returns that
959 /// element. This method changes the length of the array.
960 /// Returns `None` if the array is empty.
961 ///
962 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pop)
963 #[cfg(js_sys_unstable_apis)]
964 #[wasm_bindgen(method)]
965 pub fn pop<T>(this: &Array<T>) -> Option<T>;
966
967 // Next major: deprecate
968 /// The `pop()` method removes the last element from an array and returns that
969 /// element. This method changes the length of the array.
970 ///
971 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pop)
972 #[wasm_bindgen(method, js_name = pop)]
973 pub fn pop_checked<T>(this: &Array<T>) -> Option<T>;
974
975 /// The `push()` method adds one element to the end of an array and
976 /// returns the new length of the array.
977 ///
978 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push)
979 #[wasm_bindgen(method)]
980 pub fn push<T>(this: &Array<T>, value: &T) -> u32;
981
982 /// The `push()` method adds one or more elements to the end of an array and
983 /// returns the new length of the array.
984 ///
985 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push)
986 #[wasm_bindgen(method, js_name = push, variadic)]
987 pub fn push_many<T>(this: &Array<T>, values: &[T]) -> u32;
988
989 /// The `reduce()` method applies a function against an accumulator and each element in
990 /// the array (from left to right) to reduce it to a single value.
991 ///
992 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce)
993 #[cfg(not(js_sys_unstable_apis))]
994 #[wasm_bindgen(method)]
995 pub fn reduce<T>(
996 this: &Array<T>,
997 predicate: &mut dyn FnMut(JsValue, T, u32, Array<T>) -> JsValue,
998 initial_value: &JsValue,
999 ) -> JsValue;
1000
1001 /// The `reduce()` method applies a function against an accumulator and each element in
1002 /// the array (from left to right) to reduce it to a single value.
1003 ///
1004 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce)
1005 #[cfg(js_sys_unstable_apis)]
1006 #[wasm_bindgen(method)]
1007 pub fn reduce<T, A>(
1008 this: &Array<T>,
1009 predicate: &mut dyn FnMut(A, T, u32, Array<T>) -> A,
1010 initial_value: &A,
1011 ) -> A;
1012
1013 /// The `reduce()` method applies a function against an accumulator and each element in
1014 /// the array (from left to right) to reduce it to a single value. _(Fallible variation)_
1015 ///
1016 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce)
1017 #[wasm_bindgen(method, js_name = reduce, catch)]
1018 pub fn try_reduce<T, A>(
1019 this: &Array<T>,
1020 predicate: &mut dyn FnMut(A, T, u32) -> Result<A, JsError>,
1021 initial_value: &A,
1022 ) -> Result<A, JsValue>;
1023
1024 /// The `reduceRight()` method applies a function against an accumulator and each value
1025 /// of the array (from right-to-left) to reduce it to a single value.
1026 ///
1027 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/ReduceRight)
1028 #[cfg(not(js_sys_unstable_apis))]
1029 #[wasm_bindgen(method, js_name = reduceRight)]
1030 pub fn reduce_right<T>(
1031 this: &Array<T>,
1032 predicate: &mut dyn FnMut(JsValue, T, u32, Array<T>) -> JsValue,
1033 initial_value: &JsValue,
1034 ) -> JsValue;
1035
1036 /// The `reduceRight()` method applies a function against an accumulator and each value
1037 /// of the array (from right-to-left) to reduce it to a single value.
1038 ///
1039 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/ReduceRight)
1040 #[cfg(js_sys_unstable_apis)]
1041 #[wasm_bindgen(method, js_name = reduceRight)]
1042 pub fn reduce_right<T, A>(
1043 this: &Array<T>,
1044 predicate: &mut dyn FnMut(A, T, u32, Array<T>) -> A,
1045 initial_value: &A,
1046 ) -> A;
1047
1048 /// The `reduceRight()` method applies a function against an accumulator and each value
1049 /// of the array (from right-to-left) to reduce it to a single value. _(Fallible variation)_
1050 ///
1051 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/ReduceRight)
1052 #[wasm_bindgen(method, js_name = reduceRight, catch)]
1053 pub fn try_reduce_right<T, A>(
1054 this: &Array<T>,
1055 predicate: &mut dyn FnMut(JsValue, T, u32) -> Result<A, JsError>,
1056 initial_value: &A,
1057 ) -> Result<A, JsValue>;
1058
1059 /// The `reverse()` method reverses an array in place. The first array
1060 /// element becomes the last, and the last array element becomes the first.
1061 ///
1062 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse)
1063 #[wasm_bindgen(method)]
1064 pub fn reverse<T>(this: &Array<T>) -> Array<T>;
1065
1066 /// The `shift()` method removes the first element from an array and returns
1067 /// that removed element. This method changes the length of the array.
1068 ///
1069 /// **Note:** Consider using [`Array::shift_checked`] for handling empty arrays.
1070 ///
1071 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift)
1072 #[cfg(not(js_sys_unstable_apis))]
1073 #[wasm_bindgen(method)]
1074 pub fn shift<T>(this: &Array<T>) -> T;
1075
1076 /// The `shift()` method removes the first element from an array and returns
1077 /// that removed element. This method changes the length of the array.
1078 /// Returns `None` if the array is empty.
1079 ///
1080 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift)
1081 #[cfg(js_sys_unstable_apis)]
1082 #[wasm_bindgen(method)]
1083 pub fn shift<T>(this: &Array<T>) -> Option<T>;
1084
1085 // Next major: deprecate
1086 /// The `shift()` method removes the first element from an array and returns
1087 /// that removed element. This method changes the length of the array.
1088 ///
1089 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift)
1090 #[wasm_bindgen(method, js_name = shift)]
1091 pub fn shift_checked<T>(this: &Array<T>) -> Option<T>;
1092
1093 /// The `slice()` method returns a shallow copy of a portion of an array into
1094 /// a new array object selected from begin to end (end not included).
1095 /// The original array will not be modified.
1096 ///
1097 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)
1098 #[cfg(not(js_sys_unstable_apis))]
1099 #[wasm_bindgen(method)]
1100 pub fn slice<T>(this: &Array<T>, start: u32, end: u32) -> Array<T>;
1101
1102 /// The `slice()` method returns a shallow copy of a portion of an array into
1103 /// a new array object selected from begin to end (end not included).
1104 /// The original array will not be modified. Negative indices count from the end.
1105 ///
1106 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)
1107 #[cfg(js_sys_unstable_apis)]
1108 #[wasm_bindgen(method)]
1109 pub fn slice<T>(this: &Array<T>, start: i32, end: i32) -> Array<T>;
1110
1111 /// The `slice()` method returns a shallow copy of a portion of an array into
1112 /// a new array object selected from the given index to the end.
1113 /// The original array will not be modified.
1114 ///
1115 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)
1116 #[cfg(not(js_sys_unstable_apis))]
1117 #[wasm_bindgen(method, js_name = slice)]
1118 pub fn slice_from<T>(this: &Array<T>, start: u32) -> Array<T>;
1119
1120 /// The `slice()` method returns a shallow copy of a portion of an array into
1121 /// a new array object selected from the given index to the end.
1122 /// The original array will not be modified. Negative indices count from the end.
1123 ///
1124 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)
1125 #[cfg(js_sys_unstable_apis)]
1126 #[wasm_bindgen(method, js_name = slice)]
1127 pub fn slice_from<T>(this: &Array<T>, start: i32) -> Array<T>;
1128
1129 /// The `some()` method tests whether at least one element in the array passes the test implemented
1130 /// by the provided function.
1131 /// Note: This method returns false for any condition put on an empty array.
1132 ///
1133 /// **Note:** Consider using [`Array::try_some`] if the predicate might throw an error.
1134 ///
1135 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some)
1136 #[wasm_bindgen(method)]
1137 pub fn some<T>(this: &Array<T>, predicate: &mut dyn FnMut(T) -> bool) -> bool;
1138
1139 /// The `some()` method tests whether at least one element in the array passes the test implemented
1140 /// by the provided function. _(Fallible variation)_
1141 /// Note: This method returns false for any condition put on an empty array.
1142 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some)
1143 #[wasm_bindgen(method, js_name = some, catch)]
1144 pub fn try_some<T>(
1145 this: &Array<T>,
1146 predicate: &mut dyn FnMut(T) -> Result<bool, JsError>,
1147 ) -> Result<bool, JsValue>;
1148
1149 /// The `sort()` method sorts the elements of an array in place and returns
1150 /// the array. The sort is not necessarily stable. The default sort
1151 /// order is according to string Unicode code points.
1152 ///
1153 /// The time and space complexity of the sort cannot be guaranteed as it
1154 /// is implementation dependent.
1155 ///
1156 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)
1157 #[wasm_bindgen(method)]
1158 pub fn sort<T>(this: &Array<T>) -> Array<T>;
1159
1160 /// The `sort()` method with a custom compare function.
1161 ///
1162 /// **Note:** Consider using [`Array::try_sort_by`] if the predicate might throw an error.
1163 ///
1164 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)
1165 #[wasm_bindgen(method, js_name = sort)]
1166 pub fn sort_by<T>(this: &Array<T>, compare_fn: &mut dyn FnMut(T, T) -> i32) -> Array<T>;
1167
1168 /// The `sort()` method with a custom compare function. _(Fallible variation)_
1169 ///
1170 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)
1171 #[wasm_bindgen(method, js_name = sort, catch)]
1172 pub fn try_sort_by<T>(
1173 this: &Array<T>,
1174 compare_fn: &mut dyn FnMut(T, T) -> Result<i32, JsError>,
1175 ) -> Result<Array<T>, JsValue>;
1176
1177 /// The `splice()` method changes the contents of an array by removing existing elements and/or
1178 /// adding new elements.
1179 ///
1180 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice)
1181 #[wasm_bindgen(method)]
1182 pub fn splice<T>(this: &Array<T>, start: u32, delete_count: u32, item: &T) -> Array<T>;
1183
1184 /// The `splice()` method changes the contents of an array by removing existing elements and/or
1185 /// adding new elements.
1186 ///
1187 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice)
1188 #[wasm_bindgen(method, js_name = splice, variadic)]
1189 pub fn splice_many<T>(this: &Array<T>, start: u32, delete_count: u32, items: &[T]) -> Array<T>;
1190
1191 /// The `toLocaleString()` method returns a string representing the elements of the array.
1192 /// The elements are converted to Strings using their toLocaleString methods and these
1193 /// Strings are separated by a locale-specific String (such as a comma ",").
1194 ///
1195 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toLocaleString)
1196 #[cfg(not(js_sys_unstable_apis))]
1197 #[wasm_bindgen(method, js_name = toLocaleString)]
1198 pub fn to_locale_string<T>(this: &Array<T>, locales: &JsValue, options: &JsValue) -> JsString;
1199
1200 /// The `toLocaleString()` method returns a string representing the elements of the array.
1201 /// The elements are converted to Strings using their toLocaleString methods and these
1202 /// Strings are separated by a locale-specific String (such as a comma ",").
1203 ///
1204 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toLocaleString)
1205 #[cfg(js_sys_unstable_apis)]
1206 #[wasm_bindgen(method, js_name = toLocaleString)]
1207 pub fn to_locale_string<T>(
1208 this: &Array<T>,
1209 locales: &[JsString],
1210 options: &Intl::NumberFormatOptions,
1211 ) -> JsString;
1212
1213 /// The `toReversed()` method returns a new array with the elements in reversed order,
1214 /// without modifying the original array.
1215 ///
1216 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toReversed)
1217 #[wasm_bindgen(method, js_name = toReversed)]
1218 pub fn to_reversed<T>(this: &Array<T>) -> Array<T>;
1219
1220 /// The `toSorted()` method returns a new array with the elements sorted in ascending order,
1221 /// without modifying the original array.
1222 ///
1223 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toSorted)
1224 #[wasm_bindgen(method, js_name = toSorted)]
1225 pub fn to_sorted<T>(this: &Array<T>) -> Array<T>;
1226
1227 /// The `toSorted()` method with a custom compare function.
1228 ///
1229 /// **Note:** Consider using [`Array::try_to_sorted_by`] if the predicate might throw an error.
1230 ///
1231 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toSorted)
1232 #[wasm_bindgen(method, js_name = toSorted)]
1233 pub fn to_sorted_by<T>(this: &Array<T>, compare_fn: &mut dyn FnMut(T, T) -> i32) -> Array<T>;
1234
1235 /// The `toSorted()` method with a custom compare function. _(Fallible variation)_
1236 ///
1237 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toSorted)
1238 #[wasm_bindgen(method, js_name = toSorted, catch)]
1239 pub fn try_to_sorted_by<T>(
1240 this: &Array<T>,
1241 compare_fn: &mut dyn FnMut(T, T) -> Result<i32, JsError>,
1242 ) -> Result<Array<T>, JsValue>;
1243
1244 /// The `toSpliced()` method returns a new array with some elements removed and/or
1245 /// replaced at a given index, without modifying the original array.
1246 ///
1247 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toSpliced)
1248 #[wasm_bindgen(method, js_name = toSpliced, variadic)]
1249 pub fn to_spliced<T>(this: &Array<T>, start: u32, delete_count: u32, items: &[T]) -> Array<T>;
1250
1251 /// The `toString()` method returns a string representing the specified array
1252 /// and its elements.
1253 ///
1254 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toString)
1255 #[cfg(not(js_sys_unstable_apis))]
1256 #[wasm_bindgen(method, js_name = toString)]
1257 pub fn to_string<T>(this: &Array<T>) -> JsString;
1258
1259 /// Converts the Array into a Vector.
1260 #[wasm_bindgen(method, js_name = slice)]
1261 pub fn to_vec<T>(this: &Array<T>) -> Vec<T>;
1262
1263 /// The `unshift()` method adds one element to the beginning of an
1264 /// array and returns the new length of the array.
1265 ///
1266 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift)
1267 #[wasm_bindgen(method)]
1268 pub fn unshift<T>(this: &Array<T>, value: &T) -> u32;
1269
1270 /// The `unshift()` method adds one or more elements to the beginning of an
1271 /// array and returns the new length of the array.
1272 ///
1273 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift)
1274 #[wasm_bindgen(method, js_name = unshift, variadic)]
1275 pub fn unshift_many<T>(this: &Array<T>, values: &[T]) -> u32;
1276
1277 /// The `with()` method returns a new array with the element at the given index
1278 /// replaced with the given value, without modifying the original array.
1279 ///
1280 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/with)
1281 #[wasm_bindgen(method, js_name = with)]
1282 pub fn with<T>(this: &Array<T>, index: u32, value: &T) -> Array<T>;
1283}
1284
1285// Tuples as a typed array variant
1286#[wasm_bindgen]
1287extern "C" {
1288 #[wasm_bindgen(extends = Object, js_name = Array, is_type_of = Array::is_array, no_upcast, typescript_type = "Array<any>")]
1289 #[derive(Clone, Debug)]
1290 pub type ArrayTuple<T: JsTuple = (JsValue,)>;
1291
1292 /// Creates a new JS array typed as a 1-tuple.
1293 #[wasm_bindgen(js_class = Array, static_method_of = ArrayTuple, js_name = of)]
1294 pub fn new1<T1>(t1: &T1) -> ArrayTuple<(T1,)>;
1295
1296 /// Creates a new JS array typed as a 2-tuple.
1297 #[wasm_bindgen(js_class = Array, static_method_of = ArrayTuple, js_name = of)]
1298 pub fn new2<T1, T2>(t1: &T1, t2: &T2) -> ArrayTuple<(T1, T2)>;
1299
1300 /// Creates a new JS array typed as a 3-tuple.
1301 #[wasm_bindgen(js_class = Array, static_method_of = ArrayTuple, js_name = of)]
1302 pub fn new3<T1, T2, T3>(t1: &T1, t2: &T2, t3: &T3) -> ArrayTuple<(T1, T2, T3)>;
1303
1304 /// Creates a new JS array typed as a 4-tuple.
1305 #[wasm_bindgen(js_class = Array, static_method_of = ArrayTuple, js_name = of)]
1306 pub fn new4<T1, T2, T3, T4>(t1: &T1, t2: &T2, t3: &T3, t4: &T4)
1307 -> ArrayTuple<(T1, T2, T3, T4)>;
1308
1309 /// Creates a new JS array typed as a 5-tuple.
1310 #[wasm_bindgen(js_class = Array, static_method_of = ArrayTuple, js_name = of)]
1311 pub fn new5<T1, T2, T3, T4, T5>(
1312 t1: &T1,
1313 t2: &T2,
1314 t3: &T3,
1315 t4: &T4,
1316 t5: &T5,
1317 ) -> ArrayTuple<(T1, T2, T3, T4, T5)>;
1318
1319 /// Creates a new JS array typed as a 6-tuple.
1320 #[wasm_bindgen(js_class = Array, static_method_of = ArrayTuple, js_name = of)]
1321 pub fn new6<T1, T2, T3, T4, T5, T6>(
1322 t1: &T1,
1323 t2: &T2,
1324 t3: &T3,
1325 t4: &T4,
1326 t5: &T5,
1327 t6: &T6,
1328 ) -> ArrayTuple<(T1, T2, T3, T4, T5, T6)>;
1329
1330 /// Creates a new JS array typed as a 7-tuple.
1331 #[wasm_bindgen(js_class = Array, static_method_of = ArrayTuple, js_name = of)]
1332 pub fn new7<T1, T2, T3, T4, T5, T6, T7>(
1333 t1: &T1,
1334 t2: &T2,
1335 t3: &T3,
1336 t4: &T4,
1337 t5: &T5,
1338 t6: &T6,
1339 t7: &T7,
1340 ) -> ArrayTuple<(T1, T2, T3, T4, T5, T6, T7)>;
1341
1342 /// Creates a new JS array typed as a 8-tuple.
1343 #[wasm_bindgen(js_class = Array, static_method_of = ArrayTuple, js_name = of)]
1344 pub fn new8<T1, T2, T3, T4, T5, T6, T7, T8>(
1345 t1: &T1,
1346 t2: &T2,
1347 t3: &T3,
1348 t4: &T4,
1349 t5: &T5,
1350 t6: &T6,
1351 t7: &T7,
1352 t8: &T8,
1353 ) -> ArrayTuple<(T1, T2, T3, T4, T5, T6, T7, T8)>;
1354
1355 /// Gets the 1st item
1356 #[wasm_bindgen(
1357 method,
1358 js_class = Array,
1359 getter,
1360 js_name = "0"
1361 )]
1362 pub fn get0<T: JsTuple1 = (JsValue,)>(this: &ArrayTuple<T>) -> <T as JsTuple1>::T1;
1363
1364 /// Gets the 2nd item
1365 #[wasm_bindgen(
1366 method,
1367 js_class = Array,
1368 getter,
1369 js_name = "1"
1370 )]
1371 pub fn get1<T: JsTuple2 = (JsValue, JsValue)>(this: &ArrayTuple<T>) -> <T as JsTuple2>::T2;
1372
1373 /// Gets the 3rd item
1374 #[wasm_bindgen(
1375 method,
1376 js_class = Array,
1377 getter,
1378 js_name = "2"
1379 )]
1380 pub fn get2<T: JsTuple3 = (JsValue, JsValue, JsValue)>(
1381 this: &ArrayTuple<T>,
1382 ) -> <T as JsTuple3>::T3;
1383
1384 /// Gets the 4th item
1385 #[wasm_bindgen(
1386 method,
1387 js_class = Array,
1388 getter,
1389 js_name = "3"
1390 )]
1391 pub fn get3<T: JsTuple4 = (JsValue, JsValue, JsValue, JsValue)>(
1392 this: &ArrayTuple<T>,
1393 ) -> <T as JsTuple4>::T4;
1394
1395 /// Gets the 5th item
1396 #[wasm_bindgen(
1397 method,
1398 js_class = Array,
1399 getter,
1400 js_name = "4"
1401 )]
1402 pub fn get4<T: JsTuple5 = (JsValue, JsValue, JsValue, JsValue, JsValue)>(
1403 this: &ArrayTuple<T>,
1404 ) -> <T as JsTuple5>::T5;
1405
1406 /// Gets the 6th item
1407 #[wasm_bindgen(
1408 method,
1409 js_class = Array,
1410 getter,
1411 js_name = "5"
1412 )]
1413 pub fn get5<T: JsTuple6 = (JsValue, JsValue, JsValue, JsValue, JsValue, JsValue)>(
1414 this: &ArrayTuple<T>,
1415 ) -> <T as JsTuple6>::T6;
1416
1417 /// Gets the 7th item
1418 #[wasm_bindgen(
1419 method,
1420 js_class = Array,
1421 getter,
1422 js_name = "6"
1423 )]
1424 pub fn get6<
1425 T: JsTuple7 = (
1426 JsValue,
1427 JsValue,
1428 JsValue,
1429 JsValue,
1430 JsValue,
1431 JsValue,
1432 JsValue,
1433 ),
1434 >(
1435 this: &ArrayTuple<T>,
1436 ) -> <T as JsTuple7>::T7;
1437
1438 /// Gets the 8th item
1439 #[wasm_bindgen(
1440 method,
1441 js_class = Array,
1442 getter,
1443 js_name = "7"
1444 )]
1445 pub fn get7<
1446 T: JsTuple8 = (
1447 JsValue,
1448 JsValue,
1449 JsValue,
1450 JsValue,
1451 JsValue,
1452 JsValue,
1453 JsValue,
1454 JsValue,
1455 ),
1456 >(
1457 this: &ArrayTuple<T>,
1458 ) -> <T as JsTuple8>::T8;
1459
1460 /// Sets the 1st item
1461 #[wasm_bindgen(
1462 method,
1463 js_class = Array,
1464 setter,
1465 js_name = "0"
1466 )]
1467 pub fn set0<T: JsTuple1 = (JsValue,)>(this: &ArrayTuple<T>, value: &<T as JsTuple1>::T1);
1468
1469 /// Sets the 2nd item
1470 #[wasm_bindgen(
1471 method,
1472 js_class = Array,
1473 setter,
1474 js_name = "1"
1475 )]
1476 pub fn set1<T: JsTuple2 = (JsValue, JsValue)>(
1477 this: &ArrayTuple<T>,
1478 value: &<T as JsTuple2>::T2,
1479 );
1480
1481 /// Sets the 3rd item
1482 #[wasm_bindgen(
1483 method,
1484 js_class = Array,
1485 setter,
1486 js_name = "2"
1487 )]
1488 pub fn set2<T: JsTuple3 = (JsValue, JsValue, JsValue)>(
1489 this: &ArrayTuple<T>,
1490 value: &<T as JsTuple3>::T3,
1491 );
1492
1493 /// Sets the 4th item
1494 #[wasm_bindgen(
1495 method,
1496 js_class = Array,
1497 setter,
1498 js_name = "3"
1499 )]
1500 pub fn set3<T: JsTuple4 = (JsValue, JsValue, JsValue, JsValue)>(
1501 this: &ArrayTuple<T>,
1502 value: &<T as JsTuple4>::T4,
1503 );
1504
1505 /// Sets the 5th item
1506 #[wasm_bindgen(
1507 method,
1508 js_class = Array,
1509 setter,
1510 js_name = "4"
1511 )]
1512 pub fn set4<T: JsTuple5 = (JsValue, JsValue, JsValue, JsValue, JsValue)>(
1513 this: &ArrayTuple<T>,
1514 value: &<T as JsTuple5>::T5,
1515 );
1516
1517 /// Sets the 6th item
1518 #[wasm_bindgen(
1519 method,
1520 js_class = Array,
1521 setter,
1522 js_name = "5"
1523 )]
1524 pub fn set5<T: JsTuple6 = (JsValue, JsValue, JsValue, JsValue, JsValue, JsValue)>(
1525 this: &ArrayTuple<T>,
1526 value: &<T as JsTuple6>::T6,
1527 );
1528
1529 /// Sets the 7th item
1530 #[wasm_bindgen(
1531 method,
1532 js_class = Array,
1533 setter,
1534 js_name = "6"
1535 )]
1536 pub fn set6<
1537 T: JsTuple7 = (
1538 JsValue,
1539 JsValue,
1540 JsValue,
1541 JsValue,
1542 JsValue,
1543 JsValue,
1544 JsValue,
1545 ),
1546 >(
1547 this: &ArrayTuple<T>,
1548 value: &<T as JsTuple7>::T7,
1549 );
1550
1551 /// Sets the 8th item
1552 #[wasm_bindgen(
1553 method,
1554 js_class = Array,
1555 setter,
1556 js_name = "7"
1557 )]
1558 pub fn set7<
1559 T: JsTuple8 = (
1560 JsValue,
1561 JsValue,
1562 JsValue,
1563 JsValue,
1564 JsValue,
1565 JsValue,
1566 JsValue,
1567 JsValue,
1568 ),
1569 >(
1570 this: &ArrayTuple<T>,
1571 value: &<T as JsTuple8>::T8,
1572 );
1573}
1574
1575/// Base trait for tuple types.
1576pub trait JsTuple {
1577 const ARITY: usize;
1578}
1579
1580macro_rules! impl_tuple_traits {
1581 // Base case: first trait has no parent (besides JsTuple)
1582 ($name:ident $ty:tt) => {
1583 pub trait $name: JsTuple {
1584 type $ty;
1585 }
1586 };
1587
1588 // Recursive case: define trait with parent, then recurse
1589 ($name:ident $ty:tt $($rest_name:ident $rest_ty:tt)+) => {
1590 pub trait $name: JsTuple {
1591 type $ty;
1592 }
1593
1594 impl_tuple_traits!(@with_parent $name $($rest_name $rest_ty)+);
1595 };
1596
1597 // Internal: traits that have a parent
1598 (@with_parent $trait:ident $name:ident $ty:tt) => {
1599 pub trait $name: $trait {
1600 type $ty;
1601 }
1602 };
1603
1604 (@with_parent $trait:ident $name:ident $ty:tt $($rest_name:ident $rest_ty:tt)+) => {
1605 pub trait $name: $trait {
1606 type $ty;
1607 }
1608
1609 impl_tuple_traits!(@with_parent $name $($rest_name $rest_ty)+);
1610 };
1611}
1612
1613macro_rules! impl_parent_traits {
1614 ([$($types:tt),+] [] []) => {};
1615
1616 ([$($types:tt),+] [$trait:ident $($rest_traits:ident)*] [$ty:tt $($rest_tys:tt)*]) => {
1617 impl<$($types),+> $trait for ($($types),+,) {
1618 type $ty = $ty;
1619 }
1620
1621 impl_parent_traits!([$($types),+] [$($rest_traits)*] [$($rest_tys)*]);
1622 };
1623}
1624
1625// Define the trait hierarchy once
1626impl_tuple_traits!(
1627 JsTuple1 T1
1628 JsTuple2 T2
1629 JsTuple3 T3
1630 JsTuple4 T4
1631 JsTuple5 T5
1632 JsTuple6 T6
1633 JsTuple7 T7
1634 JsTuple8 T8
1635);
1636
1637impl<T: JsTuple> ArrayTuple<T> {
1638 /// Get the static arity of the ArrayTuple type.
1639 #[allow(clippy::len_without_is_empty)]
1640 pub fn len(&self) -> usize {
1641 <T as JsTuple>::ARITY
1642 }
1643}
1644
1645macro_rules! impl_tuple {
1646 ($arity:literal [$($traits:ident)*] [$($T:tt)+] [$($vars:tt)+] $new:ident $last:ident $last_ty:tt) => {
1647 impl<$($T),+> JsTuple for ($($T),+,) {
1648 const ARITY: usize = $arity;
1649 }
1650
1651 impl_parent_traits!([$($T),+] [$($traits)*] [$($T)*]);
1652
1653 impl<$($T: JsGeneric),+> From<($($T,)+)> for ArrayTuple<($($T),+,)> {
1654 fn from(($($vars,)+): ($($T,)+)) -> Self {
1655 $(let $vars: JsValue = $vars.upcast_into();)+
1656 Array::of(&[$($vars),+]).unchecked_into()
1657 }
1658 }
1659
1660 impl<$($T: JsGeneric + Default),+> Default for ArrayTuple<($($T),+,)> {
1661 fn default() -> Self {
1662 (
1663 $($T::default(),)+
1664 ).into()
1665 }
1666 }
1667
1668 impl<$($T: JsGeneric),+> ArrayTuple<($($T),+,)> {
1669 /// Get the first element of the ArrayTuple
1670 pub fn first(&self) -> T1 {
1671 self.get0()
1672 }
1673
1674 /// Get the last element of the ArrayTuple
1675 pub fn last(&self) -> $last_ty {
1676 self.$last()
1677 }
1678
1679 /// Convert the ArrayTuple into its corresponding Rust tuple
1680 pub fn into_parts(self) -> ($($T,)+) {
1681 ($(self.$vars(),)+)
1682 }
1683
1684 /// Create a new ArrayTuple from the corresponding parts.
1685 ///
1686 /// # Example
1687 ///
1688 /// ```
1689 /// use js_sys::{ArrayTuple, JsString};
1690 ///
1691 /// let tuple = ArrayTuple::<JsString, JsString>::new(&"a".into(), &"b".into());
1692 /// ```
1693 ///
1694 /// Note: You must specify the T using `::<...>` syntax on `ArrayTuple`.
1695 /// Alternatively, use `new1`, `new2`, etc. for type inference from the left-hand side.
1696 pub fn new($($vars: &$T),+) -> ArrayTuple<($($T),+,)> {
1697 ArrayTuple::$new($($vars),+)
1698 }
1699 }
1700 };
1701}
1702
1703// Implement for each tuple size
1704impl_tuple!(1 [JsTuple1] [T1] [get0] new1 get0 T1);
1705impl_tuple!(2 [JsTuple1 JsTuple2] [T1 T2] [get0 get1] new2 get1 T2);
1706impl_tuple!(3 [JsTuple1 JsTuple2 JsTuple3] [T1 T2 T3] [get0 get1 get2] new3 get2 T3);
1707impl_tuple!(4 [JsTuple1 JsTuple2 JsTuple3 JsTuple4] [T1 T2 T3 T4] [get0 get1 get2 get3] new4 get3 T4);
1708impl_tuple!(5 [JsTuple1 JsTuple2 JsTuple3 JsTuple4 JsTuple5] [T1 T2 T3 T4 T5] [get0 get1 get2 get3 get4] new5 get4 T5);
1709impl_tuple!(6 [JsTuple1 JsTuple2 JsTuple3 JsTuple4 JsTuple5 JsTuple6] [T1 T2 T3 T4 T5 T6] [get0 get1 get2 get3 get4 get5] new6 get5 T6);
1710impl_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);
1711impl_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);
1712
1713// Macro to generate structural covariance impls for each arity
1714macro_rules! impl_tuple_covariance {
1715 ([$($T:ident)+] [$($Target:ident)+] [$($Ts:ident)+]) => {
1716 // ArrayTuple -> Array
1717 // Allows (T1, T2, ...) to be used where (Target) is expected
1718 // when all T1, T2, ... are covariant to Target
1719 impl<$($T,)+ Target> UpcastFrom<ArrayTuple<($($T,)+)>> for Array<Target>
1720 where
1721 $(Target: UpcastFrom<$T>,)+
1722 {
1723 }
1724 impl<$($T,)+ Target> UpcastFrom<ArrayTuple<($($T,)+)>> for JsOption<Array<Target>>
1725 where
1726 $(Target: UpcastFrom<$T>,)+
1727 {}
1728 // Array<T> -> ArrayTuple<T, ...>
1729 impl<T> UpcastFrom<Array<T>> for ArrayTuple<($($Ts,)+)> {}
1730 impl<T: JsGeneric> UpcastFrom<Array<T>> for ArrayTuple<($(JsOption<$Ts>,)+)> {}
1731 };
1732}
1733
1734impl_tuple_covariance!([T1][Target1][T]);
1735impl_tuple_covariance!([T1 T2] [Target1 Target2] [T T]);
1736impl_tuple_covariance!([T1 T2 T3] [Target1 Target2 Target3] [T T T]);
1737impl_tuple_covariance!([T1 T2 T3 T4] [Target1 Target2 Target3 Target4] [T T T T]);
1738impl_tuple_covariance!([T1 T2 T3 T4 T5] [Target1 Target2 Target3 Target4 Target5] [T T T T T]);
1739impl_tuple_covariance!([T1 T2 T3 T4 T5 T6] [Target1 Target2 Target3 Target4 Target5 Target6] [T T T T T T]);
1740impl_tuple_covariance!([T1 T2 T3 T4 T5 T6 T7] [Target1 Target2 Target3 Target4 Target5 Target6 Target7] [T T T T T T T]);
1741impl_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]);
1742
1743// Tuple casting is implemented in core
1744impl<T: JsTuple, U: JsTuple> UpcastFrom<ArrayTuple<T>> for ArrayTuple<U> where U: UpcastFrom<T> {}
1745impl<T: JsTuple> UpcastFrom<ArrayTuple<T>> for JsValue {}
1746impl<T: JsTuple> UpcastFrom<ArrayTuple<T>> for JsOption<JsValue> {}
1747
1748/// Iterator returned by `Array::into_iter`
1749#[derive(Debug, Clone)]
1750pub struct ArrayIntoIter<T: JsGeneric = JsValue> {
1751 range: core::ops::Range<u32>,
1752 array: Array<T>,
1753}
1754
1755#[cfg(not(js_sys_unstable_apis))]
1756impl<T: JsGeneric> core::iter::Iterator for ArrayIntoIter<T> {
1757 type Item = T;
1758
1759 fn next(&mut self) -> Option<Self::Item> {
1760 let index = self.range.next()?;
1761 Some(self.array.get(index))
1762 }
1763
1764 #[inline]
1765 fn size_hint(&self) -> (usize, Option<usize>) {
1766 self.range.size_hint()
1767 }
1768
1769 #[inline]
1770 fn count(self) -> usize
1771 where
1772 Self: Sized,
1773 {
1774 self.range.count()
1775 }
1776
1777 #[inline]
1778 fn last(self) -> Option<Self::Item>
1779 where
1780 Self: Sized,
1781 {
1782 let Self { range, array } = self;
1783 range.last().map(|index| array.get(index))
1784 }
1785
1786 #[inline]
1787 fn nth(&mut self, n: usize) -> Option<Self::Item> {
1788 self.range.nth(n).map(|index| self.array.get(index))
1789 }
1790}
1791
1792#[cfg(js_sys_unstable_apis)]
1793impl<T: JsGeneric> core::iter::Iterator for ArrayIntoIter<T> {
1794 type Item = T;
1795
1796 fn next(&mut self) -> Option<Self::Item> {
1797 let index = self.range.next()?;
1798 self.array.get(index)
1799 }
1800
1801 #[inline]
1802 fn size_hint(&self) -> (usize, Option<usize>) {
1803 self.range.size_hint()
1804 }
1805
1806 #[inline]
1807 fn count(self) -> usize
1808 where
1809 Self: Sized,
1810 {
1811 self.range.count()
1812 }
1813
1814 #[inline]
1815 fn last(self) -> Option<Self::Item>
1816 where
1817 Self: Sized,
1818 {
1819 let Self { range, array } = self;
1820 range.last().and_then(|index| array.get(index))
1821 }
1822
1823 #[inline]
1824 fn nth(&mut self, n: usize) -> Option<Self::Item> {
1825 self.range.nth(n).and_then(|index| self.array.get(index))
1826 }
1827}
1828
1829#[cfg(not(js_sys_unstable_apis))]
1830impl<T: JsGeneric> core::iter::DoubleEndedIterator for ArrayIntoIter<T> {
1831 fn next_back(&mut self) -> Option<Self::Item> {
1832 let index = self.range.next_back()?;
1833 Some(self.array.get(index))
1834 }
1835
1836 fn nth_back(&mut self, n: usize) -> Option<Self::Item> {
1837 self.range.nth_back(n).map(|index| self.array.get(index))
1838 }
1839}
1840
1841#[cfg(js_sys_unstable_apis)]
1842impl<T: JsGeneric> core::iter::DoubleEndedIterator for ArrayIntoIter<T> {
1843 fn next_back(&mut self) -> Option<Self::Item> {
1844 let index = self.range.next_back()?;
1845 self.array.get(index)
1846 }
1847
1848 fn nth_back(&mut self, n: usize) -> Option<Self::Item> {
1849 self.range
1850 .nth_back(n)
1851 .and_then(|index| self.array.get(index))
1852 }
1853}
1854
1855impl<T: JsGeneric> core::iter::FusedIterator for ArrayIntoIter<T> {}
1856
1857impl<T: JsGeneric> core::iter::ExactSizeIterator for ArrayIntoIter<T> {}
1858
1859/// Iterator returned by `Array::iter`
1860#[derive(Debug, Clone)]
1861pub struct ArrayIter<'a, T: JsGeneric = JsValue> {
1862 range: core::ops::Range<u32>,
1863 array: &'a Array<T>,
1864}
1865
1866impl<T: JsGeneric> core::iter::Iterator for ArrayIter<'_, T> {
1867 type Item = T;
1868
1869 fn next(&mut self) -> Option<Self::Item> {
1870 let index = self.range.next()?;
1871 Some(self.array.get_unchecked(index))
1872 }
1873
1874 #[inline]
1875 fn size_hint(&self) -> (usize, Option<usize>) {
1876 self.range.size_hint()
1877 }
1878
1879 #[inline]
1880 fn count(self) -> usize
1881 where
1882 Self: Sized,
1883 {
1884 self.range.count()
1885 }
1886
1887 #[inline]
1888 fn last(self) -> Option<Self::Item>
1889 where
1890 Self: Sized,
1891 {
1892 let Self { range, array } = self;
1893 range.last().map(|index| array.get_unchecked(index))
1894 }
1895
1896 #[inline]
1897 fn nth(&mut self, n: usize) -> Option<Self::Item> {
1898 self.range
1899 .nth(n)
1900 .map(|index| self.array.get_unchecked(index))
1901 }
1902}
1903
1904impl<T: JsGeneric> core::iter::DoubleEndedIterator for ArrayIter<'_, T> {
1905 fn next_back(&mut self) -> Option<Self::Item> {
1906 let index = self.range.next_back()?;
1907 Some(self.array.get_unchecked(index))
1908 }
1909
1910 fn nth_back(&mut self, n: usize) -> Option<Self::Item> {
1911 self.range
1912 .nth_back(n)
1913 .map(|index| self.array.get_unchecked(index))
1914 }
1915}
1916
1917impl<T: JsGeneric> core::iter::FusedIterator for ArrayIter<'_, T> {}
1918
1919impl<T: JsGeneric> core::iter::ExactSizeIterator for ArrayIter<'_, T> {}
1920
1921impl<T: JsGeneric> Array<T> {
1922 /// Returns an iterator over the values of the JS array.
1923 pub fn iter(&self) -> ArrayIter<'_, T> {
1924 ArrayIter {
1925 range: 0..self.length(),
1926 array: self,
1927 }
1928 }
1929}
1930
1931impl<T: JsGeneric> core::iter::IntoIterator for Array<T> {
1932 type Item = T;
1933 type IntoIter = ArrayIntoIter<T>;
1934
1935 fn into_iter(self) -> Self::IntoIter {
1936 ArrayIntoIter {
1937 range: 0..self.length(),
1938 array: self,
1939 }
1940 }
1941}
1942
1943#[cfg(not(js_sys_unstable_apis))]
1944impl<A, T: JsGeneric> core::iter::FromIterator<A> for Array<T>
1945where
1946 A: AsRef<T>,
1947{
1948 fn from_iter<I>(iter: I) -> Array<T>
1949 where
1950 I: IntoIterator<Item = A>,
1951 {
1952 let iter = iter.into_iter();
1953 let mut out = Array::new_typed();
1954 out.extend(iter);
1955 out
1956 }
1957}
1958
1959#[cfg(js_sys_unstable_apis)]
1960impl<A, T: JsGeneric> core::iter::FromIterator<A> for Array<T>
1961where
1962 A: AsRef<T>,
1963{
1964 fn from_iter<I>(iter: I) -> Array<T>
1965 where
1966 I: IntoIterator<Item = A>,
1967 {
1968 let iter = iter.into_iter();
1969 let (lower, upper) = iter.size_hint();
1970 let capacity = upper.unwrap_or(lower);
1971 let out = Array::new_with_length_typed(capacity as u32);
1972 let mut i = 0;
1973 for value in iter {
1974 out.set(i, value.as_ref());
1975 i += 1;
1976 }
1977 out
1978 }
1979}
1980
1981impl<A, T: JsGeneric> core::iter::Extend<A> for Array<T>
1982where
1983 A: AsRef<T>,
1984{
1985 fn extend<I>(&mut self, iter: I)
1986 where
1987 I: IntoIterator<Item = A>,
1988 {
1989 for value in iter {
1990 self.push(value.as_ref());
1991 }
1992 }
1993}
1994
1995impl Default for Array<JsValue> {
1996 fn default() -> Self {
1997 Self::new()
1998 }
1999}
2000
2001impl<T> Iterable for Array<T> {
2002 type Item = T;
2003}
2004
2005impl<T: JsTuple> Iterable for ArrayTuple<T> {
2006 type Item = JsValue;
2007}
2008
2009// ArrayBufferOptions
2010#[wasm_bindgen]
2011extern "C" {
2012 #[wasm_bindgen(extends = Object, typescript_type = "ArrayBufferOptions")]
2013 #[derive(Clone, Debug, PartialEq, Eq)]
2014 pub type ArrayBufferOptions;
2015
2016 /// The maximum size, in bytes, that the array buffer can be resized to.
2017 #[wasm_bindgen(method, setter, js_name = maxByteLength)]
2018 pub fn set_max_byte_length(this: &ArrayBufferOptions, max_byte_length: usize);
2019
2020 /// The maximum size, in bytes, that the array buffer can be resized to.
2021 #[wasm_bindgen(method, getter, js_name = maxByteLength)]
2022 pub fn get_max_byte_length(this: &ArrayBufferOptions) -> usize;
2023}
2024
2025impl ArrayBufferOptions {
2026 #[cfg(not(js_sys_unstable_apis))]
2027 pub fn new(max_byte_length: usize) -> ArrayBufferOptions {
2028 let options = JsCast::unchecked_into::<ArrayBufferOptions>(Object::new());
2029 options.set_max_byte_length(max_byte_length);
2030 options
2031 }
2032
2033 #[cfg(js_sys_unstable_apis)]
2034 pub fn new(max_byte_length: usize) -> ArrayBufferOptions {
2035 let options = JsCast::unchecked_into::<ArrayBufferOptions>(Object::<JsValue>::new());
2036 options.set_max_byte_length(max_byte_length);
2037 options
2038 }
2039}
2040
2041// ArrayBuffer
2042#[wasm_bindgen]
2043extern "C" {
2044 #[wasm_bindgen(extends = Object, typescript_type = "ArrayBuffer")]
2045 #[derive(Clone, Debug, PartialEq, Eq)]
2046 pub type ArrayBuffer;
2047
2048 /// The `ArrayBuffer` object is used to represent a generic,
2049 /// fixed-length raw binary data buffer. You cannot directly
2050 /// manipulate the contents of an `ArrayBuffer`; instead, you
2051 /// create one of the typed array objects or a `DataView` object
2052 /// which represents the buffer in a specific format, and use that
2053 /// to read and write the contents of the buffer.
2054 ///
2055 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer)
2056 #[cfg(not(js_sys_unstable_apis))]
2057 #[wasm_bindgen(constructor)]
2058 pub fn new(length: u32) -> ArrayBuffer;
2059
2060 /// The `ArrayBuffer` object is used to represent a generic,
2061 /// fixed-length raw binary data buffer. You cannot directly
2062 /// manipulate the contents of an `ArrayBuffer`; instead, you
2063 /// create one of the typed array objects or a `DataView` object
2064 /// which represents the buffer in a specific format, and use that
2065 /// to read and write the contents of the buffer.
2066 ///
2067 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer)
2068 #[cfg(js_sys_unstable_apis)]
2069 #[wasm_bindgen(constructor)]
2070 pub fn new(length: usize) -> ArrayBuffer;
2071
2072 /// The `ArrayBuffer` object is used to represent a generic,
2073 /// fixed-length raw binary data buffer. You cannot directly
2074 /// manipulate the contents of an `ArrayBuffer`; instead, you
2075 /// create one of the typed array objects or a `DataView` object
2076 /// which represents the buffer in a specific format, and use that
2077 /// to read and write the contents of the buffer.
2078 ///
2079 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer)
2080 #[wasm_bindgen(constructor)]
2081 pub fn new_with_options(length: usize, options: &ArrayBufferOptions) -> ArrayBuffer;
2082
2083 /// The `byteLength` property of an object which is an instance of type ArrayBuffer
2084 /// it's an accessor property whose set accessor function is undefined,
2085 /// meaning that you can only read this property.
2086 /// The value is established when the array is constructed and cannot be changed.
2087 /// This property returns 0 if this ArrayBuffer has been detached.
2088 ///
2089 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/byteLength)
2090 #[cfg(not(js_sys_unstable_apis))]
2091 #[wasm_bindgen(method, getter, js_name = byteLength)]
2092 pub fn byte_length(this: &ArrayBuffer) -> u32;
2093
2094 /// The `byteLength` property of an object which is an instance of type ArrayBuffer
2095 /// it's an accessor property whose set accessor function is undefined,
2096 /// meaning that you can only read this property.
2097 /// The value is established when the array is constructed and cannot be changed.
2098 /// This property returns 0 if this ArrayBuffer has been detached.
2099 ///
2100 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/byteLength)
2101 #[cfg(js_sys_unstable_apis)]
2102 #[wasm_bindgen(method, getter, js_name = byteLength)]
2103 pub fn byte_length(this: &ArrayBuffer) -> usize;
2104
2105 /// The `detached` accessor property of `ArrayBuffer` instances returns a boolean indicating
2106 /// whether or not this buffer has been detached (transferred).
2107 ///
2108 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/detached)
2109 #[wasm_bindgen(method, getter)]
2110 pub fn detached(this: &ArrayBuffer) -> bool;
2111
2112 /// The `isView()` method returns true if arg is one of the `ArrayBuffer`
2113 /// views, such as typed array objects or a DataView; false otherwise.
2114 ///
2115 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/isView)
2116 #[wasm_bindgen(static_method_of = ArrayBuffer, js_name = isView)]
2117 pub fn is_view(value: &JsValue) -> bool;
2118
2119 /// The `maxByteLength` accessor property of ArrayBuffer instances returns the maximum
2120 /// length (in bytes) that this array buffer can be resized to.
2121 ///
2122 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/maxByteLength)
2123 #[wasm_bindgen(method, getter, js_name = maxByteLength)]
2124 pub fn max_byte_length(this: &ArrayBuffer) -> usize;
2125
2126 /// The `resizable` accessor property of `ArrayBuffer` instances returns whether this array buffer
2127 /// can be resized or not.
2128 ///
2129 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/resizable)
2130 #[wasm_bindgen(method, getter)]
2131 pub fn resizable(this: &ArrayBuffer) -> bool;
2132
2133 /// The `resize()` method of ArrayBuffer instances resizes the ArrayBuffer to the
2134 /// specified size, in bytes.
2135 ///
2136 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/resize)
2137 #[wasm_bindgen(method, catch)]
2138 pub fn resize(this: &ArrayBuffer, new_len: usize) -> Result<(), JsValue>;
2139
2140 /// The `slice()` method returns a new `ArrayBuffer` whose contents
2141 /// are a copy of this `ArrayBuffer`'s bytes from begin, inclusive,
2142 /// up to end, exclusive.
2143 ///
2144 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/slice)
2145 #[cfg(not(js_sys_unstable_apis))]
2146 #[wasm_bindgen(method)]
2147 pub fn slice(this: &ArrayBuffer, begin: u32) -> ArrayBuffer;
2148
2149 /// The `slice()` method returns a new `ArrayBuffer` whose contents
2150 /// are a copy of this `ArrayBuffer`'s bytes from begin, inclusive,
2151 /// up to end, exclusive. Negative indices count from the end.
2152 ///
2153 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/slice)
2154 #[cfg(js_sys_unstable_apis)]
2155 #[wasm_bindgen(method)]
2156 pub fn slice(this: &ArrayBuffer, begin: isize, end: isize) -> ArrayBuffer;
2157
2158 /// The `slice()` method returns a new `ArrayBuffer` whose contents
2159 /// are a copy of this `ArrayBuffer`'s bytes from begin, inclusive,
2160 /// up to end, exclusive.
2161 ///
2162 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/slice)
2163 #[cfg(not(js_sys_unstable_apis))]
2164 #[wasm_bindgen(method, js_name = slice)]
2165 pub fn slice_from(this: &ArrayBuffer, begin: isize) -> ArrayBuffer;
2166
2167 /// The `slice()` method returns a new `ArrayBuffer` whose contents
2168 /// are a copy of this `ArrayBuffer`'s bytes from begin to the end.
2169 /// Negative indices count from the end.
2170 ///
2171 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/slice)
2172 #[cfg(js_sys_unstable_apis)]
2173 #[wasm_bindgen(method, js_name = slice)]
2174 pub fn slice_from(this: &ArrayBuffer, begin: isize) -> ArrayBuffer;
2175
2176 // Next major: deprecate
2177 /// Like `slice()` but with the `end` argument.
2178 ///
2179 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/slice)
2180 #[wasm_bindgen(method, js_name = slice)]
2181 pub fn slice_with_end(this: &ArrayBuffer, begin: u32, end: u32) -> ArrayBuffer;
2182
2183 /// The `transfer()` method of ArrayBuffer instances creates a new `ArrayBuffer`
2184 /// with the same byte content as this buffer, then detaches this buffer.
2185 ///
2186 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/transfer)
2187 #[wasm_bindgen(method, catch)]
2188 pub fn transfer(this: &ArrayBuffer) -> Result<ArrayBuffer, JsValue>;
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, js_name = transfer)]
2195 pub fn transfer_with_length(
2196 this: &ArrayBuffer,
2197 new_byte_length: usize,
2198 ) -> Result<ArrayBuffer, JsValue>;
2199
2200 /// The `transferToFixedLength()` method of `ArrayBuffer` instances creates a new non-resizable
2201 /// ArrayBuffer with the same byte content as this buffer, then detaches this buffer.
2202 ///
2203 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/transferToFixedLength)
2204 #[wasm_bindgen(method, catch, js_name = transferToFixedLength)]
2205 pub fn transfer_to_fixed_length(this: &ArrayBuffer) -> 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_with_length(
2213 this: &ArrayBuffer,
2214 new_byte_length: usize,
2215 ) -> Result<ArrayBuffer, JsValue>;
2216}
2217
2218impl UpcastFrom<&[u8]> for ArrayBuffer {}
2219
2220// SharedArrayBuffer
2221#[wasm_bindgen]
2222extern "C" {
2223 #[wasm_bindgen(extends = Object, typescript_type = "SharedArrayBuffer")]
2224 #[derive(Clone, Debug)]
2225 pub type SharedArrayBuffer;
2226
2227 /// The `SharedArrayBuffer` object is used to represent a generic,
2228 /// fixed-length raw binary data buffer, similar to the `ArrayBuffer`
2229 /// object, but in a way that they can be used to create views
2230 /// on shared memory. Unlike an `ArrayBuffer`, a `SharedArrayBuffer`
2231 /// cannot become detached.
2232 ///
2233 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer)
2234 #[cfg(not(js_sys_unstable_apis))]
2235 #[wasm_bindgen(constructor)]
2236 pub fn new(length: u32) -> SharedArrayBuffer;
2237
2238 /// The `SharedArrayBuffer` object is used to represent a generic,
2239 /// fixed-length raw binary data buffer, similar to the `ArrayBuffer`
2240 /// object, but in a way that they can be used to create views
2241 /// on shared memory. Unlike an `ArrayBuffer`, a `SharedArrayBuffer`
2242 /// cannot become detached.
2243 ///
2244 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer)
2245 #[cfg(js_sys_unstable_apis)]
2246 #[wasm_bindgen(constructor)]
2247 pub fn new(length: usize) -> SharedArrayBuffer;
2248
2249 /// The `SharedArrayBuffer` object is used to represent a generic,
2250 /// fixed-length raw binary data buffer, similar to the `ArrayBuffer`
2251 /// object, but in a way that they can be used to create views
2252 /// on shared memory. Unlike an `ArrayBuffer`, a `SharedArrayBuffer`
2253 /// cannot become detached.
2254 ///
2255 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer)
2256 #[wasm_bindgen(constructor)]
2257 pub fn new_with_options(length: usize, options: &ArrayBufferOptions) -> SharedArrayBuffer;
2258
2259 /// The `byteLength` accessor property represents the length of
2260 /// an `SharedArrayBuffer` in bytes. This is established when
2261 /// the `SharedArrayBuffer` is constructed and cannot be changed.
2262 ///
2263 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/byteLength)
2264 #[cfg(not(js_sys_unstable_apis))]
2265 #[wasm_bindgen(method, getter, js_name = byteLength)]
2266 pub fn byte_length(this: &SharedArrayBuffer) -> u32;
2267
2268 /// The `byteLength` accessor property represents the length of
2269 /// an `SharedArrayBuffer` in bytes. This is established when
2270 /// the `SharedArrayBuffer` is constructed and cannot be changed.
2271 ///
2272 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/byteLength)
2273 #[cfg(js_sys_unstable_apis)]
2274 #[wasm_bindgen(method, getter, js_name = byteLength)]
2275 pub fn byte_length(this: &SharedArrayBuffer) -> usize;
2276
2277 /// The `growable` accessor property of `SharedArrayBuffer` instances returns whether
2278 /// this `SharedArrayBuffer` can be grown or not.
2279 ///
2280 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/growable)
2281 #[wasm_bindgen(method, getter)]
2282 pub fn growable(this: &SharedArrayBuffer) -> bool;
2283
2284 /// The `grow()` method of `SharedArrayBuffer` instances grows the
2285 /// `SharedArrayBuffer` to the specified size, in bytes.
2286 ///
2287 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/grow)
2288 #[wasm_bindgen(method, catch)]
2289 pub fn grow(this: &SharedArrayBuffer, new_byte_length: usize) -> Result<(), JsValue>;
2290
2291 /// The `maxByteLength` accessor property of `SharedArrayBuffer` instances returns the maximum
2292 /// length (in bytes) that this `SharedArrayBuffer` can be resized to.
2293 ///
2294 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/maxByteLength)
2295 #[wasm_bindgen(method, getter, js_name = maxByteLength)]
2296 pub fn max_byte_length(this: &SharedArrayBuffer) -> usize;
2297
2298 /// The `slice()` method returns a new `SharedArrayBuffer` whose contents
2299 /// are a copy of this `SharedArrayBuffer`'s bytes from begin, inclusive,
2300 /// up to end, exclusive.
2301 ///
2302 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/slice)
2303 #[cfg(not(js_sys_unstable_apis))]
2304 #[wasm_bindgen(method)]
2305 pub fn slice(this: &SharedArrayBuffer, begin: u32) -> SharedArrayBuffer;
2306
2307 /// The `slice()` method returns a new `SharedArrayBuffer` whose contents
2308 /// are a copy of this `SharedArrayBuffer`'s bytes from begin, inclusive,
2309 /// up to end, exclusive. Negative indices count from the end.
2310 ///
2311 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/slice)
2312 #[cfg(js_sys_unstable_apis)]
2313 #[wasm_bindgen(method)]
2314 pub fn slice(this: &SharedArrayBuffer, begin: isize, end: isize) -> SharedArrayBuffer;
2315
2316 /// The `slice()` method returns a new `SharedArrayBuffer` whose contents
2317 /// are a copy of this `SharedArrayBuffer`'s bytes from begin, inclusive,
2318 /// up to end, exclusive.
2319 ///
2320 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/slice)
2321 #[cfg(not(js_sys_unstable_apis))]
2322 #[wasm_bindgen(method)]
2323 pub fn slice_from(this: &SharedArrayBuffer, begin: isize) -> SharedArrayBuffer;
2324
2325 /// The `slice()` method returns a new `SharedArrayBuffer` whose contents
2326 /// are a copy of this `SharedArrayBuffer`'s bytes from begin to end.
2327 /// Negative indices count from the end.
2328 ///
2329 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/slice)
2330 #[cfg(js_sys_unstable_apis)]
2331 #[wasm_bindgen(method)]
2332 pub fn slice_from(this: &SharedArrayBuffer, begin: isize) -> SharedArrayBuffer;
2333
2334 // Next major: deprecate
2335 /// Like `slice()` but with the `end` argument.
2336 ///
2337 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/slice)
2338 #[wasm_bindgen(method, js_name = slice)]
2339 pub fn slice_with_end(this: &SharedArrayBuffer, begin: u32, end: u32) -> SharedArrayBuffer;
2340}
2341
2342// Array Iterator
2343#[wasm_bindgen]
2344extern "C" {
2345 /// The `keys()` method returns a new Array Iterator object that contains the
2346 /// keys for each index in the array.
2347 ///
2348 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/keys)
2349 #[wasm_bindgen(method)]
2350 pub fn keys<T>(this: &Array<T>) -> Iterator<T>;
2351
2352 /// The `entries()` method returns a new Array Iterator object that contains
2353 /// the key/value pairs for each index in the array.
2354 ///
2355 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries)
2356 #[cfg(not(js_sys_unstable_apis))]
2357 #[wasm_bindgen(method)]
2358 #[deprecated(note = "recommended to use `Array::entries_typed` instead for typing")]
2359 #[allow(deprecated)]
2360 pub fn entries<T>(this: &Array<T>) -> Iterator<T>;
2361
2362 /// The `entries()` method returns a new Array Iterator object that contains
2363 /// the key/value pairs for each index in the array.
2364 ///
2365 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries)
2366 #[cfg(js_sys_unstable_apis)]
2367 #[wasm_bindgen(method)]
2368 pub fn entries<T: JsGeneric>(this: &Array<T>) -> Iterator<ArrayTuple<(Number, T)>>;
2369
2370 // Next major: deprecate
2371 /// The `entries()` method returns a new Array Iterator object that contains
2372 /// the key/value pairs for each index in the array.
2373 ///
2374 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries)
2375 #[wasm_bindgen(method, js_name = entries)]
2376 pub fn entries_typed<T: JsGeneric>(this: &Array<T>) -> Iterator<ArrayTuple<(Number, T)>>;
2377
2378 /// The `values()` method returns a new Array Iterator object that
2379 /// contains the values for each index in the array.
2380 ///
2381 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/values)
2382 #[wasm_bindgen(method)]
2383 pub fn values<T>(this: &Array<T>) -> Iterator<T>;
2384}
2385
2386pub trait TypedArray: JsGeneric {}
2387
2388// Next major: use usize/isize for indices
2389/// The `Atomics` object provides atomic operations as static methods.
2390/// They are used with `SharedArrayBuffer` objects.
2391///
2392/// The Atomic operations are installed on an `Atomics` module. Unlike
2393/// the other global objects, `Atomics` is not a constructor. You cannot
2394/// use it with a new operator or invoke the `Atomics` object as a
2395/// function. All properties and methods of `Atomics` are static
2396/// (as is the case with the Math object, for example).
2397/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics)
2398#[allow(non_snake_case)]
2399pub mod Atomics {
2400 use super::*;
2401
2402 #[wasm_bindgen]
2403 extern "C" {
2404 /// The static `Atomics.add()` method adds a given value at a given
2405 /// position in the array and returns the old value at that position.
2406 /// This atomic operation guarantees that no other write happens
2407 /// until the modified value is written back.
2408 ///
2409 /// You should use `add_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2410 ///
2411 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/add)
2412 #[wasm_bindgen(js_namespace = Atomics, catch)]
2413 pub fn add<T: TypedArray = Int32Array>(
2414 typed_array: &T,
2415 index: u32,
2416 value: i32,
2417 ) -> Result<i32, JsValue>;
2418
2419 /// The static `Atomics.add()` method adds a given value at a given
2420 /// position in the array and returns the old value at that position.
2421 /// This atomic operation guarantees that no other write happens
2422 /// until the modified value is written back.
2423 ///
2424 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2425 ///
2426 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/add)
2427 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = add)]
2428 pub fn add_bigint<T: TypedArray = Int32Array>(
2429 typed_array: &T,
2430 index: u32,
2431 value: i64,
2432 ) -> Result<i64, JsValue>;
2433
2434 /// The static `Atomics.and()` method computes a bitwise AND with a given
2435 /// value at a given position in the array, and returns the old value
2436 /// at that position.
2437 /// This atomic operation guarantees that no other write happens
2438 /// until the modified value is written back.
2439 ///
2440 /// You should use `and_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2441 ///
2442 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/and)
2443 #[wasm_bindgen(js_namespace = Atomics, catch)]
2444 pub fn and<T: TypedArray = Int32Array>(
2445 typed_array: &T,
2446 index: u32,
2447 value: i32,
2448 ) -> Result<i32, JsValue>;
2449
2450 /// The static `Atomics.and()` method computes a bitwise AND with a given
2451 /// value at a given position in the array, and returns the old value
2452 /// at that position.
2453 /// This atomic operation guarantees that no other write happens
2454 /// until the modified value is written back.
2455 ///
2456 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2457 ///
2458 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/and)
2459 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = and)]
2460 pub fn and_bigint<T: TypedArray = Int32Array>(
2461 typed_array: &T,
2462 index: u32,
2463 value: i64,
2464 ) -> Result<i64, JsValue>;
2465
2466 /// The static `Atomics.compareExchange()` method exchanges a given
2467 /// replacement value at a given position in the array, if a given expected
2468 /// value equals the old value. It returns the old value at that position
2469 /// whether it was equal to the expected value or not.
2470 /// This atomic operation guarantees that no other write happens
2471 /// until the modified value is written back.
2472 ///
2473 /// You should use `compare_exchange_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2474 ///
2475 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/compareExchange)
2476 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = compareExchange)]
2477 pub fn compare_exchange<T: TypedArray = Int32Array>(
2478 typed_array: &T,
2479 index: u32,
2480 expected_value: i32,
2481 replacement_value: i32,
2482 ) -> Result<i32, JsValue>;
2483
2484 /// The static `Atomics.compareExchange()` method exchanges a given
2485 /// replacement value at a given position in the array, if a given expected
2486 /// value equals the old value. It returns the old value at that position
2487 /// whether it was equal to the expected value or not.
2488 /// This atomic operation guarantees that no other write happens
2489 /// until the modified value is written back.
2490 ///
2491 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2492 ///
2493 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/compareExchange)
2494 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = compareExchange)]
2495 pub fn compare_exchange_bigint<T: TypedArray = Int32Array>(
2496 typed_array: &T,
2497 index: u32,
2498 expected_value: i64,
2499 replacement_value: i64,
2500 ) -> Result<i64, JsValue>;
2501
2502 /// The static `Atomics.exchange()` method stores a given value at a given
2503 /// position in the array and returns the old value at that position.
2504 /// This atomic operation guarantees that no other write happens
2505 /// until the modified value is written back.
2506 ///
2507 /// You should use `exchange_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2508 ///
2509 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/exchange)
2510 #[wasm_bindgen(js_namespace = Atomics, catch)]
2511 pub fn exchange<T: TypedArray = Int32Array>(
2512 typed_array: &T,
2513 index: u32,
2514 value: i32,
2515 ) -> Result<i32, JsValue>;
2516
2517 /// The static `Atomics.exchange()` method stores a given value at a given
2518 /// position in the array and returns the old value at that position.
2519 /// This atomic operation guarantees that no other write happens
2520 /// until the modified value is written back.
2521 ///
2522 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2523 ///
2524 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/exchange)
2525 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = exchange)]
2526 pub fn exchange_bigint<T: TypedArray = Int32Array>(
2527 typed_array: &T,
2528 index: u32,
2529 value: i64,
2530 ) -> Result<i64, JsValue>;
2531
2532 /// The static `Atomics.isLockFree()` method is used to determine
2533 /// whether to use locks or atomic operations. It returns true,
2534 /// if the given size is one of the `BYTES_PER_ELEMENT` property
2535 /// of integer `TypedArray` types.
2536 ///
2537 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/isLockFree)
2538 #[wasm_bindgen(js_namespace = Atomics, js_name = isLockFree)]
2539 pub fn is_lock_free(size: u32) -> bool;
2540
2541 /// The static `Atomics.load()` method returns a value at a given
2542 /// position in the array.
2543 ///
2544 /// You should use `load_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2545 ///
2546 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/load)
2547 #[wasm_bindgen(js_namespace = Atomics, catch)]
2548 pub fn load<T: TypedArray = Int32Array>(
2549 typed_array: &T,
2550 index: u32,
2551 ) -> Result<i32, JsValue>;
2552
2553 /// The static `Atomics.load()` method returns a value at a given
2554 /// position in the array.
2555 ///
2556 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2557 ///
2558 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/load)
2559 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = load)]
2560 pub fn load_bigint<T: TypedArray = Int32Array>(
2561 typed_array: &T,
2562 index: i64,
2563 ) -> Result<i64, JsValue>;
2564
2565 /// The static `Atomics.notify()` method notifies up some agents that
2566 /// are sleeping in the wait queue.
2567 /// Note: This operation works with a shared `Int32Array` only.
2568 /// If `count` is not provided, notifies all the agents in the queue.
2569 ///
2570 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/notify)
2571 #[wasm_bindgen(js_namespace = Atomics, catch)]
2572 pub fn notify(typed_array: &Int32Array, index: u32) -> Result<u32, JsValue>;
2573
2574 /// The static `Atomics.notify()` method notifies up some agents that
2575 /// are sleeping in the wait queue.
2576 /// Note: This operation works with a shared `Int32Array` only.
2577 /// If `count` is not provided, notifies all the agents in the queue.
2578 ///
2579 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/notify)
2580 #[wasm_bindgen(js_namespace = Atomics, catch)]
2581 pub fn notify_bigint(typed_array: &BigInt64Array, index: u32) -> Result<u32, JsValue>;
2582
2583 /// Notifies up to `count` agents in the wait queue.
2584 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = notify)]
2585 pub fn notify_with_count(
2586 typed_array: &Int32Array,
2587 index: u32,
2588 count: u32,
2589 ) -> Result<u32, JsValue>;
2590
2591 /// Notifies up to `count` agents in the wait queue.
2592 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = notify)]
2593 pub fn notify_bigint_with_count(
2594 typed_array: &BigInt64Array,
2595 index: u32,
2596 count: u32,
2597 ) -> Result<u32, JsValue>;
2598
2599 /// The static `Atomics.or()` method computes a bitwise OR with a given value
2600 /// at a given position in the array, and returns the old value at that position.
2601 /// This atomic operation guarantees that no other write happens
2602 /// until the modified value is written back.
2603 ///
2604 /// You should use `or_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2605 ///
2606 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/or)
2607 #[wasm_bindgen(js_namespace = Atomics, catch)]
2608 pub fn or<T: TypedArray = Int32Array>(
2609 typed_array: &T,
2610 index: u32,
2611 value: i32,
2612 ) -> Result<i32, JsValue>;
2613
2614 /// The static `Atomics.or()` method computes a bitwise OR with a given value
2615 /// at a given position in the array, and returns the old value at that position.
2616 /// This atomic operation guarantees that no other write happens
2617 /// until the modified value is written back.
2618 ///
2619 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2620 ///
2621 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/or)
2622 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = or)]
2623 pub fn or_bigint<T: TypedArray = Int32Array>(
2624 typed_array: &T,
2625 index: u32,
2626 value: i64,
2627 ) -> Result<i64, JsValue>;
2628
2629 /// The static `Atomics.pause()` static method provides a micro-wait primitive that hints to the CPU
2630 /// that the caller is spinning while waiting on access to a shared resource. This allows the system
2631 /// to reduce the resources allocated to the core (such as power) or thread, without yielding the
2632 /// current thread.
2633 ///
2634 /// `pause()` has no observable behavior other than timing. The exact behavior is dependent on the CPU
2635 /// architecture and the operating system. For example, in Intel x86, it may be a pause instruction as
2636 /// per Intel's optimization manual. It could be a no-op in certain platforms.
2637 ///
2638 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2639 ///
2640 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/xor)
2641 #[wasm_bindgen(js_namespace = Atomics)]
2642 pub fn pause();
2643
2644 /// The static `Atomics.pause()` static method provides a micro-wait primitive that hints to the CPU
2645 /// that the caller is spinning while waiting on access to a shared resource. This allows the system
2646 /// to reduce the resources allocated to the core (such as power) or thread, without yielding the
2647 /// current thread.
2648 ///
2649 /// `pause()` has no observable behavior other than timing. The exact behavior is dependent on the CPU
2650 /// architecture and the operating system. For example, in Intel x86, it may be a pause instruction as
2651 /// per Intel's optimization manual. It could be a no-op in certain platforms.
2652 ///
2653 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2654 ///
2655 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/xor)
2656 #[wasm_bindgen(js_namespace = Atomics)]
2657 pub fn pause_with_hint(duration_hint: u32);
2658
2659 /// The static `Atomics.store()` method stores a given value at the given
2660 /// position in the array and returns that value.
2661 ///
2662 /// You should use `store_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2663 ///
2664 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/store)
2665 #[wasm_bindgen(js_namespace = Atomics, catch)]
2666 pub fn store<T: TypedArray = Int32Array>(
2667 typed_array: &T,
2668 index: u32,
2669 value: i32,
2670 ) -> Result<i32, JsValue>;
2671
2672 /// The static `Atomics.store()` method stores a given value at the given
2673 /// position in the array and returns that value.
2674 ///
2675 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2676 ///
2677 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/store)
2678 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = store)]
2679 pub fn store_bigint<T: TypedArray = Int32Array>(
2680 typed_array: &T,
2681 index: u32,
2682 value: i64,
2683 ) -> Result<i64, JsValue>;
2684
2685 /// The static `Atomics.sub()` method subtracts a given value at a
2686 /// given position in the array and returns the old value at that position.
2687 /// This atomic operation guarantees that no other write happens
2688 /// until the modified value is written back.
2689 ///
2690 /// You should use `sub_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2691 ///
2692 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/sub)
2693 #[wasm_bindgen(js_namespace = Atomics, catch)]
2694 pub fn sub<T: TypedArray = Int32Array>(
2695 typed_array: &T,
2696 index: u32,
2697 value: i32,
2698 ) -> Result<i32, JsValue>;
2699
2700 /// The static `Atomics.sub()` method subtracts a given value at a
2701 /// given position in the array and returns the old value at that position.
2702 /// This atomic operation guarantees that no other write happens
2703 /// until the modified value is written back.
2704 ///
2705 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2706 ///
2707 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/sub)
2708 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = sub)]
2709 pub fn sub_bigint<T: TypedArray = Int32Array>(
2710 typed_array: &T,
2711 index: u32,
2712 value: i64,
2713 ) -> Result<i64, JsValue>;
2714
2715 /// The static `Atomics.wait()` method verifies that a given
2716 /// position in an `Int32Array` still contains a given value
2717 /// and if so sleeps, awaiting a wakeup or a timeout.
2718 /// It returns a string which is either "ok", "not-equal", or "timed-out".
2719 /// Note: This operation only works with a shared `Int32Array`
2720 /// and may not be allowed on the main thread.
2721 ///
2722 /// You should use `wait_bigint` to operate on a `BigInt64Array`.
2723 ///
2724 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait)
2725 #[wasm_bindgen(js_namespace = Atomics, catch)]
2726 pub fn wait(typed_array: &Int32Array, index: u32, value: i32) -> Result<JsString, JsValue>;
2727
2728 /// The static `Atomics.wait()` method verifies that a given
2729 /// position in an `BigInt64Array` still contains a given value
2730 /// and if so sleeps, awaiting a wakeup or a timeout.
2731 /// It returns a string which is either "ok", "not-equal", or "timed-out".
2732 /// Note: This operation only works with a shared `BigInt64Array`
2733 /// and may not be allowed on the main thread.
2734 ///
2735 /// You should use `wait` to operate on a `Int32Array`.
2736 ///
2737 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait)
2738 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = wait)]
2739 pub fn wait_bigint(
2740 typed_array: &BigInt64Array,
2741 index: u32,
2742 value: i64,
2743 ) -> Result<JsString, JsValue>;
2744
2745 /// Like `wait()`, but with timeout
2746 ///
2747 /// You should use `wait_with_timeout_bigint` to operate on a `BigInt64Array`.
2748 ///
2749 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait)
2750 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = wait)]
2751 pub fn wait_with_timeout(
2752 typed_array: &Int32Array,
2753 index: u32,
2754 value: i32,
2755 timeout: f64,
2756 ) -> Result<JsString, JsValue>;
2757
2758 /// Like `wait()`, but with timeout
2759 ///
2760 /// You should use `wait_with_timeout` to operate on a `Int32Array`.
2761 ///
2762 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait)
2763 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = wait)]
2764 pub fn wait_with_timeout_bigint(
2765 typed_array: &BigInt64Array,
2766 index: u32,
2767 value: i64,
2768 timeout: f64,
2769 ) -> Result<JsString, JsValue>;
2770
2771 /// The static `Atomics.waitAsync()` method verifies that a given position in an
2772 /// `Int32Array` still contains a given value and if so sleeps, awaiting a
2773 /// wakeup or a timeout. It returns an object with two properties. The first
2774 /// property `async` is a boolean which if true indicates that the second
2775 /// property `value` is a promise. If `async` is false then value is a string
2776 /// whether equal to either "not-equal" or "timed-out".
2777 /// Note: This operation only works with a shared `Int32Array` and may be used
2778 /// on the main thread.
2779 ///
2780 /// You should use `wait_async_bigint` to operate on a `BigInt64Array`.
2781 ///
2782 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/waitAsync)
2783 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = waitAsync)]
2784 pub fn wait_async(
2785 typed_array: &Int32Array,
2786 index: u32,
2787 value: i32,
2788 ) -> Result<Object, JsValue>;
2789
2790 /// The static `Atomics.waitAsync()` method verifies that a given position in an
2791 /// `Int32Array` still contains a given value and if so sleeps, awaiting a
2792 /// wakeup or a timeout. It returns an object with two properties. The first
2793 /// property `async` is a boolean which if true indicates that the second
2794 /// property `value` is a promise. If `async` is false then value is a string
2795 /// whether equal to either "not-equal" or "timed-out".
2796 /// Note: This operation only works with a shared `BigInt64Array` and may be used
2797 /// on the main thread.
2798 ///
2799 /// You should use `wait_async` to operate on a `Int32Array`.
2800 ///
2801 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/waitAsync)
2802 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = waitAsync)]
2803 pub fn wait_async_bigint(
2804 typed_array: &BigInt64Array,
2805 index: u32,
2806 value: i64,
2807 ) -> Result<Object, JsValue>;
2808
2809 /// Like `waitAsync()`, but with timeout
2810 ///
2811 /// You should use `wait_async_with_timeout_bigint` to operate on a `BigInt64Array`.
2812 ///
2813 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/waitAsync)
2814 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = waitAsync)]
2815 pub fn wait_async_with_timeout(
2816 typed_array: &Int32Array,
2817 index: u32,
2818 value: i32,
2819 timeout: f64,
2820 ) -> Result<Object, JsValue>;
2821
2822 /// Like `waitAsync()`, but with timeout
2823 ///
2824 /// You should use `wait_async_with_timeout` to operate on a `Int32Array`.
2825 ///
2826 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/waitAsync)
2827 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = waitAsync)]
2828 pub fn wait_async_with_timeout_bigint(
2829 typed_array: &BigInt64Array,
2830 index: u32,
2831 value: i64,
2832 timeout: f64,
2833 ) -> Result<Object, JsValue>;
2834
2835 /// The static `Atomics.xor()` method computes a bitwise XOR
2836 /// with a given value at a given position in the array,
2837 /// and returns the old value at that position.
2838 /// This atomic operation guarantees that no other write happens
2839 /// until the modified value is written back.
2840 ///
2841 /// You should use `xor_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
2842 ///
2843 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/xor)
2844 #[wasm_bindgen(js_namespace = Atomics, catch)]
2845 pub fn xor<T: TypedArray = Int32Array>(
2846 typed_array: &T,
2847 index: u32,
2848 value: i32,
2849 ) -> Result<i32, JsValue>;
2850
2851 /// The static `Atomics.xor()` method computes a bitwise XOR
2852 /// with a given value at a given position in the array,
2853 /// and returns the old value at that position.
2854 /// This atomic operation guarantees that no other write happens
2855 /// until the modified value is written back.
2856 ///
2857 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
2858 ///
2859 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/xor)
2860 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = xor)]
2861 pub fn xor_bigint<T: TypedArray = Int32Array>(
2862 typed_array: &T,
2863 index: u32,
2864 value: i64,
2865 ) -> Result<i64, JsValue>;
2866 }
2867}
2868
2869// BigInt
2870#[wasm_bindgen]
2871extern "C" {
2872 #[wasm_bindgen(extends = Object, is_type_of = |v| v.is_bigint(), typescript_type = "bigint")]
2873 #[derive(Clone, PartialEq, Eq)]
2874 pub type BigInt;
2875
2876 #[wasm_bindgen(catch, js_name = BigInt)]
2877 fn new_bigint(value: &JsValue) -> Result<BigInt, Error>;
2878
2879 #[wasm_bindgen(js_name = BigInt)]
2880 fn new_bigint_unchecked(value: &JsValue) -> BigInt;
2881
2882 /// Clamps a BigInt value to a signed integer value, and returns that value.
2883 ///
2884 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/asIntN)
2885 #[wasm_bindgen(static_method_of = BigInt, js_name = asIntN)]
2886 pub fn as_int_n(bits: f64, bigint: &BigInt) -> BigInt;
2887
2888 /// Clamps a BigInt value to an unsigned integer value, and returns that value.
2889 ///
2890 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/asUintN)
2891 #[wasm_bindgen(static_method_of = BigInt, js_name = asUintN)]
2892 pub fn as_uint_n(bits: f64, bigint: &BigInt) -> BigInt;
2893
2894 /// 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.
2895 ///
2896 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/toLocaleString)
2897 #[cfg(not(js_sys_unstable_apis))]
2898 #[wasm_bindgen(method, js_name = toLocaleString)]
2899 pub fn to_locale_string(this: &BigInt, locales: &JsValue, options: &JsValue) -> JsString;
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(js_sys_unstable_apis)]
2905 #[wasm_bindgen(method, js_name = toLocaleString)]
2906 pub fn to_locale_string(
2907 this: &BigInt,
2908 locales: &[JsString],
2909 options: &Intl::NumberFormatOptions,
2910 ) -> JsString;
2911
2912 // Next major: deprecate
2913 /// 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.
2914 ///
2915 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/toString)
2916 #[wasm_bindgen(catch, method, js_name = toString)]
2917 pub fn to_string(this: &BigInt, radix: u8) -> Result<JsString, RangeError>;
2918
2919 /// Returns a string representing this BigInt value in the specified radix (base).
2920 ///
2921 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/toString)
2922 #[cfg(js_sys_unstable_apis)]
2923 #[wasm_bindgen(catch, method, js_name = toString)]
2924 pub fn to_string_with_radix(this: &BigInt, radix: u8) -> Result<JsString, RangeError>;
2925
2926 #[wasm_bindgen(method, js_name = toString)]
2927 fn to_string_unchecked(this: &BigInt, radix: u8) -> String;
2928
2929 /// Returns this BigInt value. Overrides the [`Object.prototype.valueOf()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf) method.
2930 ///
2931 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/valueOf)
2932 #[wasm_bindgen(method, js_name = valueOf)]
2933 pub fn value_of(this: &BigInt, radix: u8) -> BigInt;
2934}
2935
2936impl BigInt {
2937 /// Creates a new BigInt value.
2938 ///
2939 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/BigInt)
2940 #[inline]
2941 pub fn new(value: &JsValue) -> Result<BigInt, Error> {
2942 new_bigint(value)
2943 }
2944
2945 /// Applies the binary `/` JS operator on two `BigInt`s, catching and returning any `RangeError` thrown.
2946 ///
2947 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Division)
2948 pub fn checked_div(&self, rhs: &Self) -> Result<Self, RangeError> {
2949 let result = JsValue::as_ref(self).checked_div(JsValue::as_ref(rhs));
2950
2951 if result.is_instance_of::<RangeError>() {
2952 Err(result.unchecked_into())
2953 } else {
2954 Ok(result.unchecked_into())
2955 }
2956 }
2957
2958 /// Applies the binary `**` JS operator on the two `BigInt`s.
2959 ///
2960 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Exponentiation)
2961 #[inline]
2962 pub fn pow(&self, rhs: &Self) -> Self {
2963 JsValue::as_ref(self)
2964 .pow(JsValue::as_ref(rhs))
2965 .unchecked_into()
2966 }
2967
2968 /// Returns a tuple of this [`BigInt`]'s absolute value along with a
2969 /// [`bool`] indicating whether the [`BigInt`] was negative.
2970 fn abs(&self) -> (Self, bool) {
2971 if self < &BigInt::from(0) {
2972 (-self, true)
2973 } else {
2974 (self.clone(), false)
2975 }
2976 }
2977}
2978
2979macro_rules! bigint_from {
2980 ($($x:ident)*) => ($(
2981 impl From<$x> for BigInt {
2982 #[inline]
2983 fn from(x: $x) -> BigInt {
2984 new_bigint_unchecked(&JsValue::from(x))
2985 }
2986 }
2987
2988 impl PartialEq<$x> for BigInt {
2989 #[inline]
2990 fn eq(&self, other: &$x) -> bool {
2991 JsValue::from(self) == JsValue::from(BigInt::from(*other))
2992 }
2993 }
2994 )*)
2995}
2996bigint_from!(i8 u8 i16 u16 i32 u32 isize usize);
2997
2998macro_rules! bigint_from_big {
2999 ($($x:ident)*) => ($(
3000 impl From<$x> for BigInt {
3001 #[inline]
3002 fn from(x: $x) -> BigInt {
3003 JsValue::from(x).unchecked_into()
3004 }
3005 }
3006
3007 impl PartialEq<$x> for BigInt {
3008 #[inline]
3009 fn eq(&self, other: &$x) -> bool {
3010 self == &BigInt::from(*other)
3011 }
3012 }
3013
3014 impl TryFrom<BigInt> for $x {
3015 type Error = BigInt;
3016
3017 #[inline]
3018 fn try_from(x: BigInt) -> Result<Self, BigInt> {
3019 Self::try_from(JsValue::from(x)).map_err(JsCast::unchecked_into)
3020 }
3021 }
3022 )*)
3023}
3024bigint_from_big!(i64 u64 i128 u128);
3025
3026impl PartialEq<Number> for BigInt {
3027 #[inline]
3028 fn eq(&self, other: &Number) -> bool {
3029 JsValue::as_ref(self).loose_eq(JsValue::as_ref(other))
3030 }
3031}
3032
3033impl Not for &BigInt {
3034 type Output = BigInt;
3035
3036 #[inline]
3037 fn not(self) -> Self::Output {
3038 JsValue::as_ref(self).bit_not().unchecked_into()
3039 }
3040}
3041
3042forward_deref_unop!(impl Not, not for BigInt);
3043forward_js_unop!(impl Neg, neg for BigInt);
3044forward_js_binop!(impl BitAnd, bitand for BigInt);
3045forward_js_binop!(impl BitOr, bitor for BigInt);
3046forward_js_binop!(impl BitXor, bitxor for BigInt);
3047forward_js_binop!(impl Shl, shl for BigInt);
3048forward_js_binop!(impl Shr, shr for BigInt);
3049forward_js_binop!(impl Add, add for BigInt);
3050forward_js_binop!(impl Sub, sub for BigInt);
3051forward_js_binop!(impl Div, div for BigInt);
3052forward_js_binop!(impl Mul, mul for BigInt);
3053forward_js_binop!(impl Rem, rem for BigInt);
3054sum_product!(BigInt);
3055
3056partialord_ord!(BigInt);
3057
3058impl Default for BigInt {
3059 fn default() -> Self {
3060 BigInt::from(i32::default())
3061 }
3062}
3063
3064impl FromStr for BigInt {
3065 type Err = Error;
3066
3067 #[inline]
3068 fn from_str(s: &str) -> Result<Self, Self::Err> {
3069 BigInt::new(&s.into())
3070 }
3071}
3072
3073impl fmt::Debug for BigInt {
3074 #[inline]
3075 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3076 fmt::Display::fmt(self, f)
3077 }
3078}
3079
3080impl fmt::Display for BigInt {
3081 #[inline]
3082 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3083 let (abs, is_neg) = self.abs();
3084 f.pad_integral(!is_neg, "", &abs.to_string_unchecked(10))
3085 }
3086}
3087
3088impl fmt::Binary for BigInt {
3089 #[inline]
3090 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3091 let (abs, is_neg) = self.abs();
3092 f.pad_integral(!is_neg, "0b", &abs.to_string_unchecked(2))
3093 }
3094}
3095
3096impl fmt::Octal for BigInt {
3097 #[inline]
3098 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3099 let (abs, is_neg) = self.abs();
3100 f.pad_integral(!is_neg, "0o", &abs.to_string_unchecked(8))
3101 }
3102}
3103
3104impl fmt::LowerHex for BigInt {
3105 #[inline]
3106 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3107 let (abs, is_neg) = self.abs();
3108 f.pad_integral(!is_neg, "0x", &abs.to_string_unchecked(16))
3109 }
3110}
3111
3112impl fmt::UpperHex for BigInt {
3113 #[inline]
3114 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3115 let (abs, is_neg) = self.abs();
3116 let mut s: String = abs.to_string_unchecked(16);
3117 s.make_ascii_uppercase();
3118 f.pad_integral(!is_neg, "0x", &s)
3119 }
3120}
3121
3122// Boolean
3123#[wasm_bindgen]
3124extern "C" {
3125 #[wasm_bindgen(extends = Object, is_type_of = |v| v.as_bool().is_some(), typescript_type = "boolean")]
3126 #[derive(Clone, PartialEq, Eq)]
3127 pub type Boolean;
3128
3129 /// The `Boolean()` constructor creates an object wrapper for a boolean value.
3130 ///
3131 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)
3132 #[cfg(not(js_sys_unstable_apis))]
3133 #[wasm_bindgen(constructor)]
3134 #[deprecated(note = "recommended to use `Boolean::from` instead")]
3135 #[allow(deprecated)]
3136 pub fn new(value: &JsValue) -> Boolean;
3137
3138 /// The `valueOf()` method returns the primitive value of a `Boolean` object.
3139 ///
3140 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean/valueOf)
3141 #[wasm_bindgen(method, js_name = valueOf)]
3142 pub fn value_of(this: &Boolean) -> bool;
3143}
3144
3145impl UpcastFrom<bool> for Boolean {}
3146impl UpcastFrom<Boolean> for bool {}
3147
3148impl Boolean {
3149 /// Typed Boolean true constant.
3150 pub const TRUE: Boolean = Self {
3151 obj: Object {
3152 obj: JsValue::TRUE,
3153 generics: PhantomData,
3154 },
3155 };
3156
3157 /// Typed Boolean false constant.
3158 pub const FALSE: Boolean = Self {
3159 obj: Object {
3160 obj: JsValue::FALSE,
3161 generics: PhantomData,
3162 },
3163 };
3164}
3165
3166impl From<bool> for Boolean {
3167 #[inline]
3168 fn from(b: bool) -> Boolean {
3169 Boolean::unchecked_from_js(JsValue::from(b))
3170 }
3171}
3172
3173impl From<Boolean> for bool {
3174 #[inline]
3175 fn from(b: Boolean) -> bool {
3176 b.value_of()
3177 }
3178}
3179
3180impl PartialEq<bool> for Boolean {
3181 #[inline]
3182 fn eq(&self, other: &bool) -> bool {
3183 self.value_of() == *other
3184 }
3185}
3186
3187impl fmt::Debug for Boolean {
3188 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3189 fmt::Debug::fmt(&self.value_of(), f)
3190 }
3191}
3192
3193impl fmt::Display for Boolean {
3194 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3195 fmt::Display::fmt(&self.value_of(), f)
3196 }
3197}
3198
3199impl Default for Boolean {
3200 fn default() -> Self {
3201 Self::from(bool::default())
3202 }
3203}
3204
3205impl Not for &Boolean {
3206 type Output = Boolean;
3207
3208 #[inline]
3209 fn not(self) -> Self::Output {
3210 (!JsValue::as_ref(self)).into()
3211 }
3212}
3213
3214forward_deref_unop!(impl Not, not for Boolean);
3215
3216partialord_ord!(Boolean);
3217
3218// DataView
3219#[wasm_bindgen]
3220extern "C" {
3221 #[wasm_bindgen(extends = Object, typescript_type = "DataView")]
3222 #[derive(Clone, Debug, PartialEq, Eq)]
3223 pub type DataView;
3224
3225 /// The `DataView` view provides a low-level interface for reading and
3226 /// writing multiple number types in an `ArrayBuffer` irrespective of the
3227 /// platform's endianness.
3228 ///
3229 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView)
3230 #[wasm_bindgen(constructor)]
3231 pub fn new(buffer: &ArrayBuffer, byteOffset: usize, byteLength: usize) -> DataView;
3232
3233 /// The `DataView` view provides a low-level interface for reading and
3234 /// writing multiple number types in an `ArrayBuffer` irrespective of the
3235 /// platform's endianness.
3236 ///
3237 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView)
3238 #[wasm_bindgen(constructor)]
3239 pub fn new_with_shared_array_buffer(
3240 buffer: &SharedArrayBuffer,
3241 byteOffset: usize,
3242 byteLength: usize,
3243 ) -> DataView;
3244
3245 /// The ArrayBuffer referenced by this view. Fixed at construction time and thus read only.
3246 ///
3247 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/buffer)
3248 #[wasm_bindgen(method, getter)]
3249 pub fn buffer(this: &DataView) -> ArrayBuffer;
3250
3251 /// The length (in bytes) of this view from the start of its ArrayBuffer.
3252 /// Fixed at construction time and thus read only.
3253 ///
3254 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/byteLength)
3255 #[wasm_bindgen(method, getter, js_name = byteLength)]
3256 pub fn byte_length(this: &DataView) -> usize;
3257
3258 /// The offset (in bytes) of this view from the start of its ArrayBuffer.
3259 /// Fixed at construction time and thus read only.
3260 ///
3261 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/byteOffset)
3262 #[wasm_bindgen(method, getter, js_name = byteOffset)]
3263 pub fn byte_offset(this: &DataView) -> usize;
3264
3265 /// The `getInt8()` method gets a signed 8-bit integer (byte) at the
3266 /// specified byte offset from the start of the DataView.
3267 ///
3268 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt8)
3269 #[wasm_bindgen(method, js_name = getInt8)]
3270 pub fn get_int8(this: &DataView, byte_offset: usize) -> i8;
3271
3272 /// The `getUint8()` method gets a unsigned 8-bit integer (byte) at the specified
3273 /// byte offset from the start of the DataView.
3274 ///
3275 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint8)
3276 #[wasm_bindgen(method, js_name = getUint8)]
3277 pub fn get_uint8(this: &DataView, byte_offset: usize) -> u8;
3278
3279 /// The `getInt16()` method gets a signed 16-bit integer (short) at the specified
3280 /// byte offset from the start of the DataView.
3281 ///
3282 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt16)
3283 #[wasm_bindgen(method, js_name = getInt16)]
3284 pub fn get_int16(this: &DataView, byte_offset: usize) -> i16;
3285
3286 /// The `getInt16()` method gets a signed 16-bit integer (short) at the specified
3287 /// byte offset from the start of the DataView.
3288 ///
3289 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt16)
3290 #[wasm_bindgen(method, js_name = getInt16)]
3291 pub fn get_int16_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> i16;
3292
3293 /// The `getUint16()` method gets an unsigned 16-bit integer (unsigned short) at the specified
3294 /// byte offset from the start of the view.
3295 ///
3296 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint16)
3297 #[wasm_bindgen(method, js_name = getUint16)]
3298 pub fn get_uint16(this: &DataView, byte_offset: usize) -> u16;
3299
3300 /// The `getUint16()` method gets an unsigned 16-bit integer (unsigned short) at the specified
3301 /// byte offset from the start of the view.
3302 ///
3303 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint16)
3304 #[wasm_bindgen(method, js_name = getUint16)]
3305 pub fn get_uint16_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> u16;
3306
3307 /// The `getInt32()` method gets a signed 32-bit integer (long) at the specified
3308 /// byte offset from the start of the DataView.
3309 ///
3310 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt32)
3311 #[wasm_bindgen(method, js_name = getInt32)]
3312 pub fn get_int32(this: &DataView, byte_offset: usize) -> i32;
3313
3314 /// The `getInt32()` method gets a signed 32-bit integer (long) at the specified
3315 /// byte offset from the start of the DataView.
3316 ///
3317 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt32)
3318 #[wasm_bindgen(method, js_name = getInt32)]
3319 pub fn get_int32_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> i32;
3320
3321 /// The `getUint32()` method gets an unsigned 32-bit integer (unsigned long) at the specified
3322 /// byte offset from the start of the view.
3323 ///
3324 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint32)
3325 #[wasm_bindgen(method, js_name = getUint32)]
3326 pub fn get_uint32(this: &DataView, byte_offset: usize) -> u32;
3327
3328 /// The `getUint32()` method gets an unsigned 32-bit integer (unsigned long) at the specified
3329 /// byte offset from the start of the view.
3330 ///
3331 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint32)
3332 #[wasm_bindgen(method, js_name = getUint32)]
3333 pub fn get_uint32_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> u32;
3334
3335 /// The `getFloat32()` method gets a signed 32-bit float (float) at the specified
3336 /// byte offset from the start of the DataView.
3337 ///
3338 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat32)
3339 #[wasm_bindgen(method, js_name = getFloat32)]
3340 pub fn get_float32(this: &DataView, byte_offset: usize) -> f32;
3341
3342 /// The `getFloat32()` method gets a signed 32-bit float (float) at the specified
3343 /// byte offset from the start of the DataView.
3344 ///
3345 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat32)
3346 #[wasm_bindgen(method, js_name = getFloat32)]
3347 pub fn get_float32_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> f32;
3348
3349 /// The `getFloat64()` method gets a signed 64-bit float (double) at the specified
3350 /// byte offset from the start of the DataView.
3351 ///
3352 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat64)
3353 #[wasm_bindgen(method, js_name = getFloat64)]
3354 pub fn get_float64(this: &DataView, byte_offset: usize) -> f64;
3355
3356 /// The `getFloat64()` method gets a signed 64-bit float (double) at the specified
3357 /// byte offset from the start of the DataView.
3358 ///
3359 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat64)
3360 #[wasm_bindgen(method, js_name = getFloat64)]
3361 pub fn get_float64_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> f64;
3362
3363 /// The `setInt8()` method stores a signed 8-bit integer (byte) value at the
3364 /// specified byte offset from the start of the DataView.
3365 ///
3366 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt8)
3367 #[wasm_bindgen(method, js_name = setInt8)]
3368 pub fn set_int8(this: &DataView, byte_offset: usize, value: i8);
3369
3370 /// The `setUint8()` method stores an unsigned 8-bit integer (byte) value at the
3371 /// specified byte offset from the start of the DataView.
3372 ///
3373 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint8)
3374 #[wasm_bindgen(method, js_name = setUint8)]
3375 pub fn set_uint8(this: &DataView, byte_offset: usize, value: u8);
3376
3377 /// The `setInt16()` method stores a signed 16-bit integer (short) value at the
3378 /// specified byte offset from the start of the DataView.
3379 ///
3380 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt16)
3381 #[wasm_bindgen(method, js_name = setInt16)]
3382 pub fn set_int16(this: &DataView, byte_offset: usize, value: i16);
3383
3384 /// The `setInt16()` method stores a signed 16-bit integer (short) value at the
3385 /// specified byte offset from the start of the DataView.
3386 ///
3387 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt16)
3388 #[wasm_bindgen(method, js_name = setInt16)]
3389 pub fn set_int16_endian(this: &DataView, byte_offset: usize, value: i16, little_endian: bool);
3390
3391 /// The `setUint16()` method stores an unsigned 16-bit integer (unsigned short) value at the
3392 /// specified byte offset from the start of the DataView.
3393 ///
3394 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint16)
3395 #[wasm_bindgen(method, js_name = setUint16)]
3396 pub fn set_uint16(this: &DataView, byte_offset: usize, value: u16);
3397
3398 /// The `setUint16()` method stores an unsigned 16-bit integer (unsigned short) value at the
3399 /// specified byte offset from the start of the DataView.
3400 ///
3401 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint16)
3402 #[wasm_bindgen(method, js_name = setUint16)]
3403 pub fn set_uint16_endian(this: &DataView, byte_offset: usize, value: u16, little_endian: bool);
3404
3405 /// The `setInt32()` method stores a signed 32-bit integer (long) value at the
3406 /// specified byte offset from the start of the DataView.
3407 ///
3408 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt32)
3409 #[wasm_bindgen(method, js_name = setInt32)]
3410 pub fn set_int32(this: &DataView, byte_offset: usize, value: i32);
3411
3412 /// The `setInt32()` method stores a signed 32-bit integer (long) value at the
3413 /// specified byte offset from the start of the DataView.
3414 ///
3415 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt32)
3416 #[wasm_bindgen(method, js_name = setInt32)]
3417 pub fn set_int32_endian(this: &DataView, byte_offset: usize, value: i32, little_endian: bool);
3418
3419 /// The `setUint32()` method stores an unsigned 32-bit integer (unsigned long) value at the
3420 /// specified byte offset from the start of the DataView.
3421 ///
3422 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint32)
3423 #[wasm_bindgen(method, js_name = setUint32)]
3424 pub fn set_uint32(this: &DataView, byte_offset: usize, value: u32);
3425
3426 /// The `setUint32()` method stores an unsigned 32-bit integer (unsigned long) value at the
3427 /// specified byte offset from the start of the DataView.
3428 ///
3429 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint32)
3430 #[wasm_bindgen(method, js_name = setUint32)]
3431 pub fn set_uint32_endian(this: &DataView, byte_offset: usize, value: u32, little_endian: bool);
3432
3433 /// The `setFloat32()` method stores a signed 32-bit float (float) value at the
3434 /// specified byte offset from the start of the DataView.
3435 ///
3436 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat32)
3437 #[wasm_bindgen(method, js_name = setFloat32)]
3438 pub fn set_float32(this: &DataView, byte_offset: usize, value: f32);
3439
3440 /// The `setFloat32()` method stores a signed 32-bit float (float) value at the
3441 /// specified byte offset from the start of the DataView.
3442 ///
3443 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat32)
3444 #[wasm_bindgen(method, js_name = setFloat32)]
3445 pub fn set_float32_endian(this: &DataView, byte_offset: usize, value: f32, little_endian: bool);
3446
3447 /// The `setFloat64()` method stores a signed 64-bit float (double) value at the
3448 /// specified byte offset from the start of the DataView.
3449 ///
3450 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat64)
3451 #[wasm_bindgen(method, js_name = setFloat64)]
3452 pub fn set_float64(this: &DataView, byte_offset: usize, value: f64);
3453
3454 /// The `setFloat64()` method stores a signed 64-bit float (double) value at the
3455 /// specified byte offset from the start of the DataView.
3456 ///
3457 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat64)
3458 #[wasm_bindgen(method, js_name = setFloat64)]
3459 pub fn set_float64_endian(this: &DataView, byte_offset: usize, value: f64, little_endian: bool);
3460}
3461
3462// Error
3463#[wasm_bindgen]
3464extern "C" {
3465 #[wasm_bindgen(extends = Object, typescript_type = "Error")]
3466 #[derive(Clone, Debug, PartialEq, Eq)]
3467 pub type Error;
3468
3469 /// The Error constructor creates an error object.
3470 /// Instances of Error objects are thrown when runtime errors occur.
3471 /// The Error object can also be used as a base object for user-defined exceptions.
3472 /// See below for standard built-in error types.
3473 ///
3474 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)
3475 #[wasm_bindgen(constructor)]
3476 pub fn new(message: &str) -> Error;
3477 #[wasm_bindgen(constructor)]
3478 pub fn new_with_options(message: &str, options: &Object) -> Error;
3479
3480 /// The cause property is the underlying cause of the error.
3481 /// Usually this is used to add context to re-thrown errors.
3482 ///
3483 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error#differentiate_between_similar_errors)
3484 #[wasm_bindgen(method, getter)]
3485 pub fn cause(this: &Error) -> JsValue;
3486 #[wasm_bindgen(method, setter)]
3487 pub fn set_cause(this: &Error, cause: &JsValue);
3488
3489 /// The message property is a human-readable description of the error.
3490 ///
3491 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/message)
3492 #[wasm_bindgen(method, getter)]
3493 pub fn message(this: &Error) -> JsString;
3494 #[wasm_bindgen(method, setter)]
3495 pub fn set_message(this: &Error, message: &str);
3496
3497 /// The name property represents a name for the type of error. The initial value is "Error".
3498 ///
3499 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/name)
3500 #[wasm_bindgen(method, getter)]
3501 pub fn name(this: &Error) -> JsString;
3502 #[wasm_bindgen(method, setter)]
3503 pub fn set_name(this: &Error, name: &str);
3504
3505 /// The `toString()` method returns a string representing the specified Error object
3506 ///
3507 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/toString)
3508 #[cfg(not(js_sys_unstable_apis))]
3509 #[wasm_bindgen(method, js_name = toString)]
3510 pub fn to_string(this: &Error) -> JsString;
3511}
3512
3513partialord_ord!(JsString);
3514
3515// EvalError
3516#[wasm_bindgen]
3517extern "C" {
3518 #[wasm_bindgen(extends = Object, extends = Error, typescript_type = "EvalError")]
3519 #[derive(Clone, Debug, PartialEq, Eq)]
3520 pub type EvalError;
3521
3522 /// The `EvalError` object indicates an error regarding the global eval() function. This
3523 /// exception is not thrown by JavaScript anymore, however the EvalError object remains for
3524 /// compatibility.
3525 ///
3526 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/EvalError)
3527 #[wasm_bindgen(constructor)]
3528 pub fn new(message: &str) -> EvalError;
3529}
3530
3531#[wasm_bindgen]
3532extern "C" {
3533 #[wasm_bindgen(extends = Object, is_type_of = JsValue::is_function, no_upcast, typescript_type = "Function")]
3534 #[derive(Clone, Debug, PartialEq, Eq)]
3535 /// `Function` represents any generic Function in JS, by treating all arguments as `JsValue`.
3536 ///
3537 /// It takes a generic parameter of phantom type `fn (Arg1, ..., Argn) -> Ret` which
3538 /// is used to type the JS function. For example, `Function<fn () -> Number>` represents
3539 /// a function taking no arguments that returns a number.
3540 ///
3541 /// The 8 generic argument parameters (`Arg1` through `Arg8`) are the argument
3542 /// types. Arguments not provided enable strict arity checking at compile time.
3543 ///
3544 /// A void function is represented by `fn (Arg) -> Undefined`, and **not** the `()` unit
3545 /// type. This is because generics must be based on JS values in the JS generic type system.
3546 ///
3547 /// _The default without any parameters is as a void function - no arguments, `Undefined` return._
3548 ///
3549 /// _The default generic for `Function` is `fn (JsValue, JsValue, ...) -> JsValue`,
3550 /// representing any function, since all functions safely upcast into this function._
3551 ///
3552 /// ### Arity Enforcement
3553 ///
3554 /// It is not possible to use `call4` or `bind4` on a function that does not have
3555 /// at least 4 arguments — the compiler will reject this because only arguments that
3556 /// are not `None` support the trait bound for `ErasableGeneric`.
3557 ///
3558 /// ### Examples
3559 ///
3560 /// ```ignore
3561 /// // A function taking no args, returning Number
3562 /// let f: Function<Number> = get_some_fn();
3563 ///
3564 /// // A function taking (String, Number) and returning Boolean
3565 /// let f: Function<Boolean, String, Number> = get_some_fn();
3566 ///
3567 /// ### Upcasting
3568 ///
3569 /// To pass a typed `Function` where a different generic Function is expected, `upcast()` may be used
3570 /// to convert into any generic `Function` at zero cost with type-safety.
3571 ///
3572 /// MDN documentation (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
3573 pub type Function<
3574 T: JsFunction = fn(
3575 JsValue,
3576 JsValue,
3577 JsValue,
3578 JsValue,
3579 JsValue,
3580 JsValue,
3581 JsValue,
3582 JsValue,
3583 ) -> JsValue,
3584 >;
3585}
3586
3587#[wasm_bindgen]
3588extern "C" {
3589 /// The `Function` constructor creates a new `Function` object. Calling the
3590 /// constructor directly can create functions dynamically, but suffers from
3591 /// security and similar (but far less significant) performance issues
3592 /// similar to `eval`. However, unlike `eval`, the `Function` constructor
3593 /// allows executing code in the global scope, prompting better programming
3594 /// habits and allowing for more efficient code minification.
3595 ///
3596 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
3597 #[cfg(all(feature = "unsafe-eval", not(js_sys_unstable_apis)))]
3598 #[wasm_bindgen(constructor)]
3599 pub fn new_with_args(args: &str, body: &str) -> Function;
3600
3601 /// The `Function` constructor creates a new `Function` object. Calling the
3602 /// constructor directly can create functions dynamically, but suffers from
3603 /// security and similar (but far less significant) performance issues
3604 /// similar to `eval`. However, unlike `eval`, the `Function` constructor
3605 /// allows executing code in the global scope, prompting better programming
3606 /// habits and allowing for more efficient code minification.
3607 ///
3608 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
3609 #[cfg(all(feature = "unsafe-eval", js_sys_unstable_apis))]
3610 #[wasm_bindgen(constructor)]
3611 pub fn new_with_args<T: JsFunction = fn() -> JsValue>(args: &str, body: &str) -> Function<T>;
3612
3613 // Next major: deprecate
3614 /// The `Function` constructor creates a new `Function` object. Calling the
3615 /// constructor directly can create functions dynamically, but suffers from
3616 /// security and similar (but far less significant) performance issues
3617 /// similar to `eval`. However, unlike `eval`, the `Function` constructor
3618 /// allows executing code in the global scope, prompting better programming
3619 /// habits and allowing for more efficient code minification.
3620 ///
3621 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
3622 #[cfg(feature = "unsafe-eval")]
3623 #[wasm_bindgen(constructor)]
3624 pub fn new_with_args_typed<T: JsFunction = fn() -> JsValue>(
3625 args: &str,
3626 body: &str,
3627 ) -> Function<T>;
3628
3629 /// The `Function` constructor creates a new `Function` object. Calling the
3630 /// constructor directly can create functions dynamically, but suffers from
3631 /// security and similar (but far less significant) performance issues
3632 /// similar to `eval`. However, unlike `eval`, the `Function` constructor
3633 /// allows executing code in the global scope, prompting better programming
3634 /// habits and allowing for more efficient code minification.
3635 ///
3636 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
3637 #[cfg(all(feature = "unsafe-eval", not(js_sys_unstable_apis)))]
3638 #[wasm_bindgen(constructor)]
3639 pub fn new_no_args(body: &str) -> Function;
3640
3641 /// The `Function` constructor creates a new `Function` object. Calling the
3642 /// constructor directly can create functions dynamically, but suffers from
3643 /// security and similar (but far less significant) performance issues
3644 /// similar to `eval`. However, unlike `eval`, the `Function` constructor
3645 /// allows executing code in the global scope, prompting better programming
3646 /// habits and allowing for more efficient code minification.
3647 ///
3648 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
3649 #[cfg(all(feature = "unsafe-eval", js_sys_unstable_apis))]
3650 #[wasm_bindgen(constructor)]
3651 pub fn new_no_args<T: JsFunction = fn() -> JsValue>(body: &str) -> Function<T>;
3652
3653 // Next major: deprecate
3654 /// The `Function` constructor creates a new `Function` object.
3655 ///
3656 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
3657 #[cfg(feature = "unsafe-eval")]
3658 #[wasm_bindgen(constructor)]
3659 pub fn new_no_args_typed<T: JsFunction = fn() -> JsValue>(body: &str) -> Function<T>;
3660
3661 /// The `apply()` method calls a function with a given this value, and arguments provided as an array
3662 /// (or an array-like object).
3663 ///
3664 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply)
3665 #[wasm_bindgen(method, catch)]
3666 pub fn apply<T: JsFunction = fn() -> JsValue>(
3667 this: &Function<T>,
3668 context: &JsValue,
3669 args: &Array,
3670 ) -> Result<<T as JsFunction>::Ret, JsValue>;
3671
3672 // Next major: Deprecate, and separately provide provide impl
3673 /// The `call()` method calls a function with a given this value and
3674 /// arguments provided individually.
3675 ///
3676 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3677 ///
3678 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3679 #[wasm_bindgen(method, catch, js_name = call)]
3680 pub fn call0<Ret: JsGeneric, F: JsFunction<Ret = Ret> = fn() -> JsValue>(
3681 this: &Function<F>,
3682 context: &JsValue,
3683 ) -> Result<Ret, JsValue>;
3684
3685 // Next major: Deprecate, and separately provide provide impl
3686 /// The `call()` method calls a function with a given this value and
3687 /// arguments provided individually.
3688 ///
3689 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3690 ///
3691 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3692 #[wasm_bindgen(method, catch, js_name = call)]
3693 pub fn call1<
3694 Ret: JsGeneric,
3695 Arg1: JsGeneric,
3696 F: JsFunction<Ret = Ret> + JsFunction1<Arg1 = Arg1> = fn(JsValue) -> JsValue,
3697 >(
3698 this: &Function<F>,
3699 context: &JsValue,
3700 arg1: &Arg1,
3701 ) -> Result<Ret, JsValue>;
3702
3703 // Next major: Deprecate, and separately provide provide impl
3704 /// The `call()` method calls a function with a given this value and
3705 /// arguments provided individually.
3706 ///
3707 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3708 ///
3709 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3710 #[wasm_bindgen(method, catch, js_name = call)]
3711 pub fn call2<
3712 Ret: JsGeneric,
3713 Arg1: JsGeneric,
3714 Arg2: JsGeneric,
3715 F: JsFunction<Ret = Ret> + JsFunction1<Arg1 = Arg1> + JsFunction2<Arg2 = Arg2> = fn(
3716 JsValue,
3717 JsValue,
3718 ) -> JsValue,
3719 >(
3720 this: &Function<F>,
3721 context: &JsValue,
3722 arg1: &Arg1,
3723 arg2: &Arg2,
3724 ) -> Result<Ret, JsValue>;
3725
3726 // Next major: Deprecate, and separately provide provide impl
3727 /// The `call()` method calls a function with a given this value and
3728 /// arguments provided individually.
3729 ///
3730 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3731 ///
3732 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3733 #[wasm_bindgen(method, catch, js_name = call)]
3734 pub fn call3<
3735 Ret: JsGeneric,
3736 Arg1: JsGeneric,
3737 Arg2: JsGeneric,
3738 Arg3: JsGeneric,
3739 F: JsFunction<Ret = Ret> + JsFunction3<Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3> = fn(
3740 JsValue,
3741 JsValue,
3742 JsValue,
3743 ) -> JsValue,
3744 >(
3745 this: &Function<F>,
3746 context: &JsValue,
3747 arg1: &Arg1,
3748 arg2: &Arg2,
3749 arg3: &Arg3,
3750 ) -> Result<Ret, JsValue>;
3751
3752 // Next major: Deprecate, and separately provide provide impl
3753 /// The `call()` method calls a function with a given this value and
3754 /// arguments provided individually.
3755 ///
3756 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3757 ///
3758 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3759 #[wasm_bindgen(method, catch, js_name = call)]
3760 pub fn call4<
3761 Ret: JsGeneric,
3762 Arg1: JsGeneric,
3763 Arg2: JsGeneric,
3764 Arg3: JsGeneric,
3765 Arg4: JsGeneric,
3766 F: JsFunction<Ret = Ret> + JsFunction4<Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3, Arg4 = Arg4> = fn(
3767 JsValue,
3768 JsValue,
3769 JsValue,
3770 JsValue,
3771 ) -> JsValue,
3772 >(
3773 this: &Function<F>,
3774 context: &JsValue,
3775 arg1: &Arg1,
3776 arg2: &Arg2,
3777 arg3: &Arg3,
3778 arg4: &Arg4,
3779 ) -> Result<Ret, JsValue>;
3780
3781 // Next major: Deprecate, and separately provide provide impl
3782 /// The `call()` method calls a function with a given this value and
3783 /// arguments provided individually.
3784 ///
3785 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3786 ///
3787 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3788 #[wasm_bindgen(method, catch, js_name = call)]
3789 pub fn call5<
3790 Ret: JsGeneric,
3791 Arg1: JsGeneric,
3792 Arg2: JsGeneric,
3793 Arg3: JsGeneric,
3794 Arg4: JsGeneric,
3795 Arg5: JsGeneric,
3796 F: JsFunction<Ret = Ret>
3797 + JsFunction5<Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3, Arg4 = Arg4, Arg5 = Arg5> = fn(
3798 JsValue,
3799 JsValue,
3800 JsValue,
3801 JsValue,
3802 JsValue,
3803 ) -> JsValue,
3804 >(
3805 this: &Function<F>,
3806 context: &JsValue,
3807 arg1: &Arg1,
3808 arg2: &Arg2,
3809 arg3: &Arg3,
3810 arg4: &Arg4,
3811 arg5: &Arg5,
3812 ) -> Result<Ret, JsValue>;
3813
3814 // Next major: Deprecate, and separately provide provide impl
3815 /// The `call()` method calls a function with a given this value and
3816 /// arguments provided individually.
3817 ///
3818 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3819 ///
3820 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3821 #[wasm_bindgen(method, catch, js_name = call)]
3822 pub fn call6<
3823 Ret: JsGeneric,
3824 Arg1: JsGeneric,
3825 Arg2: JsGeneric,
3826 Arg3: JsGeneric,
3827 Arg4: JsGeneric,
3828 Arg5: JsGeneric,
3829 Arg6: JsGeneric,
3830 F: JsFunction<Ret = Ret>
3831 + JsFunction6<
3832 Arg1 = Arg1,
3833 Arg2 = Arg2,
3834 Arg3 = Arg3,
3835 Arg4 = Arg4,
3836 Arg5 = Arg5,
3837 Arg6 = Arg6,
3838 > = fn(JsValue, JsValue, JsValue, JsValue, JsValue, JsValue) -> JsValue,
3839 >(
3840 this: &Function<F>,
3841 context: &JsValue,
3842 arg1: &Arg1,
3843 arg2: &Arg2,
3844 arg3: &Arg3,
3845 arg4: &Arg4,
3846 arg5: &Arg5,
3847 arg6: &Arg6,
3848 ) -> Result<Ret, JsValue>;
3849
3850 // Next major: Deprecate, and separately provide provide impl
3851 /// The `call()` method calls a function with a given this value and
3852 /// arguments provided individually.
3853 ///
3854 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3855 ///
3856 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3857 #[wasm_bindgen(method, catch, js_name = call)]
3858 pub fn call7<
3859 Ret: JsGeneric,
3860 Arg1: JsGeneric,
3861 Arg2: JsGeneric,
3862 Arg3: JsGeneric,
3863 Arg4: JsGeneric,
3864 Arg5: JsGeneric,
3865 Arg6: JsGeneric,
3866 Arg7: JsGeneric,
3867 F: JsFunction<Ret = Ret>
3868 + JsFunction7<
3869 Arg1 = Arg1,
3870 Arg2 = Arg2,
3871 Arg3 = Arg3,
3872 Arg4 = Arg4,
3873 Arg5 = Arg5,
3874 Arg6 = Arg6,
3875 Arg7 = Arg7,
3876 > = fn(
3877 JsValue,
3878 JsValue,
3879 JsValue,
3880 JsValue,
3881 JsValue,
3882 JsValue,
3883 JsValue,
3884 ) -> JsValue,
3885 >(
3886 this: &Function<F>,
3887 context: &JsValue,
3888 arg1: &Arg1,
3889 arg2: &Arg2,
3890 arg3: &Arg3,
3891 arg4: &Arg4,
3892 arg5: &Arg5,
3893 arg6: &Arg6,
3894 arg7: &Arg7,
3895 ) -> Result<Ret, JsValue>;
3896
3897 // Next major: Deprecate, and separately provide provide impl
3898 /// The `call()` method calls a function with a given this value and
3899 /// arguments provided individually.
3900 ///
3901 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3902 ///
3903 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3904 #[wasm_bindgen(method, catch, js_name = call)]
3905 pub fn call8<
3906 Ret: JsGeneric,
3907 Arg1: JsGeneric,
3908 Arg2: JsGeneric,
3909 Arg3: JsGeneric,
3910 Arg4: JsGeneric,
3911 Arg5: JsGeneric,
3912 Arg6: JsGeneric,
3913 Arg7: JsGeneric,
3914 Arg8: JsGeneric,
3915 F: JsFunction8<
3916 Ret = Ret,
3917 Arg1 = Arg1,
3918 Arg2 = Arg2,
3919 Arg3 = Arg3,
3920 Arg4 = Arg4,
3921 Arg5 = Arg5,
3922 Arg6 = Arg6,
3923 Arg7 = Arg7,
3924 Arg8 = Arg8,
3925 > = fn(
3926 JsValue,
3927 JsValue,
3928 JsValue,
3929 JsValue,
3930 JsValue,
3931 JsValue,
3932 JsValue,
3933 JsValue,
3934 ) -> JsValue,
3935 >(
3936 this: &Function<F>,
3937 context: &JsValue,
3938 arg1: &Arg1,
3939 arg2: &Arg2,
3940 arg3: &Arg3,
3941 arg4: &Arg4,
3942 arg5: &Arg5,
3943 arg6: &Arg6,
3944 arg7: &Arg7,
3945 arg8: &Arg8,
3946 ) -> Result<Ret, JsValue>;
3947
3948 /// The `call()` method calls a function with a given this value and
3949 /// arguments provided individually.
3950 ///
3951 /// **Note: Use [`call()`](Function::call) to get exact arity and also checked generic type casting.**
3952 ///
3953 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
3954 #[deprecated]
3955 #[allow(deprecated)]
3956 #[wasm_bindgen(method, catch, js_name = call)]
3957 pub fn call9<
3958 Ret: JsGeneric,
3959 Arg1: JsGeneric,
3960 Arg2: JsGeneric,
3961 Arg3: JsGeneric,
3962 Arg4: JsGeneric,
3963 Arg5: JsGeneric,
3964 Arg6: JsGeneric,
3965 Arg7: JsGeneric,
3966 Arg8: JsGeneric,
3967 F: JsFunction8<
3968 Ret = Ret,
3969 Arg1 = Arg1,
3970 Arg2 = Arg2,
3971 Arg3 = Arg3,
3972 Arg4 = Arg4,
3973 Arg5 = Arg5,
3974 Arg6 = Arg6,
3975 Arg7 = Arg7,
3976 Arg8 = Arg8,
3977 > = fn(
3978 JsValue,
3979 JsValue,
3980 JsValue,
3981 JsValue,
3982 JsValue,
3983 JsValue,
3984 JsValue,
3985 JsValue,
3986 ) -> JsValue,
3987 >(
3988 this: &Function<F>,
3989 context: &JsValue,
3990 arg1: &Arg1,
3991 arg2: &Arg2,
3992 arg3: &Arg3,
3993 arg4: &Arg4,
3994 arg5: &Arg5,
3995 arg6: &Arg6,
3996 arg7: &Arg7,
3997 arg8: &Arg8,
3998 arg9: &JsValue,
3999 ) -> Result<Ret, JsValue>;
4000
4001 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4002 /// with a given sequence of arguments preceding any provided when the new function is called.
4003 ///
4004 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4005 #[cfg(not(js_sys_unstable_apis))]
4006 #[deprecated(note = "Use `Function::bind0` instead.")]
4007 #[allow(deprecated)]
4008 #[wasm_bindgen(method, js_name = bind)]
4009 pub fn bind<T: JsFunction = fn() -> JsValue>(
4010 this: &Function<T>,
4011 context: &JsValue,
4012 ) -> Function<T>;
4013
4014 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4015 /// with a given sequence of arguments preceding any provided when the new function is called.
4016 ///
4017 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4018 ///
4019 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4020 #[wasm_bindgen(method, js_name = bind)]
4021 pub fn bind0<T: JsFunction = fn() -> JsValue>(
4022 this: &Function<T>,
4023 context: &JsValue,
4024 ) -> Function<T>;
4025
4026 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4027 /// with a given sequence of arguments preceding any provided when the new function is called.
4028 ///
4029 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4030 ///
4031 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4032 #[wasm_bindgen(method, js_name = bind)]
4033 pub fn bind1<
4034 Ret: JsGeneric,
4035 Arg1: JsGeneric,
4036 F: JsFunction1<Ret = Ret, Arg1 = Arg1> = fn(JsValue) -> JsValue,
4037 >(
4038 this: &Function<F>,
4039 context: &JsValue,
4040 arg1: &Arg1,
4041 ) -> Function<<F as JsFunction1>::Bind1>;
4042
4043 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4044 /// with a given sequence of arguments preceding any provided when the new function is called.
4045 ///
4046 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4047 ///
4048 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4049 #[wasm_bindgen(method, js_name = bind)]
4050 pub fn bind2<
4051 Ret: JsGeneric,
4052 Arg1: JsGeneric,
4053 Arg2: JsGeneric,
4054 F: JsFunction2<Ret = Ret, Arg1 = Arg1, Arg2 = Arg2> = fn(JsValue, JsValue) -> JsValue,
4055 >(
4056 this: &Function<F>,
4057 context: &JsValue,
4058 arg1: &Arg1,
4059 arg2: &Arg2,
4060 ) -> Function<<F as JsFunction2>::Bind2>;
4061
4062 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4063 /// with a given sequence of arguments preceding any provided when the new function is called.
4064 ///
4065 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4066 ///
4067 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4068 #[wasm_bindgen(method, js_name = bind)]
4069 pub fn bind3<
4070 Ret: JsGeneric,
4071 Arg1: JsGeneric,
4072 Arg2: JsGeneric,
4073 Arg3: JsGeneric,
4074 F: JsFunction3<Ret = Ret, Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3> = fn(
4075 JsValue,
4076 JsValue,
4077 JsValue,
4078 ) -> JsValue,
4079 >(
4080 this: &Function<F>,
4081 context: &JsValue,
4082 arg1: &Arg1,
4083 arg2: &Arg2,
4084 arg3: &Arg3,
4085 ) -> Function<<F as JsFunction3>::Bind3>;
4086
4087 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4088 /// with a given sequence of arguments preceding any provided when the new function is called.
4089 ///
4090 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4091 ///
4092 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4093 #[wasm_bindgen(method, js_name = bind)]
4094 pub fn bind4<
4095 Ret: JsGeneric,
4096 Arg1: JsGeneric,
4097 Arg2: JsGeneric,
4098 Arg3: JsGeneric,
4099 Arg4: JsGeneric,
4100 F: JsFunction4<Ret = Ret, Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3, Arg4 = Arg4> = fn(
4101 JsValue,
4102 JsValue,
4103 JsValue,
4104 JsValue,
4105 ) -> JsValue,
4106 >(
4107 this: &Function<F>,
4108 context: &JsValue,
4109 arg1: &Arg1,
4110 arg2: &Arg2,
4111 arg3: &Arg3,
4112 arg4: &Arg4,
4113 ) -> Function<<F as JsFunction4>::Bind4>;
4114
4115 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4116 /// with a given sequence of arguments preceding any provided when the new function is called.
4117 ///
4118 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4119 ///
4120 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4121 #[wasm_bindgen(method, js_name = bind)]
4122 pub fn bind5<
4123 Ret: JsGeneric,
4124 Arg1: JsGeneric,
4125 Arg2: JsGeneric,
4126 Arg3: JsGeneric,
4127 Arg4: JsGeneric,
4128 Arg5: JsGeneric,
4129 F: JsFunction5<Ret = Ret, Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3, Arg4 = Arg4, Arg5 = Arg5> = fn(
4130 JsValue,
4131 JsValue,
4132 JsValue,
4133 JsValue,
4134 JsValue,
4135 ) -> JsValue,
4136 >(
4137 this: &Function<F>,
4138 context: &JsValue,
4139 arg1: &Arg1,
4140 arg2: &Arg2,
4141 arg3: &Arg3,
4142 arg4: &Arg4,
4143 arg5: &Arg5,
4144 ) -> Function<<F as JsFunction5>::Bind5>;
4145
4146 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4147 /// with a given sequence of arguments preceding any provided when the new function is called.
4148 ///
4149 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4150 ///
4151 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4152 #[wasm_bindgen(method, js_name = bind)]
4153 pub fn bind6<
4154 Ret: JsGeneric,
4155 Arg1: JsGeneric,
4156 Arg2: JsGeneric,
4157 Arg3: JsGeneric,
4158 Arg4: JsGeneric,
4159 Arg5: JsGeneric,
4160 Arg6: JsGeneric,
4161 F: JsFunction6<
4162 Ret = Ret,
4163 Arg1 = Arg1,
4164 Arg2 = Arg2,
4165 Arg3 = Arg3,
4166 Arg4 = Arg4,
4167 Arg5 = Arg5,
4168 Arg6 = Arg6,
4169 > = fn(JsValue, JsValue, JsValue, JsValue, JsValue, JsValue) -> JsValue,
4170 >(
4171 this: &Function<F>,
4172 context: &JsValue,
4173 arg1: &Arg1,
4174 arg2: &Arg2,
4175 arg3: &Arg3,
4176 arg4: &Arg4,
4177 arg5: &Arg5,
4178 arg6: &Arg6,
4179 ) -> Function<<F as JsFunction6>::Bind6>;
4180
4181 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4182 /// with a given sequence of arguments preceding any provided when the new function is called.
4183 ///
4184 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4185 ///
4186 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4187 #[wasm_bindgen(method, js_name = bind)]
4188 pub fn bind7<
4189 Ret: JsGeneric,
4190 Arg1: JsGeneric,
4191 Arg2: JsGeneric,
4192 Arg3: JsGeneric,
4193 Arg4: JsGeneric,
4194 Arg5: JsGeneric,
4195 Arg6: JsGeneric,
4196 Arg7: JsGeneric,
4197 F: JsFunction7<
4198 Ret = Ret,
4199 Arg1 = Arg1,
4200 Arg2 = Arg2,
4201 Arg3 = Arg3,
4202 Arg4 = Arg4,
4203 Arg5 = Arg5,
4204 Arg6 = Arg6,
4205 Arg7 = Arg7,
4206 > = fn(
4207 JsValue,
4208 JsValue,
4209 JsValue,
4210 JsValue,
4211 JsValue,
4212 JsValue,
4213 JsValue,
4214 ) -> JsValue,
4215 >(
4216 this: &Function<F>,
4217 context: &JsValue,
4218 arg1: &Arg1,
4219 arg2: &Arg2,
4220 arg3: &Arg3,
4221 arg4: &Arg4,
4222 arg5: &Arg5,
4223 arg6: &Arg6,
4224 arg7: &Arg7,
4225 ) -> Function<<F as JsFunction7>::Bind7>;
4226
4227 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4228 /// with a given sequence of arguments preceding any provided when the new function is called.
4229 ///
4230 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4231 ///
4232 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4233 #[wasm_bindgen(method, js_name = bind)]
4234 pub fn bind8<
4235 Ret: JsGeneric,
4236 Arg1: JsGeneric,
4237 Arg2: JsGeneric,
4238 Arg3: JsGeneric,
4239 Arg4: JsGeneric,
4240 Arg5: JsGeneric,
4241 Arg6: JsGeneric,
4242 Arg7: JsGeneric,
4243 Arg8: JsGeneric,
4244 F: JsFunction8<
4245 Ret = Ret,
4246 Arg1 = Arg1,
4247 Arg2 = Arg2,
4248 Arg3 = Arg3,
4249 Arg4 = Arg4,
4250 Arg5 = Arg5,
4251 Arg6 = Arg6,
4252 Arg7 = Arg7,
4253 Arg8 = Arg8,
4254 > = fn(
4255 JsValue,
4256 JsValue,
4257 JsValue,
4258 JsValue,
4259 JsValue,
4260 JsValue,
4261 JsValue,
4262 JsValue,
4263 ) -> JsValue,
4264 >(
4265 this: &Function<F>,
4266 context: &JsValue,
4267 arg1: &Arg1,
4268 arg2: &Arg2,
4269 arg3: &Arg3,
4270 arg4: &Arg4,
4271 arg5: &Arg5,
4272 arg6: &Arg6,
4273 arg7: &Arg7,
4274 arg8: &Arg8,
4275 ) -> Function<<F as JsFunction8>::Bind8>;
4276
4277 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
4278 /// with a given sequence of arguments preceding any provided when the new function is called.
4279 ///
4280 /// *Note:* See [`Function::bindn`] for arbitrary binding with function arity checking.
4281 ///
4282 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4283 #[deprecated]
4284 #[allow(deprecated)]
4285 #[wasm_bindgen(method, js_name = bind)]
4286 pub fn bind9<
4287 Ret: JsGeneric,
4288 Arg1: JsGeneric,
4289 Arg2: JsGeneric,
4290 Arg3: JsGeneric,
4291 Arg4: JsGeneric,
4292 Arg5: JsGeneric,
4293 Arg6: JsGeneric,
4294 Arg7: JsGeneric,
4295 Arg8: JsGeneric,
4296 F: JsFunction8<
4297 Ret = Ret,
4298 Arg1 = Arg1,
4299 Arg2 = Arg2,
4300 Arg3 = Arg3,
4301 Arg4 = Arg4,
4302 Arg5 = Arg5,
4303 Arg6 = Arg6,
4304 Arg7 = Arg7,
4305 Arg8 = Arg8,
4306 > = fn(
4307 JsValue,
4308 JsValue,
4309 JsValue,
4310 JsValue,
4311 JsValue,
4312 JsValue,
4313 JsValue,
4314 JsValue,
4315 ) -> JsValue,
4316 >(
4317 this: &Function<F>,
4318 context: &JsValue,
4319 arg1: &Arg1,
4320 arg2: &Arg2,
4321 arg3: &Arg3,
4322 arg4: &Arg4,
4323 arg5: &Arg5,
4324 arg6: &Arg6,
4325 arg7: &Arg7,
4326 arg8: &Arg8,
4327 arg9: &JsValue,
4328 ) -> Function<fn() -> Ret>;
4329
4330 /// The length property indicates the number of arguments expected by the function.
4331 ///
4332 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/length)
4333 #[wasm_bindgen(method, getter)]
4334 pub fn length<T: JsFunction = fn() -> JsValue>(this: &Function<T>) -> u32;
4335
4336 /// A Function object's read-only name property indicates the function's
4337 /// name as specified when it was created or "anonymous" for functions
4338 /// created anonymously.
4339 ///
4340 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name)
4341 #[wasm_bindgen(method, getter)]
4342 pub fn name<T: JsFunction = fn() -> JsValue>(this: &Function<T>) -> JsString;
4343
4344 /// The `toString()` method returns a string representing the source code of the function.
4345 ///
4346 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/toString)
4347 #[cfg(not(js_sys_unstable_apis))]
4348 #[wasm_bindgen(method, js_name = toString)]
4349 pub fn to_string<T: JsFunction = fn() -> JsValue>(this: &Function<T>) -> JsString;
4350}
4351
4352// Basic UpcastFrom impls for Function<T>
4353impl<T: JsFunction> UpcastFrom<Function<T>> for JsValue {}
4354impl<T: JsFunction> UpcastFrom<Function<T>> for JsOption<JsValue> {}
4355impl<T: JsFunction> UpcastFrom<Function<T>> for Object {}
4356impl<T: JsFunction> UpcastFrom<Function<T>> for JsOption<Object> {}
4357
4358// Blanket trait for Function upcast
4359// Function<T> upcasts to Function<U> when the underlying fn type T upcasts to U.
4360// The fn signature UpcastFrom impls already encode correct variance (covariant return, contravariant args).
4361impl<T: JsFunction, U: JsFunction> UpcastFrom<Function<T>> for Function<U> where U: UpcastFrom<T> {}
4362
4363// len() method for Function<T> using JsFunction::ARITY
4364impl<T: JsFunction> Function<T> {
4365 /// Get the static arity of this function type.
4366 #[allow(clippy::len_without_is_empty)]
4367 pub fn len(&self) -> usize {
4368 T::ARITY
4369 }
4370
4371 /// Returns true if this is a zero-argument function.
4372 pub fn is_empty(&self) -> bool {
4373 T::ARITY == 0
4374 }
4375}
4376
4377// Base traits for function signature types.
4378pub trait JsFunction {
4379 type Ret: JsGeneric;
4380 const ARITY: usize;
4381}
4382
4383pub trait JsFunction1: JsFunction {
4384 type Arg1: JsGeneric;
4385 type Bind1: JsFunction;
4386}
4387pub trait JsFunction2: JsFunction1 {
4388 type Arg2: JsGeneric;
4389 type Bind2: JsFunction;
4390}
4391pub trait JsFunction3: JsFunction2 {
4392 type Arg3: JsGeneric;
4393 type Bind3: JsFunction;
4394}
4395pub trait JsFunction4: JsFunction3 {
4396 type Arg4: JsGeneric;
4397 type Bind4: JsFunction;
4398}
4399pub trait JsFunction5: JsFunction4 {
4400 type Arg5: JsGeneric;
4401 type Bind5: JsFunction;
4402}
4403pub trait JsFunction6: JsFunction5 {
4404 type Arg6: JsGeneric;
4405 type Bind6: JsFunction;
4406}
4407pub trait JsFunction7: JsFunction6 {
4408 type Arg7: JsGeneric;
4409 type Bind7: JsFunction;
4410}
4411pub trait JsFunction8: JsFunction7 {
4412 type Arg8: JsGeneric;
4413 type Bind8: JsFunction;
4414}
4415
4416// Manual impl for fn() -> R
4417impl<Ret: JsGeneric> JsFunction for fn() -> Ret {
4418 type Ret = Ret;
4419 const ARITY: usize = 0;
4420}
4421
4422macro_rules! impl_fn {
4423 () => {
4424 impl_fn!(@impl 1 [Arg1] [
4425 JsFunction1 Arg1 Bind1 {fn() -> Ret}
4426 ]);
4427 impl_fn!(@impl 2 [Arg1 Arg2] [
4428 JsFunction1 Arg1 Bind1 {fn(Arg2) -> Ret}
4429 JsFunction2 Arg2 Bind2 {fn() -> Ret}
4430 ]);
4431 impl_fn!(@impl 3 [Arg1 Arg2 Arg3] [
4432 JsFunction1 Arg1 Bind1 {fn(Arg2, Arg3) -> Ret}
4433 JsFunction2 Arg2 Bind2 {fn(Arg3) -> Ret}
4434 JsFunction3 Arg3 Bind3 {fn() -> Ret}
4435 ]);
4436 impl_fn!(@impl 4 [Arg1 Arg2 Arg3 Arg4] [
4437 JsFunction1 Arg1 Bind1 {fn(Arg2, Arg3, Arg4) -> Ret}
4438 JsFunction2 Arg2 Bind2 {fn(Arg3, Arg4) -> Ret}
4439 JsFunction3 Arg3 Bind3 {fn(Arg4) -> Ret}
4440 JsFunction4 Arg4 Bind4 {fn() -> Ret}
4441 ]);
4442 impl_fn!(@impl 5 [Arg1 Arg2 Arg3 Arg4 Arg5] [
4443 JsFunction1 Arg1 Bind1 {fn(Arg2, Arg3, Arg4, Arg5) -> Ret}
4444 JsFunction2 Arg2 Bind2 {fn(Arg3, Arg4, Arg5) -> Ret}
4445 JsFunction3 Arg3 Bind3 {fn(Arg4, Arg5) -> Ret}
4446 JsFunction4 Arg4 Bind4 {fn(Arg5) -> Ret}
4447 JsFunction5 Arg5 Bind5 {fn() -> Ret}
4448 ]);
4449 impl_fn!(@impl 6 [Arg1 Arg2 Arg3 Arg4 Arg5 Arg6] [
4450 JsFunction1 Arg1 Bind1 {fn(Arg2, Arg3, Arg4, Arg5, Arg6) -> Ret}
4451 JsFunction2 Arg2 Bind2 {fn(Arg3, Arg4, Arg5, Arg6) -> Ret}
4452 JsFunction3 Arg3 Bind3 {fn(Arg4, Arg5, Arg6) -> Ret}
4453 JsFunction4 Arg4 Bind4 {fn(Arg5, Arg6) -> Ret}
4454 JsFunction5 Arg5 Bind5 {fn(Arg6) -> Ret}
4455 JsFunction6 Arg6 Bind6 {fn() -> Ret}
4456 ]);
4457 impl_fn!(@impl 7 [Arg1 Arg2 Arg3 Arg4 Arg5 Arg6 Arg7] [
4458 JsFunction1 Arg1 Bind1 {fn(Arg2, Arg3, Arg4, Arg5, Arg6, Arg7) -> Ret}
4459 JsFunction2 Arg2 Bind2 {fn(Arg3, Arg4, Arg5, Arg6, Arg7) -> Ret}
4460 JsFunction3 Arg3 Bind3 {fn(Arg4, Arg5, Arg6, Arg7) -> Ret}
4461 JsFunction4 Arg4 Bind4 {fn(Arg5, Arg6, Arg7) -> Ret}
4462 JsFunction5 Arg5 Bind5 {fn(Arg6, Arg7) -> Ret}
4463 JsFunction6 Arg6 Bind6 {fn(Arg7) -> Ret}
4464 JsFunction7 Arg7 Bind7 {fn() -> Ret}
4465 ]);
4466 impl_fn!(@impl 8 [Arg1 Arg2 Arg3 Arg4 Arg5 Arg6 Arg7 Arg8] [
4467 JsFunction1 Arg1 Bind1 {fn(Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8) -> Ret}
4468 JsFunction2 Arg2 Bind2 {fn(Arg3, Arg4, Arg5, Arg6, Arg7, Arg8) -> Ret}
4469 JsFunction3 Arg3 Bind3 {fn(Arg4, Arg5, Arg6, Arg7, Arg8) -> Ret}
4470 JsFunction4 Arg4 Bind4 {fn(Arg5, Arg6, Arg7, Arg8) -> Ret}
4471 JsFunction5 Arg5 Bind5 {fn(Arg6, Arg7, Arg8) -> Ret}
4472 JsFunction6 Arg6 Bind6 {fn(Arg7, Arg8) -> Ret}
4473 JsFunction7 Arg7 Bind7 {fn(Arg8) -> Ret}
4474 JsFunction8 Arg8 Bind8 {fn() -> Ret}
4475 ]);
4476 };
4477
4478 (@impl $arity:literal [$($A:ident)+] [$($trait:ident $arg:ident $bind:ident {$bind_ty:ty})+]) => {
4479 impl<Ret: JsGeneric $(, $A: JsGeneric)+> JsFunction for fn($($A),+) -> Ret {
4480 type Ret = Ret;
4481 const ARITY: usize = $arity;
4482 }
4483
4484 impl_fn!(@traits [$($A)+] [$($trait $arg $bind {$bind_ty})+]);
4485 };
4486
4487 (@traits [$($A:ident)+] []) => {};
4488
4489 (@traits [$($A:ident)+] [$trait:ident $arg:ident $bind:ident {$bind_ty:ty} $($rest:tt)*]) => {
4490 impl<Ret: JsGeneric $(, $A: JsGeneric)+> $trait for fn($($A),+) -> Ret {
4491 type $arg = $arg;
4492 type $bind = $bind_ty;
4493 }
4494
4495 impl_fn!(@traits [$($A)+] [$($rest)*]);
4496 };
4497}
4498
4499impl_fn!();
4500
4501/// Trait for argument tuples that can call or bind a `Function<T>`.
4502pub trait JsArgs<T: JsFunction> {
4503 type BindOutput;
4504 fn apply_call(self, func: &Function<T>, context: &JsValue) -> Result<T::Ret, JsValue>;
4505 fn apply_bind(self, func: &Function<T>, context: &JsValue) -> Self::BindOutput;
4506}
4507
4508// Manual impl for 0-arg
4509impl<Ret: JsGeneric, F: JsFunction<Ret = Ret>> JsArgs<F> for () {
4510 type BindOutput = Function<F>;
4511
4512 #[inline]
4513 fn apply_call(self, func: &Function<F>, context: &JsValue) -> Result<Ret, JsValue> {
4514 func.call0(context)
4515 }
4516
4517 #[inline]
4518 fn apply_bind(self, func: &Function<F>, context: &JsValue) -> Self::BindOutput {
4519 func.bind0(context)
4520 }
4521}
4522
4523macro_rules! impl_js_args {
4524 ($arity:literal $trait:ident $bind_output:ident [$($A:ident)+] [$($idx:tt)+] $call:ident $bind:ident) => {
4525 impl<Ret: JsGeneric, $($A: JsGeneric,)+ F: $trait<Ret = Ret, $($A = $A,)*>> JsArgs<F> for ($(&$A,)+)
4526 {
4527 type BindOutput = Function<<F as $trait>::$bind_output>;
4528
4529 #[inline]
4530 fn apply_call(self, func: &Function<F>, context: &JsValue) -> Result<Ret, JsValue> {
4531 func.$call(context, $(self.$idx),+)
4532 }
4533
4534 #[inline]
4535 fn apply_bind(self, func: &Function<F>, context: &JsValue) -> Self::BindOutput {
4536 func.$bind(context, $(self.$idx),+)
4537 }
4538 }
4539 };
4540}
4541
4542impl_js_args!(1 JsFunction1 Bind1 [Arg1] [0] call1 bind1);
4543impl_js_args!(2 JsFunction2 Bind2 [Arg1 Arg2] [0 1] call2 bind2);
4544impl_js_args!(3 JsFunction3 Bind3 [Arg1 Arg2 Arg3] [0 1 2] call3 bind3);
4545impl_js_args!(4 JsFunction4 Bind4 [Arg1 Arg2 Arg3 Arg4] [0 1 2 3] call4 bind4);
4546impl_js_args!(5 JsFunction5 Bind5 [Arg1 Arg2 Arg3 Arg4 Arg5] [0 1 2 3 4] call5 bind5);
4547impl_js_args!(6 JsFunction6 Bind6 [Arg1 Arg2 Arg3 Arg4 Arg5 Arg6] [0 1 2 3 4 5] call6 bind6);
4548impl_js_args!(7 JsFunction7 Bind7 [Arg1 Arg2 Arg3 Arg4 Arg5 Arg6 Arg7] [0 1 2 3 4 5 6] call7 bind7);
4549impl_js_args!(8 JsFunction8 Bind8 [Arg1 Arg2 Arg3 Arg4 Arg5 Arg6 Arg7 Arg8] [0 1 2 3 4 5 6 7] call8 bind8);
4550
4551impl<T: JsFunction> Function<T> {
4552 /// The `call()` method calls a function with a given `this` value and
4553 /// arguments provided as a tuple.
4554 ///
4555 /// This method accepts a tuple of references matching the function's
4556 /// argument types.
4557 ///
4558 /// # Example
4559 ///
4560 /// ```ignore
4561 /// // 0-arg function
4562 /// let f: Function<fn() -> Number> = get_fn();
4563 /// let result = f.call(&JsValue::NULL, ())?;
4564 ///
4565 /// // 1-arg function (note trailing comma for 1-tuple)
4566 /// let f: Function<fn(JsString) -> Number> = get_fn();
4567 /// let result = f.call(&JsValue::NULL, (&name,))?;
4568 ///
4569 /// // 2-arg function
4570 /// let f: Function<fn(JsString, Boolean) -> Number> = get_fn();
4571 /// let result = f.call(&JsValue::NULL, (&name, &flag))?;
4572 /// ```
4573 ///
4574 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
4575 #[inline]
4576 pub fn call<Args: JsArgs<T>>(&self, context: &JsValue, args: Args) -> Result<T::Ret, JsValue> {
4577 args.apply_call(self, context)
4578 }
4579
4580 /// The `bind()` method creates a new function that, when called, has its
4581 /// `this` keyword set to the provided value, with a given sequence of
4582 /// arguments preceding any provided when the new function is called.
4583 ///
4584 /// This method accepts a tuple of references to bind.
4585 ///
4586 /// # Example
4587 ///
4588 /// ```ignore
4589 /// let f: Function<fn(JsString, Boolean) -> Number> = get_fn();
4590 ///
4591 /// // Bind no args - same signature
4592 /// let bound: Function<fn(JsString, Boolean) -> Number> = f.bind(&ctx, ());
4593 ///
4594 /// // Bind one arg (use 1-tuple of references)
4595 /// let bound: Function<fn(Boolean) -> Number> = f.bind(&ctx, (&my_string,));
4596 ///
4597 /// // Bind two args - becomes 0-arg function
4598 /// let bound: Function<fn() -> Number> = f.bind(&ctx, (&my_string, &my_bool));
4599 /// ```
4600 ///
4601 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4602 #[inline]
4603 pub fn bindn<Args: JsArgs<T>>(&self, context: &JsValue, args: Args) -> Args::BindOutput {
4604 args.apply_bind(self, context)
4605 }
4606
4607 /// The `bind()` method creates a new function that, when called, has its
4608 /// `this` keyword set to the provided value, with a given sequence of
4609 /// arguments preceding any provided when the new function is called.
4610 ///
4611 /// This method accepts a tuple of references to bind.
4612 ///
4613 /// # Example
4614 ///
4615 /// ```ignore
4616 /// let f: Function<fn(JsString, Boolean) -> Number> = get_fn();
4617 ///
4618 /// // Bind no args - same signature
4619 /// let bound: Function<fn(JsString, Boolean) -> Number> = f.bind(&ctx, ());
4620 ///
4621 /// // Bind one arg (use 1-tuple of references)
4622 /// let bound: Function<fn(Boolean) -> Number> = f.bind(&ctx, (&my_string,));
4623 ///
4624 /// // Bind two args - becomes 0-arg function
4625 /// let bound: Function<fn() -> Number> = f.bind(&ctx, (&my_string, &my_bool));
4626 /// ```
4627 ///
4628 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
4629 #[cfg(js_sys_unstable_apis)]
4630 #[inline]
4631 pub fn bind<Args: JsArgs<T>>(&self, context: &JsValue, args: Args) -> Args::BindOutput {
4632 args.apply_bind(self, context)
4633 }
4634}
4635
4636pub trait FunctionIntoClosure: JsFunction {
4637 type ClosureTypeMut: WasmClosure + ?Sized;
4638}
4639
4640macro_rules! impl_function_into_closure {
4641 ( $(($($var:ident)*))* ) => {$(
4642 impl<$($var: FromWasmAbi + JsGeneric,)* R: IntoWasmAbi + JsGeneric> FunctionIntoClosure for fn($($var),*) -> R {
4643 type ClosureTypeMut = dyn FnMut($($var),*) -> R;
4644 }
4645 )*};
4646}
4647
4648impl_function_into_closure! {
4649 ()
4650 (A)
4651 (A B)
4652 (A B C)
4653 (A B C D)
4654 (A B C D E)
4655 (A B C D E F)
4656 (A B C D E F G)
4657 (A B C D E F G H)
4658}
4659
4660impl<F: JsFunction> Function<F> {
4661 /// Convert a borrowed `ScopedClosure` into a typed JavaScript Function reference.
4662 ///
4663 /// The conversion is a direct type-safe conversion and upcast of a
4664 /// closure into its corresponding typed JavaScript Function,
4665 /// based on covariance and contravariance [`Upcast`] trait hierarchy.
4666 ///
4667 /// For transferring ownership to JS, use [`Function::from_closure`].
4668 #[inline]
4669 pub fn closure_ref<'a, C>(closure: &'a ScopedClosure<'_, C>) -> &'a Self
4670 where
4671 F: FunctionIntoClosure,
4672 C: WasmClosure + ?Sized,
4673 <F as FunctionIntoClosure>::ClosureTypeMut: UpcastFrom<<C as WasmClosure>::AsMut>,
4674 {
4675 closure.as_js_value().unchecked_ref()
4676 }
4677
4678 /// Convert a Rust closure into a typed JavaScript Function.
4679 ///
4680 /// This function releases ownership of the closure to JS, and provides
4681 /// an owned function handle for the same closure.
4682 ///
4683 /// The conversion is a direct type-safe conversion and upcast of a
4684 /// closure into its corresponding typed JavaScript Function,
4685 /// based on covariance and contravariance [`Upcast`] trait hierarchy.
4686 ///
4687 /// This method is only supported for static closures which do not have
4688 /// borrowed lifetime data, and thus can be released into JS.
4689 ///
4690 /// For borrowed closures, which cannot cede ownership to JS,
4691 /// instead use [`Function::closure_ref`].
4692 #[inline]
4693 pub fn from_closure<C>(closure: ScopedClosure<'static, C>) -> Self
4694 where
4695 F: FunctionIntoClosure,
4696 C: WasmClosure + ?Sized,
4697 <F as FunctionIntoClosure>::ClosureTypeMut: UpcastFrom<<C as WasmClosure>::AsMut>,
4698 {
4699 closure.into_js_value().unchecked_into()
4700 }
4701}
4702
4703#[cfg(not(js_sys_unstable_apis))]
4704impl Function {
4705 /// Returns the `Function` value of this JS value if it's an instance of a
4706 /// function.
4707 ///
4708 /// If this JS value is not an instance of a function then this returns
4709 /// `None`.
4710 #[deprecated(note = "recommended to use dyn_ref instead which is now equivalent")]
4711 pub fn try_from(val: &JsValue) -> Option<&Function> {
4712 val.dyn_ref()
4713 }
4714}
4715
4716#[cfg(feature = "unsafe-eval")]
4717impl Default for Function {
4718 fn default() -> Self {
4719 Self::new_no_args("")
4720 }
4721}
4722
4723// Generator
4724#[wasm_bindgen]
4725extern "C" {
4726 #[wasm_bindgen(extends = Object, typescript_type = "Generator<any, any, any>")]
4727 #[derive(Clone, Debug, PartialEq, Eq)]
4728 pub type Generator<T = JsValue>;
4729
4730 /// The `next()` method returns an object with two properties done and value.
4731 /// You can also provide a parameter to the next method to send a value to the generator.
4732 ///
4733 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/next)
4734 #[cfg(not(js_sys_unstable_apis))]
4735 #[wasm_bindgen(method, catch)]
4736 pub fn next<T>(this: &Generator<T>, value: &T) -> Result<JsValue, JsValue>;
4737
4738 /// The `next()` method returns an object with two properties done and value.
4739 /// You can also provide a parameter to the next method to send a value to the generator.
4740 ///
4741 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/next)
4742 #[cfg(js_sys_unstable_apis)]
4743 #[wasm_bindgen(method, catch, js_name = next)]
4744 pub fn next<T: FromWasmAbi>(this: &Generator<T>, value: &T)
4745 -> Result<IteratorNext<T>, JsValue>;
4746
4747 // Next major: deprecate
4748 /// The `next()` method returns an object with two properties done and value.
4749 /// You can also provide a parameter to the next method to send a value to the generator.
4750 ///
4751 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/next)
4752 #[wasm_bindgen(method, catch)]
4753 pub fn next_iterator<T: FromWasmAbi>(
4754 this: &Generator<T>,
4755 value: &T,
4756 ) -> Result<IteratorNext<T>, JsValue>;
4757
4758 /// The `return()` method returns the given value and finishes the generator.
4759 ///
4760 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/return)
4761 #[cfg(not(js_sys_unstable_apis))]
4762 #[wasm_bindgen(method, js_name = "return")]
4763 pub fn return_<T>(this: &Generator<T>, value: &T) -> JsValue;
4764
4765 /// The `return()` method returns the given value and finishes the generator.
4766 ///
4767 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/return)
4768 #[cfg(js_sys_unstable_apis)]
4769 #[wasm_bindgen(method, catch, js_name = "return")]
4770 pub fn return_<T: FromWasmAbi>(
4771 this: &Generator<T>,
4772 value: &T,
4773 ) -> Result<IteratorNext<T>, JsValue>;
4774
4775 // Next major: deprecate
4776 /// The `return()` method returns the given value and finishes the generator.
4777 ///
4778 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/return)
4779 #[wasm_bindgen(method, catch, js_name = "return")]
4780 pub fn try_return<T: FromWasmAbi>(
4781 this: &Generator<T>,
4782 value: &T,
4783 ) -> Result<IteratorNext<T>, JsValue>;
4784
4785 /// The `throw()` method resumes the execution of a generator by throwing an error into it
4786 /// and returns an object with two properties done and value.
4787 ///
4788 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/throw)
4789 #[cfg(not(js_sys_unstable_apis))]
4790 #[wasm_bindgen(method, catch)]
4791 pub fn throw<T>(this: &Generator<T>, error: &Error) -> Result<JsValue, JsValue>;
4792
4793 /// The `throw()` method resumes the execution of a generator by throwing an error into it
4794 /// and returns an object with two properties done and value.
4795 ///
4796 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/throw)
4797 #[cfg(js_sys_unstable_apis)]
4798 #[wasm_bindgen(method, catch, js_name = throw)]
4799 pub fn throw<T: FromWasmAbi>(
4800 this: &Generator<T>,
4801 error: &JsValue,
4802 ) -> Result<IteratorNext<T>, JsValue>;
4803
4804 // Next major: deprecate
4805 /// The `throw()` method resumes the execution of a generator by throwing an error into it
4806 /// and returns an object with two properties done and value.
4807 ///
4808 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/throw)
4809 #[wasm_bindgen(method, catch, js_name = throw)]
4810 pub fn throw_value<T: FromWasmAbi>(
4811 this: &Generator<T>,
4812 error: &JsValue,
4813 ) -> Result<IteratorNext<T>, JsValue>;
4814}
4815
4816impl<T: FromWasmAbi> Iterable for Generator<T> {
4817 type Item = T;
4818}
4819
4820// AsyncGenerator
4821#[wasm_bindgen]
4822extern "C" {
4823 #[wasm_bindgen(extends = Object, typescript_type = "AsyncGenerator<any, any, any>")]
4824 #[derive(Clone, Debug, PartialEq, Eq)]
4825 pub type AsyncGenerator<T = JsValue>;
4826
4827 /// The `next()` method returns an object with two properties done and value.
4828 /// You can also provide a parameter to the next method to send a value to the generator.
4829 ///
4830 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncGenerator/next)
4831 #[wasm_bindgen(method, catch)]
4832 pub fn next<T>(
4833 this: &AsyncGenerator<T>,
4834 value: &T,
4835 ) -> Result<Promise<IteratorNext<T>>, JsValue>;
4836
4837 /// The `return()` method returns the given value and finishes the generator.
4838 ///
4839 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncGenerator/return)
4840 #[wasm_bindgen(method, js_name = "return", catch)]
4841 pub fn return_<T>(
4842 this: &AsyncGenerator<T>,
4843 value: &T,
4844 ) -> Result<Promise<IteratorNext<T>>, JsValue>;
4845
4846 /// The `throw()` method resumes the execution of a generator by throwing an error into it
4847 /// and returns an object with two properties done and value.
4848 ///
4849 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncGenerator/throw)
4850 #[wasm_bindgen(method, catch)]
4851 pub fn throw<T>(
4852 this: &AsyncGenerator<T>,
4853 error: &JsValue,
4854 ) -> Result<Promise<IteratorNext<T>>, JsValue>;
4855}
4856
4857impl<T: FromWasmAbi> AsyncIterable for AsyncGenerator<T> {
4858 type Item = T;
4859}
4860
4861// Map
4862#[wasm_bindgen]
4863extern "C" {
4864 #[wasm_bindgen(extends = Object, typescript_type = "Map<any, any>")]
4865 #[derive(Clone, Debug, PartialEq, Eq)]
4866 pub type Map<K = JsValue, V = JsValue>;
4867
4868 /// The Map object holds key-value pairs. Any value (both objects and
4869 /// primitive values) maybe used as either a key or a value.
4870 ///
4871 /// **Note:** Consider using [`Map::new_typed`] for typing support.
4872 ///
4873 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)
4874 #[cfg(not(js_sys_unstable_apis))]
4875 #[wasm_bindgen(constructor)]
4876 pub fn new() -> Map;
4877
4878 /// The Map object holds key-value pairs. Any value (both objects and
4879 /// primitive values) maybe used as either a key or a value.
4880 ///
4881 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)
4882 #[cfg(js_sys_unstable_apis)]
4883 #[wasm_bindgen(constructor)]
4884 pub fn new<K, V>() -> Map<K, V>;
4885
4886 // Next major: deprecate
4887 /// The Map object holds key-value pairs. Any value (both objects and
4888 /// primitive values) maybe used as either a key or a value.
4889 ///
4890 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)
4891 #[wasm_bindgen(constructor)]
4892 pub fn new_typed<K, V>() -> Map<K, V>;
4893
4894 /// The Map object holds key-value pairs. Any value (both objects and
4895 /// primitive values) maybe used as either a key or a value.
4896 ///
4897 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)
4898 #[wasm_bindgen(constructor, js_name = new)]
4899 pub fn new_from_entries<K, V, I: Iterable<Item = ArrayTuple<(K, V)>>>(entries: &I)
4900 -> Map<K, V>;
4901
4902 /// The `clear()` method removes all elements from a Map object.
4903 ///
4904 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/clear)
4905 #[wasm_bindgen(method)]
4906 pub fn clear<K, V>(this: &Map<K, V>);
4907
4908 /// The `delete()` method removes the specified element from a Map object.
4909 ///
4910 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/delete)
4911 #[wasm_bindgen(method)]
4912 pub fn delete<K, V>(this: &Map<K, V>, key: &K) -> bool;
4913
4914 /// The `forEach()` method executes a provided function once per each
4915 /// key/value pair in the Map object, in insertion order.
4916 /// Note that in Javascript land the `Key` and `Value` are reversed compared to normal expectations:
4917 /// # Examples
4918 /// ```
4919 /// let js_map = Map::new();
4920 /// js_map.for_each(&mut |value, key| {
4921 /// // Do something here...
4922 /// })
4923 /// ```
4924 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/forEach)
4925 #[wasm_bindgen(method, js_name = forEach)]
4926 pub fn for_each<K, V>(this: &Map<K, V>, callback: &mut dyn FnMut(V, K));
4927
4928 /// The `forEach()` method executes a provided function once per each
4929 /// key/value pair in the Map object, in insertion order. _(Fallible variation)_
4930 /// Note that in Javascript land the `Key` and `Value` are reversed compared to normal expectations:
4931 /// # Examples
4932 /// ```
4933 /// let js_map = Map::new();
4934 /// js_map.for_each(&mut |value, key| {
4935 /// // Do something here...
4936 /// })
4937 /// ```
4938 ///
4939 /// **Note:** Consider using [`Map::try_for_each`] if the callback might throw an error.
4940 ///
4941 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/forEach)
4942 #[wasm_bindgen(method, js_name = forEach, catch)]
4943 pub fn try_for_each<K, V>(
4944 this: &Map<K, V>,
4945 callback: &mut dyn FnMut(V, K) -> Result<(), JsError>,
4946 ) -> Result<(), JsValue>;
4947
4948 /// The `get()` method returns a specified element from a Map object.
4949 /// Returns `undefined` if the key is not found.
4950 ///
4951 /// **Note:** Consider using [`Map::get_checked`] to get an `Option<V>` instead.
4952 ///
4953 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get)
4954 #[cfg(not(js_sys_unstable_apis))]
4955 #[wasm_bindgen(method)]
4956 pub fn get<K, V>(this: &Map<K, V>, key: &K) -> V;
4957
4958 /// The `get()` method returns a specified element from a Map object.
4959 /// Returns `None` if the key is not found.
4960 ///
4961 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get)
4962 #[cfg(js_sys_unstable_apis)]
4963 #[wasm_bindgen(method)]
4964 pub fn get<K, V>(this: &Map<K, V>, key: &K) -> Option<V>;
4965
4966 /// The `get()` method returns a specified element from a Map object.
4967 /// Returns `None` if the key is not found.
4968 ///
4969 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get)
4970 #[wasm_bindgen(method, js_name = get)]
4971 pub fn get_checked<K, V>(this: &Map<K, V>, key: &K) -> Option<V>;
4972
4973 /// The `has()` method returns a boolean indicating whether an element with
4974 /// the specified key exists or not.
4975 ///
4976 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/has)
4977 #[wasm_bindgen(method)]
4978 pub fn has<K, V>(this: &Map<K, V>, key: &K) -> bool;
4979
4980 /// The `set()` method adds or updates an element with a specified key
4981 /// and value to a Map object.
4982 ///
4983 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/set)
4984 #[wasm_bindgen(method)]
4985 pub fn set<K, V>(this: &Map<K, V>, key: &K, value: &V) -> Map<K, V>;
4986
4987 /// The value of size is an integer representing how many entries
4988 /// the Map object has. A set accessor function for size is undefined;
4989 /// you can not change this property.
4990 ///
4991 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/size)
4992 #[wasm_bindgen(method, getter)]
4993 pub fn size<K, V>(this: &Map<K, V>) -> u32;
4994}
4995
4996impl Default for Map<JsValue, JsValue> {
4997 fn default() -> Self {
4998 Self::new()
4999 }
5000}
5001
5002// Map Iterator
5003#[wasm_bindgen]
5004extern "C" {
5005 /// The `entries()` method returns a new Iterator object that contains
5006 /// the [key, value] pairs for each element in the Map object in
5007 /// insertion order.
5008 ///
5009 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries)
5010 #[cfg(not(js_sys_unstable_apis))]
5011 #[wasm_bindgen(method)]
5012 pub fn entries<K, V: FromWasmAbi>(this: &Map<K, V>) -> Iterator;
5013
5014 /// The `entries()` method returns a new Iterator object that contains
5015 /// the [key, value] pairs for each element in the Map object in
5016 /// insertion order.
5017 ///
5018 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries)
5019 #[cfg(js_sys_unstable_apis)]
5020 #[wasm_bindgen(method, js_name = entries)]
5021 pub fn entries<K: JsGeneric, V: FromWasmAbi + JsGeneric>(
5022 this: &Map<K, V>,
5023 ) -> Iterator<ArrayTuple<(K, V)>>;
5024
5025 // Next major: deprecate
5026 /// The `entries()` method returns a new Iterator object that contains
5027 /// the [key, value] pairs for each element in the Map object in
5028 /// insertion order.
5029 ///
5030 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries)
5031 #[wasm_bindgen(method, js_name = entries)]
5032 pub fn entries_typed<K: JsGeneric, V: FromWasmAbi + JsGeneric>(
5033 this: &Map<K, V>,
5034 ) -> Iterator<ArrayTuple<(K, V)>>;
5035
5036 /// The `keys()` method returns a new Iterator object that contains the
5037 /// keys for each element in the Map object in insertion order.
5038 ///
5039 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/keys)
5040 #[wasm_bindgen(method)]
5041 pub fn keys<K: FromWasmAbi, V: FromWasmAbi>(this: &Map<K, V>) -> Iterator<K>;
5042
5043 /// The `values()` method returns a new Iterator object that contains the
5044 /// values for each element in the Map object in insertion order.
5045 ///
5046 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/values)
5047 #[wasm_bindgen(method)]
5048 pub fn values<K, V: FromWasmAbi>(this: &Map<K, V>) -> Iterator<V>;
5049}
5050
5051impl<K, V> Iterable for Map<K, V> {
5052 type Item = ArrayTuple<(K, V)>;
5053}
5054
5055// Iterator
5056#[wasm_bindgen]
5057extern "C" {
5058 /// Any object that conforms to the JS iterator protocol. For example,
5059 /// something returned by `myArray[Symbol.iterator]()`.
5060 ///
5061 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols)
5062 #[derive(Clone, Debug)]
5063 #[wasm_bindgen(is_type_of = Iterator::looks_like_iterator, typescript_type = "Iterator<any>")]
5064 pub type Iterator<T = JsValue>;
5065
5066 /// The `next()` method always has to return an object with appropriate
5067 /// properties including done and value. If a non-object value gets returned
5068 /// (such as false or undefined), a TypeError ("iterator.next() returned a
5069 /// non-object value") will be thrown.
5070 #[wasm_bindgen(catch, method)]
5071 pub fn next<T: FromWasmAbi>(this: &Iterator<T>) -> Result<IteratorNext<T>, JsValue>;
5072}
5073
5074impl<T> UpcastFrom<Iterator<T>> for Object {}
5075
5076impl Iterator {
5077 fn looks_like_iterator(it: &JsValue) -> bool {
5078 #[wasm_bindgen]
5079 extern "C" {
5080 type MaybeIterator;
5081
5082 #[wasm_bindgen(method, getter)]
5083 fn next(this: &MaybeIterator) -> JsValue;
5084 }
5085
5086 if !it.is_object() {
5087 return false;
5088 }
5089
5090 let it = it.unchecked_ref::<MaybeIterator>();
5091
5092 it.next().is_function()
5093 }
5094}
5095
5096// iterators in JS are themselves iterable
5097impl<T> Iterable for Iterator<T> {
5098 type Item = T;
5099}
5100
5101// Async Iterator
5102#[wasm_bindgen]
5103extern "C" {
5104 /// Any object that conforms to the JS async iterator protocol. For example,
5105 /// something returned by `myObject[Symbol.asyncIterator]()`.
5106 ///
5107 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of)
5108 #[derive(Clone, Debug)]
5109 #[wasm_bindgen(is_type_of = Iterator::looks_like_iterator, typescript_type = "AsyncIterator<any>")]
5110 pub type AsyncIterator<T = JsValue>;
5111
5112 /// The `next()` method always has to return a Promise which resolves to an object
5113 /// with appropriate properties including done and value. If a non-object value
5114 /// gets returned (such as false or undefined), a TypeError ("iterator.next()
5115 /// returned a non-object value") will be thrown.
5116 #[cfg(not(js_sys_unstable_apis))]
5117 #[wasm_bindgen(catch, method)]
5118 pub fn next<T>(this: &AsyncIterator<T>) -> Result<Promise, JsValue>;
5119
5120 /// The `next()` method always has to return a Promise which resolves to an object
5121 /// with appropriate properties including done and value. If a non-object value
5122 /// gets returned (such as false or undefined), a TypeError ("iterator.next()
5123 /// returned a non-object value") will be thrown.
5124 #[cfg(js_sys_unstable_apis)]
5125 #[wasm_bindgen(catch, method, js_name = next)]
5126 pub fn next<T: FromWasmAbi>(
5127 this: &AsyncIterator<T>,
5128 ) -> Result<Promise<IteratorNext<T>>, JsValue>;
5129
5130 // Next major: deprecate
5131 /// The `next()` method always has to return a Promise which resolves to an object
5132 /// with appropriate properties including done and value. If a non-object value
5133 /// gets returned (such as false or undefined), a TypeError ("iterator.next()
5134 /// returned a non-object value") will be thrown.
5135 #[wasm_bindgen(catch, method, js_name = next)]
5136 pub fn next_iterator<T: FromWasmAbi>(
5137 this: &AsyncIterator<T>,
5138 ) -> Result<Promise<IteratorNext<T>>, JsValue>;
5139}
5140
5141impl<T> UpcastFrom<AsyncIterator<T>> for Object {}
5142
5143// iterators in JS are themselves iterable
5144impl<T> AsyncIterable for AsyncIterator<T> {
5145 type Item = T;
5146}
5147
5148/// An iterator over the JS `Symbol.iterator` iteration protocol.
5149///
5150/// Use the `IntoIterator for &js_sys::Iterator` implementation to create this.
5151pub struct Iter<'a, T = JsValue> {
5152 js: &'a Iterator<T>,
5153 state: IterState,
5154}
5155
5156/// An iterator over the JS `Symbol.iterator` iteration protocol.
5157///
5158/// Use the `IntoIterator for js_sys::Iterator` implementation to create this.
5159pub struct IntoIter<T = JsValue> {
5160 js: Iterator<T>,
5161 state: IterState,
5162}
5163
5164struct IterState {
5165 done: bool,
5166}
5167
5168impl<'a, T: FromWasmAbi + JsGeneric> IntoIterator for &'a Iterator<T> {
5169 type Item = Result<T, JsValue>;
5170 type IntoIter = Iter<'a, T>;
5171
5172 fn into_iter(self) -> Iter<'a, T> {
5173 Iter {
5174 js: self,
5175 state: IterState::new(),
5176 }
5177 }
5178}
5179
5180impl<T: FromWasmAbi + JsGeneric> core::iter::Iterator for Iter<'_, T> {
5181 type Item = Result<T, JsValue>;
5182
5183 fn next(&mut self) -> Option<Self::Item> {
5184 self.state.next(self.js)
5185 }
5186}
5187
5188impl<T: FromWasmAbi + JsGeneric> IntoIterator for Iterator<T> {
5189 type Item = Result<T, JsValue>;
5190 type IntoIter = IntoIter<T>;
5191
5192 fn into_iter(self) -> IntoIter<T> {
5193 IntoIter {
5194 js: self,
5195 state: IterState::new(),
5196 }
5197 }
5198}
5199
5200impl<T: FromWasmAbi + JsGeneric> core::iter::Iterator for IntoIter<T> {
5201 type Item = Result<T, JsValue>;
5202
5203 fn next(&mut self) -> Option<Self::Item> {
5204 self.state.next(&self.js)
5205 }
5206}
5207
5208impl IterState {
5209 fn new() -> IterState {
5210 IterState { done: false }
5211 }
5212
5213 fn next<T: FromWasmAbi + JsGeneric>(&mut self, js: &Iterator<T>) -> Option<Result<T, JsValue>> {
5214 if self.done {
5215 return None;
5216 }
5217 let next = match js.next() {
5218 Ok(val) => val,
5219 Err(e) => {
5220 self.done = true;
5221 return Some(Err(e));
5222 }
5223 };
5224 if next.done() {
5225 self.done = true;
5226 None
5227 } else {
5228 Some(Ok(next.value()))
5229 }
5230 }
5231}
5232
5233/// Create an iterator over `val` using the JS iteration protocol and
5234/// `Symbol.iterator`.
5235// #[cfg(not(js_sys_unstable_apis))]
5236pub fn try_iter(val: &JsValue) -> Result<Option<IntoIter<JsValue>>, JsValue> {
5237 let iter_sym = Symbol::iterator();
5238
5239 let iter_fn = Reflect::get_symbol::<Object>(val.unchecked_ref(), iter_sym.as_ref())?;
5240 let iter_fn: Function = match iter_fn.dyn_into() {
5241 Ok(iter_fn) => iter_fn,
5242 Err(_) => return Ok(None),
5243 };
5244
5245 let it: Iterator = match iter_fn.call0(val)?.dyn_into() {
5246 Ok(it) => it,
5247 Err(_) => return Ok(None),
5248 };
5249
5250 Ok(Some(it.into_iter()))
5251}
5252
5253/// Trait for JavaScript types that implement the iterable protocol via `Symbol.iterator`.
5254///
5255/// Types implementing this trait can be iterated over using JavaScript's iteration
5256/// protocol. The `Item` associated type specifies the type of values yielded.
5257///
5258/// ## Built-in Iterables
5259///
5260/// Many `js-sys` collection types implement `Iterable` out of the box:
5261///
5262/// ```ignore
5263/// use js_sys::{Array, Map, Set};
5264///
5265/// // Array<T> yields T
5266/// let arr: Array<Number> = get_numbers();
5267/// for value in arr.iter() {
5268/// let num: Number = value?;
5269/// }
5270///
5271/// // Map<K, V> yields Array (key-value pairs)
5272/// let map: Map<JsString, Number> = get_map();
5273/// for entry in map.iter() {
5274/// let pair: Array = entry?;
5275/// }
5276///
5277/// // Set<T> yields T
5278/// let set: Set<JsString> = get_set();
5279/// for value in set.iter() {
5280/// let s: JsString = value?;
5281/// }
5282/// ```
5283///
5284/// ## Typing Foreign Iterators
5285///
5286/// If you have a JavaScript value that implements the iterator protocol (has a `next()`
5287/// method) but isn't a built-in type, you can use [`JsCast`] to cast it to [`Iterator<T>`]:
5288///
5289/// ```ignore
5290/// use js_sys::Iterator;
5291/// use wasm_bindgen::JsCast;
5292///
5293/// // For a value you know implements the iterator protocol
5294/// fn process_iterator(js_iter: JsValue) {
5295/// // Checked cast - returns None if not an iterator
5296/// if let Some(iter) = js_iter.dyn_ref::<Iterator<Number>>() {
5297/// for value in iter.into_iter() {
5298/// let num: Number = value.unwrap();
5299/// // ...
5300/// }
5301/// }
5302/// }
5303///
5304/// // Or with unchecked cast when you're certain of the type
5305/// fn process_known_iterator(js_iter: JsValue) {
5306/// let iter: &Iterator<JsString> = js_iter.unchecked_ref();
5307/// for value in iter.into_iter() {
5308/// let s: JsString = value.unwrap();
5309/// // ...
5310/// }
5311/// }
5312/// ```
5313///
5314/// ## Using with `JsValue`
5315///
5316/// For dynamic or unknown iterables, use [`try_iter`] which returns an untyped iterator:
5317///
5318/// ```ignore
5319/// fn iterate_unknown(val: &JsValue) -> Result<(), JsValue> {
5320/// if let Some(iter) = js_sys::try_iter(val)? {
5321/// for item in iter {
5322/// let value: JsValue = item?;
5323/// // Handle dynamically...
5324/// }
5325/// }
5326/// Ok(())
5327/// }
5328/// ```
5329///
5330/// [`JsCast`]: wasm_bindgen::JsCast
5331/// [`Iterator<T>`]: Iterator
5332/// [`try_iter`]: crate::try_iter
5333pub trait Iterable {
5334 /// The type of values yielded by this iterable.
5335 type Item;
5336}
5337
5338impl<T: Iterable> Iterable for &T {
5339 type Item = T::Item;
5340}
5341
5342/// Trait for types known to implement the iterator protocol on Symbol.asyncIterator
5343pub trait AsyncIterable {
5344 type Item;
5345}
5346
5347impl<T: AsyncIterable> AsyncIterable for &T {
5348 type Item = T::Item;
5349}
5350
5351impl AsyncIterable for JsValue {
5352 type Item = JsValue;
5353}
5354
5355// IteratorNext
5356#[wasm_bindgen]
5357extern "C" {
5358 /// The result of calling `next()` on a JS iterator.
5359 ///
5360 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols)
5361 #[wasm_bindgen(extends = Object, typescript_type = "IteratorResult<any>")]
5362 #[derive(Clone, Debug, PartialEq, Eq)]
5363 pub type IteratorNext<T = JsValue>;
5364
5365 /// Has the value `true` if the iterator is past the end of the iterated
5366 /// sequence. In this case value optionally specifies the return value of
5367 /// the iterator.
5368 ///
5369 /// Has the value `false` if the iterator was able to produce the next value
5370 /// in the sequence. This is equivalent of not specifying the done property
5371 /// altogether.
5372 #[wasm_bindgen(method, getter)]
5373 pub fn done<T>(this: &IteratorNext<T>) -> bool;
5374
5375 /// Any JavaScript value returned by the iterator. Can be omitted when done
5376 /// is true.
5377 #[wasm_bindgen(method, getter)]
5378 pub fn value<T>(this: &IteratorNext<T>) -> T;
5379}
5380
5381#[allow(non_snake_case)]
5382pub mod Math {
5383 use super::*;
5384
5385 // Math
5386 #[wasm_bindgen]
5387 extern "C" {
5388 /// The `Math.abs()` function returns the absolute value of a number, that is
5389 /// Math.abs(x) = |x|
5390 ///
5391 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/abs)
5392 #[wasm_bindgen(js_namespace = Math)]
5393 pub fn abs(x: f64) -> f64;
5394
5395 /// The `Math.acos()` function returns the arccosine (in radians) of a
5396 /// number, that is ∀x∊[-1;1]
5397 /// Math.acos(x) = arccos(x) = the unique y∊[0;π] such that cos(y)=x
5398 ///
5399 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/acos)
5400 #[wasm_bindgen(js_namespace = Math)]
5401 pub fn acos(x: f64) -> f64;
5402
5403 /// The `Math.acosh()` function returns the hyperbolic arc-cosine of a
5404 /// number, that is ∀x ≥ 1
5405 /// Math.acosh(x) = arcosh(x) = the unique y ≥ 0 such that cosh(y) = x
5406 ///
5407 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/acosh)
5408 #[wasm_bindgen(js_namespace = Math)]
5409 pub fn acosh(x: f64) -> f64;
5410
5411 /// The `Math.asin()` function returns the arcsine (in radians) of a
5412 /// number, that is ∀x ∊ [-1;1]
5413 /// Math.asin(x) = arcsin(x) = the unique y∊[-π2;π2] such that sin(y) = x
5414 ///
5415 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/asin)
5416 #[wasm_bindgen(js_namespace = Math)]
5417 pub fn asin(x: f64) -> f64;
5418
5419 /// The `Math.asinh()` function returns the hyperbolic arcsine of a
5420 /// number, that is Math.asinh(x) = arsinh(x) = the unique y such that sinh(y) = x
5421 ///
5422 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/asinh)
5423 #[wasm_bindgen(js_namespace = Math)]
5424 pub fn asinh(x: f64) -> f64;
5425
5426 /// The `Math.atan()` function returns the arctangent (in radians) of a
5427 /// number, that is Math.atan(x) = arctan(x) = the unique y ∊ [-π2;π2]such that
5428 /// tan(y) = x
5429 #[wasm_bindgen(js_namespace = Math)]
5430 pub fn atan(x: f64) -> f64;
5431
5432 /// The `Math.atan2()` function returns the arctangent of the quotient of
5433 /// its arguments.
5434 ///
5435 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/atan2)
5436 #[wasm_bindgen(js_namespace = Math)]
5437 pub fn atan2(y: f64, x: f64) -> f64;
5438
5439 /// The `Math.atanh()` function returns the hyperbolic arctangent of a number,
5440 /// that is ∀x ∊ (-1,1), Math.atanh(x) = arctanh(x) = the unique y such that
5441 /// tanh(y) = x
5442 ///
5443 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/atanh)
5444 #[wasm_bindgen(js_namespace = Math)]
5445 pub fn atanh(x: f64) -> f64;
5446
5447 /// The `Math.cbrt() `function returns the cube root of a number, that is
5448 /// Math.cbrt(x) = ∛x = the unique y such that y^3 = x
5449 ///
5450 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/cbrt)
5451 #[wasm_bindgen(js_namespace = Math)]
5452 pub fn cbrt(x: f64) -> f64;
5453
5454 /// The `Math.ceil()` function returns the smallest integer greater than
5455 /// or equal to a given number.
5456 ///
5457 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/ceil)
5458 #[wasm_bindgen(js_namespace = Math)]
5459 pub fn ceil(x: f64) -> f64;
5460
5461 /// The `Math.clz32()` function returns the number of leading zero bits in
5462 /// the 32-bit binary representation of a number.
5463 ///
5464 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/clz32)
5465 #[wasm_bindgen(js_namespace = Math)]
5466 pub fn clz32(x: i32) -> u32;
5467
5468 /// The `Math.cos()` static function returns the cosine of the specified angle,
5469 /// which must be specified in radians. This value is length(adjacent)/length(hypotenuse).
5470 ///
5471 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/cos)
5472 #[wasm_bindgen(js_namespace = Math)]
5473 pub fn cos(x: f64) -> f64;
5474
5475 /// The `Math.cosh()` function returns the hyperbolic cosine of a number,
5476 /// that can be expressed using the constant e.
5477 ///
5478 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/cosh)
5479 #[wasm_bindgen(js_namespace = Math)]
5480 pub fn cosh(x: f64) -> f64;
5481
5482 /// The `Math.exp()` function returns e^x, where x is the argument, and e is Euler's number
5483 /// (also known as Napier's constant), the base of the natural logarithms.
5484 ///
5485 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/exp)
5486 #[wasm_bindgen(js_namespace = Math)]
5487 pub fn exp(x: f64) -> f64;
5488
5489 /// The `Math.expm1()` function returns e^x - 1, where x is the argument, and e the base of the
5490 /// natural logarithms.
5491 ///
5492 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/expm1)
5493 #[wasm_bindgen(js_namespace = Math)]
5494 pub fn expm1(x: f64) -> f64;
5495
5496 /// The `Math.floor()` function returns the largest integer less than or
5497 /// equal to a given number.
5498 ///
5499 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/floor)
5500 #[wasm_bindgen(js_namespace = Math)]
5501 pub fn floor(x: f64) -> f64;
5502
5503 /// The `Math.fround()` function returns the nearest 32-bit single precision float representation
5504 /// of a Number.
5505 ///
5506 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/fround)
5507 #[wasm_bindgen(js_namespace = Math)]
5508 pub fn fround(x: f64) -> f32;
5509
5510 /// The `Math.hypot()` function returns the square root of the sum of squares of its arguments.
5511 ///
5512 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/hypot)
5513 #[wasm_bindgen(js_namespace = Math)]
5514 pub fn hypot(x: f64, y: f64) -> f64;
5515
5516 /// The `Math.imul()` function returns the result of the C-like 32-bit multiplication of the
5517 /// two parameters.
5518 ///
5519 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/imul)
5520 #[wasm_bindgen(js_namespace = Math)]
5521 pub fn imul(x: i32, y: i32) -> i32;
5522
5523 /// The `Math.log()` function returns the natural logarithm (base e) of a number.
5524 /// The JavaScript `Math.log()` function is equivalent to ln(x) in mathematics.
5525 ///
5526 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log)
5527 #[wasm_bindgen(js_namespace = Math)]
5528 pub fn log(x: f64) -> f64;
5529
5530 /// The `Math.log10()` function returns the base 10 logarithm of a number.
5531 ///
5532 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log10)
5533 #[wasm_bindgen(js_namespace = Math)]
5534 pub fn log10(x: f64) -> f64;
5535
5536 /// The `Math.log1p()` function returns the natural logarithm (base e) of 1 + a number.
5537 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log1p)
5538 #[wasm_bindgen(js_namespace = Math)]
5539 pub fn log1p(x: f64) -> f64;
5540
5541 /// The `Math.log2()` function returns the base 2 logarithm of a number.
5542 ///
5543 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log2)
5544 #[wasm_bindgen(js_namespace = Math)]
5545 pub fn log2(x: f64) -> f64;
5546
5547 /// The `Math.max()` function returns the largest of two numbers.
5548 ///
5549 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/max)
5550 #[wasm_bindgen(js_namespace = Math)]
5551 pub fn max(x: f64, y: f64) -> f64;
5552
5553 /// The static function `Math.min()` returns the lowest-valued number passed into it.
5554 ///
5555 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/min)
5556 #[wasm_bindgen(js_namespace = Math)]
5557 pub fn min(x: f64, y: f64) -> f64;
5558
5559 /// The `Math.pow()` function returns the base to the exponent power, that is, base^exponent.
5560 ///
5561 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/pow)
5562 #[wasm_bindgen(js_namespace = Math)]
5563 pub fn pow(base: f64, exponent: f64) -> f64;
5564
5565 /// The `Math.random()` function returns a floating-point, pseudo-random number
5566 /// in the range 0–1 (inclusive of 0, but not 1) with approximately uniform distribution
5567 /// over that range — which you can then scale to your desired range.
5568 /// The implementation selects the initial seed to the random number generation algorithm;
5569 /// it cannot be chosen or reset by the user.
5570 ///
5571 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random)
5572 #[wasm_bindgen(js_namespace = Math)]
5573 pub fn random() -> f64;
5574
5575 /// The `Math.round()` function returns the value of a number rounded to the nearest integer.
5576 ///
5577 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round)
5578 #[wasm_bindgen(js_namespace = Math)]
5579 pub fn round(x: f64) -> f64;
5580
5581 /// The `Math.sign()` function returns the sign of a number, indicating whether the number is
5582 /// positive, negative or zero.
5583 ///
5584 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign)
5585 #[wasm_bindgen(js_namespace = Math)]
5586 pub fn sign(x: f64) -> f64;
5587
5588 /// The `Math.sin()` function returns the sine of a number.
5589 ///
5590 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sin)
5591 #[wasm_bindgen(js_namespace = Math)]
5592 pub fn sin(x: f64) -> f64;
5593
5594 /// The `Math.sinh()` function returns the hyperbolic sine of a number, that can be expressed
5595 /// using the constant e: Math.sinh(x) = (e^x - e^-x)/2
5596 ///
5597 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sinh)
5598 #[wasm_bindgen(js_namespace = Math)]
5599 pub fn sinh(x: f64) -> f64;
5600
5601 /// The `Math.sqrt()` function returns the square root of a number, that is
5602 /// ∀x ≥ 0, Math.sqrt(x) = √x = the unique y ≥ 0 such that y^2 = x
5603 ///
5604 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sqrt)
5605 #[wasm_bindgen(js_namespace = Math)]
5606 pub fn sqrt(x: f64) -> f64;
5607
5608 /// The `Math.tan()` function returns the tangent of a number.
5609 ///
5610 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/tan)
5611 #[wasm_bindgen(js_namespace = Math)]
5612 pub fn tan(x: f64) -> f64;
5613
5614 /// The `Math.tanh()` function returns the hyperbolic tangent of a number, that is
5615 /// tanh x = sinh x / cosh x = (e^x - e^-x)/(e^x + e^-x) = (e^2x - 1)/(e^2x + 1)
5616 ///
5617 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/tanh)
5618 #[wasm_bindgen(js_namespace = Math)]
5619 pub fn tanh(x: f64) -> f64;
5620
5621 /// The `Math.trunc()` function returns the integer part of a number by removing any fractional
5622 /// digits.
5623 ///
5624 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/trunc)
5625 #[wasm_bindgen(js_namespace = Math)]
5626 pub fn trunc(x: f64) -> f64;
5627
5628 /// The `Math.PI` property represents the ratio of the circumference of a circle to its diameter,
5629 /// approximately 3.14159.
5630 ///
5631 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/PI)
5632 #[wasm_bindgen(thread_local_v2, js_namespace = Math)]
5633 pub static PI: f64;
5634 }
5635}
5636
5637// Number.
5638#[wasm_bindgen]
5639extern "C" {
5640 #[wasm_bindgen(extends = Object, is_type_of = |v| v.as_f64().is_some(), typescript_type = "number")]
5641 #[derive(Clone, PartialEq)]
5642 pub type Number;
5643
5644 /// The `Number.isFinite()` method determines whether the passed value is a finite number.
5645 ///
5646 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isFinite)
5647 #[wasm_bindgen(static_method_of = Number, js_name = isFinite)]
5648 pub fn is_finite(value: &JsValue) -> bool;
5649
5650 /// The `Number.isInteger()` method determines whether the passed value is an integer.
5651 ///
5652 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isInteger)
5653 #[wasm_bindgen(static_method_of = Number, js_name = isInteger)]
5654 pub fn is_integer(value: &JsValue) -> bool;
5655
5656 /// The `Number.isNaN()` method determines whether the passed value is `NaN` and its type is Number.
5657 /// It is a more robust version of the original, global isNaN().
5658 ///
5659 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isNaN)
5660 #[wasm_bindgen(static_method_of = Number, js_name = isNaN)]
5661 pub fn is_nan(value: &JsValue) -> bool;
5662
5663 /// The `Number.isSafeInteger()` method determines whether the provided value is a number
5664 /// that is a safe integer.
5665 ///
5666 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isSafeInteger)
5667 #[wasm_bindgen(static_method_of = Number, js_name = isSafeInteger)]
5668 pub fn is_safe_integer(value: &JsValue) -> bool;
5669
5670 /// The `Number` JavaScript object is a wrapper object allowing
5671 /// you to work with numerical values. A `Number` object is
5672 /// created using the `Number()` constructor.
5673 ///
5674 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
5675 #[cfg(not(js_sys_unstable_apis))]
5676 #[wasm_bindgen(constructor)]
5677 #[deprecated(note = "recommended to use `Number::from` instead")]
5678 #[allow(deprecated)]
5679 pub fn new(value: &JsValue) -> Number;
5680
5681 #[wasm_bindgen(constructor)]
5682 fn new_from_str(value: &str) -> Number;
5683
5684 /// The `Number.parseInt()` method parses a string argument and returns an
5685 /// integer of the specified radix or base.
5686 ///
5687 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/parseInt)
5688 #[wasm_bindgen(static_method_of = Number, js_name = parseInt)]
5689 pub fn parse_int(text: &str, radix: u8) -> f64;
5690
5691 /// The `Number.parseFloat()` method parses a string argument and returns a
5692 /// floating point number.
5693 ///
5694 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/parseFloat)
5695 #[wasm_bindgen(static_method_of = Number, js_name = parseFloat)]
5696 pub fn parse_float(text: &str) -> f64;
5697
5698 /// The `toLocaleString()` method returns a string with a language sensitive
5699 /// representation of this number.
5700 ///
5701 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString)
5702 #[cfg(not(js_sys_unstable_apis))]
5703 #[wasm_bindgen(method, js_name = toLocaleString)]
5704 pub fn to_locale_string(this: &Number, locale: &str) -> JsString;
5705
5706 /// The `toLocaleString()` method returns a string with a language sensitive
5707 /// representation of this number.
5708 ///
5709 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString)
5710 #[cfg(js_sys_unstable_apis)]
5711 #[wasm_bindgen(method, js_name = toLocaleString)]
5712 pub fn to_locale_string(
5713 this: &Number,
5714 locales: &[JsString],
5715 options: &Intl::NumberFormatOptions,
5716 ) -> JsString;
5717
5718 /// The `toPrecision()` method returns a string representing the Number
5719 /// object to the specified precision.
5720 ///
5721 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision)
5722 #[wasm_bindgen(catch, method, js_name = toPrecision)]
5723 pub fn to_precision(this: &Number, precision: u8) -> Result<JsString, JsValue>;
5724
5725 /// The `toFixed()` method returns a string representing the Number
5726 /// object using fixed-point notation.
5727 ///
5728 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed)
5729 #[wasm_bindgen(catch, method, js_name = toFixed)]
5730 pub fn to_fixed(this: &Number, digits: u8) -> Result<JsString, JsValue>;
5731
5732 /// The `toExponential()` method returns a string representing the Number
5733 /// object in exponential notation.
5734 ///
5735 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toExponential)
5736 #[wasm_bindgen(catch, method, js_name = toExponential)]
5737 pub fn to_exponential(this: &Number, fraction_digits: u8) -> Result<JsString, JsValue>;
5738
5739 /// The `toString()` method returns a string representing the
5740 /// specified Number object.
5741 ///
5742 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString)
5743 #[cfg(not(js_sys_unstable_apis))]
5744 #[deprecated(note = "Use `Number::to_string_with_radix` instead.")]
5745 #[allow(deprecated)]
5746 #[wasm_bindgen(catch, method, js_name = toString)]
5747 pub fn to_string(this: &Number, radix: u8) -> Result<JsString, JsValue>;
5748
5749 /// The `toString()` method returns a string representing the
5750 /// specified Number object.
5751 ///
5752 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString)
5753 #[wasm_bindgen(catch, method, js_name = toString)]
5754 pub fn to_string_with_radix(this: &Number, radix: u8) -> Result<JsString, JsValue>;
5755
5756 /// The `valueOf()` method returns the wrapped primitive value of
5757 /// a Number object.
5758 ///
5759 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/valueOf)
5760 #[wasm_bindgen(method, js_name = valueOf)]
5761 pub fn value_of(this: &Number) -> f64;
5762}
5763
5764impl Number {
5765 /// The smallest interval between two representable numbers.
5766 ///
5767 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/EPSILON)
5768 pub const EPSILON: f64 = f64::EPSILON;
5769 /// The maximum safe integer in JavaScript (2^53 - 1).
5770 ///
5771 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER)
5772 pub const MAX_SAFE_INTEGER: f64 = 9007199254740991.0;
5773 /// The largest positive representable number.
5774 ///
5775 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_VALUE)
5776 pub const MAX_VALUE: f64 = f64::MAX;
5777 /// The minimum safe integer in JavaScript (-(2^53 - 1)).
5778 ///
5779 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MIN_SAFE_INTEGER)
5780 pub const MIN_SAFE_INTEGER: f64 = -9007199254740991.0;
5781 /// The smallest positive representable number—that is, the positive number closest to zero
5782 /// (without actually being zero).
5783 ///
5784 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MIN_VALUE)
5785 // Cannot use f64::MIN_POSITIVE since that is the smallest **normal** positive number.
5786 pub const MIN_VALUE: f64 = 5E-324;
5787 /// Special "Not a Number" value.
5788 ///
5789 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/NaN)
5790 pub const NAN: f64 = f64::NAN;
5791 /// Special value representing negative infinity. Returned on overflow.
5792 ///
5793 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/NEGATIVE_INFINITY)
5794 pub const NEGATIVE_INFINITY: f64 = f64::NEG_INFINITY;
5795 /// Special value representing infinity. Returned on overflow.
5796 ///
5797 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/POSITIVE_INFINITY)
5798 pub const POSITIVE_INFINITY: f64 = f64::INFINITY;
5799
5800 /// Applies the binary `**` JS operator on the two `Number`s.
5801 ///
5802 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Exponentiation)
5803 #[inline]
5804 pub fn pow(&self, rhs: &Self) -> Self {
5805 JsValue::as_ref(self)
5806 .pow(JsValue::as_ref(rhs))
5807 .unchecked_into()
5808 }
5809
5810 /// Applies the binary `>>>` JS operator on the two `Number`s.
5811 ///
5812 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Unsigned_right_shift)
5813 #[inline]
5814 pub fn unsigned_shr(&self, rhs: &Self) -> Self {
5815 Number::from(JsValue::as_ref(self).unsigned_shr(JsValue::as_ref(rhs)))
5816 }
5817}
5818
5819macro_rules! number_from {
5820 ($($x:ident)*) => ($(
5821 impl From<$x> for Number {
5822 #[inline]
5823 fn from(x: $x) -> Number {
5824 Number::unchecked_from_js(JsValue::from(x))
5825 }
5826 }
5827
5828 impl PartialEq<$x> for Number {
5829 #[inline]
5830 fn eq(&self, other: &$x) -> bool {
5831 self.value_of() == f64::from(*other)
5832 }
5833 }
5834
5835 impl UpcastFrom<$x> for Number {}
5836 )*)
5837}
5838number_from!(i8 u8 i16 u16 i32 u32 f32 f64);
5839
5840// The only guarantee for a JS number
5841impl UpcastFrom<Number> for f64 {}
5842
5843/// The error type returned when a checked integral type conversion fails.
5844#[derive(Debug, Copy, Clone, PartialEq, Eq)]
5845pub struct TryFromIntError(());
5846
5847impl fmt::Display for TryFromIntError {
5848 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
5849 fmt.write_str("out of range integral type conversion attempted")
5850 }
5851}
5852
5853#[cfg(feature = "std")]
5854impl std::error::Error for TryFromIntError {}
5855
5856macro_rules! number_try_from {
5857 ($($x:ident)*) => ($(
5858 impl TryFrom<$x> for Number {
5859 type Error = TryFromIntError;
5860
5861 #[inline]
5862 fn try_from(x: $x) -> Result<Number, Self::Error> {
5863 let x_f64 = x as f64;
5864 if (Number::MIN_SAFE_INTEGER..=Number::MAX_SAFE_INTEGER).contains(&x_f64) {
5865 Ok(Number::from(x_f64))
5866 } else {
5867 Err(TryFromIntError(()))
5868 }
5869 }
5870 }
5871 )*)
5872}
5873number_try_from!(i64 u64 i128 u128);
5874
5875impl From<&Number> for f64 {
5876 #[inline]
5877 fn from(n: &Number) -> f64 {
5878 n.value_of()
5879 }
5880}
5881
5882impl From<Number> for f64 {
5883 #[inline]
5884 fn from(n: Number) -> f64 {
5885 <f64 as From<&'_ Number>>::from(&n)
5886 }
5887}
5888
5889impl fmt::Debug for Number {
5890 #[inline]
5891 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5892 fmt::Debug::fmt(&self.value_of(), f)
5893 }
5894}
5895
5896impl fmt::Display for Number {
5897 #[inline]
5898 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5899 fmt::Display::fmt(&self.value_of(), f)
5900 }
5901}
5902
5903impl Default for Number {
5904 fn default() -> Self {
5905 Self::from(f64::default())
5906 }
5907}
5908
5909impl PartialEq<BigInt> for Number {
5910 #[inline]
5911 fn eq(&self, other: &BigInt) -> bool {
5912 JsValue::as_ref(self).loose_eq(JsValue::as_ref(other))
5913 }
5914}
5915
5916impl Not for &Number {
5917 type Output = BigInt;
5918
5919 #[inline]
5920 fn not(self) -> Self::Output {
5921 JsValue::as_ref(self).bit_not().unchecked_into()
5922 }
5923}
5924
5925forward_deref_unop!(impl Not, not for Number);
5926forward_js_unop!(impl Neg, neg for Number);
5927forward_js_binop!(impl BitAnd, bitand for Number);
5928forward_js_binop!(impl BitOr, bitor for Number);
5929forward_js_binop!(impl BitXor, bitxor for Number);
5930forward_js_binop!(impl Shl, shl for Number);
5931forward_js_binop!(impl Shr, shr for Number);
5932forward_js_binop!(impl Add, add for Number);
5933forward_js_binop!(impl Sub, sub for Number);
5934forward_js_binop!(impl Div, div for Number);
5935forward_js_binop!(impl Mul, mul for Number);
5936forward_js_binop!(impl Rem, rem for Number);
5937
5938sum_product!(Number);
5939
5940impl PartialOrd for Number {
5941 #[inline]
5942 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
5943 if Number::is_nan(self) || Number::is_nan(other) {
5944 None
5945 } else if self == other {
5946 Some(Ordering::Equal)
5947 } else if self.lt(other) {
5948 Some(Ordering::Less)
5949 } else {
5950 Some(Ordering::Greater)
5951 }
5952 }
5953
5954 #[inline]
5955 fn lt(&self, other: &Self) -> bool {
5956 JsValue::as_ref(self).lt(JsValue::as_ref(other))
5957 }
5958
5959 #[inline]
5960 fn le(&self, other: &Self) -> bool {
5961 JsValue::as_ref(self).le(JsValue::as_ref(other))
5962 }
5963
5964 #[inline]
5965 fn ge(&self, other: &Self) -> bool {
5966 JsValue::as_ref(self).ge(JsValue::as_ref(other))
5967 }
5968
5969 #[inline]
5970 fn gt(&self, other: &Self) -> bool {
5971 JsValue::as_ref(self).gt(JsValue::as_ref(other))
5972 }
5973}
5974
5975#[cfg(not(js_sys_unstable_apis))]
5976impl FromStr for Number {
5977 type Err = Infallible;
5978
5979 #[allow(deprecated)]
5980 #[inline]
5981 fn from_str(s: &str) -> Result<Self, Self::Err> {
5982 Ok(Number::new_from_str(s))
5983 }
5984}
5985
5986// Date.
5987#[wasm_bindgen]
5988extern "C" {
5989 #[wasm_bindgen(extends = Object, typescript_type = "Date")]
5990 #[derive(Clone, Debug, PartialEq, Eq)]
5991 pub type Date;
5992
5993 /// The `getDate()` method returns the day of the month for the
5994 /// specified date according to local time.
5995 ///
5996 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getDate)
5997 #[wasm_bindgen(method, js_name = getDate)]
5998 pub fn get_date(this: &Date) -> u32;
5999
6000 /// The `getDay()` method returns the day of the week for the specified date according to local time,
6001 /// where 0 represents Sunday. For the day of the month see getDate().
6002 ///
6003 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getDay)
6004 #[wasm_bindgen(method, js_name = getDay)]
6005 pub fn get_day(this: &Date) -> u32;
6006
6007 /// The `getFullYear()` method returns the year of the specified date according to local time.
6008 ///
6009 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getFullYear)
6010 #[wasm_bindgen(method, js_name = getFullYear)]
6011 pub fn get_full_year(this: &Date) -> u32;
6012
6013 /// The `getHours()` method returns the hour for the specified date, according to local time.
6014 ///
6015 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getHours)
6016 #[wasm_bindgen(method, js_name = getHours)]
6017 pub fn get_hours(this: &Date) -> u32;
6018
6019 /// The `getMilliseconds()` method returns the milliseconds in the specified date according to local time.
6020 ///
6021 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMilliseconds)
6022 #[wasm_bindgen(method, js_name = getMilliseconds)]
6023 pub fn get_milliseconds(this: &Date) -> u32;
6024
6025 /// The `getMinutes()` method returns the minutes in the specified date according to local time.
6026 ///
6027 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMinutes)
6028 #[wasm_bindgen(method, js_name = getMinutes)]
6029 pub fn get_minutes(this: &Date) -> u32;
6030
6031 /// The `getMonth()` method returns the month in the specified date according to local time,
6032 /// as a zero-based value (where zero indicates the first month of the year).
6033 ///
6034 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMonth)
6035 #[wasm_bindgen(method, js_name = getMonth)]
6036 pub fn get_month(this: &Date) -> u32;
6037
6038 /// The `getSeconds()` method returns the seconds in the specified date according to local time.
6039 ///
6040 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getSeconds)
6041 #[wasm_bindgen(method, js_name = getSeconds)]
6042 pub fn get_seconds(this: &Date) -> u32;
6043
6044 /// The `getTime()` method returns the numeric value corresponding to the time for the specified date
6045 /// according to universal time.
6046 ///
6047 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTime)
6048 #[wasm_bindgen(method, js_name = getTime)]
6049 pub fn get_time(this: &Date) -> f64;
6050
6051 /// The `getTimezoneOffset()` method returns the time zone difference, in minutes,
6052 /// from current locale (host system settings) to UTC.
6053 ///
6054 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTimezoneOffset)
6055 #[wasm_bindgen(method, js_name = getTimezoneOffset)]
6056 pub fn get_timezone_offset(this: &Date) -> f64;
6057
6058 /// The `getUTCDate()` method returns the day (date) of the month in the specified date
6059 /// according to universal time.
6060 ///
6061 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCDate)
6062 #[wasm_bindgen(method, js_name = getUTCDate)]
6063 pub fn get_utc_date(this: &Date) -> u32;
6064
6065 /// The `getUTCDay()` method returns the day of the week in the specified date according to universal time,
6066 /// where 0 represents Sunday.
6067 ///
6068 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCDay)
6069 #[wasm_bindgen(method, js_name = getUTCDay)]
6070 pub fn get_utc_day(this: &Date) -> u32;
6071
6072 /// The `getUTCFullYear()` method returns the year in the specified date according to universal time.
6073 ///
6074 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCFullYear)
6075 #[wasm_bindgen(method, js_name = getUTCFullYear)]
6076 pub fn get_utc_full_year(this: &Date) -> u32;
6077
6078 /// The `getUTCHours()` method returns the hours in the specified date according to universal time.
6079 ///
6080 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCHours)
6081 #[wasm_bindgen(method, js_name = getUTCHours)]
6082 pub fn get_utc_hours(this: &Date) -> u32;
6083
6084 /// The `getUTCMilliseconds()` method returns the milliseconds in the specified date
6085 /// according to universal time.
6086 ///
6087 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCMilliseconds)
6088 #[wasm_bindgen(method, js_name = getUTCMilliseconds)]
6089 pub fn get_utc_milliseconds(this: &Date) -> u32;
6090
6091 /// The `getUTCMinutes()` method returns the minutes in the specified date according to universal time.
6092 ///
6093 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCMinutes)
6094 #[wasm_bindgen(method, js_name = getUTCMinutes)]
6095 pub fn get_utc_minutes(this: &Date) -> u32;
6096
6097 /// The `getUTCMonth()` returns the month of the specified date according to universal time,
6098 /// as a zero-based value (where zero indicates the first month of the year).
6099 ///
6100 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCMonth)
6101 #[wasm_bindgen(method, js_name = getUTCMonth)]
6102 pub fn get_utc_month(this: &Date) -> u32;
6103
6104 /// The `getUTCSeconds()` method returns the seconds in the specified date according to universal time.
6105 ///
6106 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCSeconds)
6107 #[wasm_bindgen(method, js_name = getUTCSeconds)]
6108 pub fn get_utc_seconds(this: &Date) -> u32;
6109
6110 /// Creates a JavaScript `Date` instance that represents
6111 /// a single moment in time. `Date` objects are based on a time value that is
6112 /// the number of milliseconds since 1 January 1970 UTC.
6113 ///
6114 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6115 #[wasm_bindgen(constructor)]
6116 pub fn new(init: &JsValue) -> Date;
6117
6118 /// Creates a JavaScript `Date` instance that represents the current moment in
6119 /// time.
6120 ///
6121 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6122 #[wasm_bindgen(constructor)]
6123 pub fn new_0() -> Date;
6124
6125 /// Creates a JavaScript `Date` instance that represents
6126 /// a single moment in time. `Date` objects are based on a time value that is
6127 /// the number of milliseconds since 1 January 1970 UTC.
6128 ///
6129 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6130 #[wasm_bindgen(constructor)]
6131 pub fn new_with_year_month(year: u32, month: i32) -> Date;
6132
6133 /// Creates a JavaScript `Date` instance that represents
6134 /// a single moment in time. `Date` objects are based on a time value that is
6135 /// the number of milliseconds since 1 January 1970 UTC.
6136 ///
6137 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6138 #[wasm_bindgen(constructor)]
6139 pub fn new_with_year_month_day(year: u32, month: i32, day: i32) -> Date;
6140
6141 /// Creates a JavaScript `Date` instance that represents
6142 /// a single moment in time. `Date` objects are based on a time value that is
6143 /// the number of milliseconds since 1 January 1970 UTC.
6144 ///
6145 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6146 #[wasm_bindgen(constructor)]
6147 pub fn new_with_year_month_day_hr(year: u32, month: i32, day: i32, hr: i32) -> Date;
6148
6149 /// Creates a JavaScript `Date` instance that represents
6150 /// a single moment in time. `Date` objects are based on a time value that is
6151 /// the number of milliseconds since 1 January 1970 UTC.
6152 ///
6153 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6154 #[wasm_bindgen(constructor)]
6155 pub fn new_with_year_month_day_hr_min(
6156 year: u32,
6157 month: i32,
6158 day: i32,
6159 hr: i32,
6160 min: i32,
6161 ) -> Date;
6162
6163 /// Creates a JavaScript `Date` instance that represents
6164 /// a single moment in time. `Date` objects are based on a time value that is
6165 /// the number of milliseconds since 1 January 1970 UTC.
6166 ///
6167 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6168 #[wasm_bindgen(constructor)]
6169 pub fn new_with_year_month_day_hr_min_sec(
6170 year: u32,
6171 month: i32,
6172 day: i32,
6173 hr: i32,
6174 min: i32,
6175 sec: i32,
6176 ) -> Date;
6177
6178 /// Creates a JavaScript `Date` instance that represents
6179 /// a single moment in time. `Date` objects are based on a time value that is
6180 /// the number of milliseconds since 1 January 1970 UTC.
6181 ///
6182 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
6183 #[wasm_bindgen(constructor)]
6184 pub fn new_with_year_month_day_hr_min_sec_milli(
6185 year: u32,
6186 month: i32,
6187 day: i32,
6188 hr: i32,
6189 min: i32,
6190 sec: i32,
6191 milli: i32,
6192 ) -> Date;
6193
6194 /// The `Date.now()` method returns the number of milliseconds
6195 /// elapsed since January 1, 1970 00:00:00 UTC.
6196 ///
6197 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/now)
6198 #[wasm_bindgen(static_method_of = Date)]
6199 pub fn now() -> f64;
6200
6201 /// The `Date.parse()` method parses a string representation of a date, and returns the number of milliseconds
6202 /// since January 1, 1970, 00:00:00 UTC or `NaN` if the string is unrecognized or, in some cases,
6203 /// contains illegal date values (e.g. 2015-02-31).
6204 ///
6205 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse)
6206 #[wasm_bindgen(static_method_of = Date)]
6207 pub fn parse(date: &str) -> f64;
6208
6209 /// The `setDate()` method sets the day of the Date object relative to the beginning of the currently set month.
6210 ///
6211 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setDate)
6212 #[wasm_bindgen(method, js_name = setDate)]
6213 pub fn set_date(this: &Date, day: u32) -> f64;
6214
6215 /// The `setFullYear()` method sets the full year for a specified date according to local time.
6216 /// Returns new timestamp.
6217 ///
6218 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setFullYear)
6219 #[wasm_bindgen(method, js_name = setFullYear)]
6220 pub fn set_full_year(this: &Date, year: u32) -> f64;
6221
6222 /// The `setFullYear()` method sets the full year for a specified date according to local time.
6223 /// Returns new timestamp.
6224 ///
6225 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setFullYear)
6226 #[wasm_bindgen(method, js_name = setFullYear)]
6227 pub fn set_full_year_with_month(this: &Date, year: u32, month: i32) -> f64;
6228
6229 /// The `setFullYear()` method sets the full year for a specified date according to local time.
6230 /// Returns new timestamp.
6231 ///
6232 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setFullYear)
6233 #[wasm_bindgen(method, js_name = setFullYear)]
6234 pub fn set_full_year_with_month_date(this: &Date, year: u32, month: i32, date: i32) -> f64;
6235
6236 /// The `setHours()` method sets the hours for a specified date according to local time,
6237 /// and returns the number of milliseconds since January 1, 1970 00:00:00 UTC until the time represented
6238 /// by the updated Date instance.
6239 ///
6240 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setHours)
6241 #[wasm_bindgen(method, js_name = setHours)]
6242 pub fn set_hours(this: &Date, hours: u32) -> f64;
6243
6244 /// The `setMilliseconds()` method sets the milliseconds for a specified date according to local time.
6245 ///
6246 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setMilliseconds)
6247 #[wasm_bindgen(method, js_name = setMilliseconds)]
6248 pub fn set_milliseconds(this: &Date, milliseconds: u32) -> f64;
6249
6250 /// The `setMinutes()` method sets the minutes for a specified date according to local time.
6251 ///
6252 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setMinutes)
6253 #[wasm_bindgen(method, js_name = setMinutes)]
6254 pub fn set_minutes(this: &Date, minutes: u32) -> f64;
6255
6256 /// The `setMonth()` method sets the month for a specified date according to the currently set year.
6257 ///
6258 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setMonth)
6259 #[wasm_bindgen(method, js_name = setMonth)]
6260 pub fn set_month(this: &Date, month: u32) -> f64;
6261
6262 /// The `setSeconds()` method sets the seconds for a specified date according to local time.
6263 ///
6264 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setSeconds)
6265 #[wasm_bindgen(method, js_name = setSeconds)]
6266 pub fn set_seconds(this: &Date, seconds: u32) -> f64;
6267
6268 /// The `setTime()` method sets the Date object to the time represented by a number of milliseconds
6269 /// since January 1, 1970, 00:00:00 UTC.
6270 ///
6271 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setTime)
6272 #[wasm_bindgen(method, js_name = setTime)]
6273 pub fn set_time(this: &Date, time: f64) -> f64;
6274
6275 /// The `setUTCDate()` method sets the day of the month for a specified date
6276 /// according to universal time.
6277 ///
6278 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCDate)
6279 #[wasm_bindgen(method, js_name = setUTCDate)]
6280 pub fn set_utc_date(this: &Date, day: u32) -> f64;
6281
6282 /// The `setUTCFullYear()` method sets the full year for a specified date according to universal time.
6283 ///
6284 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCFullYear)
6285 #[wasm_bindgen(method, js_name = setUTCFullYear)]
6286 pub fn set_utc_full_year(this: &Date, year: u32) -> f64;
6287
6288 /// The `setUTCFullYear()` method sets the full year for a specified date according to universal time.
6289 ///
6290 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCFullYear)
6291 #[wasm_bindgen(method, js_name = setUTCFullYear)]
6292 pub fn set_utc_full_year_with_month(this: &Date, year: u32, month: i32) -> f64;
6293
6294 /// The `setUTCFullYear()` method sets the full year for a specified date according to universal time.
6295 ///
6296 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCFullYear)
6297 #[wasm_bindgen(method, js_name = setUTCFullYear)]
6298 pub fn set_utc_full_year_with_month_date(this: &Date, year: u32, month: i32, date: i32) -> f64;
6299
6300 /// The `setUTCHours()` method sets the hour for a specified date according to universal time,
6301 /// and returns the number of milliseconds since January 1, 1970 00:00:00 UTC until the time
6302 /// represented by the updated Date instance.
6303 ///
6304 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCHours)
6305 #[wasm_bindgen(method, js_name = setUTCHours)]
6306 pub fn set_utc_hours(this: &Date, hours: u32) -> f64;
6307
6308 /// The `setUTCMilliseconds()` method sets the milliseconds for a specified date
6309 /// according to universal time.
6310 ///
6311 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCMilliseconds)
6312 #[wasm_bindgen(method, js_name = setUTCMilliseconds)]
6313 pub fn set_utc_milliseconds(this: &Date, milliseconds: u32) -> f64;
6314
6315 /// The `setUTCMinutes()` method sets the minutes for a specified date according to universal time.
6316 ///
6317 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCMinutes)
6318 #[wasm_bindgen(method, js_name = setUTCMinutes)]
6319 pub fn set_utc_minutes(this: &Date, minutes: u32) -> f64;
6320
6321 /// The `setUTCMonth()` method sets the month for a specified date according to universal time.
6322 ///
6323 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCMonth)
6324 #[wasm_bindgen(method, js_name = setUTCMonth)]
6325 pub fn set_utc_month(this: &Date, month: u32) -> f64;
6326
6327 /// The `setUTCSeconds()` method sets the seconds for a specified date according to universal time.
6328 ///
6329 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCSeconds)
6330 #[wasm_bindgen(method, js_name = setUTCSeconds)]
6331 pub fn set_utc_seconds(this: &Date, seconds: u32) -> f64;
6332
6333 /// The `toDateString()` method returns the date portion of a Date object
6334 /// in human readable form in American English.
6335 ///
6336 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toDateString)
6337 #[wasm_bindgen(method, js_name = toDateString)]
6338 pub fn to_date_string(this: &Date) -> JsString;
6339
6340 /// The `toISOString()` method returns a string in simplified extended ISO format (ISO
6341 /// 8601), which is always 24 or 27 characters long (YYYY-MM-DDTHH:mm:ss.sssZ or
6342 /// ±YYYYYY-MM-DDTHH:mm:ss.sssZ, respectively). The timezone is always zero UTC offset,
6343 /// as denoted by the suffix "Z"
6344 ///
6345 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString)
6346 #[wasm_bindgen(method, js_name = toISOString)]
6347 pub fn to_iso_string(this: &Date) -> JsString;
6348
6349 /// The `toJSON()` method returns a string representation of the Date object.
6350 ///
6351 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toJSON)
6352 #[wasm_bindgen(method, js_name = toJSON)]
6353 pub fn to_json(this: &Date) -> JsString;
6354
6355 /// The `toLocaleDateString()` method returns a string with a language sensitive
6356 /// representation of the date portion of this date. The new locales and options
6357 /// arguments let applications specify the language whose formatting conventions
6358 /// should be used and allow to customize the behavior of the function.
6359 /// In older implementations, which ignore the locales and options arguments,
6360 /// the locale used and the form of the string
6361 /// returned are entirely implementation dependent.
6362 ///
6363 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString)
6364 #[cfg(not(js_sys_unstable_apis))]
6365 #[wasm_bindgen(method, js_name = toLocaleDateString)]
6366 pub fn to_locale_date_string(this: &Date, locale: &str, options: &JsValue) -> JsString;
6367
6368 /// The `toLocaleDateString()` method returns a string with a language sensitive
6369 /// representation of the date portion of this date.
6370 ///
6371 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString)
6372 #[cfg(js_sys_unstable_apis)]
6373 #[wasm_bindgen(method, js_name = toLocaleDateString)]
6374 pub fn to_locale_date_string(
6375 this: &Date,
6376 locales: &[JsString],
6377 options: &Intl::DateTimeFormatOptions,
6378 ) -> JsString;
6379
6380 /// The `toLocaleString()` method returns a string with a language sensitive
6381 /// representation of this date. The new locales and options arguments
6382 /// let applications specify the language whose formatting conventions
6383 /// should be used and customize the behavior of the function.
6384 /// In older implementations, which ignore the locales
6385 /// and options arguments, the locale used and the form of the string
6386 /// returned are entirely implementation dependent.
6387 ///
6388 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString)
6389 #[cfg(not(js_sys_unstable_apis))]
6390 #[wasm_bindgen(method, js_name = toLocaleString)]
6391 pub fn to_locale_string(this: &Date, locale: &str, options: &JsValue) -> JsString;
6392
6393 /// The `toLocaleString()` method returns a string with a language sensitive
6394 /// representation of this date.
6395 ///
6396 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString)
6397 #[cfg(js_sys_unstable_apis)]
6398 #[wasm_bindgen(method, js_name = toLocaleString)]
6399 pub fn to_locale_string(
6400 this: &Date,
6401 locales: &[JsString],
6402 options: &Intl::DateTimeFormatOptions,
6403 ) -> JsString;
6404
6405 /// The `toLocaleTimeString()` method returns a string with a language sensitive
6406 /// representation of the time portion of this date. The new locales and options
6407 /// arguments let applications specify the language whose formatting conventions should be
6408 /// used and customize the behavior of the function. In older implementations, which ignore
6409 /// the locales and options arguments, the locale used and the form of the string
6410 /// returned are entirely implementation dependent.
6411 ///
6412 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleTimeString)
6413 #[cfg(not(js_sys_unstable_apis))]
6414 #[wasm_bindgen(method, js_name = toLocaleTimeString)]
6415 pub fn to_locale_time_string(this: &Date, locale: &str) -> JsString;
6416
6417 /// The `toLocaleTimeString()` method returns a string with a language sensitive
6418 /// representation of the time portion of this date.
6419 ///
6420 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleTimeString)
6421 #[cfg(js_sys_unstable_apis)]
6422 #[wasm_bindgen(method, js_name = toLocaleTimeString)]
6423 pub fn to_locale_time_string(
6424 this: &Date,
6425 locales: &[JsString],
6426 options: &Intl::DateTimeFormatOptions,
6427 ) -> JsString;
6428
6429 #[cfg(not(js_sys_unstable_apis))]
6430 #[wasm_bindgen(method, js_name = toLocaleTimeString)]
6431 pub fn to_locale_time_string_with_options(
6432 this: &Date,
6433 locale: &str,
6434 options: &JsValue,
6435 ) -> JsString;
6436
6437 /// The `toString()` method returns a string representing
6438 /// the specified Date object.
6439 ///
6440 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toString)
6441 #[cfg(not(js_sys_unstable_apis))]
6442 #[wasm_bindgen(method, js_name = toString)]
6443 pub fn to_string(this: &Date) -> JsString;
6444
6445 /// The `toTimeString()` method returns the time portion of a Date object in human
6446 /// readable form in American English.
6447 ///
6448 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toTimeString)
6449 #[wasm_bindgen(method, js_name = toTimeString)]
6450 pub fn to_time_string(this: &Date) -> JsString;
6451
6452 /// The `toUTCString()` method converts a date to a string,
6453 /// using the UTC time zone.
6454 ///
6455 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toUTCString)
6456 #[wasm_bindgen(method, js_name = toUTCString)]
6457 pub fn to_utc_string(this: &Date) -> JsString;
6458
6459 /// The `Date.UTC()` method accepts the same parameters as the
6460 /// longest form of the constructor, and returns the number of
6461 /// milliseconds in a `Date` object since January 1, 1970,
6462 /// 00:00:00, universal time.
6463 ///
6464 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/UTC)
6465 #[wasm_bindgen(static_method_of = Date, js_name = UTC)]
6466 pub fn utc(year: f64, month: f64) -> f64;
6467
6468 /// The `valueOf()` method returns the primitive value of
6469 /// a Date object.
6470 ///
6471 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/valueOf)
6472 #[wasm_bindgen(method, js_name = valueOf)]
6473 pub fn value_of(this: &Date) -> f64;
6474
6475 /// The `toTemporalInstant()` method converts a legacy `Date` object to a
6476 /// `Temporal.Instant` object representing the same moment in time.
6477 ///
6478 /// This method is added by the Temporal proposal to facilitate migration
6479 /// from legacy `Date` to the new Temporal API.
6480 ///
6481 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toTemporalInstant)
6482 #[cfg(js_sys_unstable_apis)]
6483 #[wasm_bindgen(method, js_name = toTemporalInstant)]
6484 pub fn to_temporal_instant(this: &Date) -> Temporal::Instant;
6485}
6486
6487// Property Descriptor.
6488#[wasm_bindgen]
6489extern "C" {
6490 #[wasm_bindgen(extends = Object)]
6491 #[derive(Clone, Debug)]
6492 pub type PropertyDescriptor<T = JsValue>;
6493
6494 #[wasm_bindgen(method, getter = writable)]
6495 pub fn get_writable<T>(this: &PropertyDescriptor<T>) -> Option<bool>;
6496
6497 #[wasm_bindgen(method, setter = writable)]
6498 pub fn set_writable<T>(this: &PropertyDescriptor<T>, writable: bool);
6499
6500 #[wasm_bindgen(method, getter = enumerable)]
6501 pub fn get_enumerable<T>(this: &PropertyDescriptor<T>) -> Option<bool>;
6502
6503 #[wasm_bindgen(method, setter = enumerable)]
6504 pub fn set_enumerable<T>(this: &PropertyDescriptor<T>, enumerable: bool);
6505
6506 #[wasm_bindgen(method, getter = configurable)]
6507 pub fn get_configurable<T>(this: &PropertyDescriptor<T>) -> Option<bool>;
6508
6509 #[wasm_bindgen(method, setter = configurable)]
6510 pub fn set_configurable<T>(this: &PropertyDescriptor<T>, configurable: bool);
6511
6512 #[wasm_bindgen(method, getter = get)]
6513 pub fn get_get<T: JsGeneric>(this: &PropertyDescriptor<T>) -> Option<Function<fn() -> T>>;
6514
6515 #[wasm_bindgen(method, setter = get)]
6516 pub fn set_get<T: JsGeneric>(this: &PropertyDescriptor<T>, get: Function<fn() -> T>);
6517
6518 #[wasm_bindgen(method, getter = set)]
6519 pub fn get_set<T: JsGeneric>(
6520 this: &PropertyDescriptor<T>,
6521 ) -> Option<Function<fn(T) -> JsValue>>;
6522
6523 #[wasm_bindgen(method, setter = set)]
6524 pub fn set_set<T: JsGeneric>(this: &PropertyDescriptor<T>, set: Function<fn(T) -> JsValue>);
6525
6526 #[wasm_bindgen(method, getter = value)]
6527 pub fn get_value<T>(this: &PropertyDescriptor<T>) -> Option<T>;
6528
6529 #[wasm_bindgen(method, setter = value)]
6530 pub fn set_value<T>(this: &PropertyDescriptor<T>, value: &T);
6531}
6532
6533impl PropertyDescriptor {
6534 #[cfg(not(js_sys_unstable_apis))]
6535 pub fn new<T>() -> PropertyDescriptor<T> {
6536 JsCast::unchecked_into(Object::new())
6537 }
6538
6539 #[cfg(js_sys_unstable_apis)]
6540 pub fn new<T>() -> PropertyDescriptor<T> {
6541 JsCast::unchecked_into(Object::<JsValue>::new())
6542 }
6543
6544 #[cfg(not(js_sys_unstable_apis))]
6545 pub fn new_value<T: JsGeneric>(value: &T) -> PropertyDescriptor<T> {
6546 let desc: PropertyDescriptor<T> = JsCast::unchecked_into(Object::new());
6547 desc.set_value(value);
6548 desc
6549 }
6550
6551 #[cfg(js_sys_unstable_apis)]
6552 pub fn new_value<T: JsGeneric>(value: &T) -> PropertyDescriptor<T> {
6553 let desc: PropertyDescriptor<T> = JsCast::unchecked_into(Object::<JsValue>::new());
6554 desc.set_value(value);
6555 desc
6556 }
6557}
6558
6559impl Default for PropertyDescriptor {
6560 fn default() -> Self {
6561 PropertyDescriptor::new()
6562 }
6563}
6564
6565// Object.
6566#[wasm_bindgen]
6567extern "C" {
6568 #[wasm_bindgen(typescript_type = "object")]
6569 #[derive(Clone, Debug)]
6570 pub type Object<T = JsValue>;
6571
6572 // Next major: deprecate
6573 /// The `Object.assign()` method is used to copy the values of all enumerable
6574 /// own properties from one or more source objects to a target object. It
6575 /// will return the target object.
6576 ///
6577 /// **Note:** Consider using [`Object::try_assign`] to support error handling.
6578 ///
6579 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
6580 #[wasm_bindgen(static_method_of = Object)]
6581 pub fn assign<T>(target: &Object<T>, source: &Object<T>) -> Object<T>;
6582
6583 // Next major: deprecate
6584 /// The `Object.assign()` method is used to copy the values of all enumerable
6585 /// own properties from one or more source objects to a target object. It
6586 /// will return the target object.
6587 ///
6588 /// **Note:** Consider using [`Object::try_assign`] to support error handling.
6589 ///
6590 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
6591 #[wasm_bindgen(static_method_of = Object, js_name = assign, catch)]
6592 pub fn try_assign<T>(target: &Object<T>, source: &Object<T>) -> Result<Object<T>, JsValue>;
6593
6594 /// The `Object.assign()` method is used to copy the values of all enumerable
6595 /// own properties from one or more source objects to a target object. It
6596 /// will return the target object.
6597 ///
6598 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
6599 #[cfg(not(js_sys_unstable_apis))]
6600 #[wasm_bindgen(static_method_of = Object, js_name = assign)]
6601 #[deprecated(note = "use `assign_many` for arbitrary assign arguments instead")]
6602 #[allow(deprecated)]
6603 pub fn assign2<T>(target: &Object<T>, source1: &Object<T>, source2: &Object<T>) -> Object<T>;
6604
6605 /// The `Object.assign()` method is used to copy the values of all enumerable
6606 /// own properties from one or more source objects to a target object. It
6607 /// will return the target object.
6608 ///
6609 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
6610 #[cfg(not(js_sys_unstable_apis))]
6611 #[wasm_bindgen(static_method_of = Object, js_name = assign)]
6612 #[deprecated(note = "use `assign_many` for arbitrary assign arguments instead")]
6613 #[allow(deprecated)]
6614 pub fn assign3<T>(
6615 target: &Object<T>,
6616 source1: &Object<T>,
6617 source2: &Object<T>,
6618 source3: &Object<T>,
6619 ) -> Object<T>;
6620
6621 /// The `Object.assign()` method is used to copy the values of all enumerable
6622 /// own properties from one or more source objects to a target object. It
6623 /// will return the target object.
6624 ///
6625 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
6626 #[wasm_bindgen(static_method_of = Object, js_name = assign, catch, variadic)]
6627 pub fn assign_many<T>(target: &Object<T>, sources: &[Object<T>]) -> Result<Object<T>, JsValue>;
6628
6629 /// The constructor property returns a reference to the `Object` constructor
6630 /// function that created the instance object.
6631 ///
6632 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/constructor)
6633 #[wasm_bindgen(method, getter)]
6634 pub fn constructor<T>(this: &Object<T>) -> Function;
6635
6636 /// The `Object.create()` method creates a new object, using an existing
6637 /// object to provide the newly created object's prototype.
6638 ///
6639 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/create)
6640 #[wasm_bindgen(static_method_of = Object)]
6641 pub fn create<T>(prototype: &Object<T>) -> Object<T>;
6642
6643 /// The static method `Object.defineProperty()` defines a new
6644 /// property directly on an object, or modifies an existing
6645 /// property on an object, and returns the object.
6646 ///
6647 /// **Note:** Consider using [`Object::define_property_str`] to support typing and error handling.
6648 ///
6649 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty)
6650 #[cfg(not(js_sys_unstable_apis))]
6651 #[wasm_bindgen(static_method_of = Object, js_name = defineProperty)]
6652 pub fn define_property<T>(obj: &Object<T>, prop: &JsValue, descriptor: &Object) -> Object<T>;
6653
6654 /// The static method `Object.defineProperty()` defines a new
6655 /// property directly on an object, or modifies an existing
6656 /// property on an object, and returns the object.
6657 ///
6658 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty)
6659 #[cfg(js_sys_unstable_apis)]
6660 #[wasm_bindgen(static_method_of = Object, js_name = defineProperty, catch)]
6661 pub fn define_property<T>(
6662 obj: &Object<T>,
6663 prop: &JsString,
6664 descriptor: &PropertyDescriptor<T>,
6665 ) -> Result<Object<T>, JsValue>;
6666
6667 // Next major: deprecate
6668 /// The static method `Object.defineProperty()` defines a new
6669 /// property directly on an object, or modifies an existing
6670 /// property on an object, and returns the object.
6671 ///
6672 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty)
6673 #[wasm_bindgen(static_method_of = Object, js_name = defineProperty, catch)]
6674 pub fn define_property_str<T>(
6675 obj: &Object<T>,
6676 prop: &JsString,
6677 descriptor: &PropertyDescriptor<T>,
6678 ) -> Result<Object<T>, JsValue>;
6679
6680 /// The static method `Object.defineProperty()` defines a new
6681 /// property directly on an object, or modifies an existing
6682 /// property on an object, and returns the object.
6683 ///
6684 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty)
6685 #[wasm_bindgen(static_method_of = Object, js_name = defineProperty, catch)]
6686 pub fn define_property_symbol<T>(
6687 obj: &Object<T>,
6688 prop: &Symbol,
6689 descriptor: &PropertyDescriptor<JsValue>,
6690 ) -> Result<Object<T>, JsValue>;
6691
6692 /// The `Object.defineProperties()` method defines new or modifies
6693 /// existing properties directly on an object, returning the
6694 /// object.
6695 ///
6696 /// **Note:** Consider using [`Object::try_define_properties`] to support typing and error handling.
6697 ///
6698 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperties)
6699 #[wasm_bindgen(static_method_of = Object, js_name = defineProperties)]
6700 pub fn define_properties<T>(obj: &Object<T>, props: &Object) -> Object<T>;
6701
6702 /// The `Object.defineProperties()` method defines new or modifies
6703 /// existing properties directly on an object, returning the
6704 /// object.
6705 ///
6706 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperties)
6707 #[cfg(js_sys_unstable_apis)]
6708 #[wasm_bindgen(static_method_of = Object, js_name = defineProperties, catch)]
6709 pub fn try_define_properties<T>(
6710 obj: &Object<T>,
6711 props: &Object<PropertyDescriptor<T>>,
6712 ) -> Result<Object<T>, JsValue>;
6713
6714 /// The `Object.entries()` method returns an array of a given
6715 /// object's own enumerable property [key, value] pairs, in the
6716 /// same order as that provided by a for...in loop (the difference
6717 /// being that a for-in loop enumerates properties in the
6718 /// prototype chain as well).
6719 ///
6720 /// **Note:** Consider using [`Object::entries_typed`] to support typing and error handling.
6721 ///
6722 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries)
6723 #[cfg(not(js_sys_unstable_apis))]
6724 #[wasm_bindgen(static_method_of = Object)]
6725 pub fn entries(object: &Object) -> Array;
6726
6727 /// The `Object.entries()` method returns an array of a given
6728 /// object's own enumerable property [key, value] pairs, in the
6729 /// same order as that provided by a for...in loop (the difference
6730 /// being that a for-in loop enumerates properties in the
6731 /// prototype chain as well).
6732 ///
6733 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries)
6734 #[cfg(js_sys_unstable_apis)]
6735 #[wasm_bindgen(static_method_of = Object, js_name = entries, catch)]
6736 pub fn entries<T: JsGeneric>(
6737 object: &Object<T>,
6738 ) -> Result<Array<ArrayTuple<(JsString, T)>>, JsValue>;
6739
6740 // Next major: deprecate
6741 /// The `Object.entries()` method returns an array of a given
6742 /// object's own enumerable property [key, value] pairs, in the
6743 /// same order as that provided by a for...in loop (the difference
6744 /// being that a for-in loop enumerates properties in the
6745 /// prototype chain as well).
6746 ///
6747 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries)
6748 #[wasm_bindgen(static_method_of = Object, js_name = entries, catch)]
6749 pub fn entries_typed<T: JsGeneric>(
6750 object: &Object<T>,
6751 ) -> Result<Array<ArrayTuple<(JsString, T)>>, JsValue>;
6752
6753 /// The `Object.freeze()` method freezes an object: that is, prevents new
6754 /// properties from being added to it; prevents existing properties from
6755 /// being removed; and prevents existing properties, or their enumerability,
6756 /// configurability, or writability, from being changed, it also prevents
6757 /// the prototype from being changed. The method returns the passed object.
6758 ///
6759 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze)
6760 #[wasm_bindgen(static_method_of = Object)]
6761 pub fn freeze<T>(value: &Object<T>) -> Object<T>;
6762
6763 /// The `Object.fromEntries()` method transforms a list of key-value pairs
6764 /// into an object.
6765 ///
6766 /// **Note:** Consider using [`Object::from_entries_typed`] to support typing and error handling.
6767 ///
6768 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/fromEntries)
6769 #[cfg(not(js_sys_unstable_apis))]
6770 #[wasm_bindgen(static_method_of = Object, catch, js_name = fromEntries)]
6771 pub fn from_entries(entries: &JsValue) -> Result<Object, JsValue>;
6772
6773 /// The `Object.fromEntries()` method transforms a list of key-value pairs
6774 /// into an object.
6775 ///
6776 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/fromEntries)
6777 #[cfg(js_sys_unstable_apis)]
6778 #[wasm_bindgen(static_method_of = Object, catch, js_name = fromEntries)]
6779 pub fn from_entries<T: JsGeneric, I: Iterable<Item = ArrayTuple<(JsString, T)>>>(
6780 entries: &I,
6781 ) -> Result<Object<T>, JsValue>;
6782
6783 // Next major: deprecate
6784 /// The `Object.fromEntries()` method transforms a list of key-value pairs
6785 /// into an object.
6786 ///
6787 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/fromEntries)
6788 #[wasm_bindgen(static_method_of = Object, catch, js_name = fromEntries)]
6789 pub fn from_entries_typed<T: JsGeneric, I: Iterable<Item = ArrayTuple<(JsString, T)>>>(
6790 entries: &I,
6791 ) -> Result<Object<T>, JsValue>;
6792
6793 /// The `Object.getOwnPropertyDescriptor()` method returns a
6794 /// property descriptor for an own property (that is, one directly
6795 /// present on an object and not in the object's prototype chain)
6796 /// of a given object.
6797 ///
6798 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor)
6799 #[cfg(not(js_sys_unstable_apis))]
6800 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptor)]
6801 pub fn get_own_property_descriptor<T>(obj: &Object<T>, prop: &JsValue) -> JsValue;
6802
6803 /// The `Object.getOwnPropertyDescriptor()` method returns a
6804 /// property descriptor for an own property (that is, one directly
6805 /// present on an object and not in the object's prototype chain)
6806 /// of a given object.
6807 ///
6808 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor)
6809 #[cfg(js_sys_unstable_apis)]
6810 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptor, catch)]
6811 pub fn get_own_property_descriptor<T>(
6812 obj: &Object<T>,
6813 prop: &JsString,
6814 ) -> Result<PropertyDescriptor<T>, JsValue>;
6815
6816 // Next major: deprecate
6817 /// The `Object.getOwnPropertyDescriptor()` method returns a
6818 /// property descriptor for an own property (that is, one directly
6819 /// present on an object and not in the object's prototype chain)
6820 /// of a given object.
6821 ///
6822 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor)
6823 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptor, catch)]
6824 pub fn get_own_property_descriptor_str<T>(
6825 obj: &Object<T>,
6826 prop: &JsString,
6827 ) -> Result<PropertyDescriptor<T>, JsValue>;
6828
6829 /// The `Object.getOwnPropertyDescriptor()` method returns a
6830 /// property descriptor for an own property (that is, one directly
6831 /// present on an object and not in the object's prototype chain)
6832 /// of a given object.
6833 ///
6834 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor)
6835 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptor, catch)]
6836 pub fn get_own_property_descriptor_symbol<T>(
6837 obj: &Object<T>,
6838 prop: &Symbol,
6839 ) -> Result<PropertyDescriptor<JsValue>, JsValue>;
6840
6841 /// The `Object.getOwnPropertyDescriptors()` method returns all own
6842 /// property descriptors of a given object.
6843 ///
6844 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptors)
6845 #[cfg(not(js_sys_unstable_apis))]
6846 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptors)]
6847 pub fn get_own_property_descriptors<T>(obj: &Object<T>) -> JsValue;
6848
6849 /// The `Object.getOwnPropertyDescriptors()` method returns all own
6850 /// property descriptors of a given object.
6851 ///
6852 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptors)
6853 #[cfg(js_sys_unstable_apis)]
6854 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptors, catch)]
6855 pub fn get_own_property_descriptors<T>(
6856 obj: &Object<T>,
6857 ) -> Result<Object<PropertyDescriptor<T>>, JsValue>;
6858
6859 /// The `Object.getOwnPropertyNames()` method returns an array of
6860 /// all properties (including non-enumerable properties except for
6861 /// those which use Symbol) found directly upon a given object.
6862 ///
6863 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyNames)
6864 #[cfg(not(js_sys_unstable_apis))]
6865 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyNames)]
6866 pub fn get_own_property_names<T>(obj: &Object<T>) -> Array;
6867
6868 /// The `Object.getOwnPropertyNames()` method returns an array of
6869 /// all properties (including non-enumerable properties except for
6870 /// those which use Symbol) found directly upon a given object.
6871 ///
6872 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyNames)
6873 #[cfg(js_sys_unstable_apis)]
6874 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyNames, catch)]
6875 pub fn get_own_property_names<T>(obj: &Object<T>) -> Result<Array<JsString>, JsValue>;
6876
6877 /// The `Object.getOwnPropertySymbols()` method returns an array of
6878 /// all symbol properties found directly upon a given object.
6879 ///
6880 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertySymbols)
6881 #[cfg(not(js_sys_unstable_apis))]
6882 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertySymbols)]
6883 pub fn get_own_property_symbols<T>(obj: &Object<T>) -> Array;
6884
6885 /// The `Object.getOwnPropertySymbols()` method returns an array of
6886 /// all symbol properties found directly upon a given object.
6887 ///
6888 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertySymbols)
6889 #[cfg(js_sys_unstable_apis)]
6890 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertySymbols, catch)]
6891 pub fn get_own_property_symbols<T>(obj: &Object<T>) -> Result<Array<Symbol>, JsValue>;
6892
6893 /// The `Object.getPrototypeOf()` method returns the prototype
6894 /// (i.e. the value of the internal [[Prototype]] property) of the
6895 /// specified object.
6896 ///
6897 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getPrototypeOf)
6898 #[wasm_bindgen(static_method_of = Object, js_name = getPrototypeOf)]
6899 pub fn get_prototype_of(obj: &JsValue) -> Object;
6900
6901 /// The `hasOwnProperty()` method returns a boolean indicating whether the
6902 /// object has the specified property as its own property (as opposed to
6903 /// inheriting it).
6904 ///
6905 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty)
6906 #[deprecated(note = "Use `Object::hasOwn` instead.")]
6907 #[allow(deprecated)]
6908 #[wasm_bindgen(method, js_name = hasOwnProperty)]
6909 pub fn has_own_property<T>(this: &Object<T>, property: &JsValue) -> bool;
6910
6911 /// The `Object.hasOwn()` method returns a boolean indicating whether the
6912 /// object passed in has the specified property as its own property (as
6913 /// opposed to inheriting it).
6914 ///
6915 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn)
6916 #[cfg(not(js_sys_unstable_apis))]
6917 #[wasm_bindgen(static_method_of = Object, js_name = hasOwn)]
6918 pub fn has_own<T>(instance: &Object<T>, property: &JsValue) -> bool;
6919
6920 /// The `Object.hasOwn()` method returns a boolean indicating whether the
6921 /// object passed in has the specified property as its own property (as
6922 /// opposed to inheriting it).
6923 ///
6924 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn)
6925 #[cfg(js_sys_unstable_apis)]
6926 #[wasm_bindgen(static_method_of = Object, js_name = hasOwn, catch)]
6927 pub fn has_own<T>(instance: &Object<T>, property: &JsString) -> Result<bool, JsValue>;
6928
6929 // Next major: deprecate
6930 /// The `Object.hasOwn()` method returns a boolean indicating whether the
6931 /// object passed in has the specified property as its own property (as
6932 /// opposed to inheriting it).
6933 ///
6934 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn)
6935 #[wasm_bindgen(static_method_of = Object, js_name = hasOwn, catch)]
6936 pub fn has_own_str<T>(instance: &Object<T>, property: &JsString) -> Result<bool, JsValue>;
6937
6938 /// The `Object.hasOwn()` method returns a boolean indicating whether the
6939 /// object passed in has the specified property as its own property (as
6940 /// opposed to inheriting it).
6941 ///
6942 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn)
6943 #[wasm_bindgen(static_method_of = Object, js_name = hasOwn, catch)]
6944 pub fn has_own_symbol<T>(instance: &Object<T>, property: &Symbol) -> Result<bool, JsValue>;
6945
6946 /// The `Object.is()` method determines whether two values are the same value.
6947 ///
6948 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is)
6949 #[wasm_bindgen(static_method_of = Object)]
6950 pub fn is(value1: &JsValue, value_2: &JsValue) -> bool;
6951
6952 /// The `Object.isExtensible()` method determines if an object is extensible
6953 /// (whether it can have new properties added to it).
6954 ///
6955 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isExtensible)
6956 #[wasm_bindgen(static_method_of = Object, js_name = isExtensible)]
6957 pub fn is_extensible<T>(object: &Object<T>) -> bool;
6958
6959 /// The `Object.isFrozen()` determines if an object is frozen.
6960 ///
6961 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isFrozen)
6962 #[wasm_bindgen(static_method_of = Object, js_name = isFrozen)]
6963 pub fn is_frozen<T>(object: &Object<T>) -> bool;
6964
6965 /// The `Object.isSealed()` method determines if an object is sealed.
6966 ///
6967 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isSealed)
6968 #[wasm_bindgen(static_method_of = Object, js_name = isSealed)]
6969 pub fn is_sealed<T>(object: &Object<T>) -> bool;
6970
6971 /// The `isPrototypeOf()` method checks if an object exists in another
6972 /// object's prototype chain.
6973 ///
6974 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isPrototypeOf)
6975 #[wasm_bindgen(method, js_name = isPrototypeOf)]
6976 pub fn is_prototype_of<T>(this: &Object<T>, value: &JsValue) -> bool;
6977
6978 /// The `Object.keys()` method returns an array of a given object's property
6979 /// names, in the same order as we get with a normal loop.
6980 ///
6981 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys)
6982 #[cfg(not(js_sys_unstable_apis))]
6983 #[wasm_bindgen(static_method_of = Object)]
6984 pub fn keys<T>(object: &Object<T>) -> Array;
6985
6986 /// The `Object.keys()` method returns an array of a given object's property
6987 /// names, in the same order as we get with a normal loop.
6988 ///
6989 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys)
6990 #[cfg(js_sys_unstable_apis)]
6991 #[wasm_bindgen(static_method_of = Object)]
6992 pub fn keys<T>(object: &Object<T>) -> Array<JsString>;
6993
6994 /// The [`Object`] constructor creates an object wrapper.
6995 ///
6996 /// **Note:** Consider using [`Object::new_typed`] for typed object records.
6997 ///
6998 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)
6999 #[wasm_bindgen(constructor)]
7000 pub fn new() -> Object;
7001
7002 // Next major: deprecate
7003 /// The [`Object`] constructor creates an object wrapper.
7004 ///
7005 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)
7006 #[wasm_bindgen(constructor)]
7007 pub fn new_typed<T>() -> Object<T>;
7008
7009 /// The `Object.preventExtensions()` method prevents new properties from
7010 /// ever being added to an object (i.e. prevents future extensions to the
7011 /// object).
7012 ///
7013 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/preventExtensions)
7014 #[wasm_bindgen(static_method_of = Object, js_name = preventExtensions)]
7015 pub fn prevent_extensions<T>(object: &Object<T>);
7016
7017 /// The `propertyIsEnumerable()` method returns a Boolean indicating
7018 /// whether the specified property is enumerable.
7019 ///
7020 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/propertyIsEnumerable)
7021 #[wasm_bindgen(method, js_name = propertyIsEnumerable)]
7022 pub fn property_is_enumerable<T>(this: &Object<T>, property: &JsValue) -> bool;
7023
7024 /// The `Object.seal()` method seals an object, preventing new properties
7025 /// from being added to it and marking all existing properties as
7026 /// non-configurable. Values of present properties can still be changed as
7027 /// long as they are writable.
7028 ///
7029 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/seal)
7030 #[wasm_bindgen(static_method_of = Object)]
7031 pub fn seal<T>(value: &Object<T>) -> Object<T>;
7032
7033 /// The `Object.setPrototypeOf()` method sets the prototype (i.e., the
7034 /// internal `[[Prototype]]` property) of a specified object to another
7035 /// object or `null`.
7036 ///
7037 /// **Note:** Consider using [`Object::try_set_prototype_of`] to support errors.
7038 ///
7039 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/setPrototypeOf)
7040 #[wasm_bindgen(static_method_of = Object, js_name = setPrototypeOf)]
7041 pub fn set_prototype_of<T>(object: &Object<T>, prototype: &Object) -> Object<T>;
7042
7043 /// The `Object.setPrototypeOf()` method sets the prototype (i.e., the
7044 /// internal `[[Prototype]]` property) of a specified object to another
7045 /// object or `null`.
7046 ///
7047 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/setPrototypeOf)
7048 #[wasm_bindgen(static_method_of = Object, js_name = setPrototypeOf, catch)]
7049 pub fn try_set_prototype_of<T>(
7050 object: &Object<T>,
7051 prototype: &Object,
7052 ) -> Result<Object<T>, JsValue>;
7053
7054 /// The `toLocaleString()` method returns a string representing the object.
7055 /// This method is meant to be overridden by derived objects for
7056 /// locale-specific purposes.
7057 ///
7058 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toLocaleString)
7059 #[wasm_bindgen(method, js_name = toLocaleString)]
7060 pub fn to_locale_string<T>(this: &Object<T>) -> JsString;
7061
7062 // Next major: deprecate
7063 /// The `toString()` method returns a string representing the object.
7064 ///
7065 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString)
7066 #[wasm_bindgen(method, js_name = toString)]
7067 pub fn to_string<T>(this: &Object<T>) -> JsString;
7068
7069 /// The `toString()` method returns a string representing the object.
7070 ///
7071 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString)
7072 #[wasm_bindgen(method, js_name = toString)]
7073 pub fn to_js_string<T>(this: &Object<T>) -> JsString;
7074
7075 /// The `valueOf()` method returns the primitive value of the
7076 /// specified object.
7077 ///
7078 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf)
7079 #[wasm_bindgen(method, js_name = valueOf)]
7080 pub fn value_of<T>(this: &Object<T>) -> Object;
7081
7082 /// The `Object.values()` method returns an array of a given object's own
7083 /// enumerable property values, in the same order as that provided by a
7084 /// `for...in` loop (the difference being that a for-in loop enumerates
7085 /// properties in the prototype chain as well).
7086 ///
7087 /// **Note:** Consider using [`Object::try_values`] to support errors.
7088 ///
7089 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values)
7090 #[cfg(not(js_sys_unstable_apis))]
7091 #[wasm_bindgen(static_method_of = Object)]
7092 pub fn values<T>(object: &Object<T>) -> Array<T>;
7093
7094 /// The `Object.values()` method returns an array of a given object's own
7095 /// enumerable property values, in the same order as that provided by a
7096 /// `for...in` loop (the difference being that a for-in loop enumerates
7097 /// properties in the prototype chain as well).
7098 ///
7099 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values)
7100 #[cfg(js_sys_unstable_apis)]
7101 #[wasm_bindgen(static_method_of = Object, catch, js_name = values)]
7102 pub fn values<T>(object: &Object<T>) -> Result<Array<T>, JsValue>;
7103
7104 // Next major: deprecate
7105 /// The `Object.values()` method returns an array of a given object's own
7106 /// enumerable property values, in the same order as that provided by a
7107 /// `for...in` loop (the difference being that a for-in loop enumerates
7108 /// properties in the prototype chain as well).
7109 ///
7110 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values)
7111 #[cfg(not(js_sys_unstable_apis))]
7112 #[wasm_bindgen(static_method_of = Object, catch, js_name = values)]
7113 pub fn try_values<T>(object: &Object<T>) -> Result<Array<T>, JsValue>;
7114}
7115
7116impl Object {
7117 /// Returns the `Object` value of this JS value if it's an instance of an
7118 /// object.
7119 ///
7120 /// If this JS value is not an instance of an object then this returns
7121 /// `None`.
7122 pub fn try_from(val: &JsValue) -> Option<&Object> {
7123 if val.is_object() {
7124 Some(val.unchecked_ref())
7125 } else {
7126 None
7127 }
7128 }
7129}
7130
7131impl PartialEq for Object {
7132 #[inline]
7133 fn eq(&self, other: &Object) -> bool {
7134 Object::is(self.as_ref(), other.as_ref())
7135 }
7136}
7137
7138impl Eq for Object {}
7139
7140impl Default for Object<JsValue> {
7141 fn default() -> Self {
7142 Self::new()
7143 }
7144}
7145
7146// Proxy
7147#[wasm_bindgen]
7148extern "C" {
7149 #[wasm_bindgen(typescript_type = "ProxyConstructor")]
7150 #[derive(Clone, Debug)]
7151 pub type Proxy;
7152
7153 /// The [`Proxy`] object is used to define custom behavior for fundamental
7154 /// operations (e.g. property lookup, assignment, enumeration, function
7155 /// invocation, etc).
7156 ///
7157 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy)
7158 #[wasm_bindgen(constructor)]
7159 pub fn new(target: &JsValue, handler: &Object) -> Proxy;
7160
7161 /// The `Proxy.revocable()` method is used to create a revocable [`Proxy`]
7162 /// object.
7163 ///
7164 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy/revocable)
7165 #[wasm_bindgen(static_method_of = Proxy)]
7166 pub fn revocable(target: &JsValue, handler: &Object) -> Object;
7167}
7168
7169// RangeError
7170#[wasm_bindgen]
7171extern "C" {
7172 /// The `RangeError` object indicates an error when a value is not in the set
7173 /// or range of allowed values.
7174 ///
7175 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError)
7176 #[wasm_bindgen(extends = Error, extends = Object, typescript_type = "RangeError")]
7177 #[derive(Clone, Debug, PartialEq, Eq)]
7178 pub type RangeError;
7179
7180 /// The `RangeError` object indicates an error when a value is not in the set
7181 /// or range of allowed values.
7182 ///
7183 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError)
7184 #[wasm_bindgen(constructor)]
7185 pub fn new(message: &str) -> RangeError;
7186}
7187
7188// ReferenceError
7189#[wasm_bindgen]
7190extern "C" {
7191 /// The `ReferenceError` object represents an error when a non-existent
7192 /// variable is referenced.
7193 ///
7194 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError)
7195 #[wasm_bindgen(extends = Error, extends = Object, typescript_type = "ReferenceError")]
7196 #[derive(Clone, Debug, PartialEq, Eq)]
7197 pub type ReferenceError;
7198
7199 /// The `ReferenceError` object represents an error when a non-existent
7200 /// variable is referenced.
7201 ///
7202 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError)
7203 #[wasm_bindgen(constructor)]
7204 pub fn new(message: &str) -> ReferenceError;
7205}
7206
7207#[allow(non_snake_case)]
7208pub mod Reflect {
7209 use super::*;
7210
7211 // Reflect
7212 #[wasm_bindgen]
7213 extern "C" {
7214 /// The static `Reflect.apply()` method calls a target function with
7215 /// arguments as specified.
7216 ///
7217 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/apply)
7218 #[wasm_bindgen(js_namespace = Reflect, catch)]
7219 pub fn apply<T: JsFunction = fn() -> JsValue>(
7220 target: &Function<T>,
7221 this_argument: &JsValue,
7222 arguments_list: &Array,
7223 ) -> Result<<T as JsFunction>::Ret, JsValue>;
7224
7225 /// The static `Reflect.construct()` method acts like the new operator, but
7226 /// as a function. It is equivalent to calling `new target(...args)`. It
7227 /// gives also the added option to specify a different prototype.
7228 ///
7229 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/construct)
7230 #[cfg(not(js_sys_unstable_apis))]
7231 #[wasm_bindgen(js_namespace = Reflect, catch)]
7232 pub fn construct<T: JsFunction = fn() -> JsValue>(
7233 target: &Function<T>,
7234 arguments_list: &Array,
7235 ) -> Result<JsValue, JsValue>;
7236
7237 /// The static `Reflect.construct()` method acts like the new operator, but
7238 /// as a function. It is equivalent to calling `new target(...args)`. It
7239 /// gives also the added option to specify a different prototype.
7240 ///
7241 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/construct)
7242 #[cfg(js_sys_unstable_apis)]
7243 #[wasm_bindgen(js_namespace = Reflect, catch)]
7244 pub fn construct<T: JsFunction = fn() -> JsValue>(
7245 target: &Function<T>,
7246 arguments_list: &ArrayTuple, // DOTO: <A1, A2, A3, A4, A5, A6, A7, A8>,
7247 ) -> Result<JsValue, JsValue>;
7248
7249 /// The static `Reflect.construct()` method acts like the new operator, but
7250 /// as a function. It is equivalent to calling `new target(...args)`. It
7251 /// gives also the added option to specify a different prototype.
7252 ///
7253 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/construct)
7254 #[wasm_bindgen(js_namespace = Reflect, js_name = construct, catch)]
7255 pub fn construct_with_new_target(
7256 target: &Function,
7257 arguments_list: &Array,
7258 new_target: &Function,
7259 ) -> Result<JsValue, JsValue>;
7260
7261 /// The static `Reflect.defineProperty()` method is like
7262 /// `Object.defineProperty()` but returns a `Boolean`.
7263 ///
7264 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/defineProperty)
7265 #[cfg(not(js_sys_unstable_apis))]
7266 #[wasm_bindgen(js_namespace = Reflect, js_name = defineProperty, catch)]
7267 pub fn define_property<T>(
7268 target: &Object<T>,
7269 property_key: &JsValue,
7270 attributes: &Object,
7271 ) -> Result<bool, JsValue>;
7272
7273 /// The static `Reflect.defineProperty()` method is like
7274 /// `Object.defineProperty()` but returns a `Boolean`.
7275 ///
7276 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/defineProperty)
7277 #[cfg(js_sys_unstable_apis)]
7278 #[wasm_bindgen(js_namespace = Reflect, js_name = defineProperty, catch)]
7279 pub fn define_property<T>(
7280 target: &Object<T>,
7281 property_key: &JsValue,
7282 attributes: &PropertyDescriptor<T>,
7283 ) -> Result<bool, JsValue>;
7284
7285 /// The static `Reflect.defineProperty()` method is like
7286 /// `Object.defineProperty()` but returns a `Boolean`.
7287 ///
7288 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/defineProperty)
7289 #[wasm_bindgen(js_namespace = Reflect, js_name = defineProperty, catch)]
7290 pub fn define_property_str<T>(
7291 target: &Object<T>,
7292 property_key: &JsString,
7293 attributes: &PropertyDescriptor<T>,
7294 ) -> Result<bool, JsValue>;
7295
7296 /// The static `Reflect.deleteProperty()` method allows to delete
7297 /// properties. It is like the `delete` operator as a function.
7298 ///
7299 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/deleteProperty)
7300 #[wasm_bindgen(js_namespace = Reflect, js_name = deleteProperty, catch)]
7301 pub fn delete_property<T>(target: &Object<T>, key: &JsValue) -> Result<bool, JsValue>;
7302
7303 /// The static `Reflect.deleteProperty()` method allows to delete
7304 /// properties. It is like the `delete` operator as a function.
7305 ///
7306 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/deleteProperty)
7307 #[wasm_bindgen(js_namespace = Reflect, js_name = deleteProperty, catch)]
7308 pub fn delete_property_str<T>(target: &Object<T>, key: &JsString) -> Result<bool, JsValue>;
7309
7310 /// The static `Reflect.get()` method works like getting a property from
7311 /// an object (`target[propertyKey]`) as a function.
7312 ///
7313 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/get)
7314 #[cfg(not(js_sys_unstable_apis))]
7315 #[wasm_bindgen(js_namespace = Reflect, catch)]
7316 pub fn get(target: &JsValue, key: &JsValue) -> Result<JsValue, JsValue>;
7317
7318 /// The static `Reflect.get()` method works like getting a property from
7319 /// an object (`target[propertyKey]`) as a function.
7320 ///
7321 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/get)
7322 #[cfg(js_sys_unstable_apis)]
7323 #[wasm_bindgen(js_namespace = Reflect, catch)]
7324 pub fn get<T>(target: &Object<T>, key: &JsString) -> Result<Option<T>, JsValue>;
7325
7326 /// The static `Reflect.get()` method works like getting a property from
7327 /// an object (`target[propertyKey]`) as a function.
7328 ///
7329 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/get)
7330 #[wasm_bindgen(js_namespace = Reflect, js_name = get, catch)]
7331 pub fn get_str<T>(target: &Object<T>, key: &JsString) -> Result<Option<T>, JsValue>;
7332
7333 /// The static `Reflect.get()` method works like getting a property from
7334 /// an object (`target[propertyKey]`) as a function.
7335 ///
7336 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/get)
7337 #[wasm_bindgen(js_namespace = Reflect, js_name = get, catch)]
7338 pub fn get_symbol<T>(target: &Object<T>, key: &Symbol) -> Result<JsValue, JsValue>;
7339
7340 /// The same as [`get`](fn.get.html)
7341 /// except the key is an `f64`, which is slightly faster.
7342 #[wasm_bindgen(js_namespace = Reflect, js_name = get, catch)]
7343 pub fn get_f64(target: &JsValue, key: f64) -> Result<JsValue, JsValue>;
7344
7345 /// The same as [`get`](fn.get.html)
7346 /// except the key is a `u32`, which is slightly faster.
7347 #[wasm_bindgen(js_namespace = Reflect, js_name = get, catch)]
7348 pub fn get_u32(target: &JsValue, key: u32) -> Result<JsValue, JsValue>;
7349
7350 /// The static `Reflect.getOwnPropertyDescriptor()` method is similar to
7351 /// `Object.getOwnPropertyDescriptor()`. It returns a property descriptor
7352 /// of the given property if it exists on the object, `undefined` otherwise.
7353 ///
7354 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getOwnPropertyDescriptor)
7355 #[wasm_bindgen(js_namespace = Reflect, js_name = getOwnPropertyDescriptor, catch)]
7356 pub fn get_own_property_descriptor<T>(
7357 target: &Object<T>,
7358 property_key: &JsValue,
7359 ) -> Result<JsValue, JsValue>;
7360
7361 /// The static `Reflect.getOwnPropertyDescriptor()` method is similar to
7362 /// `Object.getOwnPropertyDescriptor()`. It returns a property descriptor
7363 /// of the given property if it exists on the object, `undefined` otherwise.
7364 ///
7365 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getOwnPropertyDescriptor)
7366 #[wasm_bindgen(js_namespace = Reflect, js_name = getOwnPropertyDescriptor, catch)]
7367 pub fn get_own_property_descriptor_str<T>(
7368 target: &Object<T>,
7369 property_key: &JsString,
7370 ) -> Result<PropertyDescriptor<T>, JsValue>;
7371
7372 /// The static `Reflect.getPrototypeOf()` method is almost the same
7373 /// method as `Object.getPrototypeOf()`. It returns the prototype
7374 /// (i.e. the value of the internal `[[Prototype]]` property) of
7375 /// the specified object.
7376 ///
7377 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getPrototypeOf)
7378 #[cfg(not(js_sys_unstable_apis))]
7379 #[wasm_bindgen(js_namespace = Reflect, js_name = getPrototypeOf, catch)]
7380 pub fn get_prototype_of(target: &JsValue) -> Result<Object, JsValue>;
7381
7382 /// The static `Reflect.getPrototypeOf()` method is almost the same
7383 /// method as `Object.getPrototypeOf()`. It returns the prototype
7384 /// (i.e. the value of the internal `[[Prototype]]` property) of
7385 /// the specified object.
7386 ///
7387 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getPrototypeOf)
7388 #[cfg(js_sys_unstable_apis)]
7389 #[wasm_bindgen(js_namespace = Reflect, js_name = getPrototypeOf, catch)]
7390 pub fn get_prototype_of(target: &Object) -> Result<Object, JsValue>;
7391
7392 /// The static `Reflect.has()` method works like the in operator as a
7393 /// function.
7394 ///
7395 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/has)
7396 #[cfg(not(js_sys_unstable_apis))]
7397 #[wasm_bindgen(js_namespace = Reflect, catch)]
7398 pub fn has(target: &JsValue, property_key: &JsValue) -> Result<bool, JsValue>;
7399
7400 /// The static `Reflect.has()` method works like the in operator as a
7401 /// function.
7402 ///
7403 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/has)
7404 #[cfg(js_sys_unstable_apis)]
7405 #[wasm_bindgen(js_namespace = Reflect, catch)]
7406 pub fn has(target: &JsValue, property_key: &Symbol) -> Result<bool, JsValue>;
7407
7408 // Next major: deprecate
7409 /// The static `Reflect.has()` method works like the in operator as a
7410 /// function.
7411 ///
7412 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/has)
7413 #[wasm_bindgen(js_namespace = Reflect, js_name = has, catch)]
7414 pub fn has_str<T>(target: &Object<T>, property_key: &JsString) -> Result<bool, JsValue>;
7415
7416 /// The static `Reflect.has()` method works like the in operator as a
7417 /// function.
7418 ///
7419 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/has)
7420 #[wasm_bindgen(js_namespace = Reflect, js_name = has, catch)]
7421 pub fn has_symbol<T>(target: &Object<T>, property_key: &Symbol) -> Result<bool, JsValue>;
7422
7423 /// The static `Reflect.isExtensible()` method determines if an object is
7424 /// extensible (whether it can have new properties added to it). It is
7425 /// similar to `Object.isExtensible()`, but with some differences.
7426 ///
7427 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/isExtensible)
7428 #[wasm_bindgen(js_namespace = Reflect, js_name = isExtensible, catch)]
7429 pub fn is_extensible<T>(target: &Object<T>) -> Result<bool, JsValue>;
7430
7431 /// The static `Reflect.ownKeys()` method returns an array of the
7432 /// target object's own property keys.
7433 ///
7434 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/ownKeys)
7435 #[wasm_bindgen(js_namespace = Reflect, js_name = ownKeys, catch)]
7436 pub fn own_keys(target: &JsValue) -> Result<Array, JsValue>;
7437
7438 /// The static `Reflect.preventExtensions()` method prevents new
7439 /// properties from ever being added to an object (i.e. prevents
7440 /// future extensions to the object). It is similar to
7441 /// `Object.preventExtensions()`, but with some differences.
7442 ///
7443 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/preventExtensions)
7444 #[wasm_bindgen(js_namespace = Reflect, js_name = preventExtensions, catch)]
7445 pub fn prevent_extensions<T>(target: &Object<T>) -> Result<bool, JsValue>;
7446
7447 /// The static `Reflect.set()` method works like setting a
7448 /// property on an object.
7449 ///
7450 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
7451 #[cfg(not(js_sys_unstable_apis))]
7452 #[wasm_bindgen(js_namespace = Reflect, catch)]
7453 pub fn set(
7454 target: &JsValue,
7455 property_key: &JsValue,
7456 value: &JsValue,
7457 ) -> Result<bool, JsValue>;
7458
7459 /// The static `Reflect.set()` method works like setting a
7460 /// property on an object.
7461 ///
7462 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
7463 #[cfg(js_sys_unstable_apis)]
7464 #[wasm_bindgen(js_namespace = Reflect, catch)]
7465 pub fn set<T>(
7466 target: &Object<T>,
7467 property_key: &JsString,
7468 value: &T,
7469 ) -> Result<bool, JsValue>;
7470
7471 /// The static `Reflect.set()` method works like setting a
7472 /// property on an object.
7473 ///
7474 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
7475 #[cfg(js_sys_unstable_apis)]
7476 #[wasm_bindgen(js_namespace = Reflect, catch)]
7477 pub fn set_symbol<T>(
7478 target: &Object<T>,
7479 property_key: &Symbol,
7480 value: &JsValue,
7481 ) -> Result<bool, JsValue>;
7482
7483 // Next major: deprecate
7484 /// The static `Reflect.set()` method works like setting a
7485 /// property on an object.
7486 ///
7487 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
7488 #[wasm_bindgen(js_namespace = Reflect, js_name = set, catch)]
7489 pub fn set_str<T>(
7490 target: &Object<T>,
7491 property_key: &JsString,
7492 value: &T,
7493 ) -> Result<bool, JsValue>;
7494
7495 /// The same as [`set`](fn.set.html)
7496 /// except the key is an `f64`, which is slightly faster.
7497 #[wasm_bindgen(js_namespace = Reflect, js_name = set, catch)]
7498 pub fn set_f64(
7499 target: &JsValue,
7500 property_key: f64,
7501 value: &JsValue,
7502 ) -> Result<bool, JsValue>;
7503
7504 /// The same as [`set`](fn.set.html)
7505 /// except the key is a `u32`, which is slightly faster.
7506 #[wasm_bindgen(js_namespace = Reflect, js_name = set, catch)]
7507 pub fn set_u32(
7508 target: &JsValue,
7509 property_key: u32,
7510 value: &JsValue,
7511 ) -> Result<bool, JsValue>;
7512
7513 /// The static `Reflect.set()` method works like setting a
7514 /// property on an object.
7515 ///
7516 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
7517 #[wasm_bindgen(js_namespace = Reflect, js_name = set, catch)]
7518 pub fn set_with_receiver(
7519 target: &JsValue,
7520 property_key: &JsValue,
7521 value: &JsValue,
7522 receiver: &JsValue,
7523 ) -> Result<bool, JsValue>;
7524
7525 /// The static `Reflect.setPrototypeOf()` method is the same
7526 /// method as `Object.setPrototypeOf()`. It sets the prototype
7527 /// (i.e., the internal `[[Prototype]]` property) of a specified
7528 /// object to another object or to null.
7529 ///
7530 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/setPrototypeOf)
7531 #[wasm_bindgen(js_namespace = Reflect, js_name = setPrototypeOf, catch)]
7532 pub fn set_prototype_of<T>(
7533 target: &Object<T>,
7534 prototype: &JsValue,
7535 ) -> Result<bool, JsValue>;
7536 }
7537}
7538
7539// RegExp
7540#[wasm_bindgen]
7541extern "C" {
7542 #[wasm_bindgen(extends = Object, typescript_type = "RegExp")]
7543 #[derive(Clone, Debug, PartialEq, Eq)]
7544 pub type RegExp;
7545
7546 /// The `exec()` method executes a search for a match in a specified
7547 /// string. Returns a result array, or null.
7548 ///
7549 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec)
7550 #[cfg(not(js_sys_unstable_apis))]
7551 #[wasm_bindgen(method)]
7552 pub fn exec(this: &RegExp, text: &str) -> Option<Array<JsString>>;
7553
7554 /// The `exec()` method executes a search for a match in a specified
7555 /// string. Returns a result array, or null.
7556 ///
7557 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec)
7558 #[cfg(js_sys_unstable_apis)]
7559 #[wasm_bindgen(method)]
7560 pub fn exec(this: &RegExp, text: &str) -> Option<RegExpMatchArray>;
7561
7562 /// The flags property returns a string consisting of the flags of
7563 /// the current regular expression object.
7564 ///
7565 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/flags)
7566 #[wasm_bindgen(method, getter)]
7567 pub fn flags(this: &RegExp) -> JsString;
7568
7569 /// The global property indicates whether or not the "g" flag is
7570 /// used with the regular expression. global is a read-only
7571 /// property of an individual regular expression instance.
7572 ///
7573 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/global)
7574 #[wasm_bindgen(method, getter)]
7575 pub fn global(this: &RegExp) -> bool;
7576
7577 /// The ignoreCase property indicates whether or not the "i" flag
7578 /// is used with the regular expression. ignoreCase is a read-only
7579 /// property of an individual regular expression instance.
7580 ///
7581 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/ignoreCase)
7582 #[wasm_bindgen(method, getter, js_name = ignoreCase)]
7583 pub fn ignore_case(this: &RegExp) -> bool;
7584
7585 /// The non-standard input property is a static property of
7586 /// regular expressions that contains the string against which a
7587 /// regular expression is matched. RegExp.$_ is an alias for this
7588 /// property.
7589 ///
7590 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/input)
7591 #[wasm_bindgen(static_method_of = RegExp, getter)]
7592 pub fn input() -> JsString;
7593
7594 /// The lastIndex is a read/write integer property of regular expression
7595 /// instances that specifies the index at which to start the next match.
7596 ///
7597 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex)
7598 #[wasm_bindgen(structural, getter = lastIndex, method)]
7599 pub fn last_index(this: &RegExp) -> u32;
7600
7601 /// The lastIndex is a read/write integer property of regular expression
7602 /// instances that specifies the index at which to start the next match.
7603 ///
7604 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex)
7605 #[wasm_bindgen(structural, setter = lastIndex, method)]
7606 pub fn set_last_index(this: &RegExp, index: u32);
7607
7608 /// The non-standard lastMatch property is a static and read-only
7609 /// property of regular expressions that contains the last matched
7610 /// characters. `RegExp.$&` is an alias for this property.
7611 ///
7612 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastMatch)
7613 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = lastMatch)]
7614 pub fn last_match() -> JsString;
7615
7616 /// The non-standard lastParen property is a static and read-only
7617 /// property of regular expressions that contains the last
7618 /// parenthesized substring match, if any. `RegExp.$+` is an alias
7619 /// for this property.
7620 ///
7621 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastParen)
7622 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = lastParen)]
7623 pub fn last_paren() -> JsString;
7624
7625 /// The non-standard leftContext property is a static and
7626 /// read-only property of regular expressions that contains the
7627 /// substring preceding the most recent match. `RegExp.$`` is an
7628 /// alias for this property.
7629 ///
7630 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/leftContext)
7631 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = leftContext)]
7632 pub fn left_context() -> JsString;
7633
7634 /// The multiline property indicates whether or not the "m" flag
7635 /// is used with the regular expression. multiline is a read-only
7636 /// property of an individual regular expression instance.
7637 ///
7638 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/multiline)
7639 #[wasm_bindgen(method, getter)]
7640 pub fn multiline(this: &RegExp) -> bool;
7641
7642 /// The non-standard $1, $2, $3, $4, $5, $6, $7, $8, $9 properties
7643 /// are static and read-only properties of regular expressions
7644 /// that contain parenthesized substring matches.
7645 ///
7646 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/n)
7647 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$1")]
7648 pub fn n1() -> JsString;
7649 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$2")]
7650 pub fn n2() -> JsString;
7651 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$3")]
7652 pub fn n3() -> JsString;
7653 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$4")]
7654 pub fn n4() -> JsString;
7655 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$5")]
7656 pub fn n5() -> JsString;
7657 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$6")]
7658 pub fn n6() -> JsString;
7659 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$7")]
7660 pub fn n7() -> JsString;
7661 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$8")]
7662 pub fn n8() -> JsString;
7663 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$9")]
7664 pub fn n9() -> JsString;
7665
7666 /// The `RegExp` constructor creates a regular expression object for matching text with a pattern.
7667 ///
7668 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp)
7669 #[wasm_bindgen(constructor)]
7670 pub fn new(pattern: &str, flags: &str) -> RegExp;
7671 #[wasm_bindgen(constructor)]
7672 pub fn new_regexp(pattern: &RegExp, flags: &str) -> RegExp;
7673
7674 /// The non-standard rightContext property is a static and
7675 /// read-only property of regular expressions that contains the
7676 /// substring following the most recent match. `RegExp.$'` is an
7677 /// alias for this property.
7678 ///
7679 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/rightContext)
7680 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = rightContext)]
7681 pub fn right_context() -> JsString;
7682
7683 /// The source property returns a String containing the source
7684 /// text of the regexp object, and it doesn't contain the two
7685 /// forward slashes on both sides and any flags.
7686 ///
7687 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/source)
7688 #[wasm_bindgen(method, getter)]
7689 pub fn source(this: &RegExp) -> JsString;
7690
7691 /// The sticky property reflects whether or not the search is
7692 /// sticky (searches in strings only from the index indicated by
7693 /// the lastIndex property of this regular expression). sticky is
7694 /// a read-only property of an individual regular expression
7695 /// object.
7696 ///
7697 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/sticky)
7698 #[wasm_bindgen(method, getter)]
7699 pub fn sticky(this: &RegExp) -> bool;
7700
7701 /// The `test()` method executes a search for a match between a
7702 /// regular expression and a specified string. Returns true or
7703 /// false.
7704 ///
7705 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/test)
7706 #[wasm_bindgen(method)]
7707 pub fn test(this: &RegExp, text: &str) -> bool;
7708
7709 /// The `toString()` method returns a string representing the
7710 /// regular expression.
7711 ///
7712 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/toString)
7713 #[cfg(not(js_sys_unstable_apis))]
7714 #[wasm_bindgen(method, js_name = toString)]
7715 pub fn to_string(this: &RegExp) -> JsString;
7716
7717 /// The unicode property indicates whether or not the "u" flag is
7718 /// used with a regular expression. unicode is a read-only
7719 /// property of an individual regular expression instance.
7720 ///
7721 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/unicode)
7722 #[wasm_bindgen(method, getter)]
7723 pub fn unicode(this: &RegExp) -> bool;
7724}
7725
7726// RegExpMatchArray
7727#[wasm_bindgen]
7728extern "C" {
7729 /// The result array from `RegExp.exec()` or `String.matchAll()`.
7730 ///
7731 /// This is an array of strings with additional properties `index`, `input`, and `groups`.
7732 ///
7733 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec#return_value)
7734 #[wasm_bindgen(extends = Object, extends = Array, typescript_type = "RegExpMatchArray")]
7735 #[derive(Clone, Debug, PartialEq, Eq)]
7736 pub type RegExpMatchArray;
7737
7738 /// The 0-based index of the match in the string.
7739 #[wasm_bindgen(method, getter)]
7740 pub fn index(this: &RegExpMatchArray) -> u32;
7741
7742 /// The original string that was matched against.
7743 #[wasm_bindgen(method, getter)]
7744 pub fn input(this: &RegExpMatchArray) -> JsString;
7745
7746 /// An object of named capturing groups whose keys are the names and valuestype Array
7747 /// are the capturing groups, or `undefined` if no named capturing groups were defined.
7748 #[wasm_bindgen(method, getter)]
7749 pub fn groups(this: &RegExpMatchArray) -> Option<Object>;
7750
7751 /// The number of elements in the match array (full match + capture groups).
7752 #[wasm_bindgen(method, getter)]
7753 pub fn length(this: &RegExpMatchArray) -> u32;
7754
7755 /// Gets the matched string or capture group at the given index.
7756 /// Index 0 is the full match, indices 1+ are capture groups.
7757 #[wasm_bindgen(method, indexing_getter)]
7758 pub fn get(this: &RegExpMatchArray, index: u32) -> Option<JsString>;
7759}
7760
7761// Set
7762#[wasm_bindgen]
7763extern "C" {
7764 #[wasm_bindgen(extends = Object, typescript_type = "Set<any>")]
7765 #[derive(Clone, Debug, PartialEq, Eq)]
7766 pub type Set<T = JsValue>;
7767
7768 /// The [`Set`] object lets you store unique values of any type, whether
7769 /// primitive values or object references.
7770 ///
7771 /// **Note:** Consider using [`Set::new_typed`] to support typing.
7772 ///
7773 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
7774 #[cfg(not(js_sys_unstable_apis))]
7775 #[wasm_bindgen(constructor)]
7776 pub fn new(init: &JsValue) -> Set;
7777
7778 /// The [`Set`] object lets you store unique values of any type, whether
7779 /// primitive values or object references.
7780 ///
7781 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
7782 #[cfg(js_sys_unstable_apis)]
7783 #[wasm_bindgen(constructor)]
7784 pub fn new<T>() -> Set<T>;
7785
7786 // Next major: deprecate
7787 /// The [`Set`] object lets you store unique values of any type, whether
7788 /// primitive values or object references.
7789 ///
7790 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
7791 #[wasm_bindgen(constructor)]
7792 pub fn new_typed<T>() -> Set<T>;
7793
7794 /// The [`Set`] object lets you store unique values of any type, whether
7795 /// primitive values or object references.
7796 ///
7797 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
7798 #[wasm_bindgen(constructor, js_name = new)]
7799 pub fn new_empty<T>() -> Set<T>;
7800
7801 /// The [`Set`] object lets you store unique values of any type, whether
7802 /// primitive values or object references.
7803 ///
7804 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
7805 #[wasm_bindgen(constructor, js_name = new)]
7806 pub fn new_from_items<T>(items: &[T]) -> Set<T>;
7807
7808 /// The [`Set`] object lets you store unique values of any type, whether
7809 /// primitive values or object references.
7810 ///
7811 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
7812 #[wasm_bindgen(constructor, js_name = new, catch)]
7813 pub fn new_from_iterable<T, I: Iterable<Item = T>>(iterable: I) -> Result<Set<T>, JsValue>;
7814
7815 /// The `add()` method appends a new element with a specified value to the
7816 /// end of a [`Set`] object.
7817 ///
7818 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/add)
7819 #[wasm_bindgen(method)]
7820 pub fn add<T>(this: &Set<T>, value: &T) -> Set<T>;
7821
7822 /// The `clear()` method removes all elements from a [`Set`] object.
7823 ///
7824 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/clear)
7825 #[wasm_bindgen(method)]
7826 pub fn clear<T>(this: &Set<T>);
7827
7828 /// The `delete()` method removes the specified element from a [`Set`]
7829 /// object.
7830 ///
7831 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/delete)
7832 #[wasm_bindgen(method)]
7833 pub fn delete<T>(this: &Set<T>, value: &T) -> bool;
7834
7835 /// The `forEach()` method executes a provided function once for each value
7836 /// in the Set object, in insertion order.
7837 ///
7838 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/forEach)
7839 #[cfg(not(js_sys_unstable_apis))]
7840 #[wasm_bindgen(method, js_name = forEach)]
7841 pub fn for_each<T>(this: &Set<T>, callback: &mut dyn FnMut(T, T, Set<T>));
7842
7843 /// The `forEach()` method executes a provided function once for each value
7844 /// in the Set object, in insertion order.
7845 ///
7846 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/forEach)
7847 #[cfg(js_sys_unstable_apis)]
7848 #[wasm_bindgen(method, js_name = forEach)]
7849 pub fn for_each<T>(this: &Set<T>, callback: &mut dyn FnMut(T));
7850
7851 /// The `forEach()` method executes a provided function once for each value
7852 /// in the Set object, in insertion order.
7853 ///
7854 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/forEach)
7855 #[wasm_bindgen(method, js_name = forEach, catch)]
7856 pub fn try_for_each<T>(
7857 this: &Set<T>,
7858 callback: &mut dyn FnMut(T) -> Result<(), JsError>,
7859 ) -> Result<(), JsValue>;
7860
7861 /// The `has()` method returns a boolean indicating whether an element with
7862 /// the specified value exists in a [`Set`] object or not.
7863 ///
7864 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/has)
7865 #[wasm_bindgen(method)]
7866 pub fn has<T>(this: &Set<T>, value: &T) -> bool;
7867
7868 /// The size accessor property returns the number of elements in a [`Set`]
7869 /// object.
7870 ///
7871 /// [MDN documentation](https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Set/size)
7872 #[wasm_bindgen(method, getter)]
7873 pub fn size<T>(this: &Set<T>) -> u32;
7874
7875 /// The `union()` method returns a new set containing elements which are in
7876 /// either or both of this set and the given set.
7877 ///
7878 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/union)
7879 #[wasm_bindgen(method)]
7880 pub fn union<T>(this: &Set<T>, other: &Set<T>) -> Set<T>;
7881
7882 /// The `intersection()` method returns a new set containing elements which are
7883 /// in both this set and the given set.
7884 ///
7885 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/intersection)
7886 #[wasm_bindgen(method)]
7887 pub fn intersection<T>(this: &Set<T>, other: &Set<T>) -> Set<T>;
7888
7889 /// The `difference()` method returns a new set containing elements which are
7890 /// in this set but not in the given set.
7891 ///
7892 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/difference)
7893 #[wasm_bindgen(method)]
7894 pub fn difference<T>(this: &Set<T>, other: &Set<T>) -> Set<T>;
7895
7896 /// The `symmetricDifference()` method returns a new set containing elements
7897 /// which are in either this set or the given set, but not in both.
7898 ///
7899 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/symmetricDifference)
7900 #[wasm_bindgen(method, js_name = symmetricDifference)]
7901 pub fn symmetric_difference<T>(this: &Set<T>, other: &Set<T>) -> Set<T>;
7902
7903 /// The `isSubsetOf()` method returns a boolean indicating whether all elements
7904 /// of this set are in the given set.
7905 ///
7906 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/isSubsetOf)
7907 #[wasm_bindgen(method, js_name = isSubsetOf)]
7908 pub fn is_subset_of<T>(this: &Set<T>, other: &Set<T>) -> bool;
7909
7910 /// The `isSupersetOf()` method returns a boolean indicating whether all elements
7911 /// of the given set are in this set.
7912 ///
7913 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/isSupersetOf)
7914 #[wasm_bindgen(method, js_name = isSupersetOf)]
7915 pub fn is_superset_of<T>(this: &Set<T>, other: &Set<T>) -> bool;
7916
7917 /// The `isDisjointFrom()` method returns a boolean indicating whether this set
7918 /// has no elements in common with the given set.
7919 ///
7920 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/isDisjointFrom)
7921 #[wasm_bindgen(method, js_name = isDisjointFrom)]
7922 pub fn is_disjoint_from<T>(this: &Set<T>, other: &Set<T>) -> bool;
7923}
7924
7925impl Default for Set<JsValue> {
7926 fn default() -> Self {
7927 Self::new_typed()
7928 }
7929}
7930
7931impl<T> Iterable for Set<T> {
7932 type Item = T;
7933}
7934
7935// SetIterator
7936#[wasm_bindgen]
7937extern "C" {
7938 /// The `entries()` method returns a new Iterator object that contains an
7939 /// array of [value, value] for each element in the Set object, in insertion
7940 /// order. For Set objects there is no key like in Map objects. However, to
7941 /// keep the API similar to the Map object, each entry has the same value
7942 /// for its key and value here, so that an array [value, value] is returned.
7943 ///
7944 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/entries)
7945 #[cfg(not(js_sys_unstable_apis))]
7946 #[wasm_bindgen(method)]
7947 pub fn entries<T>(set: &Set<T>) -> Iterator;
7948
7949 /// The `entries()` method returns a new Iterator object that contains an
7950 /// array of [value, value] for each element in the Set object, in insertion
7951 /// order. For Set objects there is no key like in Map objects. However, to
7952 /// keep the API similar to the Map object, each entry has the same value
7953 /// for its key and value here, so that an array [value, value] is returned.
7954 ///
7955 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/entries)
7956 #[cfg(js_sys_unstable_apis)]
7957 #[wasm_bindgen(method, js_name = entries)]
7958 pub fn entries<T: JsGeneric>(set: &Set<T>) -> Iterator<ArrayTuple<(T, T)>>;
7959
7960 // Next major: deprecate
7961 /// The `entries()` method returns a new Iterator object that contains an
7962 /// array of [value, value] for each element in the Set object, in insertion
7963 /// order. For Set objects there is no key like in Map objects. However, to
7964 /// keep the API similar to the Map object, each entry has the same value
7965 /// for its key and value here, so that an array [value, value] is returned.
7966 ///
7967 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/entries)
7968 #[wasm_bindgen(method, js_name = entries)]
7969 pub fn entries_typed<T: JsGeneric>(set: &Set<T>) -> Iterator<ArrayTuple<(T, T)>>;
7970
7971 /// The `keys()` method is an alias for this method (for similarity with
7972 /// Map objects); it behaves exactly the same and returns values
7973 /// of Set elements.
7974 ///
7975 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/values)
7976 #[wasm_bindgen(method)]
7977 pub fn keys<T>(set: &Set<T>) -> Iterator<T>;
7978
7979 /// The `values()` method returns a new Iterator object that contains the
7980 /// values for each element in the Set object in insertion order.
7981 ///
7982 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/values)
7983 #[wasm_bindgen(method)]
7984 pub fn values<T>(set: &Set<T>) -> Iterator<T>;
7985}
7986
7987// SyntaxError
7988#[wasm_bindgen]
7989extern "C" {
7990 /// A `SyntaxError` is thrown when the JavaScript engine encounters tokens or
7991 /// token order that does not conform to the syntax of the language when
7992 /// parsing code.
7993 ///
7994 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError)
7995 #[wasm_bindgen(extends = Error, extends = Object, typescript_type = "SyntaxError")]
7996 #[derive(Clone, Debug, PartialEq, Eq)]
7997 pub type SyntaxError;
7998
7999 /// A `SyntaxError` is thrown when the JavaScript engine encounters tokens or
8000 /// token order that does not conform to the syntax of the language when
8001 /// parsing code.
8002 ///
8003 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError)
8004 #[wasm_bindgen(constructor)]
8005 pub fn new(message: &str) -> SyntaxError;
8006}
8007
8008// TypeError
8009#[wasm_bindgen]
8010extern "C" {
8011 /// The `TypeError` object represents an error when a value is not of the
8012 /// expected type.
8013 ///
8014 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError)
8015 #[wasm_bindgen(extends = Error, extends = Object, typescript_type = "TypeError")]
8016 #[derive(Clone, Debug, PartialEq, Eq)]
8017 pub type TypeError;
8018
8019 /// The `TypeError` object represents an error when a value is not of the
8020 /// expected type.
8021 ///
8022 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError)
8023 #[wasm_bindgen(constructor)]
8024 pub fn new(message: &str) -> TypeError;
8025}
8026
8027// URIError
8028#[wasm_bindgen]
8029extern "C" {
8030 /// The `URIError` object represents an error when a global URI handling
8031 /// function was used in a wrong way.
8032 ///
8033 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError)
8034 #[wasm_bindgen(extends = Error, extends = Object, js_name = URIError, typescript_type = "URIError")]
8035 #[derive(Clone, Debug, PartialEq, Eq)]
8036 pub type UriError;
8037
8038 /// The `URIError` object represents an error when a global URI handling
8039 /// function was used in a wrong way.
8040 ///
8041 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError)
8042 #[wasm_bindgen(constructor, js_class = "URIError")]
8043 pub fn new(message: &str) -> UriError;
8044}
8045
8046// WeakMap
8047#[wasm_bindgen]
8048extern "C" {
8049 #[wasm_bindgen(extends = Object, typescript_type = "WeakMap<object, any>")]
8050 #[derive(Clone, Debug, PartialEq, Eq)]
8051 pub type WeakMap<K = Object, V = JsValue>;
8052
8053 /// The [`WeakMap`] object is a collection of key/value pairs in which the
8054 /// keys are weakly referenced. The keys must be objects and the values can
8055 /// be arbitrary values.
8056 ///
8057 /// **Note:** Consider using [`WeakMap::new_typed`] to support typing.
8058 ///
8059 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap)
8060 #[cfg(not(js_sys_unstable_apis))]
8061 #[wasm_bindgen(constructor)]
8062 pub fn new() -> WeakMap;
8063
8064 /// The [`WeakMap`] object is a collection of key/value pairs in which the
8065 /// keys are weakly referenced. The keys must be objects and the values can
8066 /// be arbitrary values.
8067 ///
8068 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap)
8069 #[cfg(js_sys_unstable_apis)]
8070 #[wasm_bindgen(constructor)]
8071 pub fn new<K: JsGeneric = Object, V: JsGeneric = Object>() -> WeakMap<K, V>;
8072
8073 // Next major: deprecate
8074 /// The [`WeakMap`] object is a collection of key/value pairs in which the
8075 /// keys are weakly referenced. The keys must be objects and the values can
8076 /// be arbitrary values.
8077 ///
8078 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap)
8079 #[wasm_bindgen(constructor)]
8080 pub fn new_typed<K: JsGeneric = Object, V: JsGeneric = Object>() -> WeakMap<K, V>;
8081
8082 /// The `set()` method sets the value for the key in the [`WeakMap`] object.
8083 /// Returns the [`WeakMap`] object.
8084 ///
8085 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/set)
8086 #[wasm_bindgen(method, js_class = "WeakMap")]
8087 pub fn set<K, V>(this: &WeakMap<K, V>, key: &K, value: &V) -> WeakMap<K, V>;
8088
8089 /// The `get()` method returns a specified by key element
8090 /// from a [`WeakMap`] object. Returns `undefined` if the key is not found.
8091 ///
8092 /// **Note:** Consider using [`WeakMap::get_checked`] to get an `Option<V>` instead.
8093 ///
8094 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/get)
8095 #[cfg(not(js_sys_unstable_apis))]
8096 #[wasm_bindgen(method)]
8097 pub fn get<K, V>(this: &WeakMap<K, V>, key: &K) -> V;
8098
8099 /// The `get()` method returns a specified by key element
8100 /// from a [`WeakMap`] object. Returns `None` if the key is not found.
8101 ///
8102 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/get)
8103 #[cfg(js_sys_unstable_apis)]
8104 #[wasm_bindgen(method)]
8105 pub fn get<K, V>(this: &WeakMap<K, V>, key: &K) -> Option<V>;
8106
8107 /// The `get()` method returns a specified by key element
8108 /// from a [`WeakMap`] object. Returns `None` if the key is not found.
8109 ///
8110 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/get)
8111 #[wasm_bindgen(method, js_name = get)]
8112 pub fn get_checked<K, V>(this: &WeakMap<K, V>, key: &K) -> Option<V>;
8113
8114 /// The `has()` method returns a boolean indicating whether an element with
8115 /// the specified key exists in the [`WeakMap`] object or not.
8116 ///
8117 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/has)
8118 #[wasm_bindgen(method)]
8119 pub fn has<K, V>(this: &WeakMap<K, V>, key: &K) -> bool;
8120
8121 /// The `delete()` method removes the specified element from a [`WeakMap`]
8122 /// object.
8123 ///
8124 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/delete)
8125 #[wasm_bindgen(method)]
8126 pub fn delete<K, V>(this: &WeakMap<K, V>, key: &K) -> bool;
8127}
8128
8129impl Default for WeakMap {
8130 fn default() -> Self {
8131 Self::new()
8132 }
8133}
8134
8135// WeakSet
8136#[wasm_bindgen]
8137extern "C" {
8138 #[wasm_bindgen(extends = Object, typescript_type = "WeakSet<object>")]
8139 #[derive(Clone, Debug, PartialEq, Eq)]
8140 pub type WeakSet<T = Object>;
8141
8142 /// The `WeakSet` object lets you store weakly held objects in a collection.
8143 ///
8144 /// **Note:** Consider using [`WeakSet::new_typed`] for typed sets.
8145 ///
8146 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet)
8147 #[cfg(not(js_sys_unstable_apis))]
8148 #[wasm_bindgen(constructor)]
8149 pub fn new() -> WeakSet;
8150
8151 /// The `WeakSet` object lets you store weakly held objects in a collection.
8152 ///
8153 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet)
8154 #[cfg(js_sys_unstable_apis)]
8155 #[wasm_bindgen(constructor)]
8156 pub fn new<T = Object>() -> WeakSet<T>;
8157
8158 // Next major: deprecate
8159 /// The `WeakSet` object lets you store weakly held objects in a collection.
8160 ///
8161 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet)
8162 #[wasm_bindgen(constructor)]
8163 pub fn new_typed<T = Object>() -> WeakSet<T>;
8164
8165 /// The `has()` method returns a boolean indicating whether an object exists
8166 /// in a WeakSet or not.
8167 ///
8168 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet/has)
8169 #[wasm_bindgen(method)]
8170 pub fn has<T>(this: &WeakSet<T>, value: &T) -> bool;
8171
8172 /// The `add()` method appends a new object to the end of a WeakSet object.
8173 ///
8174 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet/add)
8175 #[wasm_bindgen(method)]
8176 pub fn add<T>(this: &WeakSet<T>, value: &T) -> WeakSet<T>;
8177
8178 /// The `delete()` method removes the specified element from a WeakSet
8179 /// object.
8180 ///
8181 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet/delete)
8182 #[wasm_bindgen(method)]
8183 pub fn delete<T>(this: &WeakSet<T>, value: &T) -> bool;
8184}
8185
8186impl Default for WeakSet {
8187 fn default() -> Self {
8188 Self::new()
8189 }
8190}
8191
8192// WeakRef
8193#[wasm_bindgen]
8194extern "C" {
8195 #[wasm_bindgen(extends = Object, typescript_type = "WeakRef<object>")]
8196 #[derive(Clone, Debug, PartialEq, Eq)]
8197 pub type WeakRef<T = Object>;
8198
8199 /// The `WeakRef` object contains a weak reference to an object. A weak
8200 /// reference to an object is a reference that does not prevent the object
8201 /// from being reclaimed by the garbage collector.
8202 ///
8203 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef)
8204 #[wasm_bindgen(constructor)]
8205 pub fn new<T = Object>(target: &T) -> WeakRef<T>;
8206
8207 /// Returns the `Object` this `WeakRef` points to, or `None` if the
8208 /// object has been garbage collected.
8209 ///
8210 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef/deref)
8211 #[wasm_bindgen(method)]
8212 pub fn deref<T>(this: &WeakRef<T>) -> Option<T>;
8213}
8214
8215#[cfg(js_sys_unstable_apis)]
8216#[allow(non_snake_case)]
8217pub mod Temporal;
8218
8219#[allow(non_snake_case)]
8220pub mod WebAssembly {
8221 use super::*;
8222
8223 // WebAssembly
8224 #[wasm_bindgen]
8225 extern "C" {
8226 /// The `WebAssembly.compile()` function compiles a `WebAssembly.Module`
8227 /// from WebAssembly binary code. This function is useful if it is
8228 /// necessary to a compile a module before it can be instantiated
8229 /// (otherwise, the `WebAssembly.instantiate()` function should be used).
8230 ///
8231 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compile)
8232 #[cfg(not(js_sys_unstable_apis))]
8233 #[wasm_bindgen(js_namespace = WebAssembly)]
8234 pub fn compile(buffer_source: &JsValue) -> Promise<JsValue>;
8235
8236 /// The `WebAssembly.compile()` function compiles a `WebAssembly.Module`
8237 /// from WebAssembly binary code. This function is useful if it is
8238 /// necessary to a compile a module before it can be instantiated
8239 /// (otherwise, the `WebAssembly.instantiate()` function should be used).
8240 ///
8241 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compile)
8242 #[cfg(js_sys_unstable_apis)]
8243 #[wasm_bindgen(js_namespace = WebAssembly)]
8244 pub fn compile(buffer_source: &JsValue) -> Promise<Module>;
8245
8246 /// The `WebAssembly.compileStreaming()` function compiles a
8247 /// `WebAssembly.Module` module directly from a streamed underlying
8248 /// source. This function is useful if it is necessary to a compile a
8249 /// module before it can be instantiated (otherwise, the
8250 /// `WebAssembly.instantiateStreaming()` function should be used).
8251 ///
8252 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compileStreaming)
8253 #[cfg(not(js_sys_unstable_apis))]
8254 #[wasm_bindgen(js_namespace = WebAssembly, js_name = compileStreaming)]
8255 pub fn compile_streaming(response: &Promise) -> Promise<JsValue>;
8256
8257 /// The `WebAssembly.compileStreaming()` function compiles a
8258 /// `WebAssembly.Module` module directly from a streamed underlying
8259 /// source. This function is useful if it is necessary to a compile a
8260 /// module before it can be instantiated (otherwise, the
8261 /// `WebAssembly.instantiateStreaming()` function should be used).
8262 ///
8263 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compileStreaming)
8264 #[cfg(js_sys_unstable_apis)]
8265 #[wasm_bindgen(js_namespace = WebAssembly, js_name = compileStreaming)]
8266 pub fn compile_streaming(response: &Promise) -> Promise<Module>;
8267
8268 /// The `WebAssembly.instantiate()` function allows you to compile and
8269 /// instantiate WebAssembly code.
8270 ///
8271 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate)
8272 #[cfg(not(js_sys_unstable_apis))]
8273 #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiate)]
8274 pub fn instantiate_buffer(buffer: &[u8], imports: &Object) -> Promise<JsValue>;
8275
8276 /// The `WebAssembly.instantiate()` function allows you to compile and
8277 /// instantiate WebAssembly code.
8278 ///
8279 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate)
8280 #[cfg(js_sys_unstable_apis)]
8281 #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiate)]
8282 pub fn instantiate_buffer(buffer: &[u8], imports: &Object) -> Promise<Instance>;
8283
8284 /// The `WebAssembly.instantiate()` function allows you to compile and
8285 /// instantiate WebAssembly code.
8286 ///
8287 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate)
8288 #[cfg(not(js_sys_unstable_apis))]
8289 #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiate)]
8290 pub fn instantiate_module(module: &Module, imports: &Object) -> Promise<JsValue>;
8291
8292 /// The `WebAssembly.instantiate()` function allows you to compile and
8293 /// instantiate WebAssembly code.
8294 ///
8295 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate)
8296 #[cfg(js_sys_unstable_apis)]
8297 #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiate)]
8298 pub fn instantiate_module(module: &Module, imports: &Object) -> Promise<Instance>;
8299
8300 /// The `WebAssembly.instantiateStreaming()` function compiles and
8301 /// instantiates a WebAssembly module directly from a streamed
8302 /// underlying source. This is the most efficient, optimized way to load
8303 /// Wasm code.
8304 ///
8305 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiateStreaming)
8306 #[cfg(not(js_sys_unstable_apis))]
8307 #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiateStreaming)]
8308 pub fn instantiate_streaming(response: &JsValue, imports: &Object) -> Promise<JsValue>;
8309
8310 /// The `WebAssembly.instantiateStreaming()` function compiles and
8311 /// instantiates a WebAssembly module directly from a streamed
8312 /// underlying source. This is the most efficient, optimized way to load
8313 /// Wasm code.
8314 ///
8315 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiateStreaming)
8316 #[cfg(js_sys_unstable_apis)]
8317 #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiateStreaming)]
8318 pub fn instantiate_streaming(response: &JsValue, imports: &Object) -> Promise<Instance>;
8319
8320 /// The `WebAssembly.validate()` function validates a given typed
8321 /// array of WebAssembly binary code, returning whether the bytes
8322 /// form a valid Wasm module (`true`) or not (`false`).
8323 ///
8324 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/validate)
8325 #[wasm_bindgen(js_namespace = WebAssembly, catch)]
8326 pub fn validate(buffer_source: &JsValue) -> Result<bool, JsValue>;
8327 }
8328
8329 // WebAssembly.CompileError
8330 #[wasm_bindgen]
8331 extern "C" {
8332 /// The `WebAssembly.CompileError()` constructor creates a new
8333 /// WebAssembly `CompileError` object, which indicates an error during
8334 /// WebAssembly decoding or validation.
8335 ///
8336 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/CompileError)
8337 #[wasm_bindgen(extends = Error, js_namespace = WebAssembly, typescript_type = "WebAssembly.CompileError")]
8338 #[derive(Clone, Debug, PartialEq, Eq)]
8339 pub type CompileError;
8340
8341 /// The `WebAssembly.CompileError()` constructor creates a new
8342 /// WebAssembly `CompileError` object, which indicates an error during
8343 /// WebAssembly decoding or validation.
8344 ///
8345 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/CompileError)
8346 #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
8347 pub fn new(message: &str) -> CompileError;
8348 }
8349
8350 // WebAssembly.Instance
8351 #[wasm_bindgen]
8352 extern "C" {
8353 /// A `WebAssembly.Instance` object is a stateful, executable instance
8354 /// of a `WebAssembly.Module`. Instance objects contain all the exported
8355 /// WebAssembly functions that allow calling into WebAssembly code from
8356 /// JavaScript.
8357 ///
8358 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance)
8359 #[wasm_bindgen(extends = Object, js_namespace = WebAssembly, typescript_type = "WebAssembly.Instance")]
8360 #[derive(Clone, Debug, PartialEq, Eq)]
8361 pub type Instance;
8362
8363 /// The `WebAssembly.Instance()` constructor function can be called to
8364 /// synchronously instantiate a given `WebAssembly.Module`
8365 /// object. However, the primary way to get an `Instance` is through the
8366 /// asynchronous `WebAssembly.instantiateStreaming()` function.
8367 ///
8368 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance)
8369 #[wasm_bindgen(catch, constructor, js_namespace = WebAssembly)]
8370 pub fn new(module: &Module, imports: &Object) -> Result<Instance, JsValue>;
8371
8372 /// The `exports` readonly property of the `WebAssembly.Instance` object
8373 /// prototype returns an object containing as its members all the
8374 /// functions exported from the WebAssembly module instance, to allow
8375 /// them to be accessed and used by JavaScript.
8376 ///
8377 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance/exports)
8378 #[wasm_bindgen(getter, method, js_namespace = WebAssembly)]
8379 pub fn exports(this: &Instance) -> Object;
8380 }
8381
8382 // WebAssembly.LinkError
8383 #[wasm_bindgen]
8384 extern "C" {
8385 /// The `WebAssembly.LinkError()` constructor creates a new WebAssembly
8386 /// LinkError object, which indicates an error during module
8387 /// instantiation (besides traps from the start function).
8388 ///
8389 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/LinkError)
8390 #[wasm_bindgen(extends = Error, js_namespace = WebAssembly, typescript_type = "WebAssembly.LinkError")]
8391 #[derive(Clone, Debug, PartialEq, Eq)]
8392 pub type LinkError;
8393
8394 /// The `WebAssembly.LinkError()` constructor creates a new WebAssembly
8395 /// LinkError object, which indicates an error during module
8396 /// instantiation (besides traps from the start function).
8397 ///
8398 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/LinkError)
8399 #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
8400 pub fn new(message: &str) -> LinkError;
8401 }
8402
8403 // WebAssembly.RuntimeError
8404 #[wasm_bindgen]
8405 extern "C" {
8406 /// The `WebAssembly.RuntimeError()` constructor creates a new WebAssembly
8407 /// `RuntimeError` object — the type that is thrown whenever WebAssembly
8408 /// specifies a trap.
8409 ///
8410 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/RuntimeError)
8411 #[wasm_bindgen(extends = Error, js_namespace = WebAssembly, typescript_type = "WebAssembly.RuntimeError")]
8412 #[derive(Clone, Debug, PartialEq, Eq)]
8413 pub type RuntimeError;
8414
8415 /// The `WebAssembly.RuntimeError()` constructor creates a new WebAssembly
8416 /// `RuntimeError` object — the type that is thrown whenever WebAssembly
8417 /// specifies a trap.
8418 ///
8419 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/RuntimeError)
8420 #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
8421 pub fn new(message: &str) -> RuntimeError;
8422 }
8423
8424 // WebAssembly.Module
8425 #[wasm_bindgen]
8426 extern "C" {
8427 /// A `WebAssembly.Module` object contains stateless WebAssembly code
8428 /// that has already been compiled by the browser and can be
8429 /// efficiently shared with Workers, and instantiated multiple times.
8430 ///
8431 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module)
8432 #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Module")]
8433 #[derive(Clone, Debug, PartialEq, Eq)]
8434 pub type Module;
8435
8436 /// A `WebAssembly.Module` object contains stateless WebAssembly code
8437 /// that has already been compiled by the browser and can be
8438 /// efficiently shared with Workers, and instantiated multiple times.
8439 ///
8440 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module)
8441 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
8442 pub fn new(buffer_source: &JsValue) -> Result<Module, JsValue>;
8443
8444 /// The `WebAssembly.customSections()` function returns a copy of the
8445 /// contents of all custom sections in the given module with the given
8446 /// string name.
8447 ///
8448 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/customSections)
8449 #[wasm_bindgen(static_method_of = Module, js_namespace = WebAssembly, js_name = customSections)]
8450 pub fn custom_sections(module: &Module, sectionName: &str) -> Array;
8451
8452 /// The `WebAssembly.exports()` function returns an array containing
8453 /// descriptions of all the declared exports of the given `Module`.
8454 ///
8455 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/exports)
8456 #[wasm_bindgen(static_method_of = Module, js_namespace = WebAssembly)]
8457 pub fn exports(module: &Module) -> Array;
8458
8459 /// The `WebAssembly.imports()` function returns an array containing
8460 /// descriptions of all the declared imports of the given `Module`.
8461 ///
8462 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/imports)
8463 #[wasm_bindgen(static_method_of = Module, js_namespace = WebAssembly)]
8464 pub fn imports(module: &Module) -> Array;
8465 }
8466
8467 // WebAssembly.Table
8468 #[wasm_bindgen]
8469 extern "C" {
8470 /// The `WebAssembly.Table()` constructor creates a new `Table` object
8471 /// of the given size and element type.
8472 ///
8473 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table)
8474 #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Table")]
8475 #[derive(Clone, Debug, PartialEq, Eq)]
8476 pub type Table;
8477
8478 /// The `WebAssembly.Table()` constructor creates a new `Table` object
8479 /// of the given size and element type.
8480 ///
8481 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table)
8482 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
8483 pub fn new(table_descriptor: &Object) -> Result<Table, JsValue>;
8484
8485 /// The `WebAssembly.Table()` constructor creates a new `Table` object
8486 /// of the given size and element type.
8487 ///
8488 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table)
8489 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
8490 pub fn new_with_value(table_descriptor: &Object, value: JsValue) -> Result<Table, JsValue>;
8491
8492 /// The length prototype property of the `WebAssembly.Table` object
8493 /// returns the length of the table, i.e. the number of elements in the
8494 /// table.
8495 ///
8496 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/length)
8497 #[wasm_bindgen(method, getter, js_namespace = WebAssembly)]
8498 pub fn length(this: &Table) -> u32;
8499
8500 /// The `get()` prototype method of the `WebAssembly.Table()` object
8501 /// retrieves a function reference stored at a given index.
8502 ///
8503 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/get)
8504 #[wasm_bindgen(method, catch, js_namespace = WebAssembly)]
8505 pub fn get(this: &Table, index: u32) -> Result<Function, JsValue>;
8506
8507 /// The `get()` prototype method of the `WebAssembly.Table()` object
8508 /// retrieves a function reference stored at a given index.
8509 ///
8510 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/get)
8511 #[wasm_bindgen(method, catch, js_namespace = WebAssembly, js_name = get)]
8512 pub fn get_raw(this: &Table, index: u32) -> Result<JsValue, JsValue>;
8513
8514 /// The `grow()` prototype method of the `WebAssembly.Table` object
8515 /// increases the size of the `Table` instance by a specified number of
8516 /// elements.
8517 ///
8518 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/grow)
8519 #[wasm_bindgen(method, catch, js_namespace = WebAssembly)]
8520 pub fn grow(this: &Table, additional_capacity: u32) -> Result<u32, JsValue>;
8521
8522 /// The `grow()` prototype method of the `WebAssembly.Table` object
8523 /// increases the size of the `Table` instance by a specified number of
8524 /// elements.
8525 ///
8526 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/grow)
8527 #[wasm_bindgen(method, catch, js_namespace = WebAssembly, js_name = grow)]
8528 pub fn grow_with_value(
8529 this: &Table,
8530 additional_capacity: u32,
8531 value: JsValue,
8532 ) -> Result<u32, JsValue>;
8533
8534 /// The `set()` prototype method of the `WebAssembly.Table` object mutates a
8535 /// reference stored at a given index to a different value.
8536 ///
8537 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/set)
8538 #[wasm_bindgen(method, catch, js_namespace = WebAssembly)]
8539 pub fn set(this: &Table, index: u32, function: &Function) -> Result<(), JsValue>;
8540
8541 /// The `set()` prototype method of the `WebAssembly.Table` object mutates a
8542 /// reference stored at a given index to a different value.
8543 ///
8544 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/set)
8545 #[wasm_bindgen(method, catch, js_namespace = WebAssembly, js_name = set)]
8546 pub fn set_raw(this: &Table, index: u32, value: &JsValue) -> Result<(), JsValue>;
8547 }
8548
8549 // WebAssembly.Tag
8550 #[wasm_bindgen]
8551 extern "C" {
8552 /// The `WebAssembly.Tag()` constructor creates a new `Tag` object
8553 ///
8554 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Tag)
8555 #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Tag")]
8556 #[derive(Clone, Debug, PartialEq, Eq)]
8557 pub type Tag;
8558
8559 /// The `WebAssembly.Tag()` constructor creates a new `Tag` object
8560 ///
8561 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Tag)
8562 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
8563 pub fn new(tag_descriptor: &Object) -> Result<Tag, JsValue>;
8564 }
8565
8566 // WebAssembly.Exception
8567 #[wasm_bindgen]
8568 extern "C" {
8569 /// The `WebAssembly.Exception()` constructor creates a new `Exception` object
8570 ///
8571 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception)
8572 #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Exception")]
8573 #[derive(Clone, Debug, PartialEq, Eq)]
8574 pub type Exception;
8575
8576 /// The `WebAssembly.Exception()` constructor creates a new `Exception` object
8577 ///
8578 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception)
8579 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
8580 pub fn new(tag: &Tag, payload: &Array) -> Result<Exception, JsValue>;
8581
8582 /// The `WebAssembly.Exception()` constructor creates a new `Exception` object
8583 ///
8584 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception)
8585 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
8586 pub fn new_with_options(
8587 tag: &Tag,
8588 payload: &Array,
8589 options: &Object,
8590 ) -> Result<Exception, JsValue>;
8591
8592 /// The `is()` prototype method of the `WebAssembly.Exception` can be used to
8593 /// test if the Exception matches a given tag.
8594 ///
8595 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception/is)
8596 #[wasm_bindgen(method, js_namespace = WebAssembly)]
8597 pub fn is(this: &Exception, tag: &Tag) -> bool;
8598
8599 /// The `getArg()` prototype method of the `WebAssembly.Exception` can be used
8600 /// to get the value of a specified item in the exception's data arguments
8601 ///
8602 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception/getArg)
8603 #[wasm_bindgen(method, js_namespace = WebAssembly, js_name = getArg, catch)]
8604 pub fn get_arg(this: &Exception, tag: &Tag, index: u32) -> Result<JsValue, JsValue>;
8605 }
8606
8607 // WebAssembly.Global
8608 #[wasm_bindgen]
8609 extern "C" {
8610 /// The `WebAssembly.Global()` constructor creates a new `Global` object
8611 /// of the given type and value.
8612 ///
8613 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global)
8614 #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Global")]
8615 #[derive(Clone, Debug, PartialEq, Eq)]
8616 pub type Global;
8617
8618 /// The `WebAssembly.Global()` constructor creates a new `Global` object
8619 /// of the given type and value.
8620 ///
8621 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global)
8622 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
8623 pub fn new(global_descriptor: &Object, value: &JsValue) -> Result<Global, JsValue>;
8624
8625 /// The value prototype property of the `WebAssembly.Global` object
8626 /// returns the value of the global.
8627 ///
8628 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global)
8629 #[wasm_bindgen(method, getter, js_namespace = WebAssembly)]
8630 pub fn value(this: &Global) -> JsValue;
8631 #[wasm_bindgen(method, setter = value, js_namespace = WebAssembly)]
8632 pub fn set_value(this: &Global, value: &JsValue);
8633 }
8634
8635 // WebAssembly.Memory
8636 #[wasm_bindgen]
8637 extern "C" {
8638 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory)
8639 #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Memory")]
8640 #[derive(Clone, Debug, PartialEq, Eq)]
8641 pub type Memory;
8642
8643 /// The `WebAssembly.Memory()` constructor creates a new `Memory` object
8644 /// which is a resizable `ArrayBuffer` that holds the raw bytes of
8645 /// memory accessed by a WebAssembly `Instance`.
8646 ///
8647 /// A memory created by JavaScript or in WebAssembly code will be
8648 /// accessible and mutable from both JavaScript and WebAssembly.
8649 ///
8650 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory)
8651 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
8652 pub fn new(descriptor: &Object) -> Result<Memory, JsValue>;
8653
8654 /// An accessor property that returns the buffer contained in the
8655 /// memory.
8656 ///
8657 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory/buffer)
8658 #[wasm_bindgen(method, getter, js_namespace = WebAssembly)]
8659 pub fn buffer(this: &Memory) -> JsValue;
8660
8661 /// The `grow()` prototype method of the `Memory` object increases the
8662 /// size of the memory instance by a specified number of WebAssembly
8663 /// pages.
8664 ///
8665 /// Takes the number of pages to grow (64KiB in size) and returns the
8666 /// previous size of memory, in pages.
8667 ///
8668 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory/grow)
8669 #[wasm_bindgen(method, js_namespace = WebAssembly)]
8670 pub fn grow(this: &Memory, pages: u32) -> u32;
8671 }
8672}
8673
8674/// The `JSON` object contains methods for parsing [JavaScript Object
8675/// Notation (JSON)](https://json.org/) and converting values to JSON. It
8676/// can't be called or constructed, and aside from its two method
8677/// properties, it has no interesting functionality of its own.
8678#[allow(non_snake_case)]
8679pub mod JSON {
8680 use super::*;
8681
8682 // JSON
8683 #[wasm_bindgen]
8684 extern "C" {
8685 /// The `JSON.parse()` method parses a JSON string, constructing the
8686 /// JavaScript value or object described by the string.
8687 ///
8688 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse)
8689 #[wasm_bindgen(catch, js_namespace = JSON)]
8690 pub fn parse(text: &str) -> Result<JsValue, JsValue>;
8691
8692 /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
8693 ///
8694 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
8695 #[wasm_bindgen(catch, js_namespace = JSON)]
8696 pub fn stringify(obj: &JsValue) -> Result<JsString, JsValue>;
8697
8698 /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
8699 ///
8700 /// The `replacer` argument is a function that alters the behavior of the stringification
8701 /// process, or an array of String and Number objects that serve as a whitelist
8702 /// for selecting/filtering the properties of the value object to be included
8703 /// in the JSON string. If this value is null or not provided, all properties
8704 /// of the object are included in the resulting JSON string.
8705 ///
8706 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
8707 #[cfg(not(js_sys_unstable_apis))]
8708 #[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
8709 pub fn stringify_with_replacer(
8710 obj: &JsValue,
8711 replacer: &JsValue,
8712 ) -> Result<JsString, JsValue>;
8713
8714 /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
8715 ///
8716 /// The `replacer` argument is a function that alters the behavior of the stringification
8717 /// process, or an array of String and Number objects that serve as a whitelist
8718 /// for selecting/filtering the properties of the value object to be included
8719 /// in the JSON string. If this value is null or not provided, all properties
8720 /// of the object are included in the resulting JSON string.
8721 ///
8722 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
8723 #[cfg(js_sys_unstable_apis)]
8724 #[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
8725 pub fn stringify_with_replacer<'a>(
8726 obj: &JsValue,
8727 replacer: &mut dyn FnMut(JsString, JsValue) -> Result<Option<JsValue>, JsError>,
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: &mut dyn FnMut(JsString, JsValue) -> Result<Option<JsValue>, JsError>,
8745 space: Option<u32>,
8746 ) -> Result<JsString, JsValue>;
8747
8748 /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
8749 ///
8750 /// The `replacer` argument is a function that alters the behavior of the stringification
8751 /// process, or an array of String and Number objects that serve as a whitelist
8752 /// for selecting/filtering the properties of the value object to be included
8753 /// in the JSON string. If this value is null or not provided, all properties
8754 /// of the object are included in the resulting JSON string.
8755 ///
8756 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
8757 #[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
8758 pub fn stringify_with_replacer_list(
8759 obj: &JsValue,
8760 replacer: Vec<String>,
8761 space: Option<u32>,
8762 ) -> Result<JsString, JsValue>;
8763
8764 // Next major: deprecate
8765 /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
8766 ///
8767 /// The `replacer` argument is a function that alters the behavior of the stringification
8768 /// process, or an array of String and Number objects that serve as a whitelist
8769 /// for selecting/filtering the properties of the value object to be included
8770 /// in the JSON string. If this value is null or not provided, all properties
8771 /// of the object are included in the resulting JSON string.
8772 ///
8773 /// The `space` argument is a String or Number object that's used to insert white space into
8774 /// the output JSON string for readability purposes. If this is a Number, it
8775 /// indicates the number of space characters to use as white space; this number
8776 /// is capped at 10 (if it is greater, the value is just 10). Values less than
8777 /// 1 indicate that no space should be used. If this is a String, the string
8778 /// (or the first 10 characters of the string, if it's longer than that) is
8779 /// used as white space. If this parameter is not provided (or is null), no
8780 /// white space is used.
8781 ///
8782 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
8783 #[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
8784 pub fn stringify_with_replacer_and_space(
8785 obj: &JsValue,
8786 replacer: &JsValue,
8787 space: &JsValue,
8788 ) -> Result<JsString, JsValue>;
8789 }
8790}
8791// JsString
8792#[wasm_bindgen]
8793extern "C" {
8794 #[wasm_bindgen(js_name = String, extends = Object, is_type_of = JsValue::is_string, typescript_type = "string")]
8795 #[derive(Clone, PartialEq, Eq)]
8796 pub type JsString;
8797
8798 /// The length property of a String object indicates the length of a string,
8799 /// in UTF-16 code units.
8800 ///
8801 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/length)
8802 #[wasm_bindgen(method, getter)]
8803 pub fn length(this: &JsString) -> u32;
8804
8805 /// The 'at()' method returns a new string consisting of the single UTF-16
8806 /// code unit located at the specified offset into the string, counting from
8807 /// the end if it's negative.
8808 ///
8809 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/at)
8810 #[wasm_bindgen(method, js_class = "String")]
8811 pub fn at(this: &JsString, index: i32) -> Option<JsString>;
8812
8813 /// The String object's `charAt()` method returns a new string consisting of
8814 /// the single UTF-16 code unit located at the specified offset into the
8815 /// string.
8816 ///
8817 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charAt)
8818 #[wasm_bindgen(method, js_class = "String", js_name = charAt)]
8819 pub fn char_at(this: &JsString, index: u32) -> JsString;
8820
8821 /// The `charCodeAt()` method returns an integer between 0 and 65535
8822 /// representing the UTF-16 code unit at the given index (the UTF-16 code
8823 /// unit matches the Unicode code point for code points representable in a
8824 /// single UTF-16 code unit, but might also be the first code unit of a
8825 /// surrogate pair for code points not representable in a single UTF-16 code
8826 /// unit, e.g. Unicode code points > 0x10000). If you want the entire code
8827 /// point value, use `codePointAt()`.
8828 ///
8829 /// Returns `NaN` if index is out of range.
8830 ///
8831 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charCodeAt)
8832 #[wasm_bindgen(method, js_class = "String", js_name = charCodeAt)]
8833 pub fn char_code_at(this: &JsString, index: u32) -> f64;
8834
8835 /// The `codePointAt()` method returns a non-negative integer that is the
8836 /// Unicode code point value.
8837 ///
8838 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/codePointAt)
8839 #[cfg(not(js_sys_unstable_apis))]
8840 #[wasm_bindgen(method, js_class = "String", js_name = codePointAt)]
8841 pub fn code_point_at(this: &JsString, pos: u32) -> JsValue;
8842
8843 /// The `codePointAt()` method returns a non-negative integer that is the
8844 /// Unicode code point value.
8845 ///
8846 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/codePointAt)
8847 #[cfg(js_sys_unstable_apis)]
8848 #[wasm_bindgen(method, js_class = "String", js_name = codePointAt)]
8849 pub fn code_point_at(this: &JsString, pos: u32) -> Option<u32>;
8850
8851 // Next major: deprecate
8852 /// The `codePointAt()` method returns a non-negative integer that is the
8853 /// Unicode code point value.
8854 ///
8855 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/codePointAt)
8856 #[wasm_bindgen(method, js_class = "String", js_name = codePointAt)]
8857 pub fn try_code_point_at(this: &JsString, pos: u32) -> Option<u16>;
8858
8859 /// The `concat()` method concatenates the string arguments to the calling
8860 /// string and returns a new string.
8861 ///
8862 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/concat)
8863 #[cfg(not(js_sys_unstable_apis))]
8864 #[wasm_bindgen(method, js_class = "String")]
8865 pub fn concat(this: &JsString, string_2: &JsValue) -> JsString;
8866
8867 /// The `concat()` method concatenates the string arguments to the calling
8868 /// string and returns a new string.
8869 ///
8870 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/concat)
8871 #[cfg(js_sys_unstable_apis)]
8872 #[wasm_bindgen(method, js_class = "String")]
8873 pub fn concat(this: &JsString, string: &JsString) -> JsString;
8874
8875 /// The `concat()` method concatenates the string arguments to the calling
8876 /// string and returns a new string.
8877 ///
8878 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/concat)
8879 #[wasm_bindgen(method, js_class = "String")]
8880 pub fn concat_many(this: &JsString, strings: &[JsString]) -> JsString;
8881
8882 /// The `endsWith()` method determines whether a string ends with the characters of a
8883 /// specified string, returning true or false as appropriate.
8884 ///
8885 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith)
8886 #[cfg(not(js_sys_unstable_apis))]
8887 #[wasm_bindgen(method, js_class = "String", js_name = endsWith)]
8888 pub fn ends_with(this: &JsString, search_string: &str, length: i32) -> bool;
8889
8890 /// The `endsWith()` method determines whether a string ends with the characters of a
8891 /// specified string, returning true or false as appropriate.
8892 ///
8893 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith)
8894 #[cfg(js_sys_unstable_apis)]
8895 #[wasm_bindgen(method, js_class = "String", js_name = endsWith)]
8896 pub fn ends_with(this: &JsString, search_string: &str) -> bool;
8897
8898 /// The static `String.fromCharCode()` method returns a string created from
8899 /// the specified sequence of UTF-16 code units.
8900 ///
8901 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
8902 ///
8903 /// # Notes
8904 ///
8905 /// There are a few bindings to `from_char_code` in `js-sys`: `from_char_code1`, `from_char_code2`, etc...
8906 /// with different arities.
8907 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode, variadic)]
8908 pub fn from_char_code(char_codes: &[u16]) -> JsString;
8909
8910 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
8911 #[cfg(not(js_sys_unstable_apis))]
8912 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
8913 pub fn from_char_code1(a: u32) -> JsString;
8914
8915 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
8916 #[cfg(js_sys_unstable_apis)]
8917 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
8918 pub fn from_char_code1(a: u16) -> JsString;
8919
8920 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
8921 #[cfg(not(js_sys_unstable_apis))]
8922 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
8923 pub fn from_char_code2(a: u32, b: u32) -> JsString;
8924
8925 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
8926 #[cfg(js_sys_unstable_apis)]
8927 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
8928 pub fn from_char_code2(a: u16, b: u16) -> JsString;
8929
8930 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
8931 #[cfg(not(js_sys_unstable_apis))]
8932 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
8933 pub fn from_char_code3(a: u32, b: u32, c: u32) -> JsString;
8934
8935 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
8936 #[cfg(js_sys_unstable_apis)]
8937 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
8938 pub fn from_char_code3(a: u16, b: u16, c: u16) -> JsString;
8939
8940 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
8941 #[cfg(not(js_sys_unstable_apis))]
8942 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
8943 pub fn from_char_code4(a: u32, b: u32, c: u32, d: u32) -> JsString;
8944
8945 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
8946 #[cfg(js_sys_unstable_apis)]
8947 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
8948 pub fn from_char_code4(a: u16, b: u16, c: u16, d: u16) -> JsString;
8949
8950 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
8951 #[cfg(not(js_sys_unstable_apis))]
8952 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
8953 pub fn from_char_code5(a: u32, b: u32, c: u32, d: u32, e: u32) -> JsString;
8954
8955 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
8956 #[cfg(js_sys_unstable_apis)]
8957 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
8958 pub fn from_char_code5(a: u16, b: u16, c: u16, d: u16, e: u16) -> JsString;
8959
8960 /// The static `String.fromCodePoint()` method returns a string created by
8961 /// using the specified sequence of code points.
8962 ///
8963 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
8964 ///
8965 /// # Exceptions
8966 ///
8967 /// A RangeError is thrown if an invalid Unicode code point is given
8968 ///
8969 /// # Notes
8970 ///
8971 /// There are a few bindings to `from_code_point` in `js-sys`: `from_code_point1`, `from_code_point2`, etc...
8972 /// with different arities.
8973 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint, variadic)]
8974 pub fn from_code_point(code_points: &[u32]) -> Result<JsString, JsValue>;
8975
8976 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
8977 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
8978 pub fn from_code_point1(a: u32) -> Result<JsString, JsValue>;
8979
8980 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
8981 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
8982 pub fn from_code_point2(a: u32, b: u32) -> Result<JsString, JsValue>;
8983
8984 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
8985 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
8986 pub fn from_code_point3(a: u32, b: u32, c: u32) -> Result<JsString, JsValue>;
8987
8988 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
8989 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
8990 pub fn from_code_point4(a: u32, b: u32, c: u32, d: u32) -> Result<JsString, JsValue>;
8991
8992 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
8993 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
8994 pub fn from_code_point5(a: u32, b: u32, c: u32, d: u32, e: u32) -> Result<JsString, JsValue>;
8995
8996 /// The `includes()` method determines whether one string may be found
8997 /// within another string, returning true or false as appropriate.
8998 ///
8999 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes)
9000 #[wasm_bindgen(method, js_class = "String")]
9001 pub fn includes(this: &JsString, search_string: &str, position: i32) -> bool;
9002
9003 /// The `indexOf()` method returns the index within the calling String
9004 /// object of the first occurrence of the specified value, starting the
9005 /// search at fromIndex. Returns -1 if the value is not found.
9006 ///
9007 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf)
9008 #[wasm_bindgen(method, js_class = "String", js_name = indexOf)]
9009 pub fn index_of(this: &JsString, search_value: &str, from_index: i32) -> i32;
9010
9011 /// The `lastIndexOf()` method returns the index within the calling String
9012 /// object of the last occurrence of the specified value, searching
9013 /// backwards from fromIndex. Returns -1 if the value is not found.
9014 ///
9015 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/lastIndexOf)
9016 #[wasm_bindgen(method, js_class = "String", js_name = lastIndexOf)]
9017 pub fn last_index_of(this: &JsString, search_value: &str, from_index: i32) -> i32;
9018
9019 /// The `localeCompare()` method returns a number indicating whether
9020 /// a reference string comes before or after or is the same as
9021 /// the given string in sort order.
9022 ///
9023 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare)
9024 #[cfg(not(js_sys_unstable_apis))]
9025 #[wasm_bindgen(method, js_class = "String", js_name = localeCompare)]
9026 pub fn locale_compare(
9027 this: &JsString,
9028 compare_string: &str,
9029 locales: &Array,
9030 options: &Object,
9031 ) -> i32;
9032
9033 /// The `localeCompare()` method returns a number indicating whether
9034 /// a reference string comes before or after or is the same as
9035 /// the given string in sort order.
9036 ///
9037 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare)
9038 #[cfg(js_sys_unstable_apis)]
9039 #[wasm_bindgen(method, js_class = "String", js_name = localeCompare)]
9040 pub fn locale_compare(
9041 this: &JsString,
9042 compare_string: &str,
9043 locales: &[JsString],
9044 options: &Intl::CollatorOptions,
9045 ) -> i32;
9046
9047 /// The `match()` method retrieves the matches when matching a string against a regular expression.
9048 ///
9049 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match)
9050 #[wasm_bindgen(method, js_class = "String", js_name = match)]
9051 pub fn match_(this: &JsString, pattern: &RegExp) -> Option<Object>;
9052
9053 /// The `match_all()` method is similar to `match()`, but gives an iterator of `exec()` arrays, which preserve capture groups.
9054 ///
9055 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/matchAll)
9056 #[cfg(not(js_sys_unstable_apis))]
9057 #[wasm_bindgen(method, js_class = "String", js_name = matchAll)]
9058 pub fn match_all(this: &JsString, pattern: &RegExp) -> Iterator;
9059
9060 /// The `match_all()` method is similar to `match()`, but gives an iterator of `exec()` arrays, which preserve capture groups.
9061 ///
9062 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/matchAll)
9063 #[cfg(js_sys_unstable_apis)]
9064 #[wasm_bindgen(method, js_class = "String", js_name = matchAll)]
9065 pub fn match_all(this: &JsString, pattern: &RegExp) -> Iterator<RegExpMatchArray>;
9066
9067 /// The `normalize()` method returns the Unicode Normalization Form
9068 /// of a given string (if the value isn't a string, it will be converted to one first).
9069 ///
9070 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize)
9071 #[wasm_bindgen(method, js_class = "String")]
9072 pub fn normalize(this: &JsString, form: &str) -> JsString;
9073
9074 /// The `padEnd()` method pads the current string with a given string
9075 /// (repeated, if needed) so that the resulting string reaches a given
9076 /// length. The padding is applied from the end (right) of the current
9077 /// string.
9078 ///
9079 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padEnd)
9080 #[wasm_bindgen(method, js_class = "String", js_name = padEnd)]
9081 pub fn pad_end(this: &JsString, target_length: u32, pad_string: &str) -> JsString;
9082
9083 /// The `padStart()` method pads the current string with another string
9084 /// (repeated, if needed) so that the resulting string reaches the given
9085 /// length. The padding is applied from the start (left) of the current
9086 /// string.
9087 ///
9088 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padStart)
9089 #[wasm_bindgen(method, js_class = "String", js_name = padStart)]
9090 pub fn pad_start(this: &JsString, target_length: u32, pad_string: &str) -> JsString;
9091
9092 /// The `repeat()` method constructs and returns a new string which contains the specified
9093 /// number of copies of the string on which it was called, concatenated together.
9094 ///
9095 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat)
9096 #[wasm_bindgen(method, js_class = "String")]
9097 pub fn repeat(this: &JsString, count: i32) -> JsString;
9098
9099 /// The `replace()` method returns a new string with some or all matches of a pattern
9100 /// replaced by a replacement. The pattern can be a string or a RegExp, and
9101 /// the replacement can be a string or a function to be called for each match.
9102 ///
9103 /// Note: The original string will remain unchanged.
9104 ///
9105 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
9106 #[wasm_bindgen(method, js_class = "String")]
9107 pub fn replace(this: &JsString, pattern: &str, replacement: &str) -> JsString;
9108
9109 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
9110 #[cfg(not(js_sys_unstable_apis))]
9111 #[wasm_bindgen(method, js_class = "String", js_name = replace)]
9112 pub fn replace_with_function(
9113 this: &JsString,
9114 pattern: &str,
9115 replacement: &Function,
9116 ) -> JsString;
9117
9118 /// The replacer function signature is `(match, offset, string) -> replacement`
9119 /// for patterns without capture groups, or `(match, p1, p2, ..., pN, offset, string, groups) -> replacement`
9120 /// when capture groups are present.
9121 ///
9122 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
9123 #[cfg(js_sys_unstable_apis)]
9124 #[wasm_bindgen(method, js_class = "String", js_name = replace)]
9125 pub fn replace_with_function(
9126 this: &JsString,
9127 pattern: &str,
9128 replacement: &Function<fn(JsString) -> JsString>,
9129 ) -> JsString;
9130
9131 #[wasm_bindgen(method, js_class = "String", js_name = replace)]
9132 pub fn replace_by_pattern(this: &JsString, pattern: &RegExp, replacement: &str) -> JsString;
9133
9134 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
9135 #[cfg(not(js_sys_unstable_apis))]
9136 #[wasm_bindgen(method, js_class = "String", js_name = replace)]
9137 pub fn replace_by_pattern_with_function(
9138 this: &JsString,
9139 pattern: &RegExp,
9140 replacement: &Function,
9141 ) -> JsString;
9142
9143 /// The replacer function signature is `(match, offset, string) -> replacement`
9144 /// for patterns without capture groups, or `(match, p1, p2, ..., pN, offset, string, groups) -> replacement`
9145 /// when capture groups are present.
9146 ///
9147 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
9148 #[cfg(js_sys_unstable_apis)]
9149 #[wasm_bindgen(method, js_class = "String", js_name = replace)]
9150 pub fn replace_by_pattern_with_function(
9151 this: &JsString,
9152 pattern: &RegExp,
9153 replacement: &Function<fn(JsString) -> JsString>,
9154 ) -> JsString;
9155
9156 /// The `replace_all()` method returns a new string with all matches of a pattern
9157 /// replaced by a replacement. The pattern can be a string or a global RegExp, and
9158 /// the replacement can be a string or a function to be called for each match.
9159 ///
9160 /// Note: The original string will remain unchanged.
9161 ///
9162 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)
9163 #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
9164 pub fn replace_all(this: &JsString, pattern: &str, replacement: &str) -> JsString;
9165
9166 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)
9167 #[cfg(not(js_sys_unstable_apis))]
9168 #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
9169 pub fn replace_all_with_function(
9170 this: &JsString,
9171 pattern: &str,
9172 replacement: &Function,
9173 ) -> JsString;
9174
9175 /// The replacer function signature is `(match, offset, string) -> replacement`
9176 /// for patterns without capture groups, or `(match, p1, p2, ..., pN, offset, string, groups) -> replacement`
9177 /// when capture groups are present.
9178 ///
9179 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)
9180 #[cfg(js_sys_unstable_apis)]
9181 #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
9182 pub fn replace_all_with_function(
9183 this: &JsString,
9184 pattern: &str,
9185 replacement: &Function<fn(JsString) -> JsString>,
9186 ) -> JsString;
9187
9188 #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
9189 pub fn replace_all_by_pattern(this: &JsString, pattern: &RegExp, replacement: &str)
9190 -> JsString;
9191
9192 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)
9193 #[cfg(not(js_sys_unstable_apis))]
9194 #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
9195 pub fn replace_all_by_pattern_with_function(
9196 this: &JsString,
9197 pattern: &RegExp,
9198 replacement: &Function,
9199 ) -> JsString;
9200
9201 /// The replacer function signature is `(match, offset, string) -> replacement`
9202 /// for patterns without capture groups, or `(match, p1, p2, ..., pN, offset, string, groups) -> replacement`
9203 /// when capture groups are present.
9204 ///
9205 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)
9206 #[cfg(js_sys_unstable_apis)]
9207 #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
9208 pub fn replace_all_by_pattern_with_function(
9209 this: &JsString,
9210 pattern: &RegExp,
9211 replacement: &Function<fn(JsString) -> JsString>,
9212 ) -> JsString;
9213
9214 /// The `search()` method executes a search for a match between
9215 /// a regular expression and this String object.
9216 ///
9217 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/search)
9218 #[wasm_bindgen(method, js_class = "String")]
9219 pub fn search(this: &JsString, pattern: &RegExp) -> i32;
9220
9221 /// The `slice()` method extracts a section of a string and returns it as a
9222 /// new string, without modifying the original string.
9223 ///
9224 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice)
9225 #[wasm_bindgen(method, js_class = "String")]
9226 pub fn slice(this: &JsString, start: u32, end: u32) -> JsString;
9227
9228 /// The `split()` method splits a String object into an array of strings by separating the string
9229 /// into substrings, using a specified separator string to determine where to make each split.
9230 ///
9231 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)
9232 #[wasm_bindgen(method, js_class = "String")]
9233 pub fn split(this: &JsString, separator: &str) -> Array;
9234
9235 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)
9236 #[wasm_bindgen(method, js_class = "String", js_name = split)]
9237 pub fn split_limit(this: &JsString, separator: &str, limit: u32) -> Array;
9238
9239 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)
9240 #[wasm_bindgen(method, js_class = "String", js_name = split)]
9241 pub fn split_by_pattern(this: &JsString, pattern: &RegExp) -> Array;
9242
9243 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)
9244 #[wasm_bindgen(method, js_class = "String", js_name = split)]
9245 pub fn split_by_pattern_limit(this: &JsString, pattern: &RegExp, limit: u32) -> Array;
9246
9247 /// The `startsWith()` method determines whether a string begins with the
9248 /// characters of a specified string, returning true or false as
9249 /// appropriate.
9250 ///
9251 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith)
9252 #[wasm_bindgen(method, js_class = "String", js_name = startsWith)]
9253 pub fn starts_with(this: &JsString, search_string: &str, position: u32) -> bool;
9254
9255 /// The `substring()` method returns the part of the string between the
9256 /// start and end indexes, or to the end of the string.
9257 ///
9258 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring)
9259 #[wasm_bindgen(method, js_class = "String")]
9260 pub fn substring(this: &JsString, index_start: u32, index_end: u32) -> JsString;
9261
9262 /// The `substr()` method returns the part of a string between
9263 /// the start index and a number of characters after it.
9264 ///
9265 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr)
9266 #[wasm_bindgen(method, js_class = "String")]
9267 pub fn substr(this: &JsString, start: i32, length: i32) -> JsString;
9268
9269 /// The `toLocaleLowerCase()` method returns the calling string value converted to lower case,
9270 /// according to any locale-specific case mappings.
9271 ///
9272 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLocaleLowerCase)
9273 #[wasm_bindgen(method, js_class = "String", js_name = toLocaleLowerCase)]
9274 pub fn to_locale_lower_case(this: &JsString, locale: Option<&str>) -> JsString;
9275
9276 /// The `toLocaleUpperCase()` method returns the calling string value converted to upper case,
9277 /// according to any locale-specific case mappings.
9278 ///
9279 /// [MDN documentation](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/String/toLocaleUpperCase)
9280 #[wasm_bindgen(method, js_class = "String", js_name = toLocaleUpperCase)]
9281 pub fn to_locale_upper_case(this: &JsString, locale: Option<&str>) -> JsString;
9282
9283 /// The `toLowerCase()` method returns the calling string value
9284 /// converted to lower case.
9285 ///
9286 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLowerCase)
9287 #[wasm_bindgen(method, js_class = "String", js_name = toLowerCase)]
9288 pub fn to_lower_case(this: &JsString) -> JsString;
9289
9290 /// The `toString()` method returns a string representing the specified
9291 /// object.
9292 ///
9293 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toString)
9294 #[cfg(not(js_sys_unstable_apis))]
9295 #[wasm_bindgen(method, js_class = "String", js_name = toString)]
9296 pub fn to_string(this: &JsString) -> JsString;
9297
9298 /// The `toUpperCase()` method returns the calling string value converted to
9299 /// uppercase (the value will be converted to a string if it isn't one).
9300 ///
9301 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase)
9302 #[wasm_bindgen(method, js_class = "String", js_name = toUpperCase)]
9303 pub fn to_upper_case(this: &JsString) -> JsString;
9304
9305 /// The `trim()` method removes whitespace from both ends of a string.
9306 /// Whitespace in this context is all the whitespace characters (space, tab,
9307 /// no-break space, etc.) and all the line terminator characters (LF, CR,
9308 /// etc.).
9309 ///
9310 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trim)
9311 #[wasm_bindgen(method, js_class = "String")]
9312 pub fn trim(this: &JsString) -> JsString;
9313
9314 /// The `trimEnd()` method removes whitespace from the end of a string.
9315 /// `trimRight()` is an alias of this method.
9316 ///
9317 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimEnd)
9318 #[wasm_bindgen(method, js_class = "String", js_name = trimEnd)]
9319 pub fn trim_end(this: &JsString) -> JsString;
9320
9321 /// The `trimEnd()` method removes whitespace from the end of a string.
9322 /// `trimRight()` is an alias of this method.
9323 ///
9324 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimEnd)
9325 #[wasm_bindgen(method, js_class = "String", js_name = trimRight)]
9326 pub fn trim_right(this: &JsString) -> JsString;
9327
9328 /// The `trimStart()` method removes whitespace from the beginning of a
9329 /// string. `trimLeft()` is an alias of this method.
9330 ///
9331 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimStart)
9332 #[wasm_bindgen(method, js_class = "String", js_name = trimStart)]
9333 pub fn trim_start(this: &JsString) -> JsString;
9334
9335 /// The `trimStart()` method removes whitespace from the beginning of a
9336 /// string. `trimLeft()` is an alias of this method.
9337 ///
9338 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimStart)
9339 #[wasm_bindgen(method, js_class = "String", js_name = trimLeft)]
9340 pub fn trim_left(this: &JsString) -> JsString;
9341
9342 /// The `valueOf()` method returns the primitive value of a `String` object.
9343 ///
9344 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/valueOf)
9345 #[wasm_bindgen(method, js_class = "String", js_name = valueOf)]
9346 pub fn value_of(this: &JsString) -> JsString;
9347
9348 /// The static `raw()` method is a tag function of template literals,
9349 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9350 ///
9351 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9352 #[wasm_bindgen(catch, variadic, static_method_of = JsString, js_class = "String")]
9353 pub fn raw(call_site: &Object, substitutions: &Array) -> Result<JsString, JsValue>;
9354
9355 /// The static `raw()` method is a tag function of template literals,
9356 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9357 ///
9358 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9359 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9360 pub fn raw_0(call_site: &Object) -> Result<JsString, JsValue>;
9361
9362 /// The static `raw()` method is a tag function of template literals,
9363 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9364 ///
9365 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9366 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9367 pub fn raw_1(call_site: &Object, substitutions_1: &str) -> Result<JsString, JsValue>;
9368
9369 /// The static `raw()` method is a tag function of template literals,
9370 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9371 ///
9372 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9373 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9374 pub fn raw_2(
9375 call_site: &Object,
9376 substitutions1: &str,
9377 substitutions2: &str,
9378 ) -> Result<JsString, JsValue>;
9379
9380 /// The static `raw()` method is a tag function of template literals,
9381 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9382 ///
9383 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9384 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9385 pub fn raw_3(
9386 call_site: &Object,
9387 substitutions1: &str,
9388 substitutions2: &str,
9389 substitutions3: &str,
9390 ) -> Result<JsString, JsValue>;
9391
9392 /// The static `raw()` method is a tag function of template literals,
9393 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9394 ///
9395 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9396 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9397 pub fn raw_4(
9398 call_site: &Object,
9399 substitutions1: &str,
9400 substitutions2: &str,
9401 substitutions3: &str,
9402 substitutions4: &str,
9403 ) -> Result<JsString, JsValue>;
9404
9405 /// The static `raw()` method is a tag function of template literals,
9406 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9407 ///
9408 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9409 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9410 pub fn raw_5(
9411 call_site: &Object,
9412 substitutions1: &str,
9413 substitutions2: &str,
9414 substitutions3: &str,
9415 substitutions4: &str,
9416 substitutions5: &str,
9417 ) -> Result<JsString, JsValue>;
9418
9419 /// The static `raw()` method is a tag function of template literals,
9420 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9421 ///
9422 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9423 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9424 pub fn raw_6(
9425 call_site: &Object,
9426 substitutions1: &str,
9427 substitutions2: &str,
9428 substitutions3: &str,
9429 substitutions4: &str,
9430 substitutions5: &str,
9431 substitutions6: &str,
9432 ) -> Result<JsString, JsValue>;
9433
9434 /// The static `raw()` method is a tag function of template literals,
9435 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
9436 ///
9437 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
9438 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
9439 pub fn raw_7(
9440 call_site: &Object,
9441 substitutions1: &str,
9442 substitutions2: &str,
9443 substitutions3: &str,
9444 substitutions4: &str,
9445 substitutions5: &str,
9446 substitutions6: &str,
9447 substitutions7: &str,
9448 ) -> Result<JsString, JsValue>;
9449}
9450
9451// These upcasts are non-castable due to the constraints on the function
9452// but the UpcastFrom covariance must still extend through closure types.
9453// (impl UpcastFrom really just means CovariantGeneric relation)
9454impl UpcastFrom<String> for JsString {}
9455impl UpcastFrom<JsString> for String {}
9456
9457impl UpcastFrom<&str> for JsString {}
9458impl UpcastFrom<JsString> for &str {}
9459
9460impl UpcastFrom<char> for JsString {}
9461impl UpcastFrom<JsString> for char {}
9462
9463impl JsString {
9464 /// Returns the `JsString` value of this JS value if it's an instance of a
9465 /// string.
9466 ///
9467 /// If this JS value is not an instance of a string then this returns
9468 /// `None`.
9469 #[cfg(not(js_sys_unstable_apis))]
9470 #[deprecated(note = "recommended to use dyn_ref instead which is now equivalent")]
9471 pub fn try_from(val: &JsValue) -> Option<&JsString> {
9472 val.dyn_ref()
9473 }
9474
9475 /// Returns whether this string is a valid UTF-16 string.
9476 ///
9477 /// This is useful for learning whether `String::from(..)` will return a
9478 /// lossless representation of the JS string. If this string contains
9479 /// unpaired surrogates then `String::from` will succeed but it will be a
9480 /// lossy representation of the JS string because unpaired surrogates will
9481 /// become replacement characters.
9482 ///
9483 /// If this function returns `false` then to get a lossless representation
9484 /// of the string you'll need to manually use the `iter` method (or the
9485 /// `char_code_at` accessor) to view the raw character codes.
9486 ///
9487 /// For more information, see the documentation on [JS strings vs Rust
9488 /// strings][docs]
9489 ///
9490 /// [docs]: https://wasm-bindgen.github.io/wasm-bindgen/reference/types/str.html
9491 pub fn is_valid_utf16(&self) -> bool {
9492 core::char::decode_utf16(self.iter()).all(|i| i.is_ok())
9493 }
9494
9495 /// Returns an iterator over the `u16` character codes that make up this JS
9496 /// string.
9497 ///
9498 /// This method will call `char_code_at` for each code in this JS string,
9499 /// returning an iterator of the codes in sequence.
9500 pub fn iter(
9501 &self,
9502 ) -> impl ExactSizeIterator<Item = u16> + DoubleEndedIterator<Item = u16> + '_ {
9503 (0..self.length()).map(move |i| self.char_code_at(i) as u16)
9504 }
9505
9506 /// If this string consists of a single Unicode code point, then this method
9507 /// converts it into a Rust `char` without doing any allocations.
9508 ///
9509 /// If this JS value is not a valid UTF-8 or consists of more than a single
9510 /// codepoint, then this returns `None`.
9511 ///
9512 /// Note that a single Unicode code point might be represented as more than
9513 /// one code unit on the JavaScript side. For example, a JavaScript string
9514 /// `"\uD801\uDC37"` is actually a single Unicode code point U+10437 which
9515 /// corresponds to a character '𐐷'.
9516 pub fn as_char(&self) -> Option<char> {
9517 let len = self.length();
9518
9519 if len == 0 || len > 2 {
9520 return None;
9521 }
9522
9523 #[cfg(not(js_sys_unstable_apis))]
9524 let cp = self.code_point_at(0).as_f64().unwrap_throw() as u32;
9525 #[cfg(js_sys_unstable_apis)]
9526 let cp = self.code_point_at(0)?;
9527
9528 let c = core::char::from_u32(cp)?;
9529
9530 if c.len_utf16() as u32 == len {
9531 Some(c)
9532 } else {
9533 None
9534 }
9535 }
9536}
9537
9538impl PartialEq<str> for JsString {
9539 #[allow(clippy::cmp_owned)] // prevent infinite recursion
9540 fn eq(&self, other: &str) -> bool {
9541 String::from(self) == other
9542 }
9543}
9544
9545impl<'a> PartialEq<&'a str> for JsString {
9546 fn eq(&self, other: &&'a str) -> bool {
9547 <JsString as PartialEq<str>>::eq(self, other)
9548 }
9549}
9550
9551impl PartialEq<String> for JsString {
9552 fn eq(&self, other: &String) -> bool {
9553 <JsString as PartialEq<str>>::eq(self, other)
9554 }
9555}
9556
9557impl<'a> PartialEq<&'a String> for JsString {
9558 fn eq(&self, other: &&'a String) -> bool {
9559 <JsString as PartialEq<str>>::eq(self, other)
9560 }
9561}
9562
9563impl Default for JsString {
9564 fn default() -> Self {
9565 Self::from("")
9566 }
9567}
9568
9569impl<'a> From<&'a str> for JsString {
9570 fn from(s: &'a str) -> Self {
9571 JsString::unchecked_from_js(JsValue::from_str(s))
9572 }
9573}
9574
9575impl From<String> for JsString {
9576 fn from(s: String) -> Self {
9577 From::from(&*s)
9578 }
9579}
9580
9581impl From<char> for JsString {
9582 #[inline]
9583 fn from(c: char) -> Self {
9584 JsString::from_code_point1(c as u32).unwrap_throw()
9585 }
9586}
9587
9588impl<'a> From<&'a JsString> for String {
9589 fn from(s: &'a JsString) -> Self {
9590 s.obj.as_string().unwrap_throw()
9591 }
9592}
9593
9594impl From<JsString> for String {
9595 fn from(s: JsString) -> Self {
9596 From::from(&s)
9597 }
9598}
9599
9600impl fmt::Debug for JsString {
9601 #[inline]
9602 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9603 fmt::Debug::fmt(&String::from(self), f)
9604 }
9605}
9606
9607impl fmt::Display for JsString {
9608 #[inline]
9609 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9610 fmt::Display::fmt(&String::from(self), f)
9611 }
9612}
9613
9614impl str::FromStr for JsString {
9615 type Err = convert::Infallible;
9616 fn from_str(s: &str) -> Result<Self, Self::Err> {
9617 Ok(JsString::from(s))
9618 }
9619}
9620
9621// Symbol
9622#[wasm_bindgen]
9623extern "C" {
9624 #[wasm_bindgen(is_type_of = JsValue::is_symbol, typescript_type = "Symbol")]
9625 #[derive(Clone, Debug)]
9626 pub type Symbol;
9627
9628 /// The `Symbol.hasInstance` well-known symbol is used to determine
9629 /// if a constructor object recognizes an object as its instance.
9630 /// The `instanceof` operator's behavior can be customized by this symbol.
9631 ///
9632 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/hasInstance)
9633 #[wasm_bindgen(static_method_of = Symbol, getter, js_name = hasInstance)]
9634 pub fn has_instance() -> Symbol;
9635
9636 /// The `Symbol.isConcatSpreadable` well-known symbol is used to configure
9637 /// if an object should be flattened to its array elements when using the
9638 /// `Array.prototype.concat()` method.
9639 ///
9640 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/isConcatSpreadable)
9641 #[wasm_bindgen(static_method_of = Symbol, getter, js_name = isConcatSpreadable)]
9642 pub fn is_concat_spreadable() -> Symbol;
9643
9644 /// The `Symbol.asyncIterator` well-known symbol specifies the default AsyncIterator for an object.
9645 /// If this property is set on an object, it is an async iterable and can be used in a `for await...of` loop.
9646 ///
9647 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/asyncIterator)
9648 #[wasm_bindgen(static_method_of = Symbol, getter, js_name = asyncIterator)]
9649 pub fn async_iterator() -> Symbol;
9650
9651 /// The `Symbol.iterator` well-known symbol specifies the default iterator
9652 /// for an object. Used by `for...of`.
9653 ///
9654 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/iterator)
9655 #[wasm_bindgen(static_method_of = Symbol, getter)]
9656 pub fn iterator() -> Symbol;
9657
9658 /// The `Symbol.match` well-known symbol specifies the matching of a regular
9659 /// expression against a string. This function is called by the
9660 /// `String.prototype.match()` method.
9661 ///
9662 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/match)
9663 #[wasm_bindgen(static_method_of = Symbol, getter, js_name = match)]
9664 pub fn match_() -> Symbol;
9665
9666 /// The `Symbol.replace` well-known symbol specifies the method that
9667 /// replaces matched substrings of a string. This function is called by the
9668 /// `String.prototype.replace()` method.
9669 ///
9670 /// For more information, see `RegExp.prototype[@@replace]()` and
9671 /// `String.prototype.replace()`.
9672 ///
9673 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/replace)
9674 #[wasm_bindgen(static_method_of = Symbol, getter)]
9675 pub fn replace() -> Symbol;
9676
9677 /// The `Symbol.search` well-known symbol specifies the method that returns
9678 /// the index within a string that matches the regular expression. This
9679 /// function is called by the `String.prototype.search()` method.
9680 ///
9681 /// For more information, see `RegExp.prototype[@@search]()` and
9682 /// `String.prototype.search()`.
9683 ///
9684 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/search)
9685 #[wasm_bindgen(static_method_of = Symbol, getter)]
9686 pub fn search() -> Symbol;
9687
9688 /// The well-known symbol `Symbol.species` specifies a function-valued
9689 /// property that the constructor function uses to create derived objects.
9690 ///
9691 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/species)
9692 #[wasm_bindgen(static_method_of = Symbol, getter)]
9693 pub fn species() -> Symbol;
9694
9695 /// The `Symbol.split` well-known symbol specifies the method that splits a
9696 /// string at the indices that match a regular expression. This function is
9697 /// called by the `String.prototype.split()` method.
9698 ///
9699 /// For more information, see `RegExp.prototype[@@split]()` and
9700 /// `String.prototype.split()`.
9701 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/split)
9702 #[wasm_bindgen(static_method_of = Symbol, getter)]
9703 pub fn split() -> Symbol;
9704
9705 /// The `Symbol.toPrimitive` is a symbol that specifies a function valued
9706 /// property that is called to convert an object to a corresponding
9707 /// primitive value.
9708 ///
9709 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toPrimitive)
9710 #[wasm_bindgen(static_method_of = Symbol, getter, js_name = toPrimitive)]
9711 pub fn to_primitive() -> Symbol;
9712
9713 /// The `Symbol.toStringTag` well-known symbol is a string valued property
9714 /// that is used in the creation of the default string description of an
9715 /// object. It is accessed internally by the `Object.prototype.toString()`
9716 /// method.
9717 ///
9718 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toString)
9719 #[wasm_bindgen(static_method_of = Symbol, getter, js_name = toStringTag)]
9720 pub fn to_string_tag() -> Symbol;
9721
9722 /// The `Symbol.for(key)` method searches for existing symbols in a runtime-wide symbol registry with
9723 /// the given key and returns it if found.
9724 /// Otherwise a new symbol gets created in the global symbol registry with this key.
9725 ///
9726 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/for)
9727 #[wasm_bindgen(static_method_of = Symbol, js_name = for)]
9728 pub fn for_(key: &str) -> Symbol;
9729
9730 /// The `Symbol.keyFor(sym)` method retrieves a shared symbol key from the global symbol registry for the given symbol.
9731 ///
9732 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/keyFor)
9733 #[wasm_bindgen(static_method_of = Symbol, js_name = keyFor)]
9734 pub fn key_for(sym: &Symbol) -> JsValue;
9735
9736 // Next major: deprecate
9737 /// The `toString()` method returns a string representing the specified Symbol object.
9738 ///
9739 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toString)
9740 #[wasm_bindgen(method, js_name = toString)]
9741 pub fn to_string(this: &Symbol) -> JsString;
9742
9743 /// The `toString()` method returns a string representing the specified Symbol object.
9744 ///
9745 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toString)
9746 #[wasm_bindgen(method, js_name = toString)]
9747 pub fn to_js_string(this: &Symbol) -> JsString;
9748
9749 /// The `Symbol.unscopables` well-known symbol is used to specify an object
9750 /// value of whose own and inherited property names are excluded from the
9751 /// with environment bindings of the associated object.
9752 ///
9753 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/unscopables)
9754 #[wasm_bindgen(static_method_of = Symbol, getter)]
9755 pub fn unscopables() -> Symbol;
9756
9757 /// The `valueOf()` method returns the primitive value of a Symbol object.
9758 ///
9759 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/valueOf)
9760 #[wasm_bindgen(method, js_name = valueOf)]
9761 pub fn value_of(this: &Symbol) -> Symbol;
9762}
9763
9764#[allow(non_snake_case)]
9765pub mod Intl {
9766 use super::*;
9767
9768 // Intl
9769 #[wasm_bindgen]
9770 extern "C" {
9771 /// The `Intl.getCanonicalLocales()` method returns an array containing
9772 /// the canonical locale names. Duplicates will be omitted and elements
9773 /// will be validated as structurally valid language tags.
9774 ///
9775 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/getCanonicalLocales)
9776 #[cfg(not(js_sys_unstable_apis))]
9777 #[wasm_bindgen(js_name = getCanonicalLocales, js_namespace = Intl)]
9778 pub fn get_canonical_locales(s: &JsValue) -> Array;
9779
9780 /// The `Intl.getCanonicalLocales()` method returns an array containing
9781 /// the canonical locale names. Duplicates will be omitted and elements
9782 /// will be validated as structurally valid language tags.
9783 ///
9784 /// Throws a `RangeError` if any of the strings are not valid locale identifiers.
9785 ///
9786 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/getCanonicalLocales)
9787 #[cfg(js_sys_unstable_apis)]
9788 #[wasm_bindgen(js_name = getCanonicalLocales, js_namespace = Intl, catch)]
9789 pub fn get_canonical_locales(s: &[JsString]) -> Result<Array<JsString>, JsValue>;
9790
9791 /// The `Intl.supportedValuesOf()` method returns an array containing the
9792 /// supported calendar, collation, currency, numbering system, or unit values
9793 /// supported by the implementation.
9794 ///
9795 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/supportedValuesOf)
9796 #[wasm_bindgen(js_name = supportedValuesOf, js_namespace = Intl)]
9797 pub fn supported_values_of(key: SupportedValuesKey) -> Array<JsString>;
9798 }
9799
9800 // Intl string enums
9801
9802 /// Key for `Intl.supportedValuesOf()`.
9803 #[wasm_bindgen]
9804 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9805 pub enum SupportedValuesKey {
9806 Calendar = "calendar",
9807 Collation = "collation",
9808 Currency = "currency",
9809 NumberingSystem = "numberingSystem",
9810 TimeZone = "timeZone",
9811 Unit = "unit",
9812 }
9813
9814 /// Locale matching algorithm for Intl constructors.
9815 #[wasm_bindgen]
9816 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9817 pub enum LocaleMatcher {
9818 Lookup = "lookup",
9819 BestFit = "best fit",
9820 }
9821
9822 /// Usage for `Intl.Collator`.
9823 #[wasm_bindgen]
9824 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9825 pub enum CollatorUsage {
9826 Sort = "sort",
9827 Search = "search",
9828 }
9829
9830 /// Sensitivity for `Intl.Collator`.
9831 #[wasm_bindgen]
9832 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9833 pub enum CollatorSensitivity {
9834 Base = "base",
9835 Accent = "accent",
9836 Case = "case",
9837 Variant = "variant",
9838 }
9839
9840 /// Case first option for `Intl.Collator`.
9841 #[wasm_bindgen]
9842 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9843 pub enum CollatorCaseFirst {
9844 Upper = "upper",
9845 Lower = "lower",
9846 False = "false",
9847 }
9848
9849 /// Style for `Intl.NumberFormat`.
9850 #[wasm_bindgen]
9851 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9852 pub enum NumberFormatStyle {
9853 Decimal = "decimal",
9854 Currency = "currency",
9855 Percent = "percent",
9856 Unit = "unit",
9857 }
9858
9859 /// Currency display for `Intl.NumberFormat`.
9860 #[wasm_bindgen]
9861 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9862 pub enum CurrencyDisplay {
9863 Code = "code",
9864 Symbol = "symbol",
9865 NarrowSymbol = "narrowSymbol",
9866 Name = "name",
9867 }
9868
9869 /// Currency sign for `Intl.NumberFormat`.
9870 #[wasm_bindgen]
9871 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9872 pub enum CurrencySign {
9873 Standard = "standard",
9874 Accounting = "accounting",
9875 }
9876
9877 /// Unit display for `Intl.NumberFormat`.
9878 #[wasm_bindgen]
9879 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9880 pub enum UnitDisplay {
9881 Short = "short",
9882 Narrow = "narrow",
9883 Long = "long",
9884 }
9885
9886 /// Notation for `Intl.NumberFormat`.
9887 #[wasm_bindgen]
9888 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9889 pub enum NumberFormatNotation {
9890 Standard = "standard",
9891 Scientific = "scientific",
9892 Engineering = "engineering",
9893 Compact = "compact",
9894 }
9895
9896 /// Compact display for `Intl.NumberFormat`.
9897 #[wasm_bindgen]
9898 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9899 pub enum CompactDisplay {
9900 Short = "short",
9901 Long = "long",
9902 }
9903
9904 /// Sign display for `Intl.NumberFormat`.
9905 #[wasm_bindgen]
9906 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9907 pub enum SignDisplay {
9908 Auto = "auto",
9909 Never = "never",
9910 Always = "always",
9911 ExceptZero = "exceptZero",
9912 }
9913
9914 /// Rounding mode for `Intl.NumberFormat`.
9915 #[wasm_bindgen]
9916 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9917 pub enum RoundingMode {
9918 Ceil = "ceil",
9919 Floor = "floor",
9920 Expand = "expand",
9921 Trunc = "trunc",
9922 HalfCeil = "halfCeil",
9923 HalfFloor = "halfFloor",
9924 HalfExpand = "halfExpand",
9925 HalfTrunc = "halfTrunc",
9926 HalfEven = "halfEven",
9927 }
9928
9929 /// Rounding priority for `Intl.NumberFormat`.
9930 #[wasm_bindgen]
9931 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9932 pub enum RoundingPriority {
9933 Auto = "auto",
9934 MorePrecision = "morePrecision",
9935 LessPrecision = "lessPrecision",
9936 }
9937
9938 /// Trailing zero display for `Intl.NumberFormat`.
9939 #[wasm_bindgen]
9940 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9941 pub enum TrailingZeroDisplay {
9942 Auto = "auto",
9943 StripIfInteger = "stripIfInteger",
9944 }
9945
9946 /// Use grouping option for `Intl.NumberFormat`.
9947 ///
9948 /// Determines whether to use grouping separators, such as thousands
9949 /// separators or thousand/lakh/crore separators.
9950 ///
9951 /// The default is `Min2` if notation is "compact", and `Auto` otherwise.
9952 ///
9953 /// Note: The string values `"true"` and `"false"` are accepted by JavaScript
9954 /// but are always converted to the default value. Use `True` and `False`
9955 /// variants for the boolean behavior.
9956 ///
9957 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#usegrouping)
9958 #[wasm_bindgen]
9959 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9960 pub enum UseGrouping {
9961 /// Display grouping separators even if the locale prefers otherwise.
9962 Always = "always",
9963 /// Display grouping separators based on the locale preference,
9964 /// which may also be dependent on the currency.
9965 Auto = "auto",
9966 /// Display grouping separators when there are at least 2 digits in a group.
9967 Min2 = "min2",
9968 /// Same as `Always`. Display grouping separators even if the locale prefers otherwise.
9969 True = "true",
9970 /// Display no grouping separators.
9971 False = "false",
9972 }
9973
9974 /// Date/time style for `Intl.DateTimeFormat`.
9975 #[wasm_bindgen]
9976 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9977 pub enum DateTimeStyle {
9978 Full = "full",
9979 Long = "long",
9980 Medium = "medium",
9981 Short = "short",
9982 }
9983
9984 /// Hour cycle for `Intl.DateTimeFormat`.
9985 #[wasm_bindgen]
9986 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9987 pub enum HourCycle {
9988 H11 = "h11",
9989 H12 = "h12",
9990 H23 = "h23",
9991 H24 = "h24",
9992 }
9993
9994 /// Weekday format for `Intl.DateTimeFormat`.
9995 #[wasm_bindgen]
9996 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
9997 pub enum WeekdayFormat {
9998 Narrow = "narrow",
9999 Short = "short",
10000 Long = "long",
10001 }
10002
10003 /// Era format for `Intl.DateTimeFormat`.
10004 #[wasm_bindgen]
10005 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10006 pub enum EraFormat {
10007 Narrow = "narrow",
10008 Short = "short",
10009 Long = "long",
10010 }
10011
10012 /// Year format for `Intl.DateTimeFormat`.
10013 #[wasm_bindgen]
10014 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10015 pub enum YearFormat {
10016 Numeric = "numeric",
10017 TwoDigit = "2-digit",
10018 }
10019
10020 /// Month format for `Intl.DateTimeFormat`.
10021 #[wasm_bindgen]
10022 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10023 pub enum MonthFormat {
10024 #[wasm_bindgen]
10025 Numeric = "numeric",
10026 #[wasm_bindgen]
10027 TwoDigit = "2-digit",
10028 #[wasm_bindgen]
10029 Narrow = "narrow",
10030 #[wasm_bindgen]
10031 Short = "short",
10032 #[wasm_bindgen]
10033 Long = "long",
10034 }
10035
10036 /// Day format for `Intl.DateTimeFormat`.
10037 #[wasm_bindgen]
10038 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10039 pub enum DayFormat {
10040 #[wasm_bindgen]
10041 Numeric = "numeric",
10042 #[wasm_bindgen]
10043 TwoDigit = "2-digit",
10044 }
10045
10046 /// Hour/minute/second format for `Intl.DateTimeFormat`.
10047 #[wasm_bindgen]
10048 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10049 pub enum NumericFormat {
10050 #[wasm_bindgen]
10051 Numeric = "numeric",
10052 #[wasm_bindgen]
10053 TwoDigit = "2-digit",
10054 }
10055
10056 /// Time zone name format for `Intl.DateTimeFormat`.
10057 #[wasm_bindgen]
10058 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10059 pub enum TimeZoneNameFormat {
10060 Short = "short",
10061 Long = "long",
10062 ShortOffset = "shortOffset",
10063 LongOffset = "longOffset",
10064 ShortGeneric = "shortGeneric",
10065 LongGeneric = "longGeneric",
10066 }
10067
10068 /// Day period format for `Intl.DateTimeFormat`.
10069 #[wasm_bindgen]
10070 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10071 pub enum DayPeriodFormat {
10072 Narrow = "narrow",
10073 Short = "short",
10074 Long = "long",
10075 }
10076
10077 /// Part type for `DateTimeFormat.formatToParts()`.
10078 #[wasm_bindgen]
10079 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10080 pub enum DateTimeFormatPartType {
10081 Day = "day",
10082 DayPeriod = "dayPeriod",
10083 Era = "era",
10084 FractionalSecond = "fractionalSecond",
10085 Hour = "hour",
10086 Literal = "literal",
10087 Minute = "minute",
10088 Month = "month",
10089 RelatedYear = "relatedYear",
10090 Second = "second",
10091 TimeZoneName = "timeZoneName",
10092 Weekday = "weekday",
10093 Year = "year",
10094 YearName = "yearName",
10095 }
10096
10097 /// Part type for `NumberFormat.formatToParts()`.
10098 #[wasm_bindgen]
10099 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10100 pub enum NumberFormatPartType {
10101 Compact = "compact",
10102 Currency = "currency",
10103 Decimal = "decimal",
10104 ExponentInteger = "exponentInteger",
10105 ExponentMinusSign = "exponentMinusSign",
10106 ExponentSeparator = "exponentSeparator",
10107 Fraction = "fraction",
10108 Group = "group",
10109 Infinity = "infinity",
10110 Integer = "integer",
10111 Literal = "literal",
10112 MinusSign = "minusSign",
10113 Nan = "nan",
10114 PercentSign = "percentSign",
10115 PlusSign = "plusSign",
10116 Unit = "unit",
10117 Unknown = "unknown",
10118 }
10119
10120 /// Type for `Intl.PluralRules` (cardinal or ordinal).
10121 #[wasm_bindgen]
10122 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10123 pub enum PluralRulesType {
10124 Cardinal = "cardinal",
10125 Ordinal = "ordinal",
10126 }
10127
10128 /// Plural category returned by `PluralRules.select()`.
10129 #[wasm_bindgen]
10130 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10131 pub enum PluralCategory {
10132 Zero = "zero",
10133 One = "one",
10134 Two = "two",
10135 Few = "few",
10136 Many = "many",
10137 Other = "other",
10138 }
10139
10140 /// Numeric option for `Intl.RelativeTimeFormat`.
10141 #[wasm_bindgen]
10142 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10143 pub enum RelativeTimeFormatNumeric {
10144 Always = "always",
10145 Auto = "auto",
10146 }
10147
10148 /// Style for `Intl.RelativeTimeFormat`.
10149 #[wasm_bindgen]
10150 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10151 pub enum RelativeTimeFormatStyle {
10152 Long = "long",
10153 Short = "short",
10154 Narrow = "narrow",
10155 }
10156
10157 /// Unit for `RelativeTimeFormat.format()`.
10158 #[wasm_bindgen]
10159 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10160 pub enum RelativeTimeFormatUnit {
10161 Year = "year",
10162 Years = "years",
10163 Quarter = "quarter",
10164 Quarters = "quarters",
10165 Month = "month",
10166 Months = "months",
10167 Week = "week",
10168 Weeks = "weeks",
10169 Day = "day",
10170 Days = "days",
10171 Hour = "hour",
10172 Hours = "hours",
10173 Minute = "minute",
10174 Minutes = "minutes",
10175 Second = "second",
10176 Seconds = "seconds",
10177 }
10178
10179 /// Part type for `RelativeTimeFormat.formatToParts()`.
10180 #[wasm_bindgen]
10181 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10182 pub enum RelativeTimeFormatPartType {
10183 Literal = "literal",
10184 Integer = "integer",
10185 Decimal = "decimal",
10186 Fraction = "fraction",
10187 }
10188
10189 /// Source indicator for range format parts.
10190 ///
10191 /// Indicates which part of the range (start, end, or shared) a formatted
10192 /// part belongs to when using `formatRangeToParts()`.
10193 ///
10194 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatRangeToParts#description)
10195 #[wasm_bindgen]
10196 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10197 pub enum RangeSource {
10198 /// The part is from the start of the range.
10199 StartRange = "startRange",
10200 /// The part is from the end of the range.
10201 EndRange = "endRange",
10202 /// The part is shared between start and end (e.g., a separator or common element).
10203 Shared = "shared",
10204 }
10205
10206 /// Type for `Intl.ListFormat`.
10207 #[wasm_bindgen]
10208 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10209 pub enum ListFormatType {
10210 /// For lists of standalone items (default).
10211 Conjunction = "conjunction",
10212 /// For lists representing alternatives.
10213 Disjunction = "disjunction",
10214 /// For lists of values with units.
10215 Unit = "unit",
10216 }
10217
10218 /// Style for `Intl.ListFormat`.
10219 #[wasm_bindgen]
10220 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10221 pub enum ListFormatStyle {
10222 /// "A, B, and C" (default).
10223 Long = "long",
10224 /// "A, B, C".
10225 Short = "short",
10226 /// "A B C".
10227 Narrow = "narrow",
10228 }
10229
10230 /// Part type for `Intl.ListFormat.formatToParts()`.
10231 #[wasm_bindgen]
10232 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10233 pub enum ListFormatPartType {
10234 /// A value from the list.
10235 Element = "element",
10236 /// A linguistic construct (e.g., ", ", " and ").
10237 Literal = "literal",
10238 }
10239
10240 /// Type for `Intl.Segmenter`.
10241 #[wasm_bindgen]
10242 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10243 pub enum SegmenterGranularity {
10244 /// Segment by grapheme clusters (user-perceived characters).
10245 Grapheme = "grapheme",
10246 /// Segment by words.
10247 Word = "word",
10248 /// Segment by sentences.
10249 Sentence = "sentence",
10250 }
10251
10252 /// Type for `Intl.DisplayNames`.
10253 #[wasm_bindgen]
10254 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10255 pub enum DisplayNamesType {
10256 /// Language display names.
10257 Language = "language",
10258 /// Region display names.
10259 Region = "region",
10260 /// Script display names.
10261 Script = "script",
10262 /// Currency display names.
10263 Currency = "currency",
10264 /// Calendar display names.
10265 Calendar = "calendar",
10266 /// Date/time field display names.
10267 DateTimeField = "dateTimeField",
10268 }
10269
10270 /// Style for `Intl.DisplayNames`.
10271 #[wasm_bindgen]
10272 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10273 pub enum DisplayNamesStyle {
10274 /// Full display name (default).
10275 Long = "long",
10276 /// Abbreviated display name.
10277 Short = "short",
10278 /// Minimal display name.
10279 Narrow = "narrow",
10280 }
10281
10282 /// Fallback for `Intl.DisplayNames`.
10283 #[wasm_bindgen]
10284 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10285 pub enum DisplayNamesFallback {
10286 /// Return the input code if no display name is available (default).
10287 Code = "code",
10288 /// Return undefined if no display name is available.
10289 None = "none",
10290 }
10291
10292 /// Language display for `Intl.DisplayNames`.
10293 #[wasm_bindgen]
10294 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
10295 pub enum DisplayNamesLanguageDisplay {
10296 /// Use dialect names (e.g., "British English").
10297 Dialect = "dialect",
10298 /// Use standard names (e.g., "English (United Kingdom)").
10299 Standard = "standard",
10300 }
10301
10302 // Intl.RelativeTimeFormatOptions
10303 #[wasm_bindgen]
10304 extern "C" {
10305 /// Options for `Intl.RelativeTimeFormat` constructor.
10306 ///
10307 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/RelativeTimeFormat#options)
10308 #[wasm_bindgen(extends = Object)]
10309 #[derive(Clone, Debug)]
10310 pub type RelativeTimeFormatOptions;
10311
10312 #[wasm_bindgen(method, getter = localeMatcher)]
10313 pub fn get_locale_matcher(this: &RelativeTimeFormatOptions) -> Option<LocaleMatcher>;
10314 #[wasm_bindgen(method, setter = localeMatcher)]
10315 pub fn set_locale_matcher(this: &RelativeTimeFormatOptions, value: LocaleMatcher);
10316
10317 #[wasm_bindgen(method, getter = numeric)]
10318 pub fn get_numeric(this: &RelativeTimeFormatOptions) -> Option<RelativeTimeFormatNumeric>;
10319 #[wasm_bindgen(method, setter = numeric)]
10320 pub fn set_numeric(this: &RelativeTimeFormatOptions, value: RelativeTimeFormatNumeric);
10321
10322 #[wasm_bindgen(method, getter = style)]
10323 pub fn get_style(this: &RelativeTimeFormatOptions) -> Option<RelativeTimeFormatStyle>;
10324 #[wasm_bindgen(method, setter = style)]
10325 pub fn set_style(this: &RelativeTimeFormatOptions, value: RelativeTimeFormatStyle);
10326 }
10327
10328 impl RelativeTimeFormatOptions {
10329 pub fn new() -> RelativeTimeFormatOptions {
10330 JsCast::unchecked_into(Object::new())
10331 }
10332 }
10333
10334 impl Default for RelativeTimeFormatOptions {
10335 fn default() -> Self {
10336 RelativeTimeFormatOptions::new()
10337 }
10338 }
10339
10340 // Intl.ResolvedRelativeTimeFormatOptions
10341 #[wasm_bindgen]
10342 extern "C" {
10343 /// Resolved options returned by `Intl.RelativeTimeFormat.prototype.resolvedOptions()`.
10344 ///
10345 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/resolvedOptions)
10346 #[wasm_bindgen(extends = RelativeTimeFormatOptions)]
10347 #[derive(Clone, Debug)]
10348 pub type ResolvedRelativeTimeFormatOptions;
10349
10350 /// The resolved locale string.
10351 #[wasm_bindgen(method, getter = locale)]
10352 pub fn get_locale(this: &ResolvedRelativeTimeFormatOptions) -> JsString;
10353
10354 /// The numbering system used.
10355 #[wasm_bindgen(method, getter = numberingSystem)]
10356 pub fn get_numbering_system(this: &ResolvedRelativeTimeFormatOptions) -> JsString;
10357 }
10358
10359 // Intl.RelativeTimeFormatPart
10360 #[wasm_bindgen]
10361 extern "C" {
10362 /// A part of the formatted relative time returned by `formatToParts()`.
10363 ///
10364 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/formatToParts)
10365 #[wasm_bindgen(extends = Object)]
10366 #[derive(Clone, Debug)]
10367 pub type RelativeTimeFormatPart;
10368
10369 /// The type of this part.
10370 #[wasm_bindgen(method, getter = type)]
10371 pub fn type_(this: &RelativeTimeFormatPart) -> RelativeTimeFormatPartType;
10372
10373 /// The string value of this part.
10374 #[wasm_bindgen(method, getter = value)]
10375 pub fn value(this: &RelativeTimeFormatPart) -> JsString;
10376
10377 /// The unit used in this part (only for integer parts).
10378 #[wasm_bindgen(method, getter = unit)]
10379 pub fn unit(this: &RelativeTimeFormatPart) -> Option<JsString>;
10380 }
10381
10382 // Intl.LocaleMatcherOptions
10383 #[wasm_bindgen]
10384 extern "C" {
10385 /// Options for `supportedLocalesOf` methods.
10386 #[wasm_bindgen(extends = Object)]
10387 #[derive(Clone, Debug)]
10388 pub type LocaleMatcherOptions;
10389
10390 #[wasm_bindgen(method, getter = localeMatcher)]
10391 pub fn get_locale_matcher(this: &LocaleMatcherOptions) -> Option<LocaleMatcher>;
10392
10393 #[wasm_bindgen(method, setter = localeMatcher)]
10394 pub fn set_locale_matcher(this: &LocaleMatcherOptions, value: LocaleMatcher);
10395 }
10396
10397 impl LocaleMatcherOptions {
10398 pub fn new() -> LocaleMatcherOptions {
10399 JsCast::unchecked_into(Object::new())
10400 }
10401 }
10402
10403 impl Default for LocaleMatcherOptions {
10404 fn default() -> Self {
10405 LocaleMatcherOptions::new()
10406 }
10407 }
10408
10409 // Intl.Collator Options
10410 #[wasm_bindgen]
10411 extern "C" {
10412 /// Options for `Intl.Collator` and `String.prototype.localeCompare`.
10413 ///
10414 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Collator/Collator#options)
10415 #[wasm_bindgen(extends = Object)]
10416 #[derive(Clone, Debug)]
10417 pub type CollatorOptions;
10418
10419 #[wasm_bindgen(method, getter = localeMatcher)]
10420 pub fn get_locale_matcher(this: &CollatorOptions) -> Option<LocaleMatcher>;
10421 #[wasm_bindgen(method, setter = localeMatcher)]
10422 pub fn set_locale_matcher(this: &CollatorOptions, value: LocaleMatcher);
10423
10424 #[wasm_bindgen(method, getter = usage)]
10425 pub fn get_usage(this: &CollatorOptions) -> Option<CollatorUsage>;
10426 #[wasm_bindgen(method, setter = usage)]
10427 pub fn set_usage(this: &CollatorOptions, value: CollatorUsage);
10428
10429 #[wasm_bindgen(method, getter = sensitivity)]
10430 pub fn get_sensitivity(this: &CollatorOptions) -> Option<CollatorSensitivity>;
10431 #[wasm_bindgen(method, setter = sensitivity)]
10432 pub fn set_sensitivity(this: &CollatorOptions, value: CollatorSensitivity);
10433
10434 #[wasm_bindgen(method, getter = ignorePunctuation)]
10435 pub fn get_ignore_punctuation(this: &CollatorOptions) -> Option<bool>;
10436 #[wasm_bindgen(method, setter = ignorePunctuation)]
10437 pub fn set_ignore_punctuation(this: &CollatorOptions, value: bool);
10438
10439 #[wasm_bindgen(method, getter = numeric)]
10440 pub fn get_numeric(this: &CollatorOptions) -> Option<bool>;
10441 #[wasm_bindgen(method, setter = numeric)]
10442 pub fn set_numeric(this: &CollatorOptions, value: bool);
10443
10444 #[wasm_bindgen(method, getter = caseFirst)]
10445 pub fn get_case_first(this: &CollatorOptions) -> Option<CollatorCaseFirst>;
10446 #[wasm_bindgen(method, setter = caseFirst)]
10447 pub fn set_case_first(this: &CollatorOptions, value: CollatorCaseFirst);
10448 }
10449 impl CollatorOptions {
10450 pub fn new() -> CollatorOptions {
10451 JsCast::unchecked_into(Object::new())
10452 }
10453 }
10454 impl Default for CollatorOptions {
10455 fn default() -> Self {
10456 CollatorOptions::new()
10457 }
10458 }
10459
10460 // Intl.Collator ResolvedCollatorOptions
10461 #[wasm_bindgen]
10462 extern "C" {
10463 #[wasm_bindgen(extends = CollatorOptions)]
10464 pub type ResolvedCollatorOptions;
10465
10466 #[wasm_bindgen(method, getter = locale)]
10467 pub fn get_locale(this: &ResolvedCollatorOptions) -> JsString; // not Option, always present
10468 #[wasm_bindgen(method, getter = collation)]
10469 pub fn get_collation(this: &ResolvedCollatorOptions) -> JsString;
10470 }
10471
10472 // Intl.Collator
10473 #[wasm_bindgen]
10474 extern "C" {
10475 /// The `Intl.Collator` object is a constructor for collators, objects
10476 /// that enable language sensitive string comparison.
10477 ///
10478 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator)
10479 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.Collator")]
10480 #[derive(Clone, Debug)]
10481 pub type Collator;
10482
10483 /// The `Intl.Collator` object is a constructor for collators, objects
10484 /// that enable language sensitive string comparison.
10485 ///
10486 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator)
10487 #[cfg(not(js_sys_unstable_apis))]
10488 #[wasm_bindgen(constructor, js_namespace = Intl)]
10489 pub fn new(locales: &Array, options: &Object) -> Collator;
10490
10491 /// The `Intl.Collator` object is a constructor for collators, objects
10492 /// that enable language sensitive string comparison.
10493 ///
10494 /// Throws a `RangeError` if locales contain invalid values.
10495 ///
10496 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator)
10497 #[cfg(js_sys_unstable_apis)]
10498 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
10499 pub fn new(locales: &[JsString], options: &CollatorOptions) -> Result<Collator, JsValue>;
10500
10501 /// The Intl.Collator.prototype.compare property returns a function that
10502 /// compares two strings according to the sort order of this Collator
10503 /// object.
10504 ///
10505 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/compare)
10506 #[cfg(not(js_sys_unstable_apis))]
10507 #[wasm_bindgen(method, getter, js_class = "Intl.Collator")]
10508 pub fn compare(this: &Collator) -> Function;
10509
10510 /// Compares two strings according to the sort order of this Collator.
10511 ///
10512 /// Returns a negative value if `a` comes before `b`, positive if `a` comes
10513 /// after `b`, and zero if they are equal.
10514 ///
10515 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Collator/compare)
10516 #[cfg(js_sys_unstable_apis)]
10517 #[wasm_bindgen(method, js_class = "Intl.Collator")]
10518 pub fn compare(this: &Collator, a: &str, b: &str) -> i32;
10519
10520 /// The `Intl.Collator.prototype.resolvedOptions()` method returns a new
10521 /// object with properties reflecting the locale and collation options
10522 /// computed during initialization of this Collator object.
10523 ///
10524 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/resolvedOptions)
10525 #[cfg(not(js_sys_unstable_apis))]
10526 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
10527 pub fn resolved_options(this: &Collator) -> Object;
10528
10529 /// The `Intl.Collator.prototype.resolvedOptions()` method returns a new
10530 /// object with properties reflecting the locale and collation options
10531 /// computed during initialization of this Collator object.
10532 ///
10533 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/resolvedOptions)
10534 #[cfg(js_sys_unstable_apis)]
10535 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
10536 pub fn resolved_options(this: &Collator) -> ResolvedCollatorOptions;
10537
10538 /// The `Intl.Collator.supportedLocalesOf()` method returns an array
10539 /// containing those of the provided locales that are supported in
10540 /// collation without having to fall back to the runtime's default
10541 /// locale.
10542 ///
10543 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/supportedLocalesOf)
10544 #[cfg(not(js_sys_unstable_apis))]
10545 #[wasm_bindgen(static_method_of = Collator, js_namespace = Intl, js_name = supportedLocalesOf)]
10546 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
10547
10548 /// The `Intl.Collator.supportedLocalesOf()` method returns an array
10549 /// containing those of the provided locales that are supported in
10550 /// collation without having to fall back to the runtime's default
10551 /// locale.
10552 ///
10553 /// Throws a `RangeError` if locales contain invalid values.
10554 ///
10555 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/supportedLocalesOf)
10556 #[cfg(js_sys_unstable_apis)]
10557 #[wasm_bindgen(static_method_of = Collator, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
10558 pub fn supported_locales_of(
10559 locales: &[JsString],
10560 options: &LocaleMatcherOptions,
10561 ) -> Result<Array<JsString>, JsValue>;
10562 }
10563
10564 #[cfg(not(js_sys_unstable_apis))]
10565 impl Default for Collator {
10566 fn default() -> Self {
10567 Self::new(
10568 &JsValue::UNDEFINED.unchecked_into(),
10569 &JsValue::UNDEFINED.unchecked_into(),
10570 )
10571 }
10572 }
10573
10574 #[cfg(js_sys_unstable_apis)]
10575 impl Default for Collator {
10576 fn default() -> Self {
10577 Self::new(&[], &Default::default()).unwrap()
10578 }
10579 }
10580
10581 // Intl.DateTimeFormatOptions
10582 #[wasm_bindgen]
10583 extern "C" {
10584 /// Options for `Intl.DateTimeFormat` constructor.
10585 ///
10586 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat#options)
10587 #[wasm_bindgen(extends = Object)]
10588 #[derive(Clone, Debug)]
10589 pub type DateTimeFormatOptions;
10590
10591 // Locale matching
10592 #[wasm_bindgen(method, getter = localeMatcher)]
10593 pub fn get_locale_matcher(this: &DateTimeFormatOptions) -> Option<LocaleMatcher>;
10594 #[wasm_bindgen(method, setter = localeMatcher)]
10595 pub fn set_locale_matcher(this: &DateTimeFormatOptions, value: LocaleMatcher);
10596
10597 // Calendar/numbering (free-form strings, no enum)
10598 #[wasm_bindgen(method, getter = calendar)]
10599 pub fn get_calendar(this: &DateTimeFormatOptions) -> Option<JsString>;
10600 #[wasm_bindgen(method, setter = calendar)]
10601 pub fn set_calendar(this: &DateTimeFormatOptions, value: &str);
10602
10603 #[wasm_bindgen(method, getter = numberingSystem)]
10604 pub fn get_numbering_system(this: &DateTimeFormatOptions) -> Option<JsString>;
10605 #[wasm_bindgen(method, setter = numberingSystem)]
10606 pub fn set_numbering_system(this: &DateTimeFormatOptions, value: &str);
10607
10608 // Timezone (free-form string)
10609 #[wasm_bindgen(method, getter = timeZone)]
10610 pub fn get_time_zone(this: &DateTimeFormatOptions) -> Option<JsString>;
10611 #[wasm_bindgen(method, setter = timeZone)]
10612 pub fn set_time_zone(this: &DateTimeFormatOptions, value: &str);
10613
10614 // Hour cycle
10615 #[wasm_bindgen(method, getter = hour12)]
10616 pub fn get_hour12(this: &DateTimeFormatOptions) -> Option<bool>;
10617 #[wasm_bindgen(method, setter = hour12)]
10618 pub fn set_hour12(this: &DateTimeFormatOptions, value: bool);
10619
10620 #[wasm_bindgen(method, getter = hourCycle)]
10621 pub fn get_hour_cycle(this: &DateTimeFormatOptions) -> Option<HourCycle>;
10622 #[wasm_bindgen(method, setter = hourCycle)]
10623 pub fn set_hour_cycle(this: &DateTimeFormatOptions, value: HourCycle);
10624
10625 // Style shortcuts
10626 #[wasm_bindgen(method, getter = dateStyle)]
10627 pub fn get_date_style(this: &DateTimeFormatOptions) -> Option<DateTimeStyle>;
10628 #[wasm_bindgen(method, setter = dateStyle)]
10629 pub fn set_date_style(this: &DateTimeFormatOptions, value: DateTimeStyle);
10630
10631 #[wasm_bindgen(method, getter = timeStyle)]
10632 pub fn get_time_style(this: &DateTimeFormatOptions) -> Option<DateTimeStyle>;
10633 #[wasm_bindgen(method, setter = timeStyle)]
10634 pub fn set_time_style(this: &DateTimeFormatOptions, value: DateTimeStyle);
10635
10636 // Component options
10637 #[wasm_bindgen(method, getter = weekday)]
10638 pub fn get_weekday(this: &DateTimeFormatOptions) -> Option<WeekdayFormat>;
10639 #[wasm_bindgen(method, setter = weekday)]
10640 pub fn set_weekday(this: &DateTimeFormatOptions, value: WeekdayFormat);
10641
10642 #[wasm_bindgen(method, getter = era)]
10643 pub fn get_era(this: &DateTimeFormatOptions) -> Option<EraFormat>;
10644 #[wasm_bindgen(method, setter = era)]
10645 pub fn set_era(this: &DateTimeFormatOptions, value: EraFormat);
10646
10647 #[wasm_bindgen(method, getter = year)]
10648 pub fn get_year(this: &DateTimeFormatOptions) -> Option<YearFormat>;
10649 #[wasm_bindgen(method, setter = year)]
10650 pub fn set_year(this: &DateTimeFormatOptions, value: YearFormat);
10651
10652 #[wasm_bindgen(method, getter = month)]
10653 pub fn get_month(this: &DateTimeFormatOptions) -> Option<MonthFormat>;
10654 #[wasm_bindgen(method, setter = month)]
10655 pub fn set_month(this: &DateTimeFormatOptions, value: MonthFormat);
10656
10657 #[wasm_bindgen(method, getter = day)]
10658 pub fn get_day(this: &DateTimeFormatOptions) -> Option<DayFormat>;
10659 #[wasm_bindgen(method, setter = day)]
10660 pub fn set_day(this: &DateTimeFormatOptions, value: DayFormat);
10661
10662 #[wasm_bindgen(method, getter = hour)]
10663 pub fn get_hour(this: &DateTimeFormatOptions) -> Option<NumericFormat>;
10664 #[wasm_bindgen(method, setter = hour)]
10665 pub fn set_hour(this: &DateTimeFormatOptions, value: NumericFormat);
10666
10667 #[wasm_bindgen(method, getter = minute)]
10668 pub fn get_minute(this: &DateTimeFormatOptions) -> Option<NumericFormat>;
10669 #[wasm_bindgen(method, setter = minute)]
10670 pub fn set_minute(this: &DateTimeFormatOptions, value: NumericFormat);
10671
10672 #[wasm_bindgen(method, getter = second)]
10673 pub fn get_second(this: &DateTimeFormatOptions) -> Option<NumericFormat>;
10674 #[wasm_bindgen(method, setter = second)]
10675 pub fn set_second(this: &DateTimeFormatOptions, value: NumericFormat);
10676
10677 #[wasm_bindgen(method, getter = fractionalSecondDigits)]
10678 pub fn get_fractional_second_digits(this: &DateTimeFormatOptions) -> Option<u8>;
10679 #[wasm_bindgen(method, setter = fractionalSecondDigits)]
10680 pub fn set_fractional_second_digits(this: &DateTimeFormatOptions, value: u8);
10681
10682 #[wasm_bindgen(method, getter = timeZoneName)]
10683 pub fn get_time_zone_name(this: &DateTimeFormatOptions) -> Option<TimeZoneNameFormat>;
10684 #[wasm_bindgen(method, setter = timeZoneName)]
10685 pub fn set_time_zone_name(this: &DateTimeFormatOptions, value: TimeZoneNameFormat);
10686
10687 #[wasm_bindgen(method, getter = dayPeriod)]
10688 pub fn get_day_period(this: &DateTimeFormatOptions) -> Option<DayPeriodFormat>;
10689 #[wasm_bindgen(method, setter = dayPeriod)]
10690 pub fn set_day_period(this: &DateTimeFormatOptions, value: DayPeriodFormat);
10691 }
10692
10693 impl DateTimeFormatOptions {
10694 pub fn new() -> DateTimeFormatOptions {
10695 JsCast::unchecked_into(Object::new())
10696 }
10697 }
10698
10699 impl Default for DateTimeFormatOptions {
10700 fn default() -> Self {
10701 DateTimeFormatOptions::new()
10702 }
10703 }
10704
10705 // Intl.ResolvedDateTimeFormatOptions
10706 #[wasm_bindgen]
10707 extern "C" {
10708 /// Resolved options returned by `Intl.DateTimeFormat.prototype.resolvedOptions()`.
10709 ///
10710 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/resolvedOptions)
10711 #[wasm_bindgen(extends = DateTimeFormatOptions)]
10712 #[derive(Clone, Debug)]
10713 pub type ResolvedDateTimeFormatOptions;
10714
10715 /// The resolved locale string.
10716 #[wasm_bindgen(method, getter = locale)]
10717 pub fn get_locale(this: &ResolvedDateTimeFormatOptions) -> JsString;
10718 }
10719
10720 // Intl.DateTimeFormatPart
10721 #[wasm_bindgen]
10722 extern "C" {
10723 /// A part of the formatted date returned by `formatToParts()`.
10724 ///
10725 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatToParts)
10726 #[wasm_bindgen(extends = Object)]
10727 #[derive(Clone, Debug)]
10728 pub type DateTimeFormatPart;
10729
10730 /// The type of the part (e.g., "day", "month", "year", "literal", etc.)
10731 #[wasm_bindgen(method, getter = type)]
10732 pub fn type_(this: &DateTimeFormatPart) -> DateTimeFormatPartType;
10733
10734 /// The value of the part.
10735 #[wasm_bindgen(method, getter)]
10736 pub fn value(this: &DateTimeFormatPart) -> JsString;
10737 }
10738
10739 // Intl.DateTimeRangeFormatPart
10740 #[wasm_bindgen]
10741 extern "C" {
10742 /// A part of the formatted date range returned by `formatRangeToParts()`.
10743 ///
10744 /// Extends `DateTimeFormatPart` with a `source` property indicating whether
10745 /// the part is from the start date, end date, or shared between them.
10746 ///
10747 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatRangeToParts)
10748 #[wasm_bindgen(extends = DateTimeFormatPart)]
10749 #[derive(Clone, Debug)]
10750 pub type DateTimeRangeFormatPart;
10751
10752 /// The source of the part: "startRange", "endRange", or "shared".
10753 #[wasm_bindgen(method, getter)]
10754 pub fn source(this: &DateTimeRangeFormatPart) -> RangeSource;
10755 }
10756
10757 // Intl.DateTimeFormat
10758 #[wasm_bindgen]
10759 extern "C" {
10760 /// The `Intl.DateTimeFormat` object is a constructor for objects
10761 /// that enable language-sensitive date and time formatting.
10762 ///
10763 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat)
10764 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.DateTimeFormat")]
10765 #[derive(Clone, Debug)]
10766 pub type DateTimeFormat;
10767
10768 /// The `Intl.DateTimeFormat` object is a constructor for objects
10769 /// that enable language-sensitive date and time formatting.
10770 ///
10771 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat)
10772 #[cfg(not(js_sys_unstable_apis))]
10773 #[wasm_bindgen(constructor, js_namespace = Intl)]
10774 pub fn new(locales: &Array, options: &Object) -> DateTimeFormat;
10775
10776 /// The `Intl.DateTimeFormat` object is a constructor for objects
10777 /// that enable language-sensitive date and time formatting.
10778 ///
10779 /// Throws a `RangeError` if locales contain invalid values.
10780 ///
10781 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat)
10782 #[cfg(js_sys_unstable_apis)]
10783 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
10784 pub fn new(
10785 locales: &[JsString],
10786 options: &DateTimeFormatOptions,
10787 ) -> Result<DateTimeFormat, JsValue>;
10788
10789 /// The Intl.DateTimeFormat.prototype.format property returns a getter function that
10790 /// formats a date according to the locale and formatting options of this
10791 /// Intl.DateTimeFormat object.
10792 ///
10793 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/format)
10794 #[cfg(not(js_sys_unstable_apis))]
10795 #[wasm_bindgen(method, getter, js_class = "Intl.DateTimeFormat")]
10796 pub fn format(this: &DateTimeFormat) -> Function;
10797
10798 /// Formats a date according to the locale and formatting options of this
10799 /// `Intl.DateTimeFormat` object.
10800 ///
10801 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/format)
10802 #[cfg(js_sys_unstable_apis)]
10803 #[wasm_bindgen(method, js_class = "Intl.DateTimeFormat")]
10804 pub fn format(this: &DateTimeFormat, date: &Date) -> JsString;
10805
10806 /// The `Intl.DateTimeFormat.prototype.formatToParts()` method allows locale-aware
10807 /// formatting of strings produced by DateTimeFormat formatters.
10808 ///
10809 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/formatToParts)
10810 #[cfg(not(js_sys_unstable_apis))]
10811 #[wasm_bindgen(method, js_class = "Intl.DateTimeFormat", js_name = formatToParts)]
10812 pub fn format_to_parts(this: &DateTimeFormat, date: &Date) -> Array;
10813
10814 /// The `Intl.DateTimeFormat.prototype.formatToParts()` method allows locale-aware
10815 /// formatting of strings produced by DateTimeFormat formatters.
10816 ///
10817 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/formatToParts)
10818 #[cfg(js_sys_unstable_apis)]
10819 #[wasm_bindgen(method, js_class = "Intl.DateTimeFormat", js_name = formatToParts)]
10820 pub fn format_to_parts(this: &DateTimeFormat, date: &Date) -> Array<DateTimeFormatPart>;
10821
10822 /// The `Intl.DateTimeFormat.prototype.formatRange()` method formats a date range
10823 /// in the most concise way based on the locales and options provided when
10824 /// instantiating this `Intl.DateTimeFormat` object.
10825 ///
10826 /// Throws a `TypeError` if the dates are invalid.
10827 ///
10828 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatRange)
10829 #[wasm_bindgen(method, js_class = "Intl.DateTimeFormat", js_name = formatRange, catch)]
10830 pub fn format_range(
10831 this: &DateTimeFormat,
10832 start_date: &Date,
10833 end_date: &Date,
10834 ) -> Result<JsString, JsValue>;
10835
10836 /// The `Intl.DateTimeFormat.prototype.formatRangeToParts()` method returns an array
10837 /// of locale-specific tokens representing each part of the formatted date range
10838 /// produced by `Intl.DateTimeFormat` formatters.
10839 ///
10840 /// Throws a `TypeError` if the dates are invalid.
10841 ///
10842 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatRangeToParts)
10843 #[wasm_bindgen(method, js_class = "Intl.DateTimeFormat", js_name = formatRangeToParts, catch)]
10844 pub fn format_range_to_parts(
10845 this: &DateTimeFormat,
10846 start_date: &Date,
10847 end_date: &Date,
10848 ) -> Result<Array<DateTimeRangeFormatPart>, JsValue>;
10849
10850 /// The `Intl.DateTimeFormat.prototype.resolvedOptions()` method returns a new
10851 /// object with properties reflecting the locale and date and time formatting
10852 /// options computed during initialization of this DateTimeFormat object.
10853 ///
10854 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/resolvedOptions)
10855 #[cfg(not(js_sys_unstable_apis))]
10856 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
10857 pub fn resolved_options(this: &DateTimeFormat) -> Object;
10858
10859 /// The `Intl.DateTimeFormat.prototype.resolvedOptions()` method returns a new
10860 /// object with properties reflecting the locale and date and time formatting
10861 /// options computed during initialization of this DateTimeFormat object.
10862 ///
10863 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/resolvedOptions)
10864 #[cfg(js_sys_unstable_apis)]
10865 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
10866 pub fn resolved_options(this: &DateTimeFormat) -> ResolvedDateTimeFormatOptions;
10867
10868 /// The `Intl.DateTimeFormat.supportedLocalesOf()` method returns an array
10869 /// containing those of the provided locales that are supported in date
10870 /// and time formatting without having to fall back to the runtime's default
10871 /// locale.
10872 ///
10873 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/supportedLocalesOf)
10874 #[cfg(not(js_sys_unstable_apis))]
10875 #[wasm_bindgen(static_method_of = DateTimeFormat, js_namespace = Intl, js_name = supportedLocalesOf)]
10876 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
10877
10878 /// The `Intl.DateTimeFormat.supportedLocalesOf()` method returns an array
10879 /// containing those of the provided locales that are supported in date
10880 /// and time formatting without having to fall back to the runtime's default
10881 /// locale.
10882 ///
10883 /// Throws a `RangeError` if locales contain invalid values.
10884 ///
10885 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/supportedLocalesOf)
10886 #[cfg(js_sys_unstable_apis)]
10887 #[wasm_bindgen(static_method_of = DateTimeFormat, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
10888 pub fn supported_locales_of(
10889 locales: &[JsString],
10890 options: &LocaleMatcherOptions,
10891 ) -> Result<Array<JsString>, JsValue>;
10892 }
10893
10894 #[cfg(not(js_sys_unstable_apis))]
10895 impl Default for DateTimeFormat {
10896 fn default() -> Self {
10897 Self::new(
10898 &JsValue::UNDEFINED.unchecked_into(),
10899 &JsValue::UNDEFINED.unchecked_into(),
10900 )
10901 }
10902 }
10903
10904 #[cfg(js_sys_unstable_apis)]
10905 impl Default for DateTimeFormat {
10906 fn default() -> Self {
10907 Self::new(&[], &Default::default()).unwrap()
10908 }
10909 }
10910
10911 // Intl.NumberFormatOptions
10912 #[wasm_bindgen]
10913 extern "C" {
10914 /// Options for `Intl.NumberFormat` constructor.
10915 ///
10916 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#options)
10917 #[wasm_bindgen(extends = Object)]
10918 #[derive(Clone, Debug)]
10919 pub type NumberFormatOptions;
10920
10921 // Locale matching
10922 #[wasm_bindgen(method, getter = localeMatcher)]
10923 pub fn get_locale_matcher(this: &NumberFormatOptions) -> Option<LocaleMatcher>;
10924 #[wasm_bindgen(method, setter = localeMatcher)]
10925 pub fn set_locale_matcher(this: &NumberFormatOptions, value: LocaleMatcher);
10926
10927 // Numbering system (free-form string)
10928 #[wasm_bindgen(method, getter = numberingSystem)]
10929 pub fn get_numbering_system(this: &NumberFormatOptions) -> Option<JsString>;
10930 #[wasm_bindgen(method, setter = numberingSystem)]
10931 pub fn set_numbering_system(this: &NumberFormatOptions, value: &str);
10932
10933 // Style
10934 #[wasm_bindgen(method, getter = style)]
10935 pub fn get_style(this: &NumberFormatOptions) -> Option<NumberFormatStyle>;
10936 #[wasm_bindgen(method, setter = style)]
10937 pub fn set_style(this: &NumberFormatOptions, value: NumberFormatStyle);
10938
10939 // Currency options (currency code is free-form ISO 4217 string)
10940 #[wasm_bindgen(method, getter = currency)]
10941 pub fn get_currency(this: &NumberFormatOptions) -> Option<JsString>;
10942 #[wasm_bindgen(method, setter = currency)]
10943 pub fn set_currency(this: &NumberFormatOptions, value: &str);
10944
10945 #[wasm_bindgen(method, getter = currencyDisplay)]
10946 pub fn get_currency_display(this: &NumberFormatOptions) -> Option<CurrencyDisplay>;
10947 #[wasm_bindgen(method, setter = currencyDisplay)]
10948 pub fn set_currency_display(this: &NumberFormatOptions, value: CurrencyDisplay);
10949
10950 #[wasm_bindgen(method, getter = currencySign)]
10951 pub fn get_currency_sign(this: &NumberFormatOptions) -> Option<CurrencySign>;
10952 #[wasm_bindgen(method, setter = currencySign)]
10953 pub fn set_currency_sign(this: &NumberFormatOptions, value: CurrencySign);
10954
10955 // Unit options (unit name is free-form string)
10956 #[wasm_bindgen(method, getter = unit)]
10957 pub fn get_unit(this: &NumberFormatOptions) -> Option<JsString>;
10958 #[wasm_bindgen(method, setter = unit)]
10959 pub fn set_unit(this: &NumberFormatOptions, value: &str);
10960
10961 #[wasm_bindgen(method, getter = unitDisplay)]
10962 pub fn get_unit_display(this: &NumberFormatOptions) -> Option<UnitDisplay>;
10963 #[wasm_bindgen(method, setter = unitDisplay)]
10964 pub fn set_unit_display(this: &NumberFormatOptions, value: UnitDisplay);
10965
10966 // Notation
10967 #[wasm_bindgen(method, getter = notation)]
10968 pub fn get_notation(this: &NumberFormatOptions) -> Option<NumberFormatNotation>;
10969 #[wasm_bindgen(method, setter = notation)]
10970 pub fn set_notation(this: &NumberFormatOptions, value: NumberFormatNotation);
10971
10972 #[wasm_bindgen(method, getter = compactDisplay)]
10973 pub fn get_compact_display(this: &NumberFormatOptions) -> Option<CompactDisplay>;
10974 #[wasm_bindgen(method, setter = compactDisplay)]
10975 pub fn set_compact_display(this: &NumberFormatOptions, value: CompactDisplay);
10976
10977 // Sign display
10978 #[wasm_bindgen(method, getter = signDisplay)]
10979 pub fn get_sign_display(this: &NumberFormatOptions) -> Option<SignDisplay>;
10980 #[wasm_bindgen(method, setter = signDisplay)]
10981 pub fn set_sign_display(this: &NumberFormatOptions, value: SignDisplay);
10982
10983 // Digit options
10984 #[wasm_bindgen(method, getter = minimumIntegerDigits)]
10985 pub fn get_minimum_integer_digits(this: &NumberFormatOptions) -> Option<u8>;
10986 #[wasm_bindgen(method, setter = minimumIntegerDigits)]
10987 pub fn set_minimum_integer_digits(this: &NumberFormatOptions, value: u8);
10988
10989 #[wasm_bindgen(method, getter = minimumFractionDigits)]
10990 pub fn get_minimum_fraction_digits(this: &NumberFormatOptions) -> Option<u8>;
10991 #[wasm_bindgen(method, setter = minimumFractionDigits)]
10992 pub fn set_minimum_fraction_digits(this: &NumberFormatOptions, value: u8);
10993
10994 #[wasm_bindgen(method, getter = maximumFractionDigits)]
10995 pub fn get_maximum_fraction_digits(this: &NumberFormatOptions) -> Option<u8>;
10996 #[wasm_bindgen(method, setter = maximumFractionDigits)]
10997 pub fn set_maximum_fraction_digits(this: &NumberFormatOptions, value: u8);
10998
10999 #[wasm_bindgen(method, getter = minimumSignificantDigits)]
11000 pub fn get_minimum_significant_digits(this: &NumberFormatOptions) -> Option<u8>;
11001 #[wasm_bindgen(method, setter = minimumSignificantDigits)]
11002 pub fn set_minimum_significant_digits(this: &NumberFormatOptions, value: u8);
11003
11004 #[wasm_bindgen(method, getter = maximumSignificantDigits)]
11005 pub fn get_maximum_significant_digits(this: &NumberFormatOptions) -> Option<u8>;
11006 #[wasm_bindgen(method, setter = maximumSignificantDigits)]
11007 pub fn set_maximum_significant_digits(this: &NumberFormatOptions, value: u8);
11008
11009 // Grouping
11010 #[wasm_bindgen(method, getter = useGrouping)]
11011 pub fn get_use_grouping(this: &NumberFormatOptions) -> Option<UseGrouping>;
11012 #[wasm_bindgen(method, setter = useGrouping)]
11013 pub fn set_use_grouping(this: &NumberFormatOptions, value: UseGrouping);
11014
11015 // Rounding
11016 #[wasm_bindgen(method, getter = roundingMode)]
11017 pub fn get_rounding_mode(this: &NumberFormatOptions) -> Option<RoundingMode>;
11018 #[wasm_bindgen(method, setter = roundingMode)]
11019 pub fn set_rounding_mode(this: &NumberFormatOptions, value: RoundingMode);
11020
11021 #[wasm_bindgen(method, getter = roundingPriority)]
11022 pub fn get_rounding_priority(this: &NumberFormatOptions) -> Option<RoundingPriority>;
11023 #[wasm_bindgen(method, setter = roundingPriority)]
11024 pub fn set_rounding_priority(this: &NumberFormatOptions, value: RoundingPriority);
11025
11026 #[wasm_bindgen(method, getter = roundingIncrement)]
11027 pub fn get_rounding_increment(this: &NumberFormatOptions) -> Option<u32>;
11028 #[wasm_bindgen(method, setter = roundingIncrement)]
11029 pub fn set_rounding_increment(this: &NumberFormatOptions, value: u32);
11030
11031 #[wasm_bindgen(method, getter = trailingZeroDisplay)]
11032 pub fn get_trailing_zero_display(this: &NumberFormatOptions)
11033 -> Option<TrailingZeroDisplay>;
11034 #[wasm_bindgen(method, setter = trailingZeroDisplay)]
11035 pub fn set_trailing_zero_display(this: &NumberFormatOptions, value: TrailingZeroDisplay);
11036 }
11037
11038 impl NumberFormatOptions {
11039 pub fn new() -> NumberFormatOptions {
11040 JsCast::unchecked_into(Object::new())
11041 }
11042 }
11043
11044 impl Default for NumberFormatOptions {
11045 fn default() -> Self {
11046 NumberFormatOptions::new()
11047 }
11048 }
11049
11050 // Intl.ResolvedNumberFormatOptions
11051 #[wasm_bindgen]
11052 extern "C" {
11053 /// Resolved options returned by `Intl.NumberFormat.prototype.resolvedOptions()`.
11054 ///
11055 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/resolvedOptions)
11056 #[wasm_bindgen(extends = NumberFormatOptions)]
11057 #[derive(Clone, Debug)]
11058 pub type ResolvedNumberFormatOptions;
11059
11060 /// The resolved locale string.
11061 #[wasm_bindgen(method, getter = locale)]
11062 pub fn get_locale(this: &ResolvedNumberFormatOptions) -> JsString;
11063 }
11064
11065 // Intl.NumberFormatPart
11066 #[wasm_bindgen]
11067 extern "C" {
11068 /// A part of the formatted number returned by `formatToParts()`.
11069 ///
11070 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatToParts)
11071 #[wasm_bindgen(extends = Object)]
11072 #[derive(Clone, Debug)]
11073 pub type NumberFormatPart;
11074
11075 /// The type of the part (e.g., "integer", "decimal", "fraction", "currency", etc.)
11076 #[wasm_bindgen(method, getter = type)]
11077 pub fn type_(this: &NumberFormatPart) -> NumberFormatPartType;
11078
11079 /// The value of the part.
11080 #[wasm_bindgen(method, getter)]
11081 pub fn value(this: &NumberFormatPart) -> JsString;
11082 }
11083
11084 // Intl.NumberRangeFormatPart
11085 #[wasm_bindgen]
11086 extern "C" {
11087 /// A part of the formatted number range returned by `formatRangeToParts()`.
11088 ///
11089 /// Extends `NumberFormatPart` with a `source` property indicating whether
11090 /// the part is from the start number, end number, or shared between them.
11091 ///
11092 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatRangeToParts)
11093 #[wasm_bindgen(extends = NumberFormatPart)]
11094 #[derive(Clone, Debug)]
11095 pub type NumberRangeFormatPart;
11096
11097 /// The source of the part: "startRange", "endRange", or "shared".
11098 #[wasm_bindgen(method, getter)]
11099 pub fn source(this: &NumberRangeFormatPart) -> RangeSource;
11100 }
11101
11102 // Intl.NumberFormat
11103 #[wasm_bindgen]
11104 extern "C" {
11105 /// The `Intl.NumberFormat` object is a constructor for objects
11106 /// that enable language sensitive number formatting.
11107 ///
11108 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat)
11109 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.NumberFormat")]
11110 #[derive(Clone, Debug)]
11111 pub type NumberFormat;
11112
11113 /// The `Intl.NumberFormat` object is a constructor for objects
11114 /// that enable language sensitive number formatting.
11115 ///
11116 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat)
11117 #[cfg(not(js_sys_unstable_apis))]
11118 #[wasm_bindgen(constructor, js_namespace = Intl)]
11119 pub fn new(locales: &Array, options: &Object) -> NumberFormat;
11120
11121 /// The `Intl.NumberFormat` object is a constructor for objects
11122 /// that enable language sensitive number formatting.
11123 ///
11124 /// Throws a `RangeError` if locales contain invalid values.
11125 ///
11126 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat)
11127 #[cfg(js_sys_unstable_apis)]
11128 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
11129 pub fn new(
11130 locales: &[JsString],
11131 options: &NumberFormatOptions,
11132 ) -> Result<NumberFormat, JsValue>;
11133
11134 /// The Intl.NumberFormat.prototype.format property returns a getter function that
11135 /// formats a number according to the locale and formatting options of this
11136 /// NumberFormat object.
11137 ///
11138 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/format)
11139 #[cfg(not(js_sys_unstable_apis))]
11140 #[wasm_bindgen(method, getter, js_class = "Intl.NumberFormat")]
11141 pub fn format(this: &NumberFormat) -> Function;
11142
11143 /// Formats a number according to the locale and formatting options of this
11144 /// `Intl.NumberFormat` object.
11145 ///
11146 /// Accepts numeric strings for BigInt/arbitrary precision (e.g., `"123n"` → `"123"`,
11147 /// or use E notation: `"1000000E-6"` → `"1"`).
11148 ///
11149 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/format)
11150 #[cfg(js_sys_unstable_apis)]
11151 #[wasm_bindgen(method, js_class = "Intl.NumberFormat")]
11152 pub fn format(this: &NumberFormat, value: &JsString) -> JsString;
11153
11154 /// The `Intl.Numberformat.prototype.formatToParts()` method allows locale-aware
11155 /// formatting of strings produced by NumberTimeFormat formatters.
11156 ///
11157 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/formatToParts)
11158 #[cfg(not(js_sys_unstable_apis))]
11159 #[wasm_bindgen(method, js_class = "Intl.NumberFormat", js_name = formatToParts)]
11160 pub fn format_to_parts(this: &NumberFormat, number: f64) -> Array;
11161
11162 /// The `Intl.NumberFormat.prototype.formatToParts()` method allows locale-aware
11163 /// formatting of strings produced by `Intl.NumberFormat` formatters.
11164 ///
11165 /// Accepts numeric strings for BigInt/arbitrary precision (e.g., `"123n"` → `"123"`,
11166 /// or use E notation: `"1000000E-6"` → `"1"`).
11167 ///
11168 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatToParts)
11169 #[cfg(js_sys_unstable_apis)]
11170 #[wasm_bindgen(method, js_class = "Intl.NumberFormat", js_name = formatToParts)]
11171 pub fn format_to_parts(this: &NumberFormat, value: &JsString) -> Array<NumberFormatPart>;
11172
11173 /// Formats a range of numbers according to the locale and formatting options
11174 /// of this `Intl.NumberFormat` object.
11175 ///
11176 /// Accepts numeric strings for BigInt/arbitrary precision (e.g., `"123n"` → `"123"`,
11177 /// or use E notation: `"1000000E-6"` → `"1"`).
11178 ///
11179 /// Throws a `TypeError` if the values are invalid.
11180 ///
11181 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatRange)
11182 #[wasm_bindgen(method, js_class = "Intl.NumberFormat", js_name = formatRange, catch)]
11183 pub fn format_range(
11184 this: &NumberFormat,
11185 start: &JsString,
11186 end: &JsString,
11187 ) -> Result<JsString, JsValue>;
11188
11189 /// Returns an array of locale-specific tokens representing each part of
11190 /// the formatted number range.
11191 ///
11192 /// Accepts numeric strings for BigInt/arbitrary precision (e.g., `"123n"` → `"123"`,
11193 /// or use E notation: `"1000000E-6"` → `"1"`).
11194 ///
11195 /// Throws a `TypeError` if the values are invalid.
11196 ///
11197 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatRangeToParts)
11198 #[wasm_bindgen(method, js_class = "Intl.NumberFormat", js_name = formatRangeToParts, catch)]
11199 pub fn format_range_to_parts(
11200 this: &NumberFormat,
11201 start: &JsString,
11202 end: &JsString,
11203 ) -> Result<Array<NumberRangeFormatPart>, JsValue>;
11204
11205 /// The `Intl.NumberFormat.prototype.resolvedOptions()` method returns a new
11206 /// object with properties reflecting the locale and number formatting
11207 /// options computed during initialization of this NumberFormat object.
11208 ///
11209 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/resolvedOptions)
11210 #[cfg(not(js_sys_unstable_apis))]
11211 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11212 pub fn resolved_options(this: &NumberFormat) -> Object;
11213
11214 /// The `Intl.NumberFormat.prototype.resolvedOptions()` method returns a new
11215 /// object with properties reflecting the locale and number formatting
11216 /// options computed during initialization of this NumberFormat object.
11217 ///
11218 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/resolvedOptions)
11219 #[cfg(js_sys_unstable_apis)]
11220 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11221 pub fn resolved_options(this: &NumberFormat) -> ResolvedNumberFormatOptions;
11222
11223 /// The `Intl.NumberFormat.supportedLocalesOf()` method returns an array
11224 /// containing those of the provided locales that are supported in number
11225 /// formatting without having to fall back to the runtime's default locale.
11226 ///
11227 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/supportedLocalesOf)
11228 #[cfg(not(js_sys_unstable_apis))]
11229 #[wasm_bindgen(static_method_of = NumberFormat, js_namespace = Intl, js_name = supportedLocalesOf)]
11230 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
11231
11232 /// The `Intl.NumberFormat.supportedLocalesOf()` method returns an array
11233 /// containing those of the provided locales that are supported in number
11234 /// formatting without having to fall back to the runtime's default locale.
11235 ///
11236 /// Throws a `RangeError` if locales contain invalid values.
11237 ///
11238 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/supportedLocalesOf)
11239 #[cfg(js_sys_unstable_apis)]
11240 #[wasm_bindgen(static_method_of = NumberFormat, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
11241 pub fn supported_locales_of(
11242 locales: &[JsString],
11243 options: &LocaleMatcherOptions,
11244 ) -> Result<Array<JsString>, JsValue>;
11245 }
11246
11247 #[cfg(not(js_sys_unstable_apis))]
11248 impl Default for NumberFormat {
11249 fn default() -> Self {
11250 Self::new(
11251 &JsValue::UNDEFINED.unchecked_into(),
11252 &JsValue::UNDEFINED.unchecked_into(),
11253 )
11254 }
11255 }
11256
11257 #[cfg(js_sys_unstable_apis)]
11258 impl Default for NumberFormat {
11259 fn default() -> Self {
11260 Self::new(&[], &Default::default()).unwrap()
11261 }
11262 }
11263
11264 // Intl.PluralRulesOptions
11265 #[wasm_bindgen]
11266 extern "C" {
11267 /// Options for `Intl.PluralRules` constructor.
11268 ///
11269 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules/PluralRules#options)
11270 #[wasm_bindgen(extends = Object)]
11271 #[derive(Clone, Debug)]
11272 pub type PluralRulesOptions;
11273
11274 #[wasm_bindgen(method, getter = localeMatcher)]
11275 pub fn get_locale_matcher(this: &PluralRulesOptions) -> Option<LocaleMatcher>;
11276 #[wasm_bindgen(method, setter = localeMatcher)]
11277 pub fn set_locale_matcher(this: &PluralRulesOptions, value: LocaleMatcher);
11278
11279 #[wasm_bindgen(method, getter = type)]
11280 pub fn get_type(this: &PluralRulesOptions) -> Option<PluralRulesType>;
11281 #[wasm_bindgen(method, setter = type)]
11282 pub fn set_type(this: &PluralRulesOptions, value: PluralRulesType);
11283
11284 #[wasm_bindgen(method, getter = minimumIntegerDigits)]
11285 pub fn get_minimum_integer_digits(this: &PluralRulesOptions) -> Option<u8>;
11286 #[wasm_bindgen(method, setter = minimumIntegerDigits)]
11287 pub fn set_minimum_integer_digits(this: &PluralRulesOptions, value: u8);
11288
11289 #[wasm_bindgen(method, getter = minimumFractionDigits)]
11290 pub fn get_minimum_fraction_digits(this: &PluralRulesOptions) -> Option<u8>;
11291 #[wasm_bindgen(method, setter = minimumFractionDigits)]
11292 pub fn set_minimum_fraction_digits(this: &PluralRulesOptions, value: u8);
11293
11294 #[wasm_bindgen(method, getter = maximumFractionDigits)]
11295 pub fn get_maximum_fraction_digits(this: &PluralRulesOptions) -> Option<u8>;
11296 #[wasm_bindgen(method, setter = maximumFractionDigits)]
11297 pub fn set_maximum_fraction_digits(this: &PluralRulesOptions, value: u8);
11298
11299 #[wasm_bindgen(method, getter = minimumSignificantDigits)]
11300 pub fn get_minimum_significant_digits(this: &PluralRulesOptions) -> Option<u8>;
11301 #[wasm_bindgen(method, setter = minimumSignificantDigits)]
11302 pub fn set_minimum_significant_digits(this: &PluralRulesOptions, value: u8);
11303
11304 #[wasm_bindgen(method, getter = maximumSignificantDigits)]
11305 pub fn get_maximum_significant_digits(this: &PluralRulesOptions) -> Option<u8>;
11306 #[wasm_bindgen(method, setter = maximumSignificantDigits)]
11307 pub fn set_maximum_significant_digits(this: &PluralRulesOptions, value: u8);
11308
11309 #[wasm_bindgen(method, getter = roundingPriority)]
11310 pub fn get_rounding_priority(this: &PluralRulesOptions) -> Option<RoundingPriority>;
11311 #[wasm_bindgen(method, setter = roundingPriority)]
11312 pub fn set_rounding_priority(this: &PluralRulesOptions, value: RoundingPriority);
11313
11314 #[wasm_bindgen(method, getter = roundingIncrement)]
11315 pub fn get_rounding_increment(this: &PluralRulesOptions) -> Option<u32>;
11316 #[wasm_bindgen(method, setter = roundingIncrement)]
11317 pub fn set_rounding_increment(this: &PluralRulesOptions, value: u32);
11318
11319 #[wasm_bindgen(method, getter = roundingMode)]
11320 pub fn get_rounding_mode(this: &PluralRulesOptions) -> Option<RoundingMode>;
11321 #[wasm_bindgen(method, setter = roundingMode)]
11322 pub fn set_rounding_mode(this: &PluralRulesOptions, value: RoundingMode);
11323
11324 #[wasm_bindgen(method, getter = trailingZeroDisplay)]
11325 pub fn get_trailing_zero_display(this: &PluralRulesOptions) -> Option<TrailingZeroDisplay>;
11326 #[wasm_bindgen(method, setter = trailingZeroDisplay)]
11327 pub fn set_trailing_zero_display(this: &PluralRulesOptions, value: TrailingZeroDisplay);
11328 }
11329
11330 impl PluralRulesOptions {
11331 pub fn new() -> PluralRulesOptions {
11332 JsCast::unchecked_into(Object::new())
11333 }
11334 }
11335
11336 impl Default for PluralRulesOptions {
11337 fn default() -> Self {
11338 PluralRulesOptions::new()
11339 }
11340 }
11341
11342 // Intl.ResolvedPluralRulesOptions
11343 #[wasm_bindgen]
11344 extern "C" {
11345 /// Resolved options returned by `Intl.PluralRules.prototype.resolvedOptions()`.
11346 ///
11347 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules/resolvedOptions)
11348 #[wasm_bindgen(extends = PluralRulesOptions)]
11349 #[derive(Clone, Debug)]
11350 pub type ResolvedPluralRulesOptions;
11351
11352 /// The resolved locale string.
11353 #[wasm_bindgen(method, getter = locale)]
11354 pub fn get_locale(this: &ResolvedPluralRulesOptions) -> JsString;
11355
11356 /// The plural categories used by the locale.
11357 #[wasm_bindgen(method, getter = pluralCategories)]
11358 pub fn get_plural_categories(this: &ResolvedPluralRulesOptions) -> Array<JsString>;
11359 }
11360
11361 // Intl.PluralRules
11362 #[wasm_bindgen]
11363 extern "C" {
11364 /// The `Intl.PluralRules` object is a constructor for objects
11365 /// that enable plural sensitive formatting and plural language rules.
11366 ///
11367 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules)
11368 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.PluralRules")]
11369 #[derive(Clone, Debug)]
11370 pub type PluralRules;
11371
11372 /// The `Intl.PluralRules` object is a constructor for objects
11373 /// that enable plural sensitive formatting and plural language rules.
11374 ///
11375 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules)
11376 #[cfg(not(js_sys_unstable_apis))]
11377 #[wasm_bindgen(constructor, js_namespace = Intl)]
11378 pub fn new(locales: &Array, options: &Object) -> PluralRules;
11379
11380 /// The `Intl.PluralRules` object is a constructor for objects
11381 /// that enable plural sensitive formatting and plural language rules.
11382 ///
11383 /// Throws a `RangeError` if locales contain invalid values.
11384 ///
11385 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules)
11386 #[cfg(js_sys_unstable_apis)]
11387 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
11388 pub fn new(
11389 locales: &[JsString],
11390 options: &PluralRulesOptions,
11391 ) -> Result<PluralRules, JsValue>;
11392
11393 /// The `Intl.PluralRules.prototype.resolvedOptions()` method returns a new
11394 /// object with properties reflecting the locale and plural formatting
11395 /// options computed during initialization of this PluralRules object.
11396 ///
11397 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/resolvedOptions)
11398 #[cfg(not(js_sys_unstable_apis))]
11399 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11400 pub fn resolved_options(this: &PluralRules) -> Object;
11401
11402 /// The `Intl.PluralRules.prototype.resolvedOptions()` method returns a new
11403 /// object with properties reflecting the locale and plural formatting
11404 /// options computed during initialization of this PluralRules object.
11405 ///
11406 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/resolvedOptions)
11407 #[cfg(js_sys_unstable_apis)]
11408 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11409 pub fn resolved_options(this: &PluralRules) -> ResolvedPluralRulesOptions;
11410
11411 /// The `Intl.PluralRules.prototype.select()` method returns a String indicating
11412 /// which plural rule to use for locale-aware formatting.
11413 ///
11414 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/select)
11415 #[cfg(not(js_sys_unstable_apis))]
11416 #[wasm_bindgen(method, js_namespace = Intl)]
11417 pub fn select(this: &PluralRules, number: f64) -> JsString;
11418
11419 /// The `Intl.PluralRules.prototype.select()` method returns a String indicating
11420 /// which plural rule to use for locale-aware formatting.
11421 ///
11422 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/select)
11423 #[cfg(js_sys_unstable_apis)]
11424 #[wasm_bindgen(method, js_namespace = Intl)]
11425 pub fn select(this: &PluralRules, number: f64) -> PluralCategory;
11426
11427 /// The `Intl.PluralRules.prototype.selectRange()` method returns a string indicating
11428 /// which plural rule to use for locale-aware formatting of a range of numbers.
11429 ///
11430 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules/selectRange)
11431 #[cfg(not(js_sys_unstable_apis))]
11432 #[wasm_bindgen(method, js_namespace = Intl, js_name = selectRange)]
11433 pub fn select_range(this: &PluralRules, start: f64, end: f64) -> JsString;
11434
11435 /// The `Intl.PluralRules.prototype.selectRange()` method returns a string indicating
11436 /// which plural rule to use for locale-aware formatting of a range of numbers.
11437 ///
11438 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules/selectRange)
11439 #[cfg(js_sys_unstable_apis)]
11440 #[wasm_bindgen(method, js_namespace = Intl, js_name = selectRange)]
11441 pub fn select_range(this: &PluralRules, start: f64, end: f64) -> PluralCategory;
11442
11443 /// The `Intl.PluralRules.supportedLocalesOf()` method returns an array
11444 /// containing those of the provided locales that are supported in plural
11445 /// formatting without having to fall back to the runtime's default locale.
11446 ///
11447 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/supportedLocalesOf)
11448 #[cfg(not(js_sys_unstable_apis))]
11449 #[wasm_bindgen(static_method_of = PluralRules, js_namespace = Intl, js_name = supportedLocalesOf)]
11450 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
11451
11452 /// The `Intl.PluralRules.supportedLocalesOf()` method returns an array
11453 /// containing those of the provided locales that are supported in plural
11454 /// formatting without having to fall back to the runtime's default locale.
11455 ///
11456 /// Throws a `RangeError` if locales contain invalid values.
11457 ///
11458 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/supportedLocalesOf)
11459 #[cfg(js_sys_unstable_apis)]
11460 #[wasm_bindgen(static_method_of = PluralRules, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
11461 pub fn supported_locales_of(
11462 locales: &[JsString],
11463 options: &LocaleMatcherOptions,
11464 ) -> Result<Array<JsString>, JsValue>;
11465 }
11466
11467 #[cfg(not(js_sys_unstable_apis))]
11468 impl Default for PluralRules {
11469 fn default() -> Self {
11470 Self::new(
11471 &JsValue::UNDEFINED.unchecked_into(),
11472 &JsValue::UNDEFINED.unchecked_into(),
11473 )
11474 }
11475 }
11476
11477 #[cfg(js_sys_unstable_apis)]
11478 impl Default for PluralRules {
11479 fn default() -> Self {
11480 Self::new(&[], &Default::default()).unwrap()
11481 }
11482 }
11483
11484 // Intl.RelativeTimeFormat
11485 #[wasm_bindgen]
11486 extern "C" {
11487 /// The `Intl.RelativeTimeFormat` object is a constructor for objects
11488 /// that enable language-sensitive relative time formatting.
11489 ///
11490 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat)
11491 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.RelativeTimeFormat")]
11492 #[derive(Clone, Debug)]
11493 pub type RelativeTimeFormat;
11494
11495 /// The `Intl.RelativeTimeFormat` object is a constructor for objects
11496 /// that enable language-sensitive relative time formatting.
11497 ///
11498 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat)
11499 #[cfg(not(js_sys_unstable_apis))]
11500 #[wasm_bindgen(constructor, js_namespace = Intl)]
11501 pub fn new(locales: &Array, options: &Object) -> RelativeTimeFormat;
11502
11503 /// The `Intl.RelativeTimeFormat` object is a constructor for objects
11504 /// that enable language-sensitive relative time formatting.
11505 ///
11506 /// Throws a `RangeError` if locales contain invalid values.
11507 ///
11508 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat)
11509 #[cfg(js_sys_unstable_apis)]
11510 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
11511 pub fn new(locales: &[JsString]) -> Result<RelativeTimeFormat, JsValue>;
11512
11513 /// The `Intl.RelativeTimeFormat` object is a constructor for objects
11514 /// that enable language-sensitive relative time formatting.
11515 ///
11516 /// Throws a `RangeError` if locales or options contain invalid values.
11517 ///
11518 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat)
11519 #[cfg(js_sys_unstable_apis)]
11520 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
11521 pub fn new_with_options(
11522 locales: &[JsString],
11523 options: &RelativeTimeFormatOptions,
11524 ) -> Result<RelativeTimeFormat, JsValue>;
11525
11526 /// The `Intl.RelativeTimeFormat.prototype.format` method formats a `value` and `unit`
11527 /// according to the locale and formatting options of this Intl.RelativeTimeFormat object.
11528 ///
11529 /// Throws a `RangeError` if unit is invalid.
11530 ///
11531 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/format)
11532 #[cfg(not(js_sys_unstable_apis))]
11533 #[wasm_bindgen(method, js_class = "Intl.RelativeTimeFormat")]
11534 pub fn format(this: &RelativeTimeFormat, value: f64, unit: &str) -> JsString;
11535
11536 /// The `Intl.RelativeTimeFormat.prototype.format` method formats a `value` and `unit`
11537 /// according to the locale and formatting options of this Intl.RelativeTimeFormat object.
11538 ///
11539 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/format)
11540 #[cfg(js_sys_unstable_apis)]
11541 #[wasm_bindgen(method, js_class = "Intl.RelativeTimeFormat")]
11542 pub fn format(
11543 this: &RelativeTimeFormat,
11544 value: f64,
11545 unit: RelativeTimeFormatUnit,
11546 ) -> JsString;
11547
11548 /// The `Intl.RelativeTimeFormat.prototype.formatToParts()` method returns an array of
11549 /// objects representing the relative time format in parts that can be used for custom locale-aware formatting.
11550 ///
11551 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/formatToParts)
11552 #[cfg(not(js_sys_unstable_apis))]
11553 #[wasm_bindgen(method, js_class = "Intl.RelativeTimeFormat", js_name = formatToParts)]
11554 pub fn format_to_parts(this: &RelativeTimeFormat, value: f64, unit: &str) -> Array;
11555
11556 /// The `Intl.RelativeTimeFormat.prototype.formatToParts()` method returns an array of
11557 /// objects representing the relative time format in parts that can be used for custom locale-aware formatting.
11558 ///
11559 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/formatToParts)
11560 #[cfg(js_sys_unstable_apis)]
11561 #[wasm_bindgen(method, js_class = "Intl.RelativeTimeFormat", js_name = formatToParts)]
11562 pub fn format_to_parts(
11563 this: &RelativeTimeFormat,
11564 value: f64,
11565 unit: RelativeTimeFormatUnit,
11566 ) -> Array<RelativeTimeFormatPart>;
11567
11568 /// The `Intl.RelativeTimeFormat.prototype.resolvedOptions()` method returns a new
11569 /// object with properties reflecting the locale and relative time formatting
11570 /// options computed during initialization of this RelativeTimeFormat object.
11571 ///
11572 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/resolvedOptions)
11573 #[cfg(not(js_sys_unstable_apis))]
11574 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11575 pub fn resolved_options(this: &RelativeTimeFormat) -> Object;
11576
11577 /// The `Intl.RelativeTimeFormat.prototype.resolvedOptions()` method returns a new
11578 /// object with properties reflecting the locale and relative time formatting
11579 /// options computed during initialization of this RelativeTimeFormat object.
11580 ///
11581 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/resolvedOptions)
11582 #[cfg(js_sys_unstable_apis)]
11583 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11584 pub fn resolved_options(this: &RelativeTimeFormat) -> ResolvedRelativeTimeFormatOptions;
11585
11586 /// The `Intl.RelativeTimeFormat.supportedLocalesOf()` method returns an array
11587 /// containing those of the provided locales that are supported in date and time
11588 /// formatting without having to fall back to the runtime's default locale.
11589 ///
11590 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RelativeTimeFormat/supportedLocalesOf)
11591 #[cfg(not(js_sys_unstable_apis))]
11592 #[wasm_bindgen(static_method_of = RelativeTimeFormat, js_namespace = Intl, js_name = supportedLocalesOf)]
11593 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
11594
11595 /// The `Intl.RelativeTimeFormat.supportedLocalesOf()` method returns an array
11596 /// containing those of the provided locales that are supported in date and time
11597 /// formatting without having to fall back to the runtime's default locale.
11598 ///
11599 /// Throws a `RangeError` if locales contain invalid values.
11600 ///
11601 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RelativeTimeFormat/supportedLocalesOf)
11602 #[cfg(js_sys_unstable_apis)]
11603 #[wasm_bindgen(static_method_of = RelativeTimeFormat, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
11604 pub fn supported_locales_of(
11605 locales: &[JsString],
11606 options: &LocaleMatcherOptions,
11607 ) -> Result<Array<JsString>, JsValue>;
11608 }
11609
11610 #[cfg(not(js_sys_unstable_apis))]
11611 impl Default for RelativeTimeFormat {
11612 fn default() -> Self {
11613 Self::new(
11614 &JsValue::UNDEFINED.unchecked_into(),
11615 &JsValue::UNDEFINED.unchecked_into(),
11616 )
11617 }
11618 }
11619
11620 #[cfg(js_sys_unstable_apis)]
11621 impl Default for RelativeTimeFormat {
11622 fn default() -> Self {
11623 Self::new(&[]).unwrap()
11624 }
11625 }
11626
11627 // Intl.ListFormatOptions
11628 #[wasm_bindgen]
11629 extern "C" {
11630 /// Options for `Intl.ListFormat` constructor.
11631 ///
11632 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/ListFormat#options)
11633 #[wasm_bindgen(extends = Object)]
11634 #[derive(Clone, Debug)]
11635 pub type ListFormatOptions;
11636
11637 #[wasm_bindgen(method, getter = localeMatcher)]
11638 pub fn get_locale_matcher(this: &ListFormatOptions) -> Option<LocaleMatcher>;
11639 #[wasm_bindgen(method, setter = localeMatcher)]
11640 pub fn set_locale_matcher(this: &ListFormatOptions, value: LocaleMatcher);
11641
11642 #[wasm_bindgen(method, getter = type)]
11643 pub fn get_type(this: &ListFormatOptions) -> Option<ListFormatType>;
11644 #[wasm_bindgen(method, setter = type)]
11645 pub fn set_type(this: &ListFormatOptions, value: ListFormatType);
11646
11647 #[wasm_bindgen(method, getter = style)]
11648 pub fn get_style(this: &ListFormatOptions) -> Option<ListFormatStyle>;
11649 #[wasm_bindgen(method, setter = style)]
11650 pub fn set_style(this: &ListFormatOptions, value: ListFormatStyle);
11651 }
11652
11653 impl ListFormatOptions {
11654 pub fn new() -> ListFormatOptions {
11655 JsCast::unchecked_into(Object::new())
11656 }
11657 }
11658
11659 impl Default for ListFormatOptions {
11660 fn default() -> Self {
11661 ListFormatOptions::new()
11662 }
11663 }
11664
11665 // Intl.ResolvedListFormatOptions
11666 #[wasm_bindgen]
11667 extern "C" {
11668 /// Resolved options returned by `Intl.ListFormat.prototype.resolvedOptions()`.
11669 ///
11670 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/resolvedOptions)
11671 #[wasm_bindgen(extends = ListFormatOptions)]
11672 #[derive(Clone, Debug)]
11673 pub type ResolvedListFormatOptions;
11674
11675 /// The resolved locale string.
11676 #[wasm_bindgen(method, getter = locale)]
11677 pub fn get_locale(this: &ResolvedListFormatOptions) -> JsString;
11678 }
11679
11680 // Intl.ListFormatPart
11681 #[wasm_bindgen]
11682 extern "C" {
11683 /// A part of the formatted list returned by `formatToParts()`.
11684 ///
11685 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/formatToParts)
11686 #[wasm_bindgen(extends = Object)]
11687 #[derive(Clone, Debug)]
11688 pub type ListFormatPart;
11689
11690 /// The type of the part ("element" or "literal").
11691 #[wasm_bindgen(method, getter = type)]
11692 pub fn type_(this: &ListFormatPart) -> ListFormatPartType;
11693
11694 /// The value of the part.
11695 #[wasm_bindgen(method, getter)]
11696 pub fn value(this: &ListFormatPart) -> JsString;
11697 }
11698
11699 // Intl.ListFormat
11700 #[wasm_bindgen]
11701 extern "C" {
11702 /// The `Intl.ListFormat` object enables language-sensitive list formatting.
11703 ///
11704 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat)
11705 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.ListFormat")]
11706 #[derive(Clone, Debug)]
11707 pub type ListFormat;
11708
11709 /// Creates a new `Intl.ListFormat` object.
11710 ///
11711 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/ListFormat)
11712 #[cfg(not(js_sys_unstable_apis))]
11713 #[wasm_bindgen(constructor, js_namespace = Intl)]
11714 pub fn new(locales: &Array, options: &Object) -> ListFormat;
11715
11716 /// Creates a new `Intl.ListFormat` object.
11717 ///
11718 /// Throws a `RangeError` if locales or options contain invalid values.
11719 ///
11720 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/ListFormat)
11721 #[cfg(js_sys_unstable_apis)]
11722 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
11723 pub fn new(
11724 locales: &[JsString],
11725 options: &ListFormatOptions,
11726 ) -> Result<ListFormat, JsValue>;
11727
11728 /// Formats a list of strings according to the locale and options.
11729 ///
11730 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/format)
11731 #[cfg(not(js_sys_unstable_apis))]
11732 #[wasm_bindgen(method, js_class = "Intl.ListFormat")]
11733 pub fn format(this: &ListFormat, list: &Array) -> JsString;
11734
11735 /// Formats a list of strings according to the locale and options.
11736 ///
11737 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/format)
11738 #[cfg(js_sys_unstable_apis)]
11739 #[wasm_bindgen(method, js_class = "Intl.ListFormat")]
11740 pub fn format(this: &ListFormat, list: &[JsString]) -> JsString;
11741
11742 /// Returns an array of objects representing the list in parts.
11743 ///
11744 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/formatToParts)
11745 #[cfg(not(js_sys_unstable_apis))]
11746 #[wasm_bindgen(method, js_class = "Intl.ListFormat", js_name = formatToParts)]
11747 pub fn format_to_parts(this: &ListFormat, list: &Array) -> Array;
11748
11749 /// Returns an array of objects representing the list in parts.
11750 ///
11751 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/formatToParts)
11752 #[cfg(js_sys_unstable_apis)]
11753 #[wasm_bindgen(method, js_class = "Intl.ListFormat", js_name = formatToParts)]
11754 pub fn format_to_parts(this: &ListFormat, list: &[JsString]) -> Array<ListFormatPart>;
11755
11756 /// Returns an object with properties reflecting the options used.
11757 ///
11758 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/resolvedOptions)
11759 #[cfg(not(js_sys_unstable_apis))]
11760 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11761 pub fn resolved_options(this: &ListFormat) -> Object;
11762
11763 /// Returns an object with properties reflecting the options used.
11764 ///
11765 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/resolvedOptions)
11766 #[cfg(js_sys_unstable_apis)]
11767 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11768 pub fn resolved_options(this: &ListFormat) -> ResolvedListFormatOptions;
11769
11770 /// Returns an array of supported locales.
11771 ///
11772 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/supportedLocalesOf)
11773 #[cfg(not(js_sys_unstable_apis))]
11774 #[wasm_bindgen(static_method_of = ListFormat, js_namespace = Intl, js_name = supportedLocalesOf)]
11775 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
11776
11777 /// Returns an array of supported locales.
11778 ///
11779 /// Throws a `RangeError` if locales contain invalid values.
11780 ///
11781 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/supportedLocalesOf)
11782 #[cfg(js_sys_unstable_apis)]
11783 #[wasm_bindgen(static_method_of = ListFormat, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
11784 pub fn supported_locales_of(
11785 locales: &[JsString],
11786 options: &LocaleMatcherOptions,
11787 ) -> Result<Array<JsString>, JsValue>;
11788 }
11789
11790 #[cfg(not(js_sys_unstable_apis))]
11791 impl Default for ListFormat {
11792 fn default() -> Self {
11793 Self::new(
11794 &JsValue::UNDEFINED.unchecked_into(),
11795 &JsValue::UNDEFINED.unchecked_into(),
11796 )
11797 }
11798 }
11799
11800 #[cfg(js_sys_unstable_apis)]
11801 impl Default for ListFormat {
11802 fn default() -> Self {
11803 Self::new(&[], &Default::default()).unwrap()
11804 }
11805 }
11806
11807 // Intl.SegmenterOptions
11808 #[wasm_bindgen]
11809 extern "C" {
11810 /// Options for `Intl.Segmenter` constructor.
11811 ///
11812 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/Segmenter#options)
11813 #[wasm_bindgen(extends = Object)]
11814 #[derive(Clone, Debug)]
11815 pub type SegmenterOptions;
11816
11817 #[wasm_bindgen(method, getter = localeMatcher)]
11818 pub fn get_locale_matcher(this: &SegmenterOptions) -> Option<LocaleMatcher>;
11819 #[wasm_bindgen(method, setter = localeMatcher)]
11820 pub fn set_locale_matcher(this: &SegmenterOptions, value: LocaleMatcher);
11821
11822 #[wasm_bindgen(method, getter = granularity)]
11823 pub fn get_granularity(this: &SegmenterOptions) -> Option<SegmenterGranularity>;
11824 #[wasm_bindgen(method, setter = granularity)]
11825 pub fn set_granularity(this: &SegmenterOptions, value: SegmenterGranularity);
11826 }
11827
11828 impl SegmenterOptions {
11829 pub fn new() -> SegmenterOptions {
11830 JsCast::unchecked_into(Object::new())
11831 }
11832 }
11833
11834 impl Default for SegmenterOptions {
11835 fn default() -> Self {
11836 SegmenterOptions::new()
11837 }
11838 }
11839
11840 // Intl.ResolvedSegmenterOptions
11841 #[wasm_bindgen]
11842 extern "C" {
11843 /// Resolved options returned by `Intl.Segmenter.prototype.resolvedOptions()`.
11844 ///
11845 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/resolvedOptions)
11846 #[wasm_bindgen(extends = SegmenterOptions)]
11847 #[derive(Clone, Debug)]
11848 pub type ResolvedSegmenterOptions;
11849
11850 /// The resolved locale string.
11851 #[wasm_bindgen(method, getter = locale)]
11852 pub fn get_locale(this: &ResolvedSegmenterOptions) -> JsString;
11853 }
11854
11855 // Intl.SegmentData
11856 #[wasm_bindgen]
11857 extern "C" {
11858 /// Data about a segment returned by the Segments iterator.
11859 ///
11860 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/segment/Segments#segment_data)
11861 #[wasm_bindgen(extends = Object)]
11862 #[derive(Clone, Debug)]
11863 pub type SegmentData;
11864
11865 /// The segment string.
11866 #[wasm_bindgen(method, getter)]
11867 pub fn segment(this: &SegmentData) -> JsString;
11868
11869 /// The index of the segment in the original string.
11870 #[wasm_bindgen(method, getter)]
11871 pub fn index(this: &SegmentData) -> u32;
11872
11873 /// The original input string.
11874 #[wasm_bindgen(method, getter)]
11875 pub fn input(this: &SegmentData) -> JsString;
11876
11877 /// Whether the segment is word-like (only for word granularity).
11878 #[wasm_bindgen(method, getter = isWordLike)]
11879 pub fn is_word_like(this: &SegmentData) -> Option<bool>;
11880 }
11881
11882 // Intl.Segments
11883 #[wasm_bindgen]
11884 extern "C" {
11885 /// The Segments object is an iterable collection of segments of a string.
11886 ///
11887 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/segment/Segments)
11888 #[wasm_bindgen(extends = Object)]
11889 #[derive(Clone, Debug)]
11890 pub type Segments;
11891
11892 /// Returns segment data for the segment containing the character at the given index.
11893 ///
11894 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/segment/Segments/containing)
11895 #[wasm_bindgen(method)]
11896 pub fn containing(this: &Segments, index: u32) -> Option<SegmentData>;
11897 }
11898
11899 // Intl.Segmenter
11900 #[wasm_bindgen]
11901 extern "C" {
11902 /// The `Intl.Segmenter` object enables locale-sensitive text segmentation.
11903 ///
11904 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter)
11905 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.Segmenter")]
11906 #[derive(Clone, Debug)]
11907 pub type Segmenter;
11908
11909 /// Creates a new `Intl.Segmenter` object.
11910 ///
11911 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/Segmenter)
11912 #[cfg(not(js_sys_unstable_apis))]
11913 #[wasm_bindgen(constructor, js_namespace = Intl)]
11914 pub fn new(locales: &Array, options: &Object) -> Segmenter;
11915
11916 /// Creates a new `Intl.Segmenter` object.
11917 ///
11918 /// Throws a `RangeError` if locales or options contain invalid values.
11919 ///
11920 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/Segmenter)
11921 #[cfg(js_sys_unstable_apis)]
11922 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
11923 pub fn new(locales: &[JsString], options: &SegmenterOptions) -> Result<Segmenter, JsValue>;
11924
11925 /// Returns a Segments object containing the segments of the input string.
11926 ///
11927 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/segment)
11928 #[wasm_bindgen(method, js_class = "Intl.Segmenter")]
11929 pub fn segment(this: &Segmenter, input: &str) -> Segments;
11930
11931 /// Returns an object with properties reflecting the options used.
11932 ///
11933 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/resolvedOptions)
11934 #[cfg(not(js_sys_unstable_apis))]
11935 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11936 pub fn resolved_options(this: &Segmenter) -> Object;
11937
11938 /// Returns an object with properties reflecting the options used.
11939 ///
11940 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/resolvedOptions)
11941 #[cfg(js_sys_unstable_apis)]
11942 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
11943 pub fn resolved_options(this: &Segmenter) -> ResolvedSegmenterOptions;
11944
11945 /// Returns an array of supported locales.
11946 ///
11947 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/supportedLocalesOf)
11948 #[cfg(not(js_sys_unstable_apis))]
11949 #[wasm_bindgen(static_method_of = Segmenter, js_namespace = Intl, js_name = supportedLocalesOf)]
11950 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
11951
11952 /// Returns an array of supported locales.
11953 ///
11954 /// Throws a `RangeError` if locales contain invalid values.
11955 ///
11956 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter/supportedLocalesOf)
11957 #[cfg(js_sys_unstable_apis)]
11958 #[wasm_bindgen(static_method_of = Segmenter, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
11959 pub fn supported_locales_of(
11960 locales: &[JsString],
11961 options: &LocaleMatcherOptions,
11962 ) -> Result<Array<JsString>, JsValue>;
11963 }
11964
11965 #[cfg(not(js_sys_unstable_apis))]
11966 impl Default for Segmenter {
11967 fn default() -> Self {
11968 Self::new(
11969 &JsValue::UNDEFINED.unchecked_into(),
11970 &JsValue::UNDEFINED.unchecked_into(),
11971 )
11972 }
11973 }
11974
11975 #[cfg(js_sys_unstable_apis)]
11976 impl Default for Segmenter {
11977 fn default() -> Self {
11978 Self::new(&[], &Default::default()).unwrap()
11979 }
11980 }
11981
11982 // Intl.DisplayNamesOptions
11983 #[wasm_bindgen]
11984 extern "C" {
11985 /// Options for `Intl.DisplayNames` constructor.
11986 ///
11987 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/DisplayNames#options)
11988 #[wasm_bindgen(extends = Object)]
11989 #[derive(Clone, Debug)]
11990 pub type DisplayNamesOptions;
11991
11992 #[wasm_bindgen(method, getter = localeMatcher)]
11993 pub fn get_locale_matcher(this: &DisplayNamesOptions) -> Option<LocaleMatcher>;
11994 #[wasm_bindgen(method, setter = localeMatcher)]
11995 pub fn set_locale_matcher(this: &DisplayNamesOptions, value: LocaleMatcher);
11996
11997 #[wasm_bindgen(method, getter = type)]
11998 pub fn get_type(this: &DisplayNamesOptions) -> Option<DisplayNamesType>;
11999 #[wasm_bindgen(method, setter = type)]
12000 pub fn set_type(this: &DisplayNamesOptions, value: DisplayNamesType);
12001
12002 #[wasm_bindgen(method, getter = style)]
12003 pub fn get_style(this: &DisplayNamesOptions) -> Option<DisplayNamesStyle>;
12004 #[wasm_bindgen(method, setter = style)]
12005 pub fn set_style(this: &DisplayNamesOptions, value: DisplayNamesStyle);
12006
12007 #[wasm_bindgen(method, getter = fallback)]
12008 pub fn get_fallback(this: &DisplayNamesOptions) -> Option<DisplayNamesFallback>;
12009 #[wasm_bindgen(method, setter = fallback)]
12010 pub fn set_fallback(this: &DisplayNamesOptions, value: DisplayNamesFallback);
12011
12012 #[wasm_bindgen(method, getter = languageDisplay)]
12013 pub fn get_language_display(
12014 this: &DisplayNamesOptions,
12015 ) -> Option<DisplayNamesLanguageDisplay>;
12016 #[wasm_bindgen(method, setter = languageDisplay)]
12017 pub fn set_language_display(this: &DisplayNamesOptions, value: DisplayNamesLanguageDisplay);
12018 }
12019
12020 impl DisplayNamesOptions {
12021 pub fn new() -> DisplayNamesOptions {
12022 JsCast::unchecked_into(Object::new())
12023 }
12024 }
12025
12026 impl Default for DisplayNamesOptions {
12027 fn default() -> Self {
12028 DisplayNamesOptions::new()
12029 }
12030 }
12031
12032 // Intl.ResolvedDisplayNamesOptions
12033 #[wasm_bindgen]
12034 extern "C" {
12035 /// Resolved options returned by `Intl.DisplayNames.prototype.resolvedOptions()`.
12036 ///
12037 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/resolvedOptions)
12038 #[wasm_bindgen(extends = DisplayNamesOptions)]
12039 #[derive(Clone, Debug)]
12040 pub type ResolvedDisplayNamesOptions;
12041
12042 /// The resolved locale string.
12043 #[wasm_bindgen(method, getter = locale)]
12044 pub fn get_locale(this: &ResolvedDisplayNamesOptions) -> JsString;
12045 }
12046
12047 // Intl.DisplayNames
12048 #[wasm_bindgen]
12049 extern "C" {
12050 /// The `Intl.DisplayNames` object enables the consistent translation of
12051 /// language, region, and script display names.
12052 ///
12053 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames)
12054 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.DisplayNames")]
12055 #[derive(Clone, Debug)]
12056 pub type DisplayNames;
12057
12058 /// Creates a new `Intl.DisplayNames` object.
12059 ///
12060 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/DisplayNames)
12061 #[cfg(not(js_sys_unstable_apis))]
12062 #[wasm_bindgen(constructor, js_namespace = Intl)]
12063 pub fn new(locales: &Array, options: &Object) -> DisplayNames;
12064
12065 /// Creates a new `Intl.DisplayNames` object.
12066 ///
12067 /// Throws a `RangeError` if locales or options contain invalid values.
12068 ///
12069 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/DisplayNames)
12070 #[cfg(js_sys_unstable_apis)]
12071 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
12072 pub fn new(
12073 locales: &[JsString],
12074 options: &DisplayNamesOptions,
12075 ) -> Result<DisplayNames, JsValue>;
12076
12077 /// Returns the display name for the given code.
12078 ///
12079 /// Returns `undefined` if fallback is "none" and no name is available.
12080 ///
12081 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/of)
12082 #[wasm_bindgen(method, js_class = "Intl.DisplayNames")]
12083 pub fn of(this: &DisplayNames, code: &str) -> Option<JsString>;
12084
12085 /// Returns an object with properties reflecting the options used.
12086 ///
12087 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/resolvedOptions)
12088 #[cfg(not(js_sys_unstable_apis))]
12089 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
12090 pub fn resolved_options(this: &DisplayNames) -> Object;
12091
12092 /// Returns an object with properties reflecting the options used.
12093 ///
12094 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/resolvedOptions)
12095 #[cfg(js_sys_unstable_apis)]
12096 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
12097 pub fn resolved_options(this: &DisplayNames) -> ResolvedDisplayNamesOptions;
12098
12099 /// Returns an array of supported locales.
12100 ///
12101 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/supportedLocalesOf)
12102 #[cfg(not(js_sys_unstable_apis))]
12103 #[wasm_bindgen(static_method_of = DisplayNames, js_namespace = Intl, js_name = supportedLocalesOf)]
12104 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
12105
12106 /// Returns an array of supported locales.
12107 ///
12108 /// Throws a `RangeError` if locales contain invalid values.
12109 ///
12110 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/supportedLocalesOf)
12111 #[cfg(js_sys_unstable_apis)]
12112 #[wasm_bindgen(static_method_of = DisplayNames, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
12113 pub fn supported_locales_of(
12114 locales: &[JsString],
12115 options: &LocaleMatcherOptions,
12116 ) -> Result<Array<JsString>, JsValue>;
12117 }
12118
12119 // Intl.Locale
12120 #[wasm_bindgen]
12121 extern "C" {
12122 /// The `Intl.Locale` object is a standard built-in property of the Intl object
12123 /// that represents a Unicode locale identifier.
12124 ///
12125 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale)
12126 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.Locale")]
12127 #[derive(Clone, Debug)]
12128 pub type Locale;
12129
12130 /// Creates a new `Intl.Locale` object.
12131 ///
12132 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/Locale)
12133 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
12134 pub fn new(tag: &str) -> Result<Locale, JsValue>;
12135
12136 /// Creates a new `Intl.Locale` object with options.
12137 ///
12138 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/Locale)
12139 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
12140 pub fn new_with_options(tag: &str, options: &Object) -> Result<Locale, JsValue>;
12141
12142 /// The base name of the locale (language + region + script).
12143 ///
12144 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/baseName)
12145 #[wasm_bindgen(method, getter = baseName)]
12146 pub fn base_name(this: &Locale) -> JsString;
12147
12148 /// The calendar type for the locale.
12149 ///
12150 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/calendar)
12151 #[wasm_bindgen(method, getter)]
12152 pub fn calendar(this: &Locale) -> Option<JsString>;
12153
12154 /// The case first sorting option.
12155 ///
12156 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/caseFirst)
12157 #[wasm_bindgen(method, getter = caseFirst)]
12158 pub fn case_first(this: &Locale) -> Option<JsString>;
12159
12160 /// The collation type for the locale.
12161 ///
12162 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/collation)
12163 #[wasm_bindgen(method, getter)]
12164 pub fn collation(this: &Locale) -> Option<JsString>;
12165
12166 /// The hour cycle for the locale.
12167 ///
12168 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/hourCycle)
12169 #[wasm_bindgen(method, getter = hourCycle)]
12170 pub fn hour_cycle(this: &Locale) -> Option<JsString>;
12171
12172 /// The language code for the locale.
12173 ///
12174 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/language)
12175 #[wasm_bindgen(method, getter)]
12176 pub fn language(this: &Locale) -> JsString;
12177
12178 /// The numbering system for the locale.
12179 ///
12180 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/numberingSystem)
12181 #[wasm_bindgen(method, getter = numberingSystem)]
12182 pub fn numbering_system(this: &Locale) -> Option<JsString>;
12183
12184 /// Whether the locale uses numeric collation.
12185 ///
12186 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/numeric)
12187 #[wasm_bindgen(method, getter)]
12188 pub fn numeric(this: &Locale) -> bool;
12189
12190 /// The region code for the locale.
12191 ///
12192 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/region)
12193 #[wasm_bindgen(method, getter)]
12194 pub fn region(this: &Locale) -> Option<JsString>;
12195
12196 /// The script code for the locale.
12197 ///
12198 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/script)
12199 #[wasm_bindgen(method, getter)]
12200 pub fn script(this: &Locale) -> Option<JsString>;
12201
12202 /// Returns an array of available calendars for the locale.
12203 ///
12204 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getCalendars)
12205 #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getCalendars)]
12206 pub fn get_calendars(this: &Locale) -> Array<JsString>;
12207
12208 /// Returns an array of available collations for the locale.
12209 ///
12210 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getCollations)
12211 #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getCollations)]
12212 pub fn get_collations(this: &Locale) -> Array<JsString>;
12213
12214 /// Returns an array of available hour cycles for the locale.
12215 ///
12216 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getHourCycles)
12217 #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getHourCycles)]
12218 pub fn get_hour_cycles(this: &Locale) -> Array<JsString>;
12219
12220 /// Returns an array of available numbering systems for the locale.
12221 ///
12222 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getNumberingSystems)
12223 #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getNumberingSystems)]
12224 pub fn get_numbering_systems(this: &Locale) -> Array<JsString>;
12225
12226 /// Returns an array of available time zones for the locale's region.
12227 ///
12228 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getTimeZones)
12229 #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getTimeZones)]
12230 pub fn get_time_zones(this: &Locale) -> Option<Array<JsString>>;
12231
12232 /// Returns week information for the locale.
12233 ///
12234 /// May not be available in all environments.
12235 ///
12236 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getWeekInfo)
12237 #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getWeekInfo, catch)]
12238 pub fn get_week_info(this: &Locale) -> Result<WeekInfo, JsValue>;
12239
12240 /// Returns text layout information for the locale.
12241 ///
12242 /// May not be available in all environments.
12243 ///
12244 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getTextInfo)
12245 #[wasm_bindgen(method, js_class = "Intl.Locale", js_name = getTextInfo, catch)]
12246 pub fn get_text_info(this: &Locale) -> Result<TextInfo, JsValue>;
12247
12248 /// Returns a new Locale with the specified calendar.
12249 ///
12250 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/maximize)
12251 #[wasm_bindgen(method, js_class = "Intl.Locale")]
12252 pub fn maximize(this: &Locale) -> Locale;
12253
12254 /// Returns a new Locale with the minimal subtags.
12255 ///
12256 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/minimize)
12257 #[wasm_bindgen(method, js_class = "Intl.Locale")]
12258 pub fn minimize(this: &Locale) -> Locale;
12259 }
12260
12261 // Intl.Locale WeekInfo
12262 #[wasm_bindgen]
12263 extern "C" {
12264 /// Week information for a locale.
12265 ///
12266 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getWeekInfo)
12267 #[wasm_bindgen(extends = Object)]
12268 #[derive(Clone, Debug)]
12269 pub type WeekInfo;
12270
12271 /// The first day of the week (1 = Monday, 7 = Sunday).
12272 #[wasm_bindgen(method, getter = firstDay)]
12273 pub fn first_day(this: &WeekInfo) -> u8;
12274
12275 /// Array of weekend days.
12276 #[wasm_bindgen(method, getter)]
12277 pub fn weekend(this: &WeekInfo) -> Array<Number>;
12278
12279 /// Minimal days in the first week of the year.
12280 #[wasm_bindgen(method, getter = minimalDays)]
12281 pub fn minimal_days(this: &WeekInfo) -> u8;
12282 }
12283
12284 // Intl.Locale TextInfo
12285 #[wasm_bindgen]
12286 extern "C" {
12287 /// Text layout information for a locale.
12288 ///
12289 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getTextInfo)
12290 #[wasm_bindgen(extends = Object)]
12291 #[derive(Clone, Debug)]
12292 pub type TextInfo;
12293
12294 /// The text direction ("ltr" or "rtl").
12295 #[wasm_bindgen(method, getter)]
12296 pub fn direction(this: &TextInfo) -> JsString;
12297 }
12298
12299 // Intl.DurationFormat enums
12300
12301 /// The style for duration formatting.
12302 ///
12303 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat#style)
12304 #[wasm_bindgen]
12305 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
12306 pub enum DurationFormatStyle {
12307 Long = "long",
12308 Short = "short",
12309 Narrow = "narrow",
12310 Digital = "digital",
12311 }
12312
12313 /// The display style for individual duration units.
12314 ///
12315 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat#years)
12316 #[wasm_bindgen]
12317 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
12318 pub enum DurationUnitStyle {
12319 Long = "long",
12320 Short = "short",
12321 Narrow = "narrow",
12322 }
12323
12324 /// The display style for time duration units (hours, minutes, seconds).
12325 ///
12326 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat#hours)
12327 #[wasm_bindgen]
12328 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
12329 pub enum DurationTimeUnitStyle {
12330 Long = "long",
12331 Short = "short",
12332 Narrow = "narrow",
12333 Numeric = "numeric",
12334 #[wasm_bindgen(js_name = "2-digit")]
12335 TwoDigit = "2-digit",
12336 }
12337
12338 /// The display option for duration units.
12339 ///
12340 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat#yearsdisplay)
12341 #[wasm_bindgen]
12342 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
12343 pub enum DurationUnitDisplay {
12344 Auto = "auto",
12345 Always = "always",
12346 }
12347
12348 /// The type of a duration format part.
12349 ///
12350 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/formatToParts#type)
12351 #[wasm_bindgen]
12352 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
12353 pub enum DurationFormatPartType {
12354 Years = "years",
12355 Months = "months",
12356 Weeks = "weeks",
12357 Days = "days",
12358 Hours = "hours",
12359 Minutes = "minutes",
12360 Seconds = "seconds",
12361 Milliseconds = "milliseconds",
12362 Microseconds = "microseconds",
12363 Nanoseconds = "nanoseconds",
12364 Literal = "literal",
12365 Integer = "integer",
12366 Decimal = "decimal",
12367 Fraction = "fraction",
12368 }
12369
12370 // Intl.DurationFormatOptions
12371 #[wasm_bindgen]
12372 extern "C" {
12373 /// Options for `Intl.DurationFormat` constructor.
12374 ///
12375 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat#options)
12376 #[wasm_bindgen(extends = Object)]
12377 #[derive(Clone, Debug)]
12378 pub type DurationFormatOptions;
12379
12380 #[wasm_bindgen(method, getter = localeMatcher)]
12381 pub fn get_locale_matcher(this: &DurationFormatOptions) -> Option<LocaleMatcher>;
12382 #[wasm_bindgen(method, setter = localeMatcher)]
12383 pub fn set_locale_matcher(this: &DurationFormatOptions, value: LocaleMatcher);
12384
12385 #[wasm_bindgen(method, getter = style)]
12386 pub fn get_style(this: &DurationFormatOptions) -> Option<DurationFormatStyle>;
12387 #[wasm_bindgen(method, setter = style)]
12388 pub fn set_style(this: &DurationFormatOptions, value: DurationFormatStyle);
12389
12390 #[wasm_bindgen(method, getter = years)]
12391 pub fn get_years(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
12392 #[wasm_bindgen(method, setter = years)]
12393 pub fn set_years(this: &DurationFormatOptions, value: DurationUnitStyle);
12394
12395 #[wasm_bindgen(method, getter = yearsDisplay)]
12396 pub fn get_years_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
12397 #[wasm_bindgen(method, setter = yearsDisplay)]
12398 pub fn set_years_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12399
12400 #[wasm_bindgen(method, getter = months)]
12401 pub fn get_months(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
12402 #[wasm_bindgen(method, setter = months)]
12403 pub fn set_months(this: &DurationFormatOptions, value: DurationUnitStyle);
12404
12405 #[wasm_bindgen(method, getter = monthsDisplay)]
12406 pub fn get_months_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
12407 #[wasm_bindgen(method, setter = monthsDisplay)]
12408 pub fn set_months_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12409
12410 #[wasm_bindgen(method, getter = weeks)]
12411 pub fn get_weeks(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
12412 #[wasm_bindgen(method, setter = weeks)]
12413 pub fn set_weeks(this: &DurationFormatOptions, value: DurationUnitStyle);
12414
12415 #[wasm_bindgen(method, getter = weeksDisplay)]
12416 pub fn get_weeks_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
12417 #[wasm_bindgen(method, setter = weeksDisplay)]
12418 pub fn set_weeks_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12419
12420 #[wasm_bindgen(method, getter = days)]
12421 pub fn get_days(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
12422 #[wasm_bindgen(method, setter = days)]
12423 pub fn set_days(this: &DurationFormatOptions, value: DurationUnitStyle);
12424
12425 #[wasm_bindgen(method, getter = daysDisplay)]
12426 pub fn get_days_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
12427 #[wasm_bindgen(method, setter = daysDisplay)]
12428 pub fn set_days_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12429
12430 #[wasm_bindgen(method, getter = hours)]
12431 pub fn get_hours(this: &DurationFormatOptions) -> Option<DurationTimeUnitStyle>;
12432 #[wasm_bindgen(method, setter = hours)]
12433 pub fn set_hours(this: &DurationFormatOptions, value: DurationTimeUnitStyle);
12434
12435 #[wasm_bindgen(method, getter = hoursDisplay)]
12436 pub fn get_hours_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
12437 #[wasm_bindgen(method, setter = hoursDisplay)]
12438 pub fn set_hours_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12439
12440 #[wasm_bindgen(method, getter = minutes)]
12441 pub fn get_minutes(this: &DurationFormatOptions) -> Option<DurationTimeUnitStyle>;
12442 #[wasm_bindgen(method, setter = minutes)]
12443 pub fn set_minutes(this: &DurationFormatOptions, value: DurationTimeUnitStyle);
12444
12445 #[wasm_bindgen(method, getter = minutesDisplay)]
12446 pub fn get_minutes_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
12447 #[wasm_bindgen(method, setter = minutesDisplay)]
12448 pub fn set_minutes_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12449
12450 #[wasm_bindgen(method, getter = seconds)]
12451 pub fn get_seconds(this: &DurationFormatOptions) -> Option<DurationTimeUnitStyle>;
12452 #[wasm_bindgen(method, setter = seconds)]
12453 pub fn set_seconds(this: &DurationFormatOptions, value: DurationTimeUnitStyle);
12454
12455 #[wasm_bindgen(method, getter = secondsDisplay)]
12456 pub fn get_seconds_display(this: &DurationFormatOptions) -> Option<DurationUnitDisplay>;
12457 #[wasm_bindgen(method, setter = secondsDisplay)]
12458 pub fn set_seconds_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12459
12460 #[wasm_bindgen(method, getter = milliseconds)]
12461 pub fn get_milliseconds(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
12462 #[wasm_bindgen(method, setter = milliseconds)]
12463 pub fn set_milliseconds(this: &DurationFormatOptions, value: DurationUnitStyle);
12464
12465 #[wasm_bindgen(method, getter = millisecondsDisplay)]
12466 pub fn get_milliseconds_display(
12467 this: &DurationFormatOptions,
12468 ) -> Option<DurationUnitDisplay>;
12469 #[wasm_bindgen(method, setter = millisecondsDisplay)]
12470 pub fn set_milliseconds_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12471
12472 #[wasm_bindgen(method, getter = microseconds)]
12473 pub fn get_microseconds(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
12474 #[wasm_bindgen(method, setter = microseconds)]
12475 pub fn set_microseconds(this: &DurationFormatOptions, value: DurationUnitStyle);
12476
12477 #[wasm_bindgen(method, getter = microsecondsDisplay)]
12478 pub fn get_microseconds_display(
12479 this: &DurationFormatOptions,
12480 ) -> Option<DurationUnitDisplay>;
12481 #[wasm_bindgen(method, setter = microsecondsDisplay)]
12482 pub fn set_microseconds_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12483
12484 #[wasm_bindgen(method, getter = nanoseconds)]
12485 pub fn get_nanoseconds(this: &DurationFormatOptions) -> Option<DurationUnitStyle>;
12486 #[wasm_bindgen(method, setter = nanoseconds)]
12487 pub fn set_nanoseconds(this: &DurationFormatOptions, value: DurationUnitStyle);
12488
12489 #[wasm_bindgen(method, getter = nanosecondsDisplay)]
12490 pub fn get_nanoseconds_display(this: &DurationFormatOptions)
12491 -> Option<DurationUnitDisplay>;
12492 #[wasm_bindgen(method, setter = nanosecondsDisplay)]
12493 pub fn set_nanoseconds_display(this: &DurationFormatOptions, value: DurationUnitDisplay);
12494
12495 #[wasm_bindgen(method, getter = fractionalDigits)]
12496 pub fn get_fractional_digits(this: &DurationFormatOptions) -> Option<u8>;
12497 #[wasm_bindgen(method, setter = fractionalDigits)]
12498 pub fn set_fractional_digits(this: &DurationFormatOptions, value: u8);
12499 }
12500
12501 impl DurationFormatOptions {
12502 pub fn new() -> DurationFormatOptions {
12503 JsCast::unchecked_into(Object::new())
12504 }
12505 }
12506
12507 impl Default for DurationFormatOptions {
12508 fn default() -> Self {
12509 DurationFormatOptions::new()
12510 }
12511 }
12512
12513 // Intl.ResolvedDurationFormatOptions
12514 #[wasm_bindgen]
12515 extern "C" {
12516 /// Resolved options returned by `Intl.DurationFormat.prototype.resolvedOptions()`.
12517 ///
12518 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/resolvedOptions)
12519 #[wasm_bindgen(extends = DurationFormatOptions)]
12520 #[derive(Clone, Debug)]
12521 pub type ResolvedDurationFormatOptions;
12522
12523 /// The resolved locale string.
12524 #[wasm_bindgen(method, getter = locale)]
12525 pub fn get_locale(this: &ResolvedDurationFormatOptions) -> JsString;
12526
12527 /// The resolved numbering system.
12528 #[wasm_bindgen(method, getter = numberingSystem)]
12529 pub fn get_numbering_system(this: &ResolvedDurationFormatOptions) -> JsString;
12530 }
12531
12532 // Intl.Duration (input object for DurationFormat)
12533 #[wasm_bindgen]
12534 extern "C" {
12535 /// A duration object used as input to `Intl.DurationFormat.format()`.
12536 ///
12537 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/format#duration)
12538 #[wasm_bindgen(extends = Object)]
12539 #[derive(Clone, Debug)]
12540 pub type Duration;
12541
12542 #[wasm_bindgen(method, getter)]
12543 pub fn years(this: &Duration) -> Option<f64>;
12544 #[wasm_bindgen(method, setter)]
12545 pub fn set_years(this: &Duration, value: f64);
12546
12547 #[wasm_bindgen(method, getter)]
12548 pub fn months(this: &Duration) -> Option<f64>;
12549 #[wasm_bindgen(method, setter)]
12550 pub fn set_months(this: &Duration, value: f64);
12551
12552 #[wasm_bindgen(method, getter)]
12553 pub fn weeks(this: &Duration) -> Option<f64>;
12554 #[wasm_bindgen(method, setter)]
12555 pub fn set_weeks(this: &Duration, value: f64);
12556
12557 #[wasm_bindgen(method, getter)]
12558 pub fn days(this: &Duration) -> Option<f64>;
12559 #[wasm_bindgen(method, setter)]
12560 pub fn set_days(this: &Duration, value: f64);
12561
12562 #[wasm_bindgen(method, getter)]
12563 pub fn hours(this: &Duration) -> Option<f64>;
12564 #[wasm_bindgen(method, setter)]
12565 pub fn set_hours(this: &Duration, value: f64);
12566
12567 #[wasm_bindgen(method, getter)]
12568 pub fn minutes(this: &Duration) -> Option<f64>;
12569 #[wasm_bindgen(method, setter)]
12570 pub fn set_minutes(this: &Duration, value: f64);
12571
12572 #[wasm_bindgen(method, getter)]
12573 pub fn seconds(this: &Duration) -> Option<f64>;
12574 #[wasm_bindgen(method, setter)]
12575 pub fn set_seconds(this: &Duration, value: f64);
12576
12577 #[wasm_bindgen(method, getter)]
12578 pub fn milliseconds(this: &Duration) -> Option<f64>;
12579 #[wasm_bindgen(method, setter)]
12580 pub fn set_milliseconds(this: &Duration, value: f64);
12581
12582 #[wasm_bindgen(method, getter)]
12583 pub fn microseconds(this: &Duration) -> Option<f64>;
12584 #[wasm_bindgen(method, setter)]
12585 pub fn set_microseconds(this: &Duration, value: f64);
12586
12587 #[wasm_bindgen(method, getter)]
12588 pub fn nanoseconds(this: &Duration) -> Option<f64>;
12589 #[wasm_bindgen(method, setter)]
12590 pub fn set_nanoseconds(this: &Duration, value: f64);
12591 }
12592
12593 impl Duration {
12594 pub fn new() -> Duration {
12595 JsCast::unchecked_into(Object::new())
12596 }
12597 }
12598
12599 impl Default for Duration {
12600 fn default() -> Self {
12601 Duration::new()
12602 }
12603 }
12604
12605 // Intl.DurationFormatPart
12606 #[wasm_bindgen]
12607 extern "C" {
12608 /// A part of the formatted duration returned by `formatToParts()`.
12609 ///
12610 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/formatToParts)
12611 #[wasm_bindgen(extends = Object)]
12612 #[derive(Clone, Debug)]
12613 pub type DurationFormatPart;
12614
12615 /// The type of the part.
12616 #[wasm_bindgen(method, getter = type)]
12617 pub fn type_(this: &DurationFormatPart) -> DurationFormatPartType;
12618
12619 /// The value of the part.
12620 #[wasm_bindgen(method, getter)]
12621 pub fn value(this: &DurationFormatPart) -> JsString;
12622
12623 /// The unit this part represents (if applicable).
12624 #[wasm_bindgen(method, getter)]
12625 pub fn unit(this: &DurationFormatPart) -> Option<JsString>;
12626 }
12627
12628 // Intl.DurationFormat
12629 #[wasm_bindgen]
12630 extern "C" {
12631 /// The `Intl.DurationFormat` object enables language-sensitive duration formatting.
12632 ///
12633 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat)
12634 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.DurationFormat")]
12635 #[derive(Clone, Debug)]
12636 pub type DurationFormat;
12637
12638 /// Creates a new `Intl.DurationFormat` object.
12639 ///
12640 /// Throws a `RangeError` if locales or options contain invalid values.
12641 ///
12642 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/DurationFormat)
12643 #[wasm_bindgen(constructor, js_namespace = Intl, catch)]
12644 pub fn new(
12645 locales: &[JsString],
12646 options: &DurationFormatOptions,
12647 ) -> Result<DurationFormat, JsValue>;
12648
12649 /// Formats a duration according to the locale and formatting options.
12650 ///
12651 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/format)
12652 #[wasm_bindgen(method, js_class = "Intl.DurationFormat")]
12653 pub fn format(this: &DurationFormat, duration: &Duration) -> JsString;
12654
12655 /// Returns an array of objects representing the formatted duration in parts.
12656 ///
12657 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/formatToParts)
12658 #[wasm_bindgen(method, js_class = "Intl.DurationFormat", js_name = formatToParts)]
12659 pub fn format_to_parts(
12660 this: &DurationFormat,
12661 duration: &Duration,
12662 ) -> Array<DurationFormatPart>;
12663
12664 /// Returns an object with properties reflecting the options used.
12665 ///
12666 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/resolvedOptions)
12667 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
12668 pub fn resolved_options(this: &DurationFormat) -> ResolvedDurationFormatOptions;
12669
12670 /// Returns an array of supported locales.
12671 ///
12672 /// Throws a `RangeError` if locales contain invalid values.
12673 ///
12674 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat/supportedLocalesOf)
12675 #[wasm_bindgen(static_method_of = DurationFormat, js_namespace = Intl, js_name = supportedLocalesOf, catch)]
12676 pub fn supported_locales_of(
12677 locales: &[JsString],
12678 options: &LocaleMatcherOptions,
12679 ) -> Result<Array<JsString>, JsValue>;
12680 }
12681
12682 impl Default for DurationFormat {
12683 fn default() -> Self {
12684 Self::new(&[], &Default::default()).unwrap()
12685 }
12686 }
12687}
12688
12689#[wasm_bindgen]
12690extern "C" {
12691 /// The `PromiseState` object represents the the status of the promise,
12692 /// as used in `allSettled`.
12693 ///
12694 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled)
12695 #[must_use]
12696 #[wasm_bindgen(extends = Object, typescript_type = "any")]
12697 #[derive(Clone, Debug)]
12698 pub type PromiseState<T = JsValue>;
12699
12700 /// A string, either "fulfilled" or "rejected", indicating the eventual state of the promise.
12701 #[wasm_bindgen(method, getter = status)]
12702 pub fn get_status<T>(this: &PromiseState<T>) -> String;
12703
12704 /// Only present if status is "fulfilled". The value that the promise was fulfilled with.
12705 #[wasm_bindgen(method, getter = value)]
12706 pub fn get_value<T>(this: &PromiseState<T>) -> Option<T>;
12707
12708 /// Only present if status is "rejected". The reason that the promise was rejected with.
12709 #[wasm_bindgen(method, getter = reason)]
12710 pub fn get_reason<T>(this: &PromiseState<T>) -> Option<JsValue>;
12711}
12712
12713impl<T> PromiseState<T> {
12714 pub fn is_fulfilled(&self) -> bool {
12715 self.get_status() == "fulfilled"
12716 }
12717
12718 pub fn is_rejected(&self) -> bool {
12719 self.get_status() == "rejected"
12720 }
12721}
12722
12723// Promise
12724#[wasm_bindgen]
12725extern "C" {
12726 /// The `Promise` object represents the eventual completion (or failure) of
12727 /// an asynchronous operation, and its resulting value.
12728 ///
12729 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
12730 #[must_use]
12731 #[wasm_bindgen(extends = Object, typescript_type = "Promise<any>", no_promising)]
12732 #[derive(Clone, Debug)]
12733 pub type Promise<T = JsValue>;
12734
12735 /// Creates a new `Promise` with the provided executor `cb`
12736 ///
12737 /// The `cb` is a function that is passed with the arguments `resolve` and
12738 /// `reject`. The `cb` function is executed immediately by the `Promise`
12739 /// implementation, passing `resolve` and `reject` functions (the executor
12740 /// is called before the `Promise` constructor even returns the created
12741 /// object). The `resolve` and `reject` functions, when called, resolve or
12742 /// reject the promise, respectively. The executor normally initiates
12743 /// some asynchronous work, and then, once that completes, either calls
12744 /// the `resolve` function to resolve the promise or else rejects it if an
12745 /// error occurred.
12746 ///
12747 /// If an error is thrown in the executor function, the promise is rejected.
12748 /// The return value of the executor is ignored.
12749 ///
12750 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
12751 #[cfg(not(js_sys_unstable_apis))]
12752 #[wasm_bindgen(constructor)]
12753 pub fn new(cb: &mut dyn FnMut(Function, Function)) -> Promise;
12754
12755 /// Creates a new `Promise` with the provided executor `cb`
12756 ///
12757 /// The `cb` is a function that is passed with the arguments `resolve` and
12758 /// `reject`. The `cb` function is executed immediately by the `Promise`
12759 /// implementation, passing `resolve` and `reject` functions (the executor
12760 /// is called before the `Promise` constructor even returns the created
12761 /// object). The `resolve` and `reject` functions, when called, resolve or
12762 /// reject the promise, respectively. The executor normally initiates
12763 /// some asynchronous work, and then, once that completes, either calls
12764 /// the `resolve` function to resolve the promise or else rejects it if an
12765 /// error occurred.
12766 ///
12767 /// If an error is thrown in the executor function, the promise is rejected.
12768 /// The return value of the executor is ignored.
12769 ///
12770 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
12771 #[cfg(js_sys_unstable_apis)]
12772 #[wasm_bindgen(constructor)]
12773 pub fn new<T: JsGeneric>(
12774 cb: &mut dyn FnMut(Function<fn(T) -> Undefined>, Function<fn(JsValue) -> Undefined>),
12775 ) -> Promise<T>;
12776
12777 // Next major: deprecate
12778 /// Creates a new `Promise` with the provided executor `cb`
12779 ///
12780 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
12781 #[wasm_bindgen(constructor)]
12782 pub fn new_typed<T: JsGeneric>(
12783 cb: &mut dyn FnMut(Function<fn(T) -> Undefined>, Function<fn(JsValue) -> Undefined>),
12784 ) -> Promise<T>;
12785
12786 /// The `Promise.all(iterable)` method returns a single `Promise` that
12787 /// resolves when all of the promises in the iterable argument have resolved
12788 /// or when the iterable argument contains no promises. It rejects with the
12789 /// reason of the first promise that rejects.
12790 ///
12791 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all)
12792 #[cfg(not(js_sys_unstable_apis))]
12793 #[wasm_bindgen(static_method_of = Promise)]
12794 pub fn all(obj: &JsValue) -> Promise;
12795
12796 /// The `Promise.all(iterable)` method returns a single `Promise` that
12797 /// resolves when all of the promises in the iterable argument have resolved
12798 /// or when the iterable argument contains no promises. It rejects with the
12799 /// reason of the first promise that rejects.
12800 ///
12801 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all)
12802 #[cfg(js_sys_unstable_apis)]
12803 #[wasm_bindgen(static_method_of = Promise, js_name = all)]
12804 pub fn all<I: Iterable>(obj: &I) -> Promise<Array<<I::Item as Promising>::Resolution>>
12805 where
12806 I::Item: Promising;
12807
12808 // Next major: deprecate
12809 /// The `Promise.all(iterable)` method returns a single `Promise` that
12810 /// resolves when all of the promises in the iterable argument have resolved
12811 /// or when the iterable argument contains no promises. It rejects with the
12812 /// reason of the first promise that rejects.
12813 ///
12814 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all)
12815 #[wasm_bindgen(static_method_of = Promise, js_name = all)]
12816 pub fn all_iterable<I: Iterable>(obj: &I) -> Promise<Array<<I::Item as Promising>::Resolution>>
12817 where
12818 I::Item: Promising;
12819
12820 /// The `Promise.allSettled(iterable)` method returns a single `Promise` that
12821 /// resolves when all of the promises in the iterable argument have either
12822 /// fulfilled or rejected or when the iterable argument contains no promises.
12823 ///
12824 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled)
12825 #[cfg(not(js_sys_unstable_apis))]
12826 #[wasm_bindgen(static_method_of = Promise, js_name = allSettled)]
12827 pub fn all_settled(obj: &JsValue) -> Promise;
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(js_sys_unstable_apis)]
12835 #[wasm_bindgen(static_method_of = Promise, js_name = allSettled)]
12836 pub fn all_settled<I: Iterable>(
12837 obj: &I,
12838 ) -> Promise<Array<PromiseState<<I::Item as Promising>::Resolution>>>
12839 where
12840 I::Item: Promising;
12841
12842 // Next major: deprecate
12843 /// The `Promise.allSettled(iterable)` method returns a single `Promise` that
12844 /// resolves when all of the promises in the iterable argument have either
12845 /// fulfilled or rejected or when the iterable argument contains no promises.
12846 ///
12847 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled)
12848 #[wasm_bindgen(static_method_of = Promise, js_name = allSettled)]
12849 pub fn all_settled_iterable<I: Iterable>(
12850 obj: &I,
12851 ) -> Promise<Array<PromiseState<<I::Item as Promising>::Resolution>>>
12852 where
12853 I::Item: Promising;
12854
12855 /// The `Promise.any(iterable)` method returns a single `Promise` that
12856 /// resolves when any of the promises in the iterable argument have resolved
12857 /// or when the iterable argument contains no promises. It rejects with an
12858 /// `AggregateError` if all promises in the iterable rejected.
12859 ///
12860 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/any)
12861 #[cfg(not(js_sys_unstable_apis))]
12862 #[wasm_bindgen(static_method_of = Promise)]
12863 pub fn any(obj: &JsValue) -> Promise;
12864
12865 /// The `Promise.any(iterable)` method returns a single `Promise` that
12866 /// resolves when any of the promises in the iterable argument have resolved
12867 /// or when the iterable argument contains no promises. It rejects with an
12868 /// `AggregateError` if all promises in the iterable rejected.
12869 ///
12870 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/any)
12871 #[cfg(js_sys_unstable_apis)]
12872 #[wasm_bindgen(static_method_of = Promise, js_name = any)]
12873 pub fn any<I: Iterable>(obj: &I) -> Promise<<I::Item as Promising>::Resolution>
12874 where
12875 I::Item: Promising;
12876
12877 // Next major: deprecate
12878 /// The `Promise.any(iterable)` method returns a single `Promise` that
12879 /// resolves when any of the promises in the iterable argument have resolved
12880 /// or when the iterable argument contains no promises. It rejects with an
12881 /// `AggregateError` if all promises in the iterable rejected.
12882 ///
12883 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/any)
12884 #[cfg(not(js_sys_unstable_apis))]
12885 #[wasm_bindgen(static_method_of = Promise, js_name = any)]
12886 pub fn any_iterable<I: Iterable>(obj: &I) -> Promise<<I::Item as Promising>::Resolution>
12887 where
12888 I::Item: Promising;
12889
12890 /// The `Promise.race(iterable)` method returns a promise that resolves or
12891 /// rejects as soon as one of the promises in the iterable resolves or
12892 /// rejects, with the value or reason from that promise.
12893 ///
12894 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/race)
12895 #[cfg(not(js_sys_unstable_apis))]
12896 #[wasm_bindgen(static_method_of = Promise)]
12897 pub fn race(obj: &JsValue) -> Promise;
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(js_sys_unstable_apis)]
12905 #[wasm_bindgen(static_method_of = Promise, js_name = race)]
12906 pub fn race<I: Iterable>(obj: &I) -> Promise<<I::Item as Promising>::Resolution>
12907 where
12908 I::Item: Promising;
12909
12910 // Next major: deprecate
12911 /// The `Promise.race(iterable)` method returns a promise that resolves or
12912 /// rejects as soon as one of the promises in the iterable resolves or
12913 /// rejects, with the value or reason from that promise.
12914 ///
12915 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/race)
12916 #[wasm_bindgen(static_method_of = Promise, js_name = race)]
12917 pub fn race_iterable<I: Iterable>(obj: &I) -> Promise<<I::Item as Promising>::Resolution>
12918 where
12919 I::Item: Promising;
12920
12921 /// The `Promise.reject(reason)` method returns a `Promise` object that is
12922 /// rejected with the given reason.
12923 ///
12924 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/reject)
12925 #[cfg(not(js_sys_unstable_apis))]
12926 #[wasm_bindgen(static_method_of = Promise)]
12927 pub fn reject(obj: &JsValue) -> Promise;
12928
12929 /// The `Promise.reject(reason)` method returns a `Promise` object that is
12930 /// rejected with the given reason.
12931 ///
12932 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/reject)
12933 #[cfg(js_sys_unstable_apis)]
12934 #[wasm_bindgen(static_method_of = Promise, js_name = reject)]
12935 pub fn reject<T>(obj: &JsValue) -> Promise<T>;
12936
12937 // Next major: deprecate
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 #[wasm_bindgen(static_method_of = Promise, js_name = reject)]
12943 pub fn reject_typed<T>(obj: &JsValue) -> Promise<T>;
12944
12945 /// The `Promise.resolve(value)` method returns a `Promise` object that is
12946 /// resolved with the given value. If the value is a promise, that promise
12947 /// is returned; if the value is a thenable (i.e. has a "then" method), the
12948 /// returned promise will "follow" that thenable, adopting its eventual
12949 /// state; otherwise the returned promise will be fulfilled with the value.
12950 ///
12951 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/resolve)
12952 #[wasm_bindgen(static_method_of = Promise, js_name = resolve)]
12953 pub fn resolve<U: Promising>(obj: &U) -> Promise<U::Resolution>;
12954
12955 /// The `catch()` method returns a `Promise` and deals with rejected cases
12956 /// only. It behaves the same as calling `Promise.prototype.then(undefined,
12957 /// onRejected)` (in fact, calling `obj.catch(onRejected)` internally calls
12958 /// `obj.then(undefined, onRejected)`).
12959 ///
12960 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch)
12961 #[cfg(not(js_sys_unstable_apis))]
12962 #[wasm_bindgen(method)]
12963 pub fn catch<T>(this: &Promise<T>, cb: &ScopedClosure<dyn FnMut(JsValue)>) -> Promise<JsValue>;
12964
12965 /// The `catch()` method returns a `Promise` and deals with rejected cases
12966 /// only. It behaves the same as calling `Promise.prototype.then(undefined,
12967 /// onRejected)` (in fact, calling `obj.catch(onRejected)` internally calls
12968 /// `obj.then(undefined, onRejected)`).
12969 ///
12970 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch)
12971 #[cfg(js_sys_unstable_apis)]
12972 #[wasm_bindgen(method, js_name = catch)]
12973 pub fn catch<'a, T, R: Promising>(
12974 this: &Promise<T>,
12975 cb: &ScopedClosure<'a, dyn FnMut(T) -> Result<R, JsError>>,
12976 ) -> Promise<R::Resolution>;
12977
12978 // Next major: deprecate
12979 /// Same as `catch`, but returning a result to become the new Promise value.
12980 #[wasm_bindgen(method, js_name = catch)]
12981 pub fn catch_map<'a, T, R: Promising>(
12982 this: &Promise<T>,
12983 cb: &ScopedClosure<'a, dyn FnMut(T) -> Result<R, JsError>>,
12984 ) -> Promise<R::Resolution>;
12985
12986 /// The `then()` method returns a `Promise`. It takes up to two arguments:
12987 /// callback functions for the success and failure cases of the `Promise`.
12988 ///
12989 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then)
12990 #[cfg(not(js_sys_unstable_apis))]
12991 #[wasm_bindgen(method)]
12992 pub fn then<'a, T>(this: &Promise<T>, cb: &ScopedClosure<'a, dyn FnMut(T)>)
12993 -> Promise<JsValue>;
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(js_sys_unstable_apis)]
13000 #[wasm_bindgen(method, js_name = then)]
13001 pub fn then<'a, T, R: Promising>(
13002 this: &Promise<T>,
13003 cb: &ScopedClosure<'a, dyn FnMut(T) -> Result<R, JsError>>,
13004 ) -> Promise<R::Resolution>;
13005
13006 /// The `then()` method returns a `Promise`. It takes up to two arguments:
13007 /// callback functions for the success and failure cases of the `Promise`.
13008 ///
13009 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then)
13010 #[wasm_bindgen(method, js_name = then)]
13011 pub fn then_with_reject<'a, T, R: Promising>(
13012 this: &Promise<T>,
13013 resolve: &ScopedClosure<'a, dyn FnMut(T) -> Result<R, JsError>>,
13014 reject: &ScopedClosure<'a, dyn FnMut(JsValue) -> Result<R, JsError>>,
13015 ) -> Promise<R::Resolution>;
13016
13017 // Next major: deprecate
13018 /// Alias for `then()` with a return value.
13019 /// The `then()` method returns a `Promise`. It takes up to two arguments:
13020 /// callback functions for the success and failure cases of the `Promise`.
13021 ///
13022 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then)
13023 #[wasm_bindgen(method, js_name = then)]
13024 pub fn then_map<'a, T, R: Promising>(
13025 this: &Promise<T>,
13026 cb: &ScopedClosure<'a, dyn FnMut(T) -> Result<R, JsError>>,
13027 ) -> Promise<R::Resolution>;
13028
13029 /// Same as `then`, only with both arguments provided.
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 then2(
13034 this: &Promise,
13035 resolve: &ScopedClosure<dyn FnMut(JsValue)>,
13036 reject: &ScopedClosure<dyn FnMut(JsValue)>,
13037 ) -> Promise;
13038
13039 /// The `finally()` method returns a `Promise`. When the promise is settled,
13040 /// whether fulfilled or rejected, the specified callback function is
13041 /// executed. This provides a way for code that must be executed once the
13042 /// `Promise` has been dealt with to be run whether the promise was
13043 /// fulfilled successfully or rejected.
13044 ///
13045 /// This lets you avoid duplicating code in both the promise's `then()` and
13046 /// `catch()` handlers.
13047 ///
13048 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/finally)
13049 #[wasm_bindgen(method)]
13050 pub fn finally<T>(this: &Promise<T>, cb: &ScopedClosure<dyn FnMut()>) -> Promise<JsValue>;
13051}
13052
13053impl<T: JsGeneric> Promising for Promise<T> {
13054 type Resolution = T;
13055}
13056
13057/// Returns a handle to the global scope object.
13058///
13059/// This allows access to the global properties and global names by accessing
13060/// the `Object` returned.
13061pub fn global() -> Object {
13062 use once_cell::unsync::Lazy;
13063
13064 struct Wrapper<T>(Lazy<T>);
13065
13066 #[cfg(not(target_feature = "atomics"))]
13067 unsafe impl<T> Sync for Wrapper<T> {}
13068
13069 #[cfg(not(target_feature = "atomics"))]
13070 unsafe impl<T> Send for Wrapper<T> {}
13071
13072 #[cfg_attr(target_feature = "atomics", thread_local)]
13073 static GLOBAL: Wrapper<Object> = Wrapper(Lazy::new(get_global_object));
13074
13075 return GLOBAL.0.clone();
13076
13077 fn get_global_object() -> Object {
13078 // Accessing the global object is not an easy thing to do, and what we
13079 // basically want is `globalThis` but we can't rely on that existing
13080 // everywhere. In the meantime we've got the fallbacks mentioned in:
13081 //
13082 // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis
13083 //
13084 // Note that this is pretty heavy code-size wise but it at least gets
13085 // the job largely done for now and avoids the `Function` constructor at
13086 // the end which triggers CSP errors.
13087 #[wasm_bindgen]
13088 extern "C" {
13089 type Global;
13090
13091 #[wasm_bindgen(thread_local_v2, js_name = globalThis)]
13092 static GLOBAL_THIS: Option<Object>;
13093
13094 #[wasm_bindgen(thread_local_v2, js_name = self)]
13095 static SELF: Option<Object>;
13096
13097 #[wasm_bindgen(thread_local_v2, js_name = window)]
13098 static WINDOW: Option<Object>;
13099
13100 #[wasm_bindgen(thread_local_v2, js_name = global)]
13101 static GLOBAL: Option<Object>;
13102 }
13103
13104 // The order is important: in Firefox Extension Content Scripts `globalThis`
13105 // is a Sandbox (not Window), so `globalThis` must be checked after `window`.
13106 let static_object = SELF
13107 .with(Option::clone)
13108 .or_else(|| WINDOW.with(Option::clone))
13109 .or_else(|| GLOBAL_THIS.with(Option::clone))
13110 .or_else(|| GLOBAL.with(Option::clone));
13111 if let Some(obj) = static_object {
13112 if !obj.is_undefined() {
13113 return obj;
13114 }
13115 }
13116
13117 // Global object not found
13118 JsValue::undefined().unchecked_into()
13119 }
13120}
13121
13122macro_rules! arrays {
13123 ($(#[doc = $ctor:literal] #[doc = $mdn:literal] $name:ident: $ty:ident,)*) => ($(
13124 #[wasm_bindgen]
13125 extern "C" {
13126 #[wasm_bindgen(extends = Object, typescript_type = $name)]
13127 #[derive(Clone, Debug)]
13128 pub type $name;
13129
13130 /// The
13131 #[doc = $ctor]
13132 /// constructor creates a new array.
13133 ///
13134 /// [MDN documentation](
13135 #[doc = $mdn]
13136 /// )
13137 #[wasm_bindgen(constructor)]
13138 pub fn new(constructor_arg: &JsValue) -> $name;
13139
13140 /// An
13141 #[doc = $ctor]
13142 /// which creates an array with an internal buffer large
13143 /// enough for `length` elements.
13144 ///
13145 /// [MDN documentation](
13146 #[doc = $mdn]
13147 /// )
13148 #[wasm_bindgen(constructor)]
13149 pub fn new_with_length(length: u32) -> $name;
13150
13151 /// An
13152 #[doc = $ctor]
13153 /// which creates an array from a Rust slice.
13154 ///
13155 /// [MDN documentation](
13156 #[doc = $mdn]
13157 /// )
13158 #[wasm_bindgen(constructor)]
13159 pub fn new_from_slice(slice: &[$ty]) -> $name;
13160
13161 /// An
13162 #[doc = $ctor]
13163 /// which creates an array with the given buffer but is a
13164 /// view starting at `byte_offset`.
13165 ///
13166 /// [MDN documentation](
13167 #[doc = $mdn]
13168 /// )
13169 #[wasm_bindgen(constructor)]
13170 pub fn new_with_byte_offset(buffer: &JsValue, byte_offset: u32) -> $name;
13171
13172 /// An
13173 #[doc = $ctor]
13174 /// which creates an array with the given buffer but is a
13175 /// view starting at `byte_offset` for `length` elements.
13176 ///
13177 /// [MDN documentation](
13178 #[doc = $mdn]
13179 /// )
13180 #[wasm_bindgen(constructor)]
13181 pub fn new_with_byte_offset_and_length(
13182 buffer: &JsValue,
13183 byte_offset: u32,
13184 length: u32,
13185 ) -> $name;
13186
13187 /// The `fill()` method fills all the elements of an array from a start index
13188 /// to an end index with a static value. The end index is not included.
13189 ///
13190 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/fill)
13191 #[wasm_bindgen(method)]
13192 pub fn fill(this: &$name, value: $ty, start: u32, end: u32) -> $name;
13193
13194 /// The buffer accessor property represents the `ArrayBuffer` referenced
13195 /// by a `TypedArray` at construction time.
13196 #[wasm_bindgen(getter, method)]
13197 pub fn buffer(this: &$name) -> ArrayBuffer;
13198
13199 /// The `subarray()` method returns a new `TypedArray` on the same
13200 /// `ArrayBuffer` store and with the same element types as for this
13201 /// `TypedArray` object.
13202 #[wasm_bindgen(method)]
13203 pub fn subarray(this: &$name, begin: u32, end: u32) -> $name;
13204
13205 /// The `slice()` method returns a shallow copy of a portion of a typed
13206 /// array into a new typed array object. This method has the same algorithm
13207 /// as `Array.prototype.slice()`.
13208 #[wasm_bindgen(method)]
13209 pub fn slice(this: &$name, begin: u32, end: u32) -> $name;
13210
13211 /// The `forEach()` method executes a provided function once per array
13212 /// element. This method has the same algorithm as
13213 /// `Array.prototype.forEach()`. `TypedArray` is one of the typed array
13214 /// types here.
13215 #[wasm_bindgen(method, js_name = forEach)]
13216 pub fn for_each(this: &$name, callback: &mut dyn FnMut($ty, u32, $name));
13217
13218 /// The `forEach()` method executes a provided function once per array
13219 /// element. This method has the same algorithm as
13220 /// `Array.prototype.forEach()`. `TypedArray` is one of the typed array
13221 /// types here.
13222 #[wasm_bindgen(method, js_name = forEach, catch)]
13223 pub fn try_for_each(this: &$name, callback: &mut dyn FnMut($ty, u32, $name) -> Result<(), JsError>) -> Result<(), JsValue>;
13224
13225 /// The length accessor property represents the length (in elements) of a
13226 /// typed array.
13227 #[wasm_bindgen(method, getter)]
13228 pub fn length(this: &$name) -> u32;
13229
13230 /// The byteLength accessor property represents the length (in bytes) of a
13231 /// typed array.
13232 #[wasm_bindgen(method, getter, js_name = byteLength)]
13233 pub fn byte_length(this: &$name) -> u32;
13234
13235 /// The byteOffset accessor property represents the offset (in bytes) of a
13236 /// typed array from the start of its `ArrayBuffer`.
13237 #[wasm_bindgen(method, getter, js_name = byteOffset)]
13238 pub fn byte_offset(this: &$name) -> u32;
13239
13240 /// The `set()` method stores multiple values in the typed array, reading
13241 /// input values from a specified array.
13242 #[wasm_bindgen(method)]
13243 pub fn set(this: &$name, src: &JsValue, offset: u32);
13244
13245 /// Gets the value at `idx`, counting from the end if negative.
13246 #[wasm_bindgen(method)]
13247 pub fn at(this: &$name, idx: i32) -> Option<$ty>;
13248
13249 /// The `copyWithin()` method shallow copies part of a typed array to another
13250 /// location in the same typed array and returns it, without modifying its size.
13251 ///
13252 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin)
13253 #[wasm_bindgen(method, js_name = copyWithin)]
13254 pub fn copy_within(this: &$name, target: i32, start: i32, end: i32) -> $name;
13255
13256 /// Gets the value at `idx`, equivalent to the javascript `my_var = arr[idx]`.
13257 #[wasm_bindgen(method, indexing_getter)]
13258 pub fn get_index(this: &$name, idx: u32) -> $ty;
13259
13260 /// Sets the value at `idx`, equivalent to the javascript `arr[idx] = value`.
13261 #[wasm_bindgen(method, indexing_setter)]
13262 pub fn set_index(this: &$name, idx: u32, value: $ty);
13263
13264 /// Copies the Rust slice's data to self.
13265 ///
13266 /// This method is not expected to be public. It requires the length of the
13267 /// TypedArray to be the same as the slice, use `self.copy_from(slice)` instead.
13268 #[wasm_bindgen(method, js_name = set)]
13269 fn copy_from_slice(this: &$name, slice: &[$ty]);
13270
13271 /// Copies this TypedArray's data to Rust slice;
13272 ///
13273 /// This method is not expected to be public. It requires the length of the
13274 /// TypedArray to be the same as the slice, use `self.copy_to(slice)` instead.
13275 ///
13276 /// # Workaround
13277 ///
13278 /// We actually need `slice.set(typed_array)` here, but since slice cannot be treated as
13279 /// `Uint8Array` on the Rust side, we use `Uint8Array.prototype.set.call`, which allows
13280 /// us to specify the `this` value inside the function.
13281 ///
13282 /// Therefore, `Uint8Array.prototype.set.call(slice, typed_array)` is equivalent to
13283 /// `slice.set(typed_array)`.
13284 #[wasm_bindgen(js_namespace = $name, js_name = "prototype.set.call")]
13285 fn copy_to_slice(slice: &mut [$ty], this: &$name);
13286 }
13287
13288 impl $name {
13289 /// Creates a JS typed array which is a view into wasm's linear
13290 /// memory at the slice specified.
13291 ///
13292 /// This function returns a new typed array which is a view into
13293 /// wasm's memory. This view does not copy the underlying data.
13294 ///
13295 /// # Safety
13296 ///
13297 /// Views into WebAssembly memory are only valid so long as the
13298 /// backing buffer isn't resized in JS. Once this function is called
13299 /// any future calls to `Box::new` (or malloc of any form) may cause
13300 /// the returned value here to be invalidated. Use with caution!
13301 ///
13302 /// Additionally the returned object can be safely mutated but the
13303 /// input slice isn't guaranteed to be mutable.
13304 ///
13305 /// Finally, the returned object is disconnected from the input
13306 /// slice's lifetime, so there's no guarantee that the data is read
13307 /// at the right time.
13308 pub unsafe fn view(rust: &[$ty]) -> $name {
13309 wasm_bindgen::__rt::wbg_cast(rust)
13310 }
13311
13312 /// Creates a JS typed array which is a view into wasm's linear
13313 /// memory at the specified pointer with specified length.
13314 ///
13315 /// This function returns a new typed array which is a view into
13316 /// wasm's memory. This view does not copy the underlying data.
13317 ///
13318 /// # Safety
13319 ///
13320 /// Views into WebAssembly memory are only valid so long as the
13321 /// backing buffer isn't resized in JS. Once this function is called
13322 /// any future calls to `Box::new` (or malloc of any form) may cause
13323 /// the returned value here to be invalidated. Use with caution!
13324 ///
13325 /// Additionally the returned object can be safely mutated,
13326 /// the changes are guaranteed to be reflected in the input array.
13327 pub unsafe fn view_mut_raw(ptr: *mut $ty, length: usize) -> $name {
13328 let slice = core::slice::from_raw_parts_mut(ptr, length);
13329 Self::view(slice)
13330 }
13331
13332 /// Copy the contents of this JS typed array into the destination
13333 /// Rust pointer.
13334 ///
13335 /// This function will efficiently copy the memory from a typed
13336 /// array into this Wasm module's own linear memory, initializing
13337 /// the memory destination provided.
13338 ///
13339 /// # Safety
13340 ///
13341 /// This function requires `dst` to point to a buffer
13342 /// large enough to fit this array's contents.
13343 pub unsafe fn raw_copy_to_ptr(&self, dst: *mut $ty) {
13344 let slice = core::slice::from_raw_parts_mut(dst, self.length() as usize);
13345 self.copy_to(slice);
13346 }
13347
13348 /// Copy the contents of this JS typed array into the destination
13349 /// Rust slice.
13350 ///
13351 /// This function will efficiently copy the memory from a typed
13352 /// array into this Wasm module's own linear memory, initializing
13353 /// the memory destination provided.
13354 ///
13355 /// # Panics
13356 ///
13357 /// This function will panic if this typed array's length is
13358 /// different than the length of the provided `dst` array.
13359 pub fn copy_to(&self, dst: &mut [$ty]) {
13360 core::assert_eq!(self.length() as usize, dst.len());
13361 $name::copy_to_slice(dst, self);
13362 }
13363
13364 /// Copy the contents of this JS typed array into the destination
13365 /// Rust slice.
13366 ///
13367 /// This function will efficiently copy the memory from a typed
13368 /// array into this Wasm module's own linear memory, initializing
13369 /// the memory destination provided.
13370 ///
13371 /// # Panics
13372 ///
13373 /// This function will panic if this typed array's length is
13374 /// different than the length of the provided `dst` array.
13375 pub fn copy_to_uninit<'dst>(&self, dst: &'dst mut [MaybeUninit<$ty>]) -> &'dst mut [$ty] {
13376 core::assert_eq!(self.length() as usize, dst.len());
13377 let dst = unsafe { &mut *(dst as *mut [MaybeUninit<$ty>] as *mut [$ty]) };
13378 self.copy_to(dst);
13379 dst
13380 }
13381
13382 /// Copy the contents of the source Rust slice into this
13383 /// JS typed array.
13384 ///
13385 /// This function will efficiently copy the memory from within
13386 /// the Wasm module's own linear memory to this typed array.
13387 ///
13388 /// # Panics
13389 ///
13390 /// This function will panic if this typed array's length is
13391 /// different than the length of the provided `src` array.
13392 pub fn copy_from(&self, src: &[$ty]) {
13393 core::assert_eq!(self.length() as usize, src.len());
13394 self.copy_from_slice(src);
13395 }
13396
13397 /// Efficiently copies the contents of this JS typed array into a new Vec.
13398 pub fn to_vec(&self) -> Vec<$ty> {
13399 let len = self.length() as usize;
13400 let mut output = Vec::with_capacity(len);
13401 // Safety: the capacity has been set
13402 unsafe {
13403 self.raw_copy_to_ptr(output.as_mut_ptr());
13404 output.set_len(len);
13405 }
13406 output
13407 }
13408 }
13409
13410 impl<'a> From<&'a [$ty]> for $name {
13411 #[inline]
13412 fn from(slice: &'a [$ty]) -> $name {
13413 // This is safe because the `new` function makes a copy if its argument is a TypedArray
13414 $name::new_from_slice(slice)
13415 }
13416 }
13417
13418 impl Default for $name {
13419 fn default() -> Self {
13420 Self::new(&JsValue::UNDEFINED.unchecked_into())
13421 }
13422 }
13423
13424 impl TypedArray for $name {}
13425
13426
13427 )*);
13428}
13429
13430arrays! {
13431 /// `Int8Array()`
13432 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int8Array
13433 Int8Array: i8,
13434
13435 /// `Int16Array()`
13436 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int16Array
13437 Int16Array: i16,
13438
13439 /// `Int32Array()`
13440 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int32Array
13441 Int32Array: i32,
13442
13443 /// `Uint8Array()`
13444 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array
13445 Uint8Array: u8,
13446
13447 /// `Uint8ClampedArray()`
13448 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8ClampedArray
13449 Uint8ClampedArray: u8,
13450
13451 /// `Uint16Array()`
13452 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint16Array
13453 Uint16Array: u16,
13454
13455 /// `Uint32Array()`
13456 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint32Array
13457 Uint32Array: u32,
13458
13459 /// `Float32Array()`
13460 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array
13461 Float32Array: f32,
13462
13463 /// `Float64Array()`
13464 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float64Array
13465 Float64Array: f64,
13466
13467 /// `BigInt64Array()`
13468 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt64Array
13469 BigInt64Array: i64,
13470
13471 /// `BigUint64Array()`
13472 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigUint64Array
13473 BigUint64Array: u64,
13474}