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#![doc(html_root_url = "https://docs.rs/js-sys/0.2")]
20#![cfg_attr(not(feature = "std"), no_std)]
21#![cfg_attr(target_feature = "atomics", feature(thread_local))]
22
23extern crate alloc;
24
25use alloc::string::String;
26use alloc::vec::Vec;
27use core::cmp::Ordering;
28use core::convert::{self, Infallible, TryFrom};
29use core::f64;
30use core::fmt;
31use core::iter::{self, Product, Sum};
32use core::mem::MaybeUninit;
33use core::ops::{Add, BitAnd, BitOr, BitXor, Div, Mul, Neg, Not, Rem, Shl, Shr, Sub};
34use core::str;
35use core::str::FromStr;
36
37pub use wasm_bindgen;
38use wasm_bindgen::prelude::*;
39
40// When adding new imports:
41//
42// * Keep imports in alphabetical order.
43//
44// * Rename imports with `js_name = ...` according to the note about `camelCase`
45// and `snake_case` in the module's documentation above.
46//
47// * Include the one sentence summary of the import from the MDN link in the
48// module's documentation above, and the MDN link itself.
49//
50// * If a function or method can throw an exception, make it catchable by adding
51// `#[wasm_bindgen(catch)]`.
52//
53// * Add a new `#[test]` into the appropriate file in the
54// `crates/js-sys/tests/wasm/` directory. If the imported function or method
55// can throw an exception, make sure to also add test coverage for that case.
56//
57// * Arguments that are `JsValue`s or imported JavaScript types should be taken
58// by reference.
59
60macro_rules! forward_deref_unop {
61 (impl $imp:ident, $method:ident for $t:ty) => {
62 impl $imp for $t {
63 type Output = <&'static $t as $imp>::Output;
64
65 #[inline]
66 fn $method(self) -> Self::Output {
67 $imp::$method(&self)
68 }
69 }
70 };
71}
72
73macro_rules! forward_deref_binop {
74 (impl $imp:ident, $method:ident for $t:ty) => {
75 impl<'a> $imp<$t> for &'a $t {
76 type Output = <&'static $t as $imp<&'static $t>>::Output;
77
78 #[inline]
79 fn $method(self, other: $t) -> Self::Output {
80 $imp::$method(self, &other)
81 }
82 }
83
84 impl $imp<&$t> for $t {
85 type Output = <&'static $t as $imp<&'static $t>>::Output;
86
87 #[inline]
88 fn $method(self, other: &$t) -> Self::Output {
89 $imp::$method(&self, other)
90 }
91 }
92
93 impl $imp<$t> for $t {
94 type Output = <&'static $t as $imp<&'static $t>>::Output;
95
96 #[inline]
97 fn $method(self, other: $t) -> Self::Output {
98 $imp::$method(&self, &other)
99 }
100 }
101 };
102}
103
104macro_rules! forward_js_unop {
105 (impl $imp:ident, $method:ident for $t:ty) => {
106 impl $imp for &$t {
107 type Output = $t;
108
109 #[inline]
110 fn $method(self) -> Self::Output {
111 $imp::$method(JsValue::as_ref(self)).unchecked_into()
112 }
113 }
114
115 forward_deref_unop!(impl $imp, $method for $t);
116 };
117}
118
119macro_rules! forward_js_binop {
120 (impl $imp:ident, $method:ident for $t:ty) => {
121 impl $imp<&$t> for &$t {
122 type Output = $t;
123
124 #[inline]
125 fn $method(self, other: &$t) -> Self::Output {
126 $imp::$method(JsValue::as_ref(self), JsValue::as_ref(other)).unchecked_into()
127 }
128 }
129
130 forward_deref_binop!(impl $imp, $method for $t);
131 };
132}
133
134macro_rules! sum_product {
135 ($($a:ident)*) => ($(
136 impl Sum for $a {
137 #[inline]
138 fn sum<I: iter::Iterator<Item=Self>>(iter: I) -> Self {
139 iter.fold(
140 $a::from(0),
141 |a, b| a + b,
142 )
143 }
144 }
145
146 impl Product for $a {
147 #[inline]
148 fn product<I: iter::Iterator<Item=Self>>(iter: I) -> Self {
149 iter.fold(
150 $a::from(1),
151 |a, b| a * b,
152 )
153 }
154 }
155
156 impl<'a> Sum<&'a $a> for $a {
157 fn sum<I: iter::Iterator<Item=&'a Self>>(iter: I) -> Self {
158 iter.fold(
159 $a::from(0),
160 |a, b| a + b,
161 )
162 }
163 }
164
165 impl<'a> Product<&'a $a> for $a {
166 #[inline]
167 fn product<I: iter::Iterator<Item=&'a Self>>(iter: I) -> Self {
168 iter.fold(
169 $a::from(1),
170 |a, b| a * b,
171 )
172 }
173 }
174 )*)
175}
176
177macro_rules! partialord_ord {
178 ($t:ident) => {
179 impl PartialOrd for $t {
180 #[inline]
181 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
182 Some(self.cmp(other))
183 }
184
185 #[inline]
186 fn lt(&self, other: &Self) -> bool {
187 JsValue::as_ref(self).lt(JsValue::as_ref(other))
188 }
189
190 #[inline]
191 fn le(&self, other: &Self) -> bool {
192 JsValue::as_ref(self).le(JsValue::as_ref(other))
193 }
194
195 #[inline]
196 fn ge(&self, other: &Self) -> bool {
197 JsValue::as_ref(self).ge(JsValue::as_ref(other))
198 }
199
200 #[inline]
201 fn gt(&self, other: &Self) -> bool {
202 JsValue::as_ref(self).gt(JsValue::as_ref(other))
203 }
204 }
205
206 impl Ord for $t {
207 #[inline]
208 fn cmp(&self, other: &Self) -> Ordering {
209 if self == other {
210 Ordering::Equal
211 } else if self.lt(other) {
212 Ordering::Less
213 } else {
214 Ordering::Greater
215 }
216 }
217 }
218 };
219}
220
221#[wasm_bindgen]
222extern "C" {
223 /// The `decodeURI()` function decodes a Uniform Resource Identifier (URI)
224 /// previously created by `encodeURI` or by a similar routine.
225 ///
226 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURI)
227 #[wasm_bindgen(catch, js_name = decodeURI)]
228 pub fn decode_uri(encoded: &str) -> Result<JsString, JsValue>;
229
230 /// The `decodeURIComponent()` function decodes a Uniform Resource Identifier (URI) component
231 /// previously created by `encodeURIComponent` or by a similar routine.
232 ///
233 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURIComponent)
234 #[wasm_bindgen(catch, js_name = decodeURIComponent)]
235 pub fn decode_uri_component(encoded: &str) -> Result<JsString, JsValue>;
236
237 /// The `encodeURI()` function encodes a Uniform Resource Identifier (URI)
238 /// by replacing each instance of certain characters by one, two, three, or
239 /// four escape sequences representing the UTF-8 encoding of the character
240 /// (will only be four escape sequences for characters composed of two
241 /// "surrogate" characters).
242 ///
243 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURI)
244 #[wasm_bindgen(js_name = encodeURI)]
245 pub fn encode_uri(decoded: &str) -> JsString;
246
247 /// The `encodeURIComponent()` function encodes a Uniform Resource Identifier (URI) component
248 /// by replacing each instance of certain characters by one, two, three, or four escape sequences
249 /// representing the UTF-8 encoding of the character
250 /// (will only be four escape sequences for characters composed of two "surrogate" characters).
251 ///
252 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent)
253 #[wasm_bindgen(js_name = encodeURIComponent)]
254 pub fn encode_uri_component(decoded: &str) -> JsString;
255
256 /// The `eval()` function evaluates JavaScript code represented as a string.
257 ///
258 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval)
259 #[wasm_bindgen(catch)]
260 pub fn eval(js_source_text: &str) -> Result<JsValue, JsValue>;
261
262 /// The global `isFinite()` function determines whether the passed value is a finite number.
263 /// If needed, the parameter is first converted to a number.
264 ///
265 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isFinite)
266 #[wasm_bindgen(js_name = isFinite)]
267 pub fn is_finite(value: &JsValue) -> bool;
268
269 /// The `parseInt()` function parses a string argument and returns an integer
270 /// of the specified radix (the base in mathematical numeral systems), or NaN on error.
271 ///
272 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt)
273 #[wasm_bindgen(js_name = parseInt)]
274 pub fn parse_int(text: &str, radix: u8) -> f64;
275
276 /// The `parseFloat()` function parses an argument and returns a floating point number,
277 /// or NaN on error.
278 ///
279 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseFloat)
280 #[wasm_bindgen(js_name = parseFloat)]
281 pub fn parse_float(text: &str) -> f64;
282
283 /// The `escape()` function computes a new string in which certain characters have been
284 /// replaced by a hexadecimal escape sequence.
285 ///
286 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/escape)
287 #[wasm_bindgen]
288 pub fn escape(string: &str) -> JsString;
289
290 /// The `unescape()` function computes a new string in which hexadecimal escape
291 /// sequences are replaced with the character that it represents. The escape sequences might
292 /// be introduced by a function like `escape`. Usually, `decodeURI` or `decodeURIComponent`
293 /// are preferred over `unescape`.
294 ///
295 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/unescape)
296 #[wasm_bindgen]
297 pub fn unescape(string: &str) -> JsString;
298}
299
300// Array
301#[wasm_bindgen]
302extern "C" {
303 #[wasm_bindgen(extends = Object, is_type_of = Array::is_array, typescript_type = "Array<any>")]
304 #[derive(Clone, Debug, PartialEq, Eq)]
305 pub type Array;
306
307 /// Creates a new empty array.
308 #[wasm_bindgen(constructor)]
309 pub fn new() -> Array;
310
311 /// Creates a new array with the specified length (elements are initialized to `undefined`).
312 #[wasm_bindgen(constructor)]
313 pub fn new_with_length(len: u32) -> Array;
314
315 /// Retrieves the element at the index, counting from the end if negative
316 /// (returns `undefined` if the index is out of range).
317 #[wasm_bindgen(method)]
318 pub fn at(this: &Array, index: i32) -> JsValue;
319
320 /// Retrieves the element at the index (returns `undefined` if the index is out of range).
321 #[wasm_bindgen(method, structural, indexing_getter)]
322 pub fn get(this: &Array, index: u32) -> JsValue;
323
324 /// Sets the element at the index (auto-enlarges the array if the index is out of range).
325 #[wasm_bindgen(method, structural, indexing_setter)]
326 pub fn set(this: &Array, index: u32, value: JsValue);
327
328 /// Deletes the element at the index (does nothing if the index is out of range).
329 ///
330 /// The element at the index is set to `undefined`.
331 ///
332 /// This does not resize the array, the array will still be the same length.
333 #[wasm_bindgen(method, structural, indexing_deleter)]
334 pub fn delete(this: &Array, index: u32);
335
336 /// The `Array.from()` method creates a new, shallow-copied `Array` instance
337 /// from an array-like or iterable object.
338 #[wasm_bindgen(static_method_of = Array)]
339 pub fn from(val: &JsValue) -> Array;
340
341 /// The `copyWithin()` method shallow copies part of an array to another
342 /// location in the same array and returns it, without modifying its size.
343 ///
344 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin)
345 #[wasm_bindgen(method, js_name = copyWithin)]
346 pub fn copy_within(this: &Array, target: i32, start: i32, end: i32) -> Array;
347
348 /// The `concat()` method is used to merge two or more arrays. This method
349 /// does not change the existing arrays, but instead returns a new array.
350 ///
351 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat)
352 #[wasm_bindgen(method)]
353 pub fn concat(this: &Array, array: &Array) -> Array;
354
355 /// The `every()` method tests whether all elements in the array pass the test
356 /// implemented by the provided function.
357 ///
358 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every)
359 #[wasm_bindgen(method)]
360 pub fn every(this: &Array, predicate: &mut dyn FnMut(JsValue, u32, Array) -> bool) -> bool;
361
362 /// The `fill()` method fills all the elements of an array from a start index
363 /// to an end index with a static value. The end index is not included.
364 ///
365 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill)
366 #[wasm_bindgen(method)]
367 pub fn fill(this: &Array, value: &JsValue, start: u32, end: u32) -> Array;
368
369 /// The `filter()` method creates a new array with all elements that pass the
370 /// test implemented by the provided function.
371 ///
372 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter)
373 #[wasm_bindgen(method)]
374 pub fn filter(this: &Array, predicate: &mut dyn FnMut(JsValue, u32, Array) -> bool) -> Array;
375
376 /// The `find()` method returns the value of the first element in the array that satisfies
377 /// the provided testing function. Otherwise `undefined` is returned.
378 ///
379 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)
380 #[wasm_bindgen(method)]
381 pub fn find(this: &Array, predicate: &mut dyn FnMut(JsValue, u32, Array) -> bool) -> JsValue;
382
383 /// The `findIndex()` method returns the index of the first element in the array that
384 /// satisfies the provided testing function. Otherwise -1 is returned.
385 ///
386 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex)
387 #[wasm_bindgen(method, js_name = findIndex)]
388 pub fn find_index(this: &Array, predicate: &mut dyn FnMut(JsValue, u32, Array) -> bool) -> i32;
389
390 /// The `findLast()` method of Array instances iterates the array in reverse order
391 /// and returns the value of the first element that satisfies the provided testing function.
392 /// If no elements satisfy the testing function, undefined is returned.
393 ///
394 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLast)
395 #[wasm_bindgen(method, js_name = findLast)]
396 pub fn find_last(
397 this: &Array,
398 predicate: &mut dyn FnMut(JsValue, u32, Array) -> bool,
399 ) -> JsValue;
400
401 /// The `findLastIndex()` method of Array instances iterates the array in reverse order
402 /// and returns the index of the first element that satisfies the provided testing function.
403 /// If no elements satisfy the testing function, -1 is returned.
404 ///
405 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLastIndex)
406 #[wasm_bindgen(method, js_name = findLastIndex)]
407 pub fn find_last_index(
408 this: &Array,
409 predicate: &mut dyn FnMut(JsValue, u32, Array) -> bool,
410 ) -> i32;
411
412 /// The `flat()` method creates a new array with all sub-array elements concatenated into it
413 /// recursively up to the specified depth.
414 ///
415 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat)
416 #[wasm_bindgen(method)]
417 pub fn flat(this: &Array, depth: i32) -> Array;
418
419 /// The `flatMap()` method first maps each element using a mapping function, then flattens
420 /// the result into a new array.
421 ///
422 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap)
423 #[wasm_bindgen(method, js_name = flatMap)]
424 pub fn flat_map(
425 this: &Array,
426 callback: &mut dyn FnMut(JsValue, u32, Array) -> Vec<JsValue>,
427 ) -> Array;
428
429 /// The `forEach()` method executes a provided function once for each array element.
430 ///
431 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach)
432 #[wasm_bindgen(method, js_name = forEach)]
433 pub fn for_each(this: &Array, callback: &mut dyn FnMut(JsValue, u32, Array));
434
435 /// The `includes()` method determines whether an array includes a certain
436 /// element, returning true or false as appropriate.
437 ///
438 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes)
439 #[wasm_bindgen(method)]
440 pub fn includes(this: &Array, value: &JsValue, from_index: i32) -> bool;
441
442 /// The `indexOf()` method returns the first index at which a given element
443 /// can be found in the array, or -1 if it is not present.
444 ///
445 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf)
446 #[wasm_bindgen(method, js_name = indexOf)]
447 pub fn index_of(this: &Array, value: &JsValue, from_index: i32) -> i32;
448
449 /// The `Array.isArray()` method determines whether the passed value is an Array.
450 ///
451 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray)
452 #[wasm_bindgen(static_method_of = Array, js_name = isArray)]
453 pub fn is_array(value: &JsValue) -> bool;
454
455 /// The `join()` method joins all elements of an array (or an array-like object)
456 /// into a string and returns this string.
457 ///
458 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join)
459 #[wasm_bindgen(method)]
460 pub fn join(this: &Array, delimiter: &str) -> JsString;
461
462 /// The `lastIndexOf()` method returns the last index at which a given element
463 /// can be found in the array, or -1 if it is not present. The array is
464 /// searched backwards, starting at fromIndex.
465 ///
466 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/lastIndexOf)
467 #[wasm_bindgen(method, js_name = lastIndexOf)]
468 pub fn last_index_of(this: &Array, value: &JsValue, from_index: i32) -> i32;
469
470 /// The length property of an object which is an instance of type Array
471 /// sets or returns the number of elements in that array. The value is an
472 /// unsigned, 32-bit integer that is always numerically greater than the
473 /// highest index in the array.
474 ///
475 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/length)
476 #[wasm_bindgen(method, getter, structural)]
477 pub fn length(this: &Array) -> u32;
478
479 /// Sets the length of the array.
480 ///
481 /// If it is set to less than the current length of the array, it will
482 /// shrink the array.
483 ///
484 /// If it is set to more than the current length of the array, it will
485 /// increase the length of the array, filling the new space with empty
486 /// slots.
487 ///
488 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/length)
489 #[wasm_bindgen(method, setter)]
490 pub fn set_length(this: &Array, value: u32);
491
492 /// `map()` calls a provided callback function once for each element in an array,
493 /// in order, and constructs a new array from the results. callback is invoked
494 /// only for indexes of the array which have assigned values, including undefined.
495 /// It is not called for missing elements of the array (that is, indexes that have
496 /// never been set, which have been deleted or which have never been assigned a value).
497 ///
498 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map)
499 #[wasm_bindgen(method)]
500 pub fn map(this: &Array, predicate: &mut dyn FnMut(JsValue, u32, Array) -> JsValue) -> Array;
501
502 /// The `Array.of()` method creates a new Array instance with a variable
503 /// number of arguments, regardless of number or type of the arguments.
504 ///
505 /// The difference between `Array.of()` and the `Array` constructor is in the
506 /// handling of integer arguments: `Array.of(7)` creates an array with a single
507 /// element, `7`, whereas `Array(7)` creates an empty array with a `length`
508 /// property of `7` (Note: this implies an array of 7 empty slots, not slots
509 /// with actual undefined values).
510 ///
511 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of)
512 ///
513 /// # Notes
514 ///
515 /// There are a few bindings to `of` in `js-sys`: `of1`, `of2`, etc...
516 /// with different arities.
517 #[wasm_bindgen(static_method_of = Array, js_name = of)]
518 pub fn of1(a: &JsValue) -> Array;
519
520 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of)
521 #[wasm_bindgen(static_method_of = Array, js_name = of)]
522 pub fn of2(a: &JsValue, b: &JsValue) -> Array;
523
524 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of)
525 #[wasm_bindgen(static_method_of = Array, js_name = of)]
526 pub fn of3(a: &JsValue, b: &JsValue, c: &JsValue) -> Array;
527
528 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of)
529 #[wasm_bindgen(static_method_of = Array, js_name = of)]
530 pub fn of4(a: &JsValue, b: &JsValue, c: &JsValue, d: &JsValue) -> Array;
531
532 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of)
533 #[wasm_bindgen(static_method_of = Array, js_name = of)]
534 pub fn of5(a: &JsValue, b: &JsValue, c: &JsValue, d: &JsValue, e: &JsValue) -> Array;
535
536 /// The `pop()` method removes the last element from an array and returns that
537 /// element. This method changes the length of the array.
538 ///
539 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pop)
540 #[wasm_bindgen(method)]
541 pub fn pop(this: &Array) -> JsValue;
542
543 /// The `push()` method adds one or more elements to the end of an array and
544 /// returns the new length of the array.
545 ///
546 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push)
547 #[wasm_bindgen(method)]
548 pub fn push(this: &Array, value: &JsValue) -> u32;
549
550 /// The `reduce()` method applies a function against an accumulator and each element in
551 /// the array (from left to right) to reduce it to a single value.
552 ///
553 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce)
554 #[wasm_bindgen(method)]
555 pub fn reduce(
556 this: &Array,
557 predicate: &mut dyn FnMut(JsValue, JsValue, u32, Array) -> JsValue,
558 initial_value: &JsValue,
559 ) -> JsValue;
560
561 /// The `reduceRight()` method applies a function against an accumulator and each value
562 /// of the array (from right-to-left) to reduce it to a single value.
563 ///
564 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/ReduceRight)
565 #[wasm_bindgen(method, js_name = reduceRight)]
566 pub fn reduce_right(
567 this: &Array,
568 predicate: &mut dyn FnMut(JsValue, JsValue, u32, Array) -> JsValue,
569 initial_value: &JsValue,
570 ) -> JsValue;
571
572 /// The `reverse()` method reverses an array in place. The first array
573 /// element becomes the last, and the last array element becomes the first.
574 ///
575 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse)
576 #[wasm_bindgen(method)]
577 pub fn reverse(this: &Array) -> Array;
578
579 /// The `shift()` method removes the first element from an array and returns
580 /// that removed element. This method changes the length of the array.
581 ///
582 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift)
583 #[wasm_bindgen(method)]
584 pub fn shift(this: &Array) -> JsValue;
585
586 /// The `slice()` method returns a shallow copy of a portion of an array into
587 /// a new array object selected from begin to end (end not included).
588 /// The original array will not be modified.
589 ///
590 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)
591 #[wasm_bindgen(method)]
592 pub fn slice(this: &Array, start: u32, end: u32) -> Array;
593
594 /// The `some()` method tests whether at least one element in the array passes the test implemented
595 /// by the provided function.
596 /// Note: This method returns false for any condition put on an empty array.
597 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some)
598 #[wasm_bindgen(method)]
599 pub fn some(this: &Array, predicate: &mut dyn FnMut(JsValue) -> bool) -> bool;
600
601 /// The `sort()` method sorts the elements of an array in place and returns
602 /// the array. The sort is not necessarily stable. The default sort
603 /// order is according to string Unicode code points.
604 ///
605 /// The time and space complexity of the sort cannot be guaranteed as it
606 /// is implementation dependent.
607 ///
608 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)
609 #[wasm_bindgen(method)]
610 pub fn sort(this: &Array) -> Array;
611
612 /// The `splice()` method changes the contents of an array by removing existing elements and/or
613 /// adding new elements.
614 ///
615 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice)
616 #[wasm_bindgen(method)]
617 pub fn splice(this: &Array, start: u32, delete_count: u32, item: &JsValue) -> Array;
618
619 /// The `toLocaleString()` method returns a string representing the elements of the array.
620 /// The elements are converted to Strings using their toLocaleString methods and these
621 /// Strings are separated by a locale-specific String (such as a comma “,”).
622 ///
623 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toLocaleString)
624 #[wasm_bindgen(method, js_name = toLocaleString)]
625 pub fn to_locale_string(this: &Array, locales: &JsValue, options: &JsValue) -> JsString;
626
627 /// The `toString()` method returns a string representing the specified array
628 /// and its elements.
629 ///
630 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toString)
631 #[wasm_bindgen(method, js_name = toString)]
632 pub fn to_string(this: &Array) -> JsString;
633
634 /// The `unshift()` method adds one or more elements to the beginning of an
635 /// array and returns the new length of the array.
636 ///
637 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift)
638 #[wasm_bindgen(method)]
639 pub fn unshift(this: &Array, value: &JsValue) -> u32;
640}
641
642/// Iterator returned by `Array::into_iter`
643#[derive(Debug, Clone)]
644pub struct ArrayIntoIter {
645 range: core::ops::Range<u32>,
646 array: Array,
647}
648
649impl core::iter::Iterator for ArrayIntoIter {
650 type Item = JsValue;
651
652 fn next(&mut self) -> Option<Self::Item> {
653 let index = self.range.next()?;
654 Some(self.array.get(index))
655 }
656
657 #[inline]
658 fn size_hint(&self) -> (usize, Option<usize>) {
659 self.range.size_hint()
660 }
661
662 #[inline]
663 fn count(self) -> usize
664 where
665 Self: Sized,
666 {
667 self.range.count()
668 }
669
670 #[inline]
671 fn last(self) -> Option<Self::Item>
672 where
673 Self: Sized,
674 {
675 let Self { range, array } = self;
676 range.last().map(|index| array.get(index))
677 }
678
679 #[inline]
680 fn nth(&mut self, n: usize) -> Option<Self::Item> {
681 self.range.nth(n).map(|index| self.array.get(index))
682 }
683}
684
685impl core::iter::DoubleEndedIterator for ArrayIntoIter {
686 fn next_back(&mut self) -> Option<Self::Item> {
687 let index = self.range.next_back()?;
688 Some(self.array.get(index))
689 }
690
691 fn nth_back(&mut self, n: usize) -> Option<Self::Item> {
692 self.range.nth_back(n).map(|index| self.array.get(index))
693 }
694}
695
696impl core::iter::FusedIterator for ArrayIntoIter {}
697
698impl core::iter::ExactSizeIterator for ArrayIntoIter {}
699
700/// Iterator returned by `Array::iter`
701#[derive(Debug, Clone)]
702pub struct ArrayIter<'a> {
703 range: core::ops::Range<u32>,
704 array: &'a Array,
705}
706
707impl core::iter::Iterator for ArrayIter<'_> {
708 type Item = JsValue;
709
710 fn next(&mut self) -> Option<Self::Item> {
711 let index = self.range.next()?;
712 Some(self.array.get(index))
713 }
714
715 #[inline]
716 fn size_hint(&self) -> (usize, Option<usize>) {
717 self.range.size_hint()
718 }
719
720 #[inline]
721 fn count(self) -> usize
722 where
723 Self: Sized,
724 {
725 self.range.count()
726 }
727
728 #[inline]
729 fn last(self) -> Option<Self::Item>
730 where
731 Self: Sized,
732 {
733 let Self { range, array } = self;
734 range.last().map(|index| array.get(index))
735 }
736
737 #[inline]
738 fn nth(&mut self, n: usize) -> Option<Self::Item> {
739 self.range.nth(n).map(|index| self.array.get(index))
740 }
741}
742
743impl core::iter::DoubleEndedIterator for ArrayIter<'_> {
744 fn next_back(&mut self) -> Option<Self::Item> {
745 let index = self.range.next_back()?;
746 Some(self.array.get(index))
747 }
748
749 fn nth_back(&mut self, n: usize) -> Option<Self::Item> {
750 self.range.nth_back(n).map(|index| self.array.get(index))
751 }
752}
753
754impl core::iter::FusedIterator for ArrayIter<'_> {}
755
756impl core::iter::ExactSizeIterator for ArrayIter<'_> {}
757
758impl Array {
759 /// Returns an iterator over the values of the JS array.
760 pub fn iter(&self) -> ArrayIter<'_> {
761 ArrayIter {
762 range: 0..self.length(),
763 array: self,
764 }
765 }
766
767 /// Converts the JS array into a new Vec.
768 pub fn to_vec(&self) -> Vec<JsValue> {
769 let len = self.length();
770
771 let mut output = Vec::with_capacity(len as usize);
772
773 for i in 0..len {
774 output.push(self.get(i));
775 }
776
777 output
778 }
779}
780
781impl core::iter::IntoIterator for Array {
782 type Item = JsValue;
783 type IntoIter = ArrayIntoIter;
784
785 fn into_iter(self) -> Self::IntoIter {
786 ArrayIntoIter {
787 range: 0..self.length(),
788 array: self,
789 }
790 }
791}
792
793// TODO pre-initialize the Array with the correct length using TrustedLen
794impl<A> core::iter::FromIterator<A> for Array
795where
796 A: AsRef<JsValue>,
797{
798 fn from_iter<T>(iter: T) -> Array
799 where
800 T: IntoIterator<Item = A>,
801 {
802 let mut out = Array::new();
803 out.extend(iter);
804 out
805 }
806}
807
808impl<A> core::iter::Extend<A> for Array
809where
810 A: AsRef<JsValue>,
811{
812 fn extend<T>(&mut self, iter: T)
813 where
814 T: IntoIterator<Item = A>,
815 {
816 for value in iter {
817 self.push(value.as_ref());
818 }
819 }
820}
821
822impl Default for Array {
823 fn default() -> Self {
824 Self::new()
825 }
826}
827
828// ArrayBuffer
829#[wasm_bindgen]
830extern "C" {
831 #[wasm_bindgen(extends = Object, typescript_type = "ArrayBuffer")]
832 #[derive(Clone, Debug, PartialEq, Eq)]
833 pub type ArrayBuffer;
834
835 /// The `ArrayBuffer` object is used to represent a generic,
836 /// fixed-length raw binary data buffer. You cannot directly
837 /// manipulate the contents of an `ArrayBuffer`; instead, you
838 /// create one of the typed array objects or a `DataView` object
839 /// which represents the buffer in a specific format, and use that
840 /// to read and write the contents of the buffer.
841 ///
842 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer)
843 #[wasm_bindgen(constructor)]
844 pub fn new(length: u32) -> ArrayBuffer;
845
846 /// The byteLength property of an object which is an instance of type ArrayBuffer
847 /// it's an accessor property whose set accessor function is undefined,
848 /// meaning that you can only read this property.
849 /// The value is established when the array is constructed and cannot be changed.
850 /// This property returns 0 if this ArrayBuffer has been detached.
851 ///
852 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/byteLength)
853 #[wasm_bindgen(method, getter, js_name = byteLength)]
854 pub fn byte_length(this: &ArrayBuffer) -> u32;
855
856 /// The `isView()` method returns true if arg is one of the `ArrayBuffer`
857 /// views, such as typed array objects or a DataView; false otherwise.
858 ///
859 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/isView)
860 #[wasm_bindgen(static_method_of = ArrayBuffer, js_name = isView)]
861 pub fn is_view(value: &JsValue) -> bool;
862
863 /// The `slice()` method returns a new `ArrayBuffer` whose contents
864 /// are a copy of this `ArrayBuffer`'s bytes from begin, inclusive,
865 /// up to end, exclusive.
866 ///
867 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/slice)
868 #[wasm_bindgen(method)]
869 pub fn slice(this: &ArrayBuffer, begin: u32) -> ArrayBuffer;
870
871 /// Like `slice()` but with the `end` argument.
872 ///
873 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/slice)
874 #[wasm_bindgen(method, js_name = slice)]
875 pub fn slice_with_end(this: &ArrayBuffer, begin: u32, end: u32) -> ArrayBuffer;
876}
877
878// SharedArrayBuffer
879#[wasm_bindgen]
880extern "C" {
881 #[wasm_bindgen(extends = Object, typescript_type = "SharedArrayBuffer")]
882 #[derive(Clone, Debug)]
883 pub type SharedArrayBuffer;
884
885 /// The `SharedArrayBuffer` object is used to represent a generic,
886 /// fixed-length raw binary data buffer, similar to the `ArrayBuffer`
887 /// object, but in a way that they can be used to create views
888 /// on shared memory. Unlike an `ArrayBuffer`, a `SharedArrayBuffer`
889 /// cannot become detached.
890 ///
891 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer)
892 #[wasm_bindgen(constructor)]
893 pub fn new(length: u32) -> SharedArrayBuffer;
894
895 /// The byteLength accessor property represents the length of
896 /// an `SharedArrayBuffer` in bytes. This is established when
897 /// the `SharedArrayBuffer` is constructed and cannot be changed.
898 ///
899 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/byteLength)
900 #[wasm_bindgen(method, getter, js_name = byteLength)]
901 pub fn byte_length(this: &SharedArrayBuffer) -> u32;
902
903 /// The `slice()` method returns a new `SharedArrayBuffer` whose contents
904 /// are a copy of this `SharedArrayBuffer`'s bytes from begin, inclusive,
905 /// up to end, exclusive.
906 ///
907 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/slice)
908 #[wasm_bindgen(method)]
909 pub fn slice(this: &SharedArrayBuffer, begin: u32) -> SharedArrayBuffer;
910
911 /// Like `slice()` but with the `end` argument.
912 ///
913 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/slice)
914 #[wasm_bindgen(method, js_name = slice)]
915 pub fn slice_with_end(this: &SharedArrayBuffer, begin: u32, end: u32) -> SharedArrayBuffer;
916}
917
918// Array Iterator
919#[wasm_bindgen]
920extern "C" {
921 /// The `keys()` method returns a new Array Iterator object that contains the
922 /// keys for each index in the array.
923 ///
924 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/keys)
925 #[wasm_bindgen(method)]
926 pub fn keys(this: &Array) -> Iterator;
927
928 /// The `entries()` method returns a new Array Iterator object that contains
929 /// the key/value pairs for each index in the array.
930 ///
931 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries)
932 #[wasm_bindgen(method)]
933 pub fn entries(this: &Array) -> Iterator;
934
935 /// The `values()` method returns a new Array Iterator object that
936 /// contains the values for each index in the array.
937 ///
938 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/values)
939 #[wasm_bindgen(method)]
940 pub fn values(this: &Array) -> Iterator;
941}
942
943/// The `Atomics` object provides atomic operations as static methods.
944/// They are used with `SharedArrayBuffer` objects.
945///
946/// The Atomic operations are installed on an `Atomics` module. Unlike
947/// the other global objects, `Atomics` is not a constructor. You cannot
948/// use it with a new operator or invoke the `Atomics` object as a
949/// function. All properties and methods of `Atomics` are static
950/// (as is the case with the Math object, for example).
951/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics)
952#[allow(non_snake_case)]
953pub mod Atomics {
954 use super::*;
955
956 #[wasm_bindgen]
957 extern "C" {
958 /// The static `Atomics.add()` method adds a given value at a given
959 /// position in the array and returns the old value at that position.
960 /// This atomic operation guarantees that no other write happens
961 /// until the modified value is written back.
962 ///
963 /// You should use `add_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
964 ///
965 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/add)
966 #[wasm_bindgen(js_namespace = Atomics, catch)]
967 pub fn add(typed_array: &JsValue, index: u32, value: i32) -> Result<i32, JsValue>;
968
969 /// The static `Atomics.add()` method adds a given value at a given
970 /// position in the array and returns the old value at that position.
971 /// This atomic operation guarantees that no other write happens
972 /// until the modified value is written back.
973 ///
974 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
975 ///
976 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/add)
977 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = add)]
978 pub fn add_bigint(typed_array: &JsValue, index: u32, value: i64) -> Result<i64, JsValue>;
979
980 /// The static `Atomics.and()` method computes a bitwise AND with a given
981 /// value at a given position in the array, and returns the old value
982 /// at that position.
983 /// This atomic operation guarantees that no other write happens
984 /// until the modified value is written back.
985 ///
986 /// You should use `and_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
987 ///
988 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/and)
989 #[wasm_bindgen(js_namespace = Atomics, catch)]
990 pub fn and(typed_array: &JsValue, index: u32, value: i32) -> Result<i32, JsValue>;
991
992 /// The static `Atomics.and()` method computes a bitwise AND with a given
993 /// value at a given position in the array, and returns the old value
994 /// at that position.
995 /// This atomic operation guarantees that no other write happens
996 /// until the modified value is written back.
997 ///
998 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
999 ///
1000 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/and)
1001 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = and)]
1002 pub fn and_bigint(typed_array: &JsValue, index: u32, value: i64) -> Result<i64, JsValue>;
1003
1004 /// The static `Atomics.compareExchange()` method exchanges a given
1005 /// replacement value at a given position in the array, if a given expected
1006 /// value equals the old value. It returns the old value at that position
1007 /// whether it was equal to the expected value or not.
1008 /// This atomic operation guarantees that no other write happens
1009 /// until the modified value is written back.
1010 ///
1011 /// You should use `compare_exchange_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
1012 ///
1013 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/compareExchange)
1014 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = compareExchange)]
1015 pub fn compare_exchange(
1016 typed_array: &JsValue,
1017 index: u32,
1018 expected_value: i32,
1019 replacement_value: i32,
1020 ) -> Result<i32, JsValue>;
1021
1022 /// The static `Atomics.compareExchange()` method exchanges a given
1023 /// replacement value at a given position in the array, if a given expected
1024 /// value equals the old value. It returns the old value at that position
1025 /// whether it was equal to the expected value or not.
1026 /// This atomic operation guarantees that no other write happens
1027 /// until the modified value is written back.
1028 ///
1029 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
1030 ///
1031 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/compareExchange)
1032 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = compareExchange)]
1033 pub fn compare_exchange_bigint(
1034 typed_array: &JsValue,
1035 index: u32,
1036 expected_value: i64,
1037 replacement_value: i64,
1038 ) -> Result<i64, JsValue>;
1039
1040 /// The static `Atomics.exchange()` method stores a given value at a given
1041 /// position in the array and returns the old value at that position.
1042 /// This atomic operation guarantees that no other write happens
1043 /// until the modified value is written back.
1044 ///
1045 /// You should use `exchange_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
1046 ///
1047 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/exchange)
1048 #[wasm_bindgen(js_namespace = Atomics, catch)]
1049 pub fn exchange(typed_array: &JsValue, index: u32, value: i32) -> Result<i32, JsValue>;
1050
1051 /// The static `Atomics.exchange()` method stores a given value at a given
1052 /// position in the array and returns the old value at that position.
1053 /// This atomic operation guarantees that no other write happens
1054 /// until the modified value is written back.
1055 ///
1056 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
1057 ///
1058 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/exchange)
1059 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = exchange)]
1060 pub fn exchange_bigint(
1061 typed_array: &JsValue,
1062 index: u32,
1063 value: i64,
1064 ) -> Result<i64, JsValue>;
1065
1066 /// The static `Atomics.isLockFree()` method is used to determine
1067 /// whether to use locks or atomic operations. It returns true,
1068 /// if the given size is one of the `BYTES_PER_ELEMENT` property
1069 /// of integer `TypedArray` types.
1070 ///
1071 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/isLockFree)
1072 #[wasm_bindgen(js_namespace = Atomics, js_name = isLockFree)]
1073 pub fn is_lock_free(size: u32) -> bool;
1074
1075 /// The static `Atomics.load()` method returns a value at a given
1076 /// position in the array.
1077 ///
1078 /// You should use `load_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
1079 ///
1080 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/load)
1081 #[wasm_bindgen(js_namespace = Atomics, catch)]
1082 pub fn load(typed_array: &JsValue, index: u32) -> Result<i32, JsValue>;
1083
1084 /// The static `Atomics.load()` method returns a value at a given
1085 /// position in the array.
1086 ///
1087 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
1088 ///
1089 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/load)
1090 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = load)]
1091 pub fn load_bigint(typed_array: &JsValue, index: i64) -> Result<i64, JsValue>;
1092
1093 /// The static `Atomics.notify()` method notifies up some agents that
1094 /// are sleeping in the wait queue.
1095 /// Note: This operation works with a shared `Int32Array` only.
1096 /// If `count` is not provided, notifies all the agents in the queue.
1097 ///
1098 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/notify)
1099 #[wasm_bindgen(js_namespace = Atomics, catch)]
1100 pub fn notify(typed_array: &Int32Array, index: u32) -> Result<u32, JsValue>;
1101
1102 /// Notifies up to `count` agents in the wait queue.
1103 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = notify)]
1104 pub fn notify_with_count(
1105 typed_array: &Int32Array,
1106 index: u32,
1107 count: u32,
1108 ) -> Result<u32, JsValue>;
1109
1110 /// The static `Atomics.or()` method computes a bitwise OR with a given value
1111 /// at a given position in the array, and returns the old value at that position.
1112 /// This atomic operation guarantees that no other write happens
1113 /// until the modified value is written back.
1114 ///
1115 /// You should use `or_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
1116 ///
1117 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/or)
1118 #[wasm_bindgen(js_namespace = Atomics, catch)]
1119 pub fn or(typed_array: &JsValue, index: u32, value: i32) -> Result<i32, JsValue>;
1120
1121 /// The static `Atomics.or()` method computes a bitwise OR with a given value
1122 /// at a given position in the array, and returns the old value at that position.
1123 /// This atomic operation guarantees that no other write happens
1124 /// until the modified value is written back.
1125 ///
1126 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
1127 ///
1128 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/or)
1129 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = or)]
1130 pub fn or_bigint(typed_array: &JsValue, index: u32, value: i64) -> Result<i64, JsValue>;
1131
1132 /// The static `Atomics.store()` method stores a given value at the given
1133 /// position in the array and returns that value.
1134 ///
1135 /// You should use `store_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
1136 ///
1137 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/store)
1138 #[wasm_bindgen(js_namespace = Atomics, catch)]
1139 pub fn store(typed_array: &JsValue, index: u32, value: i32) -> Result<i32, JsValue>;
1140
1141 /// The static `Atomics.store()` method stores a given value at the given
1142 /// position in the array and returns that value.
1143 ///
1144 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
1145 ///
1146 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/store)
1147 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = store)]
1148 pub fn store_bigint(typed_array: &JsValue, index: u32, value: i64) -> Result<i64, JsValue>;
1149
1150 /// The static `Atomics.sub()` method subtracts a given value at a
1151 /// given position in the array and returns the old value at that position.
1152 /// This atomic operation guarantees that no other write happens
1153 /// until the modified value is written back.
1154 ///
1155 /// You should use `sub_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
1156 ///
1157 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/sub)
1158 #[wasm_bindgen(js_namespace = Atomics, catch)]
1159 pub fn sub(typed_array: &JsValue, index: u32, value: i32) -> Result<i32, JsValue>;
1160
1161 /// The static `Atomics.sub()` method subtracts a given value at a
1162 /// given position in the array and returns the old value at that position.
1163 /// This atomic operation guarantees that no other write happens
1164 /// until the modified value is written back.
1165 ///
1166 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
1167 ///
1168 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/sub)
1169 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = sub)]
1170 pub fn sub_bigint(typed_array: &JsValue, index: u32, value: i64) -> Result<i64, JsValue>;
1171
1172 /// The static `Atomics.wait()` method verifies that a given
1173 /// position in an `Int32Array` still contains a given value
1174 /// and if so sleeps, awaiting a wakeup or a timeout.
1175 /// It returns a string which is either "ok", "not-equal", or "timed-out".
1176 /// Note: This operation only works with a shared `Int32Array`
1177 /// and may not be allowed on the main thread.
1178 ///
1179 /// You should use `wait_bigint` to operate on a `BigInt64Array`.
1180 ///
1181 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait)
1182 #[wasm_bindgen(js_namespace = Atomics, catch)]
1183 pub fn wait(typed_array: &Int32Array, index: u32, value: i32) -> Result<JsString, JsValue>;
1184
1185 /// The static `Atomics.wait()` method verifies that a given
1186 /// position in an `BigInt64Array` still contains a given value
1187 /// and if so sleeps, awaiting a wakeup or a timeout.
1188 /// It returns a string which is either "ok", "not-equal", or "timed-out".
1189 /// Note: This operation only works with a shared `BigInt64Array`
1190 /// and may not be allowed on the main thread.
1191 ///
1192 /// You should use `wait` to operate on a `Int32Array`.
1193 ///
1194 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait)
1195 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = wait)]
1196 pub fn wait_bigint(
1197 typed_array: &BigInt64Array,
1198 index: u32,
1199 value: i64,
1200 ) -> Result<JsString, JsValue>;
1201
1202 /// Like `wait()`, but with timeout
1203 ///
1204 /// You should use `wait_with_timeout_bigint` to operate on a `BigInt64Array`.
1205 ///
1206 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait)
1207 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = wait)]
1208 pub fn wait_with_timeout(
1209 typed_array: &Int32Array,
1210 index: u32,
1211 value: i32,
1212 timeout: f64,
1213 ) -> Result<JsString, JsValue>;
1214
1215 /// Like `wait()`, but with timeout
1216 ///
1217 /// You should use `wait_with_timeout` to operate on a `Int32Array`.
1218 ///
1219 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait)
1220 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = wait)]
1221 pub fn wait_with_timeout_bigint(
1222 typed_array: &BigInt64Array,
1223 index: u32,
1224 value: i64,
1225 timeout: f64,
1226 ) -> Result<JsString, JsValue>;
1227
1228 /// The static `Atomics.waitAsync()` method verifies that a given position in an
1229 /// `Int32Array` still contains a given value and if so sleeps, awaiting a
1230 /// wakeup or a timeout. It returns an object with two properties. The first
1231 /// property `async` is a boolean which if true indicates that the second
1232 /// property `value` is a promise. If `async` is false then value is a string
1233 /// whether equal to either "not-equal" or "timed-out".
1234 /// Note: This operation only works with a shared `Int32Array` and may be used
1235 /// on the main thread.
1236 ///
1237 /// You should use `wait_async_bigint` to operate on a `BigInt64Array`.
1238 ///
1239 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/waitAsync)
1240 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = waitAsync)]
1241 pub fn wait_async(
1242 typed_array: &Int32Array,
1243 index: u32,
1244 value: i32,
1245 ) -> Result<Object, JsValue>;
1246
1247 /// The static `Atomics.waitAsync()` method verifies that a given position in an
1248 /// `Int32Array` still contains a given value and if so sleeps, awaiting a
1249 /// wakeup or a timeout. It returns an object with two properties. The first
1250 /// property `async` is a boolean which if true indicates that the second
1251 /// property `value` is a promise. If `async` is false then value is a string
1252 /// whether equal to either "not-equal" or "timed-out".
1253 /// Note: This operation only works with a shared `BigInt64Array` and may be used
1254 /// on the main thread.
1255 ///
1256 /// You should use `wait_async` to operate on a `Int32Array`.
1257 ///
1258 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/waitAsync)
1259 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = waitAsync)]
1260 pub fn wait_async_bigint(
1261 typed_array: &BigInt64Array,
1262 index: u32,
1263 value: i64,
1264 ) -> Result<Object, JsValue>;
1265
1266 /// Like `waitAsync()`, but with timeout
1267 ///
1268 /// You should use `wait_async_with_timeout_bigint` to operate on a `BigInt64Array`.
1269 ///
1270 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/waitAsync)
1271 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = waitAsync)]
1272 pub fn wait_async_with_timeout(
1273 typed_array: &Int32Array,
1274 index: u32,
1275 value: i32,
1276 timeout: f64,
1277 ) -> Result<Object, JsValue>;
1278
1279 /// Like `waitAsync()`, but with timeout
1280 ///
1281 /// You should use `wait_async_with_timeout` to operate on a `Int32Array`.
1282 ///
1283 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/waitAsync)
1284 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = waitAsync)]
1285 pub fn wait_async_with_timeout_bigint(
1286 typed_array: &BigInt64Array,
1287 index: u32,
1288 value: i64,
1289 timeout: f64,
1290 ) -> Result<Object, JsValue>;
1291
1292 /// The static `Atomics.xor()` method computes a bitwise XOR
1293 /// with a given value at a given position in the array,
1294 /// and returns the old value at that position.
1295 /// This atomic operation guarantees that no other write happens
1296 /// until the modified value is written back.
1297 ///
1298 /// You should use `xor_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`.
1299 ///
1300 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/xor)
1301 #[wasm_bindgen(js_namespace = Atomics, catch)]
1302 pub fn xor(typed_array: &JsValue, index: u32, value: i32) -> Result<i32, JsValue>;
1303
1304 /// The static `Atomics.xor()` method computes a bitwise XOR
1305 /// with a given value at a given position in the array,
1306 /// and returns the old value at that position.
1307 /// This atomic operation guarantees that no other write happens
1308 /// until the modified value is written back.
1309 ///
1310 /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`.
1311 ///
1312 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/xor)
1313 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = xor)]
1314 pub fn xor_bigint(typed_array: &JsValue, index: u32, value: i64) -> Result<i64, JsValue>;
1315 }
1316}
1317
1318// BigInt
1319#[wasm_bindgen]
1320extern "C" {
1321 #[wasm_bindgen(extends = Object, is_type_of = |v| v.is_bigint(), typescript_type = "bigint")]
1322 #[derive(Clone, PartialEq, Eq)]
1323 pub type BigInt;
1324
1325 #[wasm_bindgen(catch, js_name = BigInt)]
1326 fn new_bigint(value: &JsValue) -> Result<BigInt, Error>;
1327
1328 #[wasm_bindgen(js_name = BigInt)]
1329 fn new_bigint_unchecked(value: &JsValue) -> BigInt;
1330
1331 /// Clamps a BigInt value to a signed integer value, and returns that value.
1332 ///
1333 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/asIntN)
1334 #[wasm_bindgen(static_method_of = BigInt, js_name = asIntN)]
1335 pub fn as_int_n(bits: f64, bigint: &BigInt) -> BigInt;
1336
1337 /// Clamps a BigInt value to an unsigned integer value, and returns that value.
1338 ///
1339 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/asUintN)
1340 #[wasm_bindgen(static_method_of = BigInt, js_name = asUintN)]
1341 pub fn as_uint_n(bits: f64, bigint: &BigInt) -> BigInt;
1342
1343 /// 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.
1344 ///
1345 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/toLocaleString)
1346 #[wasm_bindgen(method, js_name = toLocaleString)]
1347 pub fn to_locale_string(this: &BigInt, locales: &JsValue, options: &JsValue) -> JsString;
1348
1349 /// 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.
1350 ///
1351 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/toString)
1352 #[wasm_bindgen(catch, method, js_name = toString)]
1353 pub fn to_string(this: &BigInt, radix: u8) -> Result<JsString, RangeError>;
1354
1355 #[wasm_bindgen(method, js_name = toString)]
1356 fn to_string_unchecked(this: &BigInt, radix: u8) -> String;
1357
1358 /// Returns this BigInt value. Overrides the [`Object.prototype.valueOf()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf) method.
1359 ///
1360 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/valueOf)
1361 #[wasm_bindgen(method, js_name = valueOf)]
1362 pub fn value_of(this: &BigInt, radix: u8) -> BigInt;
1363}
1364
1365impl BigInt {
1366 /// Creates a new BigInt value.
1367 ///
1368 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/BigInt)
1369 #[inline]
1370 pub fn new(value: &JsValue) -> Result<BigInt, Error> {
1371 new_bigint(value)
1372 }
1373
1374 /// Applies the binary `/` JS operator on two `BigInt`s, catching and returning any `RangeError` thrown.
1375 ///
1376 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Division)
1377 pub fn checked_div(&self, rhs: &Self) -> Result<Self, RangeError> {
1378 let result = JsValue::as_ref(self).checked_div(JsValue::as_ref(rhs));
1379
1380 if result.is_instance_of::<RangeError>() {
1381 Err(result.unchecked_into())
1382 } else {
1383 Ok(result.unchecked_into())
1384 }
1385 }
1386
1387 /// Applies the binary `**` JS operator on the two `BigInt`s.
1388 ///
1389 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Exponentiation)
1390 #[inline]
1391 pub fn pow(&self, rhs: &Self) -> Self {
1392 JsValue::as_ref(self)
1393 .pow(JsValue::as_ref(rhs))
1394 .unchecked_into()
1395 }
1396
1397 /// Returns a tuple of this [`BigInt`]'s absolute value along with a
1398 /// [`bool`] indicating whether the [`BigInt`] was negative.
1399 fn abs(&self) -> (Self, bool) {
1400 if self < &BigInt::from(0) {
1401 (-self, true)
1402 } else {
1403 (self.clone(), false)
1404 }
1405 }
1406}
1407
1408macro_rules! bigint_from {
1409 ($($x:ident)*) => ($(
1410 impl From<$x> for BigInt {
1411 #[inline]
1412 fn from(x: $x) -> BigInt {
1413 new_bigint_unchecked(&JsValue::from(x))
1414 }
1415 }
1416
1417 impl PartialEq<$x> for BigInt {
1418 #[inline]
1419 fn eq(&self, other: &$x) -> bool {
1420 JsValue::from(self) == JsValue::from(BigInt::from(*other))
1421 }
1422 }
1423 )*)
1424}
1425bigint_from!(i8 u8 i16 u16 i32 u32 isize usize);
1426
1427macro_rules! bigint_from_big {
1428 ($($x:ident)*) => ($(
1429 impl From<$x> for BigInt {
1430 #[inline]
1431 fn from(x: $x) -> BigInt {
1432 JsValue::from(x).unchecked_into()
1433 }
1434 }
1435
1436 impl PartialEq<$x> for BigInt {
1437 #[inline]
1438 fn eq(&self, other: &$x) -> bool {
1439 self == &BigInt::from(*other)
1440 }
1441 }
1442
1443 impl TryFrom<BigInt> for $x {
1444 type Error = BigInt;
1445
1446 #[inline]
1447 fn try_from(x: BigInt) -> Result<Self, BigInt> {
1448 Self::try_from(JsValue::from(x)).map_err(JsCast::unchecked_into)
1449 }
1450 }
1451 )*)
1452}
1453bigint_from_big!(i64 u64 i128 u128);
1454
1455impl PartialEq<Number> for BigInt {
1456 #[inline]
1457 fn eq(&self, other: &Number) -> bool {
1458 JsValue::as_ref(self).loose_eq(JsValue::as_ref(other))
1459 }
1460}
1461
1462impl Not for &BigInt {
1463 type Output = BigInt;
1464
1465 #[inline]
1466 fn not(self) -> Self::Output {
1467 JsValue::as_ref(self).bit_not().unchecked_into()
1468 }
1469}
1470
1471forward_deref_unop!(impl Not, not for BigInt);
1472forward_js_unop!(impl Neg, neg for BigInt);
1473forward_js_binop!(impl BitAnd, bitand for BigInt);
1474forward_js_binop!(impl BitOr, bitor for BigInt);
1475forward_js_binop!(impl BitXor, bitxor for BigInt);
1476forward_js_binop!(impl Shl, shl for BigInt);
1477forward_js_binop!(impl Shr, shr for BigInt);
1478forward_js_binop!(impl Add, add for BigInt);
1479forward_js_binop!(impl Sub, sub for BigInt);
1480forward_js_binop!(impl Div, div for BigInt);
1481forward_js_binop!(impl Mul, mul for BigInt);
1482forward_js_binop!(impl Rem, rem for BigInt);
1483sum_product!(BigInt);
1484
1485partialord_ord!(BigInt);
1486
1487impl Default for BigInt {
1488 fn default() -> Self {
1489 BigInt::from(i32::default())
1490 }
1491}
1492
1493impl FromStr for BigInt {
1494 type Err = Error;
1495
1496 #[inline]
1497 fn from_str(s: &str) -> Result<Self, Self::Err> {
1498 BigInt::new(&s.into())
1499 }
1500}
1501
1502impl fmt::Debug for BigInt {
1503 #[inline]
1504 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1505 fmt::Display::fmt(self, f)
1506 }
1507}
1508
1509impl fmt::Display for BigInt {
1510 #[inline]
1511 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1512 let (abs, is_neg) = self.abs();
1513 f.pad_integral(!is_neg, "", &abs.to_string_unchecked(10))
1514 }
1515}
1516
1517impl fmt::Binary for BigInt {
1518 #[inline]
1519 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1520 let (abs, is_neg) = self.abs();
1521 f.pad_integral(!is_neg, "0b", &abs.to_string_unchecked(2))
1522 }
1523}
1524
1525impl fmt::Octal for BigInt {
1526 #[inline]
1527 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1528 let (abs, is_neg) = self.abs();
1529 f.pad_integral(!is_neg, "0o", &abs.to_string_unchecked(8))
1530 }
1531}
1532
1533impl fmt::LowerHex for BigInt {
1534 #[inline]
1535 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1536 let (abs, is_neg) = self.abs();
1537 f.pad_integral(!is_neg, "0x", &abs.to_string_unchecked(16))
1538 }
1539}
1540
1541impl fmt::UpperHex for BigInt {
1542 #[inline]
1543 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1544 let (abs, is_neg) = self.abs();
1545 let mut s: String = abs.to_string_unchecked(16);
1546 s.make_ascii_uppercase();
1547 f.pad_integral(!is_neg, "0x", &s)
1548 }
1549}
1550
1551// Boolean
1552#[wasm_bindgen]
1553extern "C" {
1554 #[wasm_bindgen(extends = Object, is_type_of = |v| v.as_bool().is_some(), typescript_type = "boolean")]
1555 #[derive(Clone, PartialEq, Eq)]
1556 pub type Boolean;
1557
1558 /// The `Boolean()` constructor creates an object wrapper for a boolean value.
1559 ///
1560 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)
1561 #[wasm_bindgen(constructor)]
1562 #[deprecated(note = "recommended to use `Boolean::from` instead")]
1563 #[allow(deprecated)]
1564 pub fn new(value: &JsValue) -> Boolean;
1565
1566 /// The `valueOf()` method returns the primitive value of a `Boolean` object.
1567 ///
1568 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean/valueOf)
1569 #[wasm_bindgen(method, js_name = valueOf)]
1570 pub fn value_of(this: &Boolean) -> bool;
1571}
1572
1573impl From<bool> for Boolean {
1574 #[inline]
1575 fn from(b: bool) -> Boolean {
1576 Boolean::unchecked_from_js(JsValue::from(b))
1577 }
1578}
1579
1580impl From<Boolean> for bool {
1581 #[inline]
1582 fn from(b: Boolean) -> bool {
1583 b.value_of()
1584 }
1585}
1586
1587impl PartialEq<bool> for Boolean {
1588 #[inline]
1589 fn eq(&self, other: &bool) -> bool {
1590 self.value_of() == *other
1591 }
1592}
1593
1594impl fmt::Debug for Boolean {
1595 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1596 fmt::Debug::fmt(&self.value_of(), f)
1597 }
1598}
1599
1600impl fmt::Display for Boolean {
1601 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1602 fmt::Display::fmt(&self.value_of(), f)
1603 }
1604}
1605
1606impl Default for Boolean {
1607 fn default() -> Self {
1608 Self::from(bool::default())
1609 }
1610}
1611
1612impl Not for &Boolean {
1613 type Output = Boolean;
1614
1615 #[inline]
1616 fn not(self) -> Self::Output {
1617 (!JsValue::as_ref(self)).into()
1618 }
1619}
1620
1621forward_deref_unop!(impl Not, not for Boolean);
1622
1623partialord_ord!(Boolean);
1624
1625// DataView
1626#[wasm_bindgen]
1627extern "C" {
1628 #[wasm_bindgen(extends = Object, typescript_type = "DataView")]
1629 #[derive(Clone, Debug, PartialEq, Eq)]
1630 pub type DataView;
1631
1632 /// The `DataView` view provides a low-level interface for reading and
1633 /// writing multiple number types in an `ArrayBuffer` irrespective of the
1634 /// platform's endianness.
1635 ///
1636 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView)
1637 #[wasm_bindgen(constructor)]
1638 pub fn new(buffer: &ArrayBuffer, byteOffset: usize, byteLength: usize) -> DataView;
1639
1640 /// The `DataView` view provides a low-level interface for reading and
1641 /// writing multiple number types in an `ArrayBuffer` irrespective of the
1642 /// platform's endianness.
1643 ///
1644 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView)
1645 #[wasm_bindgen(constructor)]
1646 pub fn new_with_shared_array_buffer(
1647 buffer: &SharedArrayBuffer,
1648 byteOffset: usize,
1649 byteLength: usize,
1650 ) -> DataView;
1651
1652 /// The ArrayBuffer referenced by this view. Fixed at construction time and thus read only.
1653 ///
1654 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/buffer)
1655 #[wasm_bindgen(method, getter, structural)]
1656 pub fn buffer(this: &DataView) -> ArrayBuffer;
1657
1658 /// The length (in bytes) of this view from the start of its ArrayBuffer.
1659 /// Fixed at construction time and thus read only.
1660 ///
1661 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/byteLength)
1662 #[wasm_bindgen(method, getter, structural, js_name = byteLength)]
1663 pub fn byte_length(this: &DataView) -> usize;
1664
1665 /// The offset (in bytes) of this view from the start of its ArrayBuffer.
1666 /// Fixed at construction time and thus read only.
1667 ///
1668 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/byteOffset)
1669 #[wasm_bindgen(method, getter, structural, js_name = byteOffset)]
1670 pub fn byte_offset(this: &DataView) -> usize;
1671
1672 /// The `getInt8()` method gets a signed 8-bit integer (byte) at the
1673 /// specified byte offset from the start of the DataView.
1674 ///
1675 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt8)
1676 #[wasm_bindgen(method, js_name = getInt8)]
1677 pub fn get_int8(this: &DataView, byte_offset: usize) -> i8;
1678
1679 /// The `getUint8()` method gets a unsigned 8-bit integer (byte) at the specified
1680 /// byte offset from the start of the DataView.
1681 ///
1682 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint8)
1683 #[wasm_bindgen(method, js_name = getUint8)]
1684 pub fn get_uint8(this: &DataView, byte_offset: usize) -> u8;
1685
1686 /// The `getInt16()` method gets a signed 16-bit integer (short) at the specified
1687 /// byte offset from the start of the DataView.
1688 ///
1689 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt16)
1690 #[wasm_bindgen(method, js_name = getInt16)]
1691 pub fn get_int16(this: &DataView, byte_offset: usize) -> i16;
1692
1693 /// The `getInt16()` method gets a signed 16-bit integer (short) at the specified
1694 /// byte offset from the start of the DataView.
1695 ///
1696 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt16)
1697 #[wasm_bindgen(method, js_name = getInt16)]
1698 pub fn get_int16_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> i16;
1699
1700 /// The `getUint16()` method gets an unsigned 16-bit integer (unsigned short) at the specified
1701 /// byte offset from the start of the view.
1702 ///
1703 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint16)
1704 #[wasm_bindgen(method, js_name = getUint16)]
1705 pub fn get_uint16(this: &DataView, byte_offset: usize) -> u16;
1706
1707 /// The `getUint16()` method gets an unsigned 16-bit integer (unsigned short) at the specified
1708 /// byte offset from the start of the view.
1709 ///
1710 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint16)
1711 #[wasm_bindgen(method, js_name = getUint16)]
1712 pub fn get_uint16_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> u16;
1713
1714 /// The `getInt32()` method gets a signed 32-bit integer (long) at the specified
1715 /// byte offset from the start of the DataView.
1716 ///
1717 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt32)
1718 #[wasm_bindgen(method, js_name = getInt32)]
1719 pub fn get_int32(this: &DataView, byte_offset: usize) -> i32;
1720
1721 /// The `getInt32()` method gets a signed 32-bit integer (long) at the specified
1722 /// byte offset from the start of the DataView.
1723 ///
1724 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt32)
1725 #[wasm_bindgen(method, js_name = getInt32)]
1726 pub fn get_int32_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> i32;
1727
1728 /// The `getUint32()` method gets an unsigned 32-bit integer (unsigned long) at the specified
1729 /// byte offset from the start of the view.
1730 ///
1731 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint32)
1732 #[wasm_bindgen(method, js_name = getUint32)]
1733 pub fn get_uint32(this: &DataView, byte_offset: usize) -> u32;
1734
1735 /// The `getUint32()` method gets an unsigned 32-bit integer (unsigned long) at the specified
1736 /// byte offset from the start of the view.
1737 ///
1738 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint32)
1739 #[wasm_bindgen(method, js_name = getUint32)]
1740 pub fn get_uint32_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> u32;
1741
1742 /// The `getFloat32()` method gets a signed 32-bit float (float) at the specified
1743 /// byte offset from the start of the DataView.
1744 ///
1745 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat32)
1746 #[wasm_bindgen(method, js_name = getFloat32)]
1747 pub fn get_float32(this: &DataView, byte_offset: usize) -> f32;
1748
1749 /// The `getFloat32()` method gets a signed 32-bit float (float) at the specified
1750 /// byte offset from the start of the DataView.
1751 ///
1752 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat32)
1753 #[wasm_bindgen(method, js_name = getFloat32)]
1754 pub fn get_float32_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> f32;
1755
1756 /// The `getFloat64()` method gets a signed 64-bit float (double) at the specified
1757 /// byte offset from the start of the DataView.
1758 ///
1759 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat64)
1760 #[wasm_bindgen(method, js_name = getFloat64)]
1761 pub fn get_float64(this: &DataView, byte_offset: usize) -> f64;
1762
1763 /// The `getFloat64()` method gets a signed 64-bit float (double) at the specified
1764 /// byte offset from the start of the DataView.
1765 ///
1766 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat64)
1767 #[wasm_bindgen(method, js_name = getFloat64)]
1768 pub fn get_float64_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> f64;
1769
1770 /// The `setInt8()` method stores a signed 8-bit integer (byte) value at the
1771 /// specified byte offset from the start of the DataView.
1772 ///
1773 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt8)
1774 #[wasm_bindgen(method, js_name = setInt8)]
1775 pub fn set_int8(this: &DataView, byte_offset: usize, value: i8);
1776
1777 /// The `setUint8()` method stores an unsigned 8-bit integer (byte) value at the
1778 /// specified byte offset from the start of the DataView.
1779 ///
1780 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint8)
1781 #[wasm_bindgen(method, js_name = setUint8)]
1782 pub fn set_uint8(this: &DataView, byte_offset: usize, value: u8);
1783
1784 /// The `setInt16()` method stores a signed 16-bit integer (short) value at the
1785 /// specified byte offset from the start of the DataView.
1786 ///
1787 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt16)
1788 #[wasm_bindgen(method, js_name = setInt16)]
1789 pub fn set_int16(this: &DataView, byte_offset: usize, value: i16);
1790
1791 /// The `setInt16()` method stores a signed 16-bit integer (short) value at the
1792 /// specified byte offset from the start of the DataView.
1793 ///
1794 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt16)
1795 #[wasm_bindgen(method, js_name = setInt16)]
1796 pub fn set_int16_endian(this: &DataView, byte_offset: usize, value: i16, little_endian: bool);
1797
1798 /// The `setUint16()` method stores an unsigned 16-bit integer (unsigned short) value at the
1799 /// specified byte offset from the start of the DataView.
1800 ///
1801 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint16)
1802 #[wasm_bindgen(method, js_name = setUint16)]
1803 pub fn set_uint16(this: &DataView, byte_offset: usize, value: u16);
1804
1805 /// The `setUint16()` method stores an unsigned 16-bit integer (unsigned short) value at the
1806 /// specified byte offset from the start of the DataView.
1807 ///
1808 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint16)
1809 #[wasm_bindgen(method, js_name = setUint16)]
1810 pub fn set_uint16_endian(this: &DataView, byte_offset: usize, value: u16, little_endian: bool);
1811
1812 /// The `setInt32()` method stores a signed 32-bit integer (long) value at the
1813 /// specified byte offset from the start of the DataView.
1814 ///
1815 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt32)
1816 #[wasm_bindgen(method, js_name = setInt32)]
1817 pub fn set_int32(this: &DataView, byte_offset: usize, value: i32);
1818
1819 /// The `setInt32()` method stores a signed 32-bit integer (long) value at the
1820 /// specified byte offset from the start of the DataView.
1821 ///
1822 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt32)
1823 #[wasm_bindgen(method, js_name = setInt32)]
1824 pub fn set_int32_endian(this: &DataView, byte_offset: usize, value: i32, little_endian: bool);
1825
1826 /// The `setUint32()` method stores an unsigned 32-bit integer (unsigned long) value at the
1827 /// specified byte offset from the start of the DataView.
1828 ///
1829 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint32)
1830 #[wasm_bindgen(method, js_name = setUint32)]
1831 pub fn set_uint32(this: &DataView, byte_offset: usize, value: u32);
1832
1833 /// The `setUint32()` method stores an unsigned 32-bit integer (unsigned long) value at the
1834 /// specified byte offset from the start of the DataView.
1835 ///
1836 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint32)
1837 #[wasm_bindgen(method, js_name = setUint32)]
1838 pub fn set_uint32_endian(this: &DataView, byte_offset: usize, value: u32, little_endian: bool);
1839
1840 /// The `setFloat32()` method stores a signed 32-bit float (float) value at the
1841 /// specified byte offset from the start of the DataView.
1842 ///
1843 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat32)
1844 #[wasm_bindgen(method, js_name = setFloat32)]
1845 pub fn set_float32(this: &DataView, byte_offset: usize, value: f32);
1846
1847 /// The `setFloat32()` method stores a signed 32-bit float (float) value at the
1848 /// specified byte offset from the start of the DataView.
1849 ///
1850 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat32)
1851 #[wasm_bindgen(method, js_name = setFloat32)]
1852 pub fn set_float32_endian(this: &DataView, byte_offset: usize, value: f32, little_endian: bool);
1853
1854 /// The `setFloat64()` method stores a signed 64-bit float (double) value at the
1855 /// specified byte offset from the start of the DataView.
1856 ///
1857 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat64)
1858 #[wasm_bindgen(method, js_name = setFloat64)]
1859 pub fn set_float64(this: &DataView, byte_offset: usize, value: f64);
1860
1861 /// The `setFloat64()` method stores a signed 64-bit float (double) value at the
1862 /// specified byte offset from the start of the DataView.
1863 ///
1864 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat64)
1865 #[wasm_bindgen(method, js_name = setFloat64)]
1866 pub fn set_float64_endian(this: &DataView, byte_offset: usize, value: f64, little_endian: bool);
1867}
1868
1869// Error
1870#[wasm_bindgen]
1871extern "C" {
1872 #[wasm_bindgen(extends = Object, typescript_type = "Error")]
1873 #[derive(Clone, Debug, PartialEq, Eq)]
1874 pub type Error;
1875
1876 /// The Error constructor creates an error object.
1877 /// Instances of Error objects are thrown when runtime errors occur.
1878 /// The Error object can also be used as a base object for user-defined exceptions.
1879 /// See below for standard built-in error types.
1880 ///
1881 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)
1882 #[wasm_bindgen(constructor)]
1883 pub fn new(message: &str) -> Error;
1884 #[wasm_bindgen(constructor)]
1885 pub fn new_with_options(message: &str, options: &Object) -> Error;
1886
1887 /// The cause property is the underlying cause of the error.
1888 /// Usually this is used to add context to re-thrown errors.
1889 ///
1890 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error#differentiate_between_similar_errors)
1891 #[wasm_bindgen(method, getter, structural)]
1892 pub fn cause(this: &Error) -> JsValue;
1893 #[wasm_bindgen(method, setter, structural)]
1894 pub fn set_cause(this: &Error, cause: &JsValue);
1895
1896 /// The message property is a human-readable description of the error.
1897 ///
1898 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/message)
1899 #[wasm_bindgen(method, getter, structural)]
1900 pub fn message(this: &Error) -> JsString;
1901 #[wasm_bindgen(method, setter, structural)]
1902 pub fn set_message(this: &Error, message: &str);
1903
1904 /// The name property represents a name for the type of error. The initial value is "Error".
1905 ///
1906 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/name)
1907 #[wasm_bindgen(method, getter, structural)]
1908 pub fn name(this: &Error) -> JsString;
1909 #[wasm_bindgen(method, setter, structural)]
1910 pub fn set_name(this: &Error, name: &str);
1911
1912 /// The `toString()` method returns a string representing the specified Error object
1913 ///
1914 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/toString)
1915 #[wasm_bindgen(method, js_name = toString)]
1916 pub fn to_string(this: &Error) -> JsString;
1917}
1918
1919partialord_ord!(JsString);
1920
1921// EvalError
1922#[wasm_bindgen]
1923extern "C" {
1924 #[wasm_bindgen(extends = Object, extends = Error, typescript_type = "EvalError")]
1925 #[derive(Clone, Debug, PartialEq, Eq)]
1926 pub type EvalError;
1927
1928 /// The EvalError object indicates an error regarding the global eval() function. This
1929 /// exception is not thrown by JavaScript anymore, however the EvalError object remains for
1930 /// compatibility.
1931 ///
1932 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/EvalError)
1933 #[wasm_bindgen(constructor)]
1934 pub fn new(message: &str) -> EvalError;
1935}
1936
1937// Function
1938#[wasm_bindgen]
1939extern "C" {
1940 #[wasm_bindgen(extends = Object, is_type_of = JsValue::is_function, typescript_type = "Function")]
1941 #[derive(Clone, Debug, PartialEq, Eq)]
1942 pub type Function;
1943
1944 /// The `Function` constructor creates a new `Function` object. Calling the
1945 /// constructor directly can create functions dynamically, but suffers from
1946 /// security and similar (but far less significant) performance issues
1947 /// similar to `eval`. However, unlike `eval`, the `Function` constructor
1948 /// allows executing code in the global scope, prompting better programming
1949 /// habits and allowing for more efficient code minification.
1950 ///
1951 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
1952 #[wasm_bindgen(constructor)]
1953 pub fn new_with_args(args: &str, body: &str) -> Function;
1954
1955 /// The `Function` constructor creates a new `Function` object. Calling the
1956 /// constructor directly can create functions dynamically, but suffers from
1957 /// security and similar (but far less significant) performance issues
1958 /// similar to `eval`. However, unlike `eval`, the `Function` constructor
1959 /// allows executing code in the global scope, prompting better programming
1960 /// habits and allowing for more efficient code minification.
1961 ///
1962 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
1963 #[wasm_bindgen(constructor)]
1964 pub fn new_no_args(body: &str) -> Function;
1965
1966 /// The `apply()` method calls a function with a given this value, and arguments provided as an array
1967 /// (or an array-like object).
1968 ///
1969 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply)
1970 #[wasm_bindgen(method, catch)]
1971 pub fn apply(this: &Function, context: &JsValue, args: &Array) -> Result<JsValue, JsValue>;
1972
1973 /// The `call()` method calls a function with a given this value and
1974 /// arguments provided individually.
1975 ///
1976 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
1977 #[wasm_bindgen(method, catch, js_name = call)]
1978 pub fn call0(this: &Function, context: &JsValue) -> Result<JsValue, JsValue>;
1979
1980 /// The `call()` method calls a function with a given this value and
1981 /// arguments provided individually.
1982 ///
1983 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
1984 #[wasm_bindgen(method, catch, js_name = call)]
1985 pub fn call1(this: &Function, context: &JsValue, arg1: &JsValue) -> Result<JsValue, JsValue>;
1986
1987 /// The `call()` method calls a function with a given this value and
1988 /// arguments provided individually.
1989 ///
1990 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
1991 #[wasm_bindgen(method, catch, js_name = call)]
1992 pub fn call2(
1993 this: &Function,
1994 context: &JsValue,
1995 arg1: &JsValue,
1996 arg2: &JsValue,
1997 ) -> Result<JsValue, JsValue>;
1998
1999 /// The `call()` method calls a function with a given this value and
2000 /// arguments provided individually.
2001 ///
2002 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
2003 #[wasm_bindgen(method, catch, js_name = call)]
2004 pub fn call3(
2005 this: &Function,
2006 context: &JsValue,
2007 arg1: &JsValue,
2008 arg2: &JsValue,
2009 arg3: &JsValue,
2010 ) -> Result<JsValue, JsValue>;
2011
2012 /// The `call()` method calls a function with a given this value and
2013 /// arguments provided individually.
2014 ///
2015 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
2016 #[wasm_bindgen(method, catch, js_name = call)]
2017 pub fn call4(
2018 this: &Function,
2019 context: &JsValue,
2020 arg1: &JsValue,
2021 arg2: &JsValue,
2022 arg3: &JsValue,
2023 arg4: &JsValue,
2024 ) -> Result<JsValue, JsValue>;
2025
2026 /// The `call()` method calls a function with a given this value and
2027 /// arguments provided individually.
2028 ///
2029 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
2030 #[wasm_bindgen(method, catch, js_name = call)]
2031 pub fn call5(
2032 this: &Function,
2033 context: &JsValue,
2034 arg1: &JsValue,
2035 arg2: &JsValue,
2036 arg3: &JsValue,
2037 arg4: &JsValue,
2038 arg5: &JsValue,
2039 ) -> Result<JsValue, JsValue>;
2040
2041 /// The `call()` method calls a function with a given this value and
2042 /// arguments provided individually.
2043 ///
2044 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
2045 #[wasm_bindgen(method, catch, js_name = call)]
2046 pub fn call6(
2047 this: &Function,
2048 context: &JsValue,
2049 arg1: &JsValue,
2050 arg2: &JsValue,
2051 arg3: &JsValue,
2052 arg4: &JsValue,
2053 arg5: &JsValue,
2054 arg6: &JsValue,
2055 ) -> Result<JsValue, JsValue>;
2056
2057 /// The `call()` method calls a function with a given this value and
2058 /// arguments provided individually.
2059 ///
2060 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
2061 #[wasm_bindgen(method, catch, js_name = call)]
2062 pub fn call7(
2063 this: &Function,
2064 context: &JsValue,
2065 arg1: &JsValue,
2066 arg2: &JsValue,
2067 arg3: &JsValue,
2068 arg4: &JsValue,
2069 arg5: &JsValue,
2070 arg6: &JsValue,
2071 arg7: &JsValue,
2072 ) -> Result<JsValue, JsValue>;
2073
2074 /// The `call()` method calls a function with a given this value and
2075 /// arguments provided individually.
2076 ///
2077 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
2078 #[wasm_bindgen(method, catch, js_name = call)]
2079 pub fn call8(
2080 this: &Function,
2081 context: &JsValue,
2082 arg1: &JsValue,
2083 arg2: &JsValue,
2084 arg3: &JsValue,
2085 arg4: &JsValue,
2086 arg5: &JsValue,
2087 arg6: &JsValue,
2088 arg7: &JsValue,
2089 arg8: &JsValue,
2090 ) -> Result<JsValue, JsValue>;
2091
2092 /// The `call()` method calls a function with a given this value and
2093 /// arguments provided individually.
2094 ///
2095 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
2096 #[wasm_bindgen(method, catch, js_name = call)]
2097 pub fn call9(
2098 this: &Function,
2099 context: &JsValue,
2100 arg1: &JsValue,
2101 arg2: &JsValue,
2102 arg3: &JsValue,
2103 arg4: &JsValue,
2104 arg5: &JsValue,
2105 arg6: &JsValue,
2106 arg7: &JsValue,
2107 arg8: &JsValue,
2108 arg9: &JsValue,
2109 ) -> Result<JsValue, JsValue>;
2110
2111 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
2112 /// with a given sequence of arguments preceding any provided when the new function is called.
2113 ///
2114 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
2115 #[wasm_bindgen(method, js_name = bind)]
2116 pub fn bind(this: &Function, context: &JsValue) -> Function;
2117
2118 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
2119 /// with a given sequence of arguments preceding any provided when the new function is called.
2120 ///
2121 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
2122 #[wasm_bindgen(method, js_name = bind)]
2123 pub fn bind0(this: &Function, context: &JsValue) -> Function;
2124
2125 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
2126 /// with a given sequence of arguments preceding any provided when the new function is called.
2127 ///
2128 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
2129 #[wasm_bindgen(method, js_name = bind)]
2130 pub fn bind1(this: &Function, context: &JsValue, arg1: &JsValue) -> Function;
2131
2132 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
2133 /// with a given sequence of arguments preceding any provided when the new function is called.
2134 ///
2135 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
2136 #[wasm_bindgen(method, js_name = bind)]
2137 pub fn bind2(this: &Function, context: &JsValue, arg1: &JsValue, arg2: &JsValue) -> Function;
2138
2139 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
2140 /// with a given sequence of arguments preceding any provided when the new function is called.
2141 ///
2142 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
2143 #[wasm_bindgen(method, js_name = bind)]
2144 pub fn bind3(
2145 this: &Function,
2146 context: &JsValue,
2147 arg1: &JsValue,
2148 arg2: &JsValue,
2149 arg3: &JsValue,
2150 ) -> Function;
2151
2152 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
2153 /// with a given sequence of arguments preceding any provided when the new function is called.
2154 ///
2155 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
2156 #[wasm_bindgen(method, js_name = bind)]
2157 pub fn bind4(
2158 this: &Function,
2159 context: &JsValue,
2160 arg1: &JsValue,
2161 arg2: &JsValue,
2162 arg3: &JsValue,
2163 arg4: &JsValue,
2164 ) -> Function;
2165
2166 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
2167 /// with a given sequence of arguments preceding any provided when the new function is called.
2168 ///
2169 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
2170 #[wasm_bindgen(method, js_name = bind)]
2171 pub fn bind5(
2172 this: &Function,
2173 context: &JsValue,
2174 arg1: &JsValue,
2175 arg2: &JsValue,
2176 arg3: &JsValue,
2177 arg4: &JsValue,
2178 arg5: &JsValue,
2179 ) -> Function;
2180
2181 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
2182 /// with a given sequence of arguments preceding any provided when the new function is called.
2183 ///
2184 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
2185 #[wasm_bindgen(method, js_name = bind)]
2186 pub fn bind6(
2187 this: &Function,
2188 context: &JsValue,
2189 arg1: &JsValue,
2190 arg2: &JsValue,
2191 arg3: &JsValue,
2192 arg4: &JsValue,
2193 arg5: &JsValue,
2194 arg6: &JsValue,
2195 ) -> Function;
2196
2197 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
2198 /// with a given sequence of arguments preceding any provided when the new function is called.
2199 ///
2200 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
2201 #[wasm_bindgen(method, js_name = bind)]
2202 pub fn bind7(
2203 this: &Function,
2204 context: &JsValue,
2205 arg1: &JsValue,
2206 arg2: &JsValue,
2207 arg3: &JsValue,
2208 arg4: &JsValue,
2209 arg5: &JsValue,
2210 arg6: &JsValue,
2211 arg7: &JsValue,
2212 ) -> Function;
2213
2214 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
2215 /// with a given sequence of arguments preceding any provided when the new function is called.
2216 ///
2217 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
2218 #[wasm_bindgen(method, js_name = bind)]
2219 pub fn bind8(
2220 this: &Function,
2221 context: &JsValue,
2222 arg1: &JsValue,
2223 arg2: &JsValue,
2224 arg3: &JsValue,
2225 arg4: &JsValue,
2226 arg5: &JsValue,
2227 arg6: &JsValue,
2228 arg7: &JsValue,
2229 arg8: &JsValue,
2230 ) -> Function;
2231
2232 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
2233 /// with a given sequence of arguments preceding any provided when the new function is called.
2234 ///
2235 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
2236 #[wasm_bindgen(method, js_name = bind)]
2237 pub fn bind9(
2238 this: &Function,
2239 context: &JsValue,
2240 arg1: &JsValue,
2241 arg2: &JsValue,
2242 arg3: &JsValue,
2243 arg4: &JsValue,
2244 arg5: &JsValue,
2245 arg6: &JsValue,
2246 arg7: &JsValue,
2247 arg8: &JsValue,
2248 arg9: &JsValue,
2249 ) -> Function;
2250
2251 /// The length property indicates the number of arguments expected by the function.
2252 ///
2253 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/length)
2254 #[wasm_bindgen(method, getter, structural)]
2255 pub fn length(this: &Function) -> u32;
2256
2257 /// A Function object's read-only name property indicates the function's
2258 /// name as specified when it was created or "anonymous" for functions
2259 /// created anonymously.
2260 ///
2261 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name)
2262 #[wasm_bindgen(method, getter, structural)]
2263 pub fn name(this: &Function) -> JsString;
2264
2265 /// The `toString()` method returns a string representing the source code of the function.
2266 ///
2267 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/toString)
2268 #[wasm_bindgen(method, js_name = toString)]
2269 pub fn to_string(this: &Function) -> JsString;
2270}
2271
2272impl Function {
2273 /// Returns the `Function` value of this JS value if it's an instance of a
2274 /// function.
2275 ///
2276 /// If this JS value is not an instance of a function then this returns
2277 /// `None`.
2278 #[deprecated(note = "recommended to use dyn_ref instead which is now equivalent")]
2279 pub fn try_from(val: &JsValue) -> Option<&Function> {
2280 val.dyn_ref()
2281 }
2282}
2283
2284impl Default for Function {
2285 fn default() -> Self {
2286 Self::new_no_args("")
2287 }
2288}
2289
2290// Generator
2291#[wasm_bindgen]
2292extern "C" {
2293 #[wasm_bindgen(extends = Object, typescript_type = "Generator<any, any, any>")]
2294 #[derive(Clone, Debug, PartialEq, Eq)]
2295 pub type Generator;
2296
2297 /// The `next()` method returns an object with two properties done and value.
2298 /// You can also provide a parameter to the next method to send a value to the generator.
2299 ///
2300 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/next)
2301 #[wasm_bindgen(method, structural, catch)]
2302 pub fn next(this: &Generator, value: &JsValue) -> Result<JsValue, JsValue>;
2303
2304 /// The `return()` method returns the given value and finishes the generator.
2305 ///
2306 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/return)
2307 #[wasm_bindgen(method, structural, js_name = return)]
2308 pub fn return_(this: &Generator, value: &JsValue) -> JsValue;
2309
2310 /// The `throw()` method resumes the execution of a generator by throwing an error into it
2311 /// and returns an object with two properties done and value.
2312 ///
2313 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/throw)
2314 #[wasm_bindgen(method, structural, catch)]
2315 pub fn throw(this: &Generator, error: &Error) -> Result<JsValue, JsValue>;
2316}
2317
2318// Map
2319#[wasm_bindgen]
2320extern "C" {
2321 #[wasm_bindgen(extends = Object, typescript_type = "Map<any, any>")]
2322 #[derive(Clone, Debug, PartialEq, Eq)]
2323 pub type Map;
2324
2325 /// The `clear()` method removes all elements from a Map object.
2326 ///
2327 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/clear)
2328 #[wasm_bindgen(method)]
2329 pub fn clear(this: &Map);
2330
2331 /// The `delete()` method removes the specified element from a Map object.
2332 ///
2333 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/delete)
2334 #[wasm_bindgen(method)]
2335 pub fn delete(this: &Map, key: &JsValue) -> bool;
2336
2337 /// The `forEach()` method executes a provided function once per each
2338 /// key/value pair in the Map object, in insertion order.
2339 /// Note that in Javascript land the `Key` and `Value` are reversed compared to normal expectations:
2340 /// # Examples
2341 /// ```
2342 /// let js_map = Map::new();
2343 /// js_map.for_each(&mut |value, key| {
2344 /// // Do something here...
2345 /// })
2346 /// ```
2347 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/forEach)
2348 #[wasm_bindgen(method, js_name = forEach)]
2349 pub fn for_each(this: &Map, callback: &mut dyn FnMut(JsValue, JsValue));
2350
2351 /// The `get()` method returns a specified element from a Map object.
2352 ///
2353 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get)
2354 #[wasm_bindgen(method)]
2355 pub fn get(this: &Map, key: &JsValue) -> JsValue;
2356
2357 /// The `has()` method returns a boolean indicating whether an element with
2358 /// the specified key exists or not.
2359 ///
2360 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/has)
2361 #[wasm_bindgen(method)]
2362 pub fn has(this: &Map, key: &JsValue) -> bool;
2363
2364 /// The Map object holds key-value pairs. Any value (both objects and
2365 /// primitive values) maybe used as either a key or a value.
2366 ///
2367 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)
2368 #[wasm_bindgen(constructor)]
2369 pub fn new() -> Map;
2370
2371 /// The `set()` method adds or updates an element with a specified key
2372 /// and value to a Map object.
2373 ///
2374 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/set)
2375 #[wasm_bindgen(method)]
2376 pub fn set(this: &Map, key: &JsValue, value: &JsValue) -> Map;
2377
2378 /// The value of size is an integer representing how many entries
2379 /// the Map object has. A set accessor function for size is undefined;
2380 /// you can not change this property.
2381 ///
2382 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/size)
2383 #[wasm_bindgen(method, getter, structural)]
2384 pub fn size(this: &Map) -> u32;
2385}
2386
2387impl Default for Map {
2388 fn default() -> Self {
2389 Self::new()
2390 }
2391}
2392
2393// Map Iterator
2394#[wasm_bindgen]
2395extern "C" {
2396 /// The `entries()` method returns a new Iterator object that contains
2397 /// the [key, value] pairs for each element in the Map object in
2398 /// insertion order.
2399 ///
2400 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries)
2401 #[wasm_bindgen(method)]
2402 pub fn entries(this: &Map) -> Iterator;
2403
2404 /// The `keys()` method returns a new Iterator object that contains the
2405 /// keys for each element in the Map object in insertion order.
2406 ///
2407 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/keys)
2408 #[wasm_bindgen(method)]
2409 pub fn keys(this: &Map) -> Iterator;
2410
2411 /// The `values()` method returns a new Iterator object that contains the
2412 /// values for each element in the Map object in insertion order.
2413 ///
2414 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/values)
2415 #[wasm_bindgen(method)]
2416 pub fn values(this: &Map) -> Iterator;
2417}
2418
2419// Iterator
2420#[wasm_bindgen]
2421extern "C" {
2422 /// Any object that conforms to the JS iterator protocol. For example,
2423 /// something returned by `myArray[Symbol.iterator]()`.
2424 ///
2425 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols)
2426 #[derive(Clone, Debug)]
2427 #[wasm_bindgen(is_type_of = Iterator::looks_like_iterator, typescript_type = "Iterator<any>")]
2428 pub type Iterator;
2429
2430 /// The `next()` method always has to return an object with appropriate
2431 /// properties including done and value. If a non-object value gets returned
2432 /// (such as false or undefined), a TypeError ("iterator.next() returned a
2433 /// non-object value") will be thrown.
2434 #[wasm_bindgen(catch, method, structural)]
2435 pub fn next(this: &Iterator) -> Result<IteratorNext, JsValue>;
2436}
2437
2438impl Iterator {
2439 fn looks_like_iterator(it: &JsValue) -> bool {
2440 #[wasm_bindgen]
2441 extern "C" {
2442 type MaybeIterator;
2443
2444 #[wasm_bindgen(method, getter)]
2445 fn next(this: &MaybeIterator) -> JsValue;
2446 }
2447
2448 if !it.is_object() {
2449 return false;
2450 }
2451
2452 let it = it.unchecked_ref::<MaybeIterator>();
2453
2454 it.next().is_function()
2455 }
2456}
2457
2458// Async Iterator
2459#[wasm_bindgen]
2460extern "C" {
2461 /// Any object that conforms to the JS async iterator protocol. For example,
2462 /// something returned by `myObject[Symbol.asyncIterator]()`.
2463 ///
2464 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of)
2465 #[derive(Clone, Debug)]
2466 #[wasm_bindgen(is_type_of = Iterator::looks_like_iterator, typescript_type = "AsyncIterator<any>")]
2467 pub type AsyncIterator;
2468
2469 /// The `next()` method always has to return a Promise which resolves to an object
2470 /// with appropriate properties including done and value. If a non-object value
2471 /// gets returned (such as false or undefined), a TypeError ("iterator.next()
2472 /// returned a non-object value") will be thrown.
2473 #[wasm_bindgen(catch, method, structural)]
2474 pub fn next(this: &AsyncIterator) -> Result<Promise, JsValue>;
2475}
2476
2477/// An iterator over the JS `Symbol.iterator` iteration protocol.
2478///
2479/// Use the `IntoIterator for &js_sys::Iterator` implementation to create this.
2480pub struct Iter<'a> {
2481 js: &'a Iterator,
2482 state: IterState,
2483}
2484
2485/// An iterator over the JS `Symbol.iterator` iteration protocol.
2486///
2487/// Use the `IntoIterator for js_sys::Iterator` implementation to create this.
2488pub struct IntoIter {
2489 js: Iterator,
2490 state: IterState,
2491}
2492
2493struct IterState {
2494 done: bool,
2495}
2496
2497impl<'a> IntoIterator for &'a Iterator {
2498 type Item = Result<JsValue, JsValue>;
2499 type IntoIter = Iter<'a>;
2500
2501 fn into_iter(self) -> Iter<'a> {
2502 Iter {
2503 js: self,
2504 state: IterState::new(),
2505 }
2506 }
2507}
2508
2509impl core::iter::Iterator for Iter<'_> {
2510 type Item = Result<JsValue, JsValue>;
2511
2512 fn next(&mut self) -> Option<Self::Item> {
2513 self.state.next(self.js)
2514 }
2515}
2516
2517impl IntoIterator for Iterator {
2518 type Item = Result<JsValue, JsValue>;
2519 type IntoIter = IntoIter;
2520
2521 fn into_iter(self) -> IntoIter {
2522 IntoIter {
2523 js: self,
2524 state: IterState::new(),
2525 }
2526 }
2527}
2528
2529impl core::iter::Iterator for IntoIter {
2530 type Item = Result<JsValue, JsValue>;
2531
2532 fn next(&mut self) -> Option<Self::Item> {
2533 self.state.next(&self.js)
2534 }
2535}
2536
2537impl IterState {
2538 fn new() -> IterState {
2539 IterState { done: false }
2540 }
2541
2542 fn next(&mut self, js: &Iterator) -> Option<Result<JsValue, JsValue>> {
2543 if self.done {
2544 return None;
2545 }
2546 let next = match js.next() {
2547 Ok(val) => val,
2548 Err(e) => {
2549 self.done = true;
2550 return Some(Err(e));
2551 }
2552 };
2553 if next.done() {
2554 self.done = true;
2555 None
2556 } else {
2557 Some(Ok(next.value()))
2558 }
2559 }
2560}
2561
2562/// Create an iterator over `val` using the JS iteration protocol and
2563/// `Symbol.iterator`.
2564pub fn try_iter(val: &JsValue) -> Result<Option<IntoIter>, JsValue> {
2565 let iter_sym = Symbol::iterator();
2566 let iter_fn = Reflect::get(val, iter_sym.as_ref())?;
2567
2568 let iter_fn: Function = match iter_fn.dyn_into() {
2569 Ok(iter_fn) => iter_fn,
2570 Err(_) => return Ok(None),
2571 };
2572
2573 let it: Iterator = match iter_fn.call0(val)?.dyn_into() {
2574 Ok(it) => it,
2575 Err(_) => return Ok(None),
2576 };
2577
2578 Ok(Some(it.into_iter()))
2579}
2580
2581// IteratorNext
2582#[wasm_bindgen]
2583extern "C" {
2584 /// The result of calling `next()` on a JS iterator.
2585 ///
2586 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols)
2587 #[wasm_bindgen(extends = Object, typescript_type = "IteratorResult<any>")]
2588 #[derive(Clone, Debug, PartialEq, Eq)]
2589 pub type IteratorNext;
2590
2591 /// Has the value `true` if the iterator is past the end of the iterated
2592 /// sequence. In this case value optionally specifies the return value of
2593 /// the iterator.
2594 ///
2595 /// Has the value `false` if the iterator was able to produce the next value
2596 /// in the sequence. This is equivalent of not specifying the done property
2597 /// altogether.
2598 #[wasm_bindgen(method, getter, structural)]
2599 pub fn done(this: &IteratorNext) -> bool;
2600
2601 /// Any JavaScript value returned by the iterator. Can be omitted when done
2602 /// is true.
2603 #[wasm_bindgen(method, getter, structural)]
2604 pub fn value(this: &IteratorNext) -> JsValue;
2605}
2606
2607#[allow(non_snake_case)]
2608pub mod Math {
2609 use super::*;
2610
2611 // Math
2612 #[wasm_bindgen]
2613 extern "C" {
2614 /// The `Math.abs()` function returns the absolute value of a number, that is
2615 /// Math.abs(x) = |x|
2616 ///
2617 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/abs)
2618 #[wasm_bindgen(js_namespace = Math)]
2619 pub fn abs(x: f64) -> f64;
2620
2621 /// The `Math.acos()` function returns the arccosine (in radians) of a
2622 /// number, that is ∀x∊[-1;1]
2623 /// Math.acos(x) = arccos(x) = the unique y∊[0;π] such that cos(y)=x
2624 ///
2625 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/acos)
2626 #[wasm_bindgen(js_namespace = Math)]
2627 pub fn acos(x: f64) -> f64;
2628
2629 /// The `Math.acosh()` function returns the hyperbolic arc-cosine of a
2630 /// number, that is ∀x ≥ 1
2631 /// Math.acosh(x) = arcosh(x) = the unique y ≥ 0 such that cosh(y) = x
2632 ///
2633 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/acosh)
2634 #[wasm_bindgen(js_namespace = Math)]
2635 pub fn acosh(x: f64) -> f64;
2636
2637 /// The `Math.asin()` function returns the arcsine (in radians) of a
2638 /// number, that is ∀x ∊ [-1;1]
2639 /// Math.asin(x) = arcsin(x) = the unique y∊[-π2;π2] such that sin(y) = x
2640 ///
2641 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/asin)
2642 #[wasm_bindgen(js_namespace = Math)]
2643 pub fn asin(x: f64) -> f64;
2644
2645 /// The `Math.asinh()` function returns the hyperbolic arcsine of a
2646 /// number, that is Math.asinh(x) = arsinh(x) = the unique y such that sinh(y) = x
2647 ///
2648 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/asinh)
2649 #[wasm_bindgen(js_namespace = Math)]
2650 pub fn asinh(x: f64) -> f64;
2651
2652 /// The `Math.atan()` function returns the arctangent (in radians) of a
2653 /// number, that is Math.atan(x) = arctan(x) = the unique y ∊ [-π2;π2]such that
2654 /// tan(y) = x
2655 #[wasm_bindgen(js_namespace = Math)]
2656 pub fn atan(x: f64) -> f64;
2657
2658 /// The `Math.atan2()` function returns the arctangent of the quotient of
2659 /// its arguments.
2660 ///
2661 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/atan2)
2662 #[wasm_bindgen(js_namespace = Math)]
2663 pub fn atan2(y: f64, x: f64) -> f64;
2664
2665 /// The `Math.atanh()` function returns the hyperbolic arctangent of a number,
2666 /// that is ∀x ∊ (-1,1), Math.atanh(x) = arctanh(x) = the unique y such that
2667 /// tanh(y) = x
2668 ///
2669 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/atanh)
2670 #[wasm_bindgen(js_namespace = Math)]
2671 pub fn atanh(x: f64) -> f64;
2672
2673 /// The `Math.cbrt() `function returns the cube root of a number, that is
2674 /// Math.cbrt(x) = ∛x = the unique y such that y^3 = x
2675 ///
2676 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/cbrt)
2677 #[wasm_bindgen(js_namespace = Math)]
2678 pub fn cbrt(x: f64) -> f64;
2679
2680 /// The `Math.ceil()` function returns the smallest integer greater than
2681 /// or equal to a given number.
2682 ///
2683 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/ceil)
2684 #[wasm_bindgen(js_namespace = Math)]
2685 pub fn ceil(x: f64) -> f64;
2686
2687 /// The `Math.clz32()` function returns the number of leading zero bits in
2688 /// the 32-bit binary representation of a number.
2689 ///
2690 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/clz32)
2691 #[wasm_bindgen(js_namespace = Math)]
2692 pub fn clz32(x: i32) -> u32;
2693
2694 /// The `Math.cos()` static function returns the cosine of the specified angle,
2695 /// which must be specified in radians. This value is length(adjacent)/length(hypotenuse).
2696 ///
2697 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/cos)
2698 #[wasm_bindgen(js_namespace = Math)]
2699 pub fn cos(x: f64) -> f64;
2700
2701 /// The `Math.cosh()` function returns the hyperbolic cosine of a number,
2702 /// that can be expressed using the constant e.
2703 ///
2704 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/cosh)
2705 #[wasm_bindgen(js_namespace = Math)]
2706 pub fn cosh(x: f64) -> f64;
2707
2708 /// The `Math.exp()` function returns e^x, where x is the argument, and e is Euler's number
2709 /// (also known as Napier's constant), the base of the natural logarithms.
2710 ///
2711 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/exp)
2712 #[wasm_bindgen(js_namespace = Math)]
2713 pub fn exp(x: f64) -> f64;
2714
2715 /// The `Math.expm1()` function returns e^x - 1, where x is the argument, and e the base of the
2716 /// natural logarithms.
2717 ///
2718 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/expm1)
2719 #[wasm_bindgen(js_namespace = Math)]
2720 pub fn expm1(x: f64) -> f64;
2721
2722 /// The `Math.floor()` function returns the largest integer less than or
2723 /// equal to a given number.
2724 ///
2725 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/floor)
2726 #[wasm_bindgen(js_namespace = Math)]
2727 pub fn floor(x: f64) -> f64;
2728
2729 /// The `Math.fround()` function returns the nearest 32-bit single precision float representation
2730 /// of a Number.
2731 ///
2732 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/fround)
2733 #[wasm_bindgen(js_namespace = Math)]
2734 pub fn fround(x: f64) -> f32;
2735
2736 /// The `Math.hypot()` function returns the square root of the sum of squares of its arguments.
2737 ///
2738 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/hypot)
2739 #[wasm_bindgen(js_namespace = Math)]
2740 pub fn hypot(x: f64, y: f64) -> f64;
2741
2742 /// The `Math.imul()` function returns the result of the C-like 32-bit multiplication of the
2743 /// two parameters.
2744 ///
2745 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/imul)
2746 #[wasm_bindgen(js_namespace = Math)]
2747 pub fn imul(x: i32, y: i32) -> i32;
2748
2749 /// The `Math.log()` function returns the natural logarithm (base e) of a number.
2750 /// The JavaScript `Math.log()` function is equivalent to ln(x) in mathematics.
2751 ///
2752 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log)
2753 #[wasm_bindgen(js_namespace = Math)]
2754 pub fn log(x: f64) -> f64;
2755
2756 /// The `Math.log10()` function returns the base 10 logarithm of a number.
2757 ///
2758 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log10)
2759 #[wasm_bindgen(js_namespace = Math)]
2760 pub fn log10(x: f64) -> f64;
2761
2762 /// The `Math.log1p()` function returns the natural logarithm (base e) of 1 + a number.
2763 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log1p)
2764 #[wasm_bindgen(js_namespace = Math)]
2765 pub fn log1p(x: f64) -> f64;
2766
2767 /// The `Math.log2()` function returns the base 2 logarithm of a number.
2768 ///
2769 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log2)
2770 #[wasm_bindgen(js_namespace = Math)]
2771 pub fn log2(x: f64) -> f64;
2772
2773 /// The `Math.max()` function returns the largest of two numbers.
2774 ///
2775 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/max)
2776 #[wasm_bindgen(js_namespace = Math)]
2777 pub fn max(x: f64, y: f64) -> f64;
2778
2779 /// The static function `Math.min()` returns the lowest-valued number passed into it.
2780 ///
2781 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/min)
2782 #[wasm_bindgen(js_namespace = Math)]
2783 pub fn min(x: f64, y: f64) -> f64;
2784
2785 /// The `Math.pow()` function returns the base to the exponent power, that is, base^exponent.
2786 ///
2787 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/pow)
2788 #[wasm_bindgen(js_namespace = Math)]
2789 pub fn pow(base: f64, exponent: f64) -> f64;
2790
2791 /// The `Math.random()` function returns a floating-point, pseudo-random number
2792 /// in the range 0–1 (inclusive of 0, but not 1) with approximately uniform distribution
2793 /// over that range — which you can then scale to your desired range.
2794 /// The implementation selects the initial seed to the random number generation algorithm;
2795 /// it cannot be chosen or reset by the user.
2796 ///
2797 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random)
2798 #[wasm_bindgen(js_namespace = Math)]
2799 pub fn random() -> f64;
2800
2801 /// The `Math.round()` function returns the value of a number rounded to the nearest integer.
2802 ///
2803 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round)
2804 #[wasm_bindgen(js_namespace = Math)]
2805 pub fn round(x: f64) -> f64;
2806
2807 /// The `Math.sign()` function returns the sign of a number, indicating whether the number is
2808 /// positive, negative or zero.
2809 ///
2810 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign)
2811 #[wasm_bindgen(js_namespace = Math)]
2812 pub fn sign(x: f64) -> f64;
2813
2814 /// The `Math.sin()` function returns the sine of a number.
2815 ///
2816 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sin)
2817 #[wasm_bindgen(js_namespace = Math)]
2818 pub fn sin(x: f64) -> f64;
2819
2820 /// The `Math.sinh()` function returns the hyperbolic sine of a number, that can be expressed
2821 /// using the constant e: Math.sinh(x) = (e^x - e^-x)/2
2822 ///
2823 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sinh)
2824 #[wasm_bindgen(js_namespace = Math)]
2825 pub fn sinh(x: f64) -> f64;
2826
2827 /// The `Math.sqrt()` function returns the square root of a number, that is
2828 /// ∀x ≥ 0, Math.sqrt(x) = √x = the unique y ≥ 0 such that y^2 = x
2829 ///
2830 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sqrt)
2831 #[wasm_bindgen(js_namespace = Math)]
2832 pub fn sqrt(x: f64) -> f64;
2833
2834 /// The `Math.tan()` function returns the tangent of a number.
2835 ///
2836 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/tan)
2837 #[wasm_bindgen(js_namespace = Math)]
2838 pub fn tan(x: f64) -> f64;
2839
2840 /// The `Math.tanh()` function returns the hyperbolic tangent of a number, that is
2841 /// tanh x = sinh x / cosh x = (e^x - e^-x)/(e^x + e^-x) = (e^2x - 1)/(e^2x + 1)
2842 ///
2843 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/tanh)
2844 #[wasm_bindgen(js_namespace = Math)]
2845 pub fn tanh(x: f64) -> f64;
2846
2847 /// The `Math.trunc()` function returns the integer part of a number by removing any fractional
2848 /// digits.
2849 ///
2850 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/trunc)
2851 #[wasm_bindgen(js_namespace = Math)]
2852 pub fn trunc(x: f64) -> f64;
2853
2854 /// The `Math.PI` property represents the ratio of the circumference of a circle to its diameter,
2855 /// approximately 3.14159.
2856 ///
2857 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/PI)
2858 #[wasm_bindgen(thread_local_v2, js_namespace = Math)]
2859 pub static PI: f64;
2860 }
2861}
2862
2863// Number.
2864#[wasm_bindgen]
2865extern "C" {
2866 #[wasm_bindgen(extends = Object, is_type_of = |v| v.as_f64().is_some(), typescript_type = "number")]
2867 #[derive(Clone, PartialEq)]
2868 pub type Number;
2869
2870 /// The `Number.isFinite()` method determines whether the passed value is a finite number.
2871 ///
2872 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isFinite)
2873 #[wasm_bindgen(static_method_of = Number, js_name = isFinite)]
2874 pub fn is_finite(value: &JsValue) -> bool;
2875
2876 /// The `Number.isInteger()` method determines whether the passed value is an integer.
2877 ///
2878 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isInteger)
2879 #[wasm_bindgen(static_method_of = Number, js_name = isInteger)]
2880 pub fn is_integer(value: &JsValue) -> bool;
2881
2882 /// The `Number.isNaN()` method determines whether the passed value is `NaN` and its type is Number.
2883 /// It is a more robust version of the original, global isNaN().
2884 ///
2885 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isNaN)
2886 #[wasm_bindgen(static_method_of = Number, js_name = isNaN)]
2887 pub fn is_nan(value: &JsValue) -> bool;
2888
2889 /// The `Number.isSafeInteger()` method determines whether the provided value is a number
2890 /// that is a safe integer.
2891 ///
2892 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isSafeInteger)
2893 #[wasm_bindgen(static_method_of = Number, js_name = isSafeInteger)]
2894 pub fn is_safe_integer(value: &JsValue) -> bool;
2895
2896 /// The `Number` JavaScript object is a wrapper object allowing
2897 /// you to work with numerical values. A `Number` object is
2898 /// created using the `Number()` constructor.
2899 ///
2900 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
2901 #[wasm_bindgen(constructor)]
2902 #[deprecated(note = "recommended to use `Number::from` instead")]
2903 #[allow(deprecated)]
2904 pub fn new(value: &JsValue) -> Number;
2905
2906 #[wasm_bindgen(constructor)]
2907 fn new_from_str(value: &str) -> Number;
2908
2909 /// The `Number.parseInt()` method parses a string argument and returns an
2910 /// integer of the specified radix or base.
2911 ///
2912 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/parseInt)
2913 #[wasm_bindgen(static_method_of = Number, js_name = parseInt)]
2914 pub fn parse_int(text: &str, radix: u8) -> f64;
2915
2916 /// The `Number.parseFloat()` method parses a string argument and returns a
2917 /// floating point number.
2918 ///
2919 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/parseFloat)
2920 #[wasm_bindgen(static_method_of = Number, js_name = parseFloat)]
2921 pub fn parse_float(text: &str) -> f64;
2922
2923 /// The `toLocaleString()` method returns a string with a language sensitive
2924 /// representation of this number.
2925 ///
2926 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString)
2927 #[wasm_bindgen(method, js_name = toLocaleString)]
2928 pub fn to_locale_string(this: &Number, locale: &str) -> JsString;
2929
2930 /// The `toPrecision()` method returns a string representing the Number
2931 /// object to the specified precision.
2932 ///
2933 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision)
2934 #[wasm_bindgen(catch, method, js_name = toPrecision)]
2935 pub fn to_precision(this: &Number, precision: u8) -> Result<JsString, JsValue>;
2936
2937 /// The `toFixed()` method returns a string representing the Number
2938 /// object using fixed-point notation.
2939 ///
2940 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed)
2941 #[wasm_bindgen(catch, method, js_name = toFixed)]
2942 pub fn to_fixed(this: &Number, digits: u8) -> Result<JsString, JsValue>;
2943
2944 /// The `toExponential()` method returns a string representing the Number
2945 /// object in exponential notation.
2946 ///
2947 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toExponential)
2948 #[wasm_bindgen(catch, method, js_name = toExponential)]
2949 pub fn to_exponential(this: &Number, fraction_digits: u8) -> Result<JsString, JsValue>;
2950
2951 /// The `toString()` method returns a string representing the
2952 /// specified Number object.
2953 ///
2954 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString)
2955 #[wasm_bindgen(catch, method, js_name = toString)]
2956 pub fn to_string(this: &Number, radix: u8) -> Result<JsString, JsValue>;
2957
2958 /// The `valueOf()` method returns the wrapped primitive value of
2959 /// a Number object.
2960 ///
2961 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/valueOf)
2962 #[wasm_bindgen(method, js_name = valueOf)]
2963 pub fn value_of(this: &Number) -> f64;
2964}
2965
2966impl Number {
2967 /// The smallest interval between two representable numbers.
2968 ///
2969 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/EPSILON)
2970 pub const EPSILON: f64 = f64::EPSILON;
2971 /// The maximum safe integer in JavaScript (2^53 - 1).
2972 ///
2973 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER)
2974 pub const MAX_SAFE_INTEGER: f64 = 9007199254740991.0;
2975 /// The largest positive representable number.
2976 ///
2977 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_VALUE)
2978 pub const MAX_VALUE: f64 = f64::MAX;
2979 /// The minimum safe integer in JavaScript (-(2^53 - 1)).
2980 ///
2981 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MIN_SAFE_INTEGER)
2982 pub const MIN_SAFE_INTEGER: f64 = -9007199254740991.0;
2983 /// The smallest positive representable number—that is, the positive number closest to zero
2984 /// (without actually being zero).
2985 ///
2986 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MIN_VALUE)
2987 // Cannot use f64::MIN_POSITIVE since that is the smallest **normal** positive number.
2988 pub const MIN_VALUE: f64 = 5E-324;
2989 /// Special "Not a Number" value.
2990 ///
2991 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/NaN)
2992 pub const NAN: f64 = f64::NAN;
2993 /// Special value representing negative infinity. Returned on overflow.
2994 ///
2995 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/NEGATIVE_INFINITY)
2996 pub const NEGATIVE_INFINITY: f64 = f64::NEG_INFINITY;
2997 /// Special value representing infinity. Returned on overflow.
2998 ///
2999 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/POSITIVE_INFINITY)
3000 pub const POSITIVE_INFINITY: f64 = f64::INFINITY;
3001
3002 /// Applies the binary `**` JS operator on the two `Number`s.
3003 ///
3004 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Exponentiation)
3005 #[inline]
3006 pub fn pow(&self, rhs: &Self) -> Self {
3007 JsValue::as_ref(self)
3008 .pow(JsValue::as_ref(rhs))
3009 .unchecked_into()
3010 }
3011
3012 /// Applies the binary `>>>` JS operator on the two `Number`s.
3013 ///
3014 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Unsigned_right_shift)
3015 #[inline]
3016 pub fn unsigned_shr(&self, rhs: &Self) -> Self {
3017 Number::from(JsValue::as_ref(self).unsigned_shr(JsValue::as_ref(rhs)))
3018 }
3019}
3020
3021macro_rules! number_from {
3022 ($($x:ident)*) => ($(
3023 impl From<$x> for Number {
3024 #[inline]
3025 fn from(x: $x) -> Number {
3026 Number::unchecked_from_js(JsValue::from(x))
3027 }
3028 }
3029
3030 impl PartialEq<$x> for Number {
3031 #[inline]
3032 fn eq(&self, other: &$x) -> bool {
3033 self.value_of() == f64::from(*other)
3034 }
3035 }
3036 )*)
3037}
3038number_from!(i8 u8 i16 u16 i32 u32 f32 f64);
3039
3040/// The error type returned when a checked integral type conversion fails.
3041#[derive(Debug, Copy, Clone, PartialEq, Eq)]
3042pub struct TryFromIntError(());
3043
3044impl fmt::Display for TryFromIntError {
3045 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
3046 fmt.write_str("out of range integral type conversion attempted")
3047 }
3048}
3049
3050#[cfg(feature = "std")]
3051impl std::error::Error for TryFromIntError {}
3052
3053macro_rules! number_try_from {
3054 ($($x:ident)*) => ($(
3055 impl TryFrom<$x> for Number {
3056 type Error = TryFromIntError;
3057
3058 #[inline]
3059 fn try_from(x: $x) -> Result<Number, Self::Error> {
3060 let x_f64 = x as f64;
3061 if (Number::MIN_SAFE_INTEGER..=Number::MAX_SAFE_INTEGER).contains(&x_f64) {
3062 Ok(Number::from(x_f64))
3063 } else {
3064 Err(TryFromIntError(()))
3065 }
3066 }
3067 }
3068 )*)
3069}
3070number_try_from!(i64 u64 i128 u128);
3071
3072// TODO: add this on the next major version, when blanket impl is removed
3073/*
3074impl convert::TryFrom<JsValue> for Number {
3075 type Error = Error;
3076
3077 fn try_from(value: JsValue) -> Result<Self, Self::Error> {
3078 return match f64::try_from(value) {
3079 Ok(num) => Ok(Number::from(num)),
3080 Err(jsval) => Err(jsval.unchecked_into())
3081 }
3082 }
3083}
3084*/
3085
3086impl From<&Number> for f64 {
3087 #[inline]
3088 fn from(n: &Number) -> f64 {
3089 n.value_of()
3090 }
3091}
3092
3093impl From<Number> for f64 {
3094 #[inline]
3095 fn from(n: Number) -> f64 {
3096 <f64 as From<&'_ Number>>::from(&n)
3097 }
3098}
3099
3100impl fmt::Debug for Number {
3101 #[inline]
3102 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3103 fmt::Debug::fmt(&self.value_of(), f)
3104 }
3105}
3106
3107impl fmt::Display for Number {
3108 #[inline]
3109 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3110 fmt::Display::fmt(&self.value_of(), f)
3111 }
3112}
3113
3114impl Default for Number {
3115 fn default() -> Self {
3116 Self::from(f64::default())
3117 }
3118}
3119
3120impl PartialEq<BigInt> for Number {
3121 #[inline]
3122 fn eq(&self, other: &BigInt) -> bool {
3123 JsValue::as_ref(self).loose_eq(JsValue::as_ref(other))
3124 }
3125}
3126
3127impl Not for &Number {
3128 type Output = BigInt;
3129
3130 #[inline]
3131 fn not(self) -> Self::Output {
3132 JsValue::as_ref(self).bit_not().unchecked_into()
3133 }
3134}
3135
3136forward_deref_unop!(impl Not, not for Number);
3137forward_js_unop!(impl Neg, neg for Number);
3138forward_js_binop!(impl BitAnd, bitand for Number);
3139forward_js_binop!(impl BitOr, bitor for Number);
3140forward_js_binop!(impl BitXor, bitxor for Number);
3141forward_js_binop!(impl Shl, shl for Number);
3142forward_js_binop!(impl Shr, shr for Number);
3143forward_js_binop!(impl Add, add for Number);
3144forward_js_binop!(impl Sub, sub for Number);
3145forward_js_binop!(impl Div, div for Number);
3146forward_js_binop!(impl Mul, mul for Number);
3147forward_js_binop!(impl Rem, rem for Number);
3148
3149sum_product!(Number);
3150
3151impl PartialOrd for Number {
3152 #[inline]
3153 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
3154 if Number::is_nan(self) || Number::is_nan(other) {
3155 None
3156 } else if self == other {
3157 Some(Ordering::Equal)
3158 } else if self.lt(other) {
3159 Some(Ordering::Less)
3160 } else {
3161 Some(Ordering::Greater)
3162 }
3163 }
3164
3165 #[inline]
3166 fn lt(&self, other: &Self) -> bool {
3167 JsValue::as_ref(self).lt(JsValue::as_ref(other))
3168 }
3169
3170 #[inline]
3171 fn le(&self, other: &Self) -> bool {
3172 JsValue::as_ref(self).le(JsValue::as_ref(other))
3173 }
3174
3175 #[inline]
3176 fn ge(&self, other: &Self) -> bool {
3177 JsValue::as_ref(self).ge(JsValue::as_ref(other))
3178 }
3179
3180 #[inline]
3181 fn gt(&self, other: &Self) -> bool {
3182 JsValue::as_ref(self).gt(JsValue::as_ref(other))
3183 }
3184}
3185
3186impl FromStr for Number {
3187 type Err = Infallible;
3188
3189 #[allow(deprecated)]
3190 #[inline]
3191 fn from_str(s: &str) -> Result<Self, Self::Err> {
3192 Ok(Number::new_from_str(s))
3193 }
3194}
3195
3196// Date.
3197#[wasm_bindgen]
3198extern "C" {
3199 #[wasm_bindgen(extends = Object, typescript_type = "Date")]
3200 #[derive(Clone, Debug, PartialEq, Eq)]
3201 pub type Date;
3202
3203 /// The `getDate()` method returns the day of the month for the
3204 /// specified date according to local time.
3205 ///
3206 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getDate)
3207 #[wasm_bindgen(method, js_name = getDate)]
3208 pub fn get_date(this: &Date) -> u32;
3209
3210 /// The `getDay()` method returns the day of the week for the specified date according to local time,
3211 /// where 0 represents Sunday. For the day of the month see getDate().
3212 ///
3213 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getDay)
3214 #[wasm_bindgen(method, js_name = getDay)]
3215 pub fn get_day(this: &Date) -> u32;
3216
3217 /// The `getFullYear()` method returns the year of the specified date according to local time.
3218 ///
3219 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getFullYear)
3220 #[wasm_bindgen(method, js_name = getFullYear)]
3221 pub fn get_full_year(this: &Date) -> u32;
3222
3223 /// The `getHours()` method returns the hour for the specified date, according to local time.
3224 ///
3225 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getHours)
3226 #[wasm_bindgen(method, js_name = getHours)]
3227 pub fn get_hours(this: &Date) -> u32;
3228
3229 /// The `getMilliseconds()` method returns the milliseconds in the specified date according to local time.
3230 ///
3231 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMilliseconds)
3232 #[wasm_bindgen(method, js_name = getMilliseconds)]
3233 pub fn get_milliseconds(this: &Date) -> u32;
3234
3235 /// The `getMinutes()` method returns the minutes in the specified date according to local time.
3236 ///
3237 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMinutes)
3238 #[wasm_bindgen(method, js_name = getMinutes)]
3239 pub fn get_minutes(this: &Date) -> u32;
3240
3241 /// The `getMonth()` method returns the month in the specified date according to local time,
3242 /// as a zero-based value (where zero indicates the first month of the year).
3243 ///
3244 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMonth)
3245 #[wasm_bindgen(method, js_name = getMonth)]
3246 pub fn get_month(this: &Date) -> u32;
3247
3248 /// The `getSeconds()` method returns the seconds in the specified date according to local time.
3249 ///
3250 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getSeconds)
3251 #[wasm_bindgen(method, js_name = getSeconds)]
3252 pub fn get_seconds(this: &Date) -> u32;
3253
3254 /// The `getTime()` method returns the numeric value corresponding to the time for the specified date
3255 /// according to universal time.
3256 ///
3257 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTime)
3258 #[wasm_bindgen(method, js_name = getTime)]
3259 pub fn get_time(this: &Date) -> f64;
3260
3261 /// The `getTimezoneOffset()` method returns the time zone difference, in minutes,
3262 /// from current locale (host system settings) to UTC.
3263 ///
3264 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTimezoneOffset)
3265 #[wasm_bindgen(method, js_name = getTimezoneOffset)]
3266 pub fn get_timezone_offset(this: &Date) -> f64;
3267
3268 /// The `getUTCDate()` method returns the day (date) of the month in the specified date
3269 /// according to universal time.
3270 ///
3271 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCDate)
3272 #[wasm_bindgen(method, js_name = getUTCDate)]
3273 pub fn get_utc_date(this: &Date) -> u32;
3274
3275 /// The `getUTCDay()` method returns the day of the week in the specified date according to universal time,
3276 /// where 0 represents Sunday.
3277 ///
3278 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCDay)
3279 #[wasm_bindgen(method, js_name = getUTCDay)]
3280 pub fn get_utc_day(this: &Date) -> u32;
3281
3282 /// The `getUTCFullYear()` method returns the year in the specified date according to universal time.
3283 ///
3284 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCFullYear)
3285 #[wasm_bindgen(method, js_name = getUTCFullYear)]
3286 pub fn get_utc_full_year(this: &Date) -> u32;
3287
3288 /// The `getUTCHours()` method returns the hours in the specified date according to universal time.
3289 ///
3290 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCHours)
3291 #[wasm_bindgen(method, js_name = getUTCHours)]
3292 pub fn get_utc_hours(this: &Date) -> u32;
3293
3294 /// The `getUTCMilliseconds()` method returns the milliseconds in the specified date
3295 /// according to universal time.
3296 ///
3297 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCMilliseconds)
3298 #[wasm_bindgen(method, js_name = getUTCMilliseconds)]
3299 pub fn get_utc_milliseconds(this: &Date) -> u32;
3300
3301 /// The `getUTCMinutes()` method returns the minutes in the specified date according to universal time.
3302 ///
3303 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCMinutes)
3304 #[wasm_bindgen(method, js_name = getUTCMinutes)]
3305 pub fn get_utc_minutes(this: &Date) -> u32;
3306
3307 /// The `getUTCMonth()` returns the month of the specified date according to universal time,
3308 /// as a zero-based value (where zero indicates the first month of the year).
3309 ///
3310 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCMonth)
3311 #[wasm_bindgen(method, js_name = getUTCMonth)]
3312 pub fn get_utc_month(this: &Date) -> u32;
3313
3314 /// The `getUTCSeconds()` method returns the seconds in the specified date according to universal time.
3315 ///
3316 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCSeconds)
3317 #[wasm_bindgen(method, js_name = getUTCSeconds)]
3318 pub fn get_utc_seconds(this: &Date) -> u32;
3319
3320 /// Creates a JavaScript `Date` instance that represents
3321 /// a single moment in time. `Date` objects are based on a time value that is
3322 /// the number of milliseconds since 1 January 1970 UTC.
3323 ///
3324 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
3325 #[wasm_bindgen(constructor)]
3326 pub fn new(init: &JsValue) -> Date;
3327
3328 /// Creates a JavaScript `Date` instance that represents the current moment in
3329 /// time.
3330 ///
3331 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
3332 #[wasm_bindgen(constructor)]
3333 pub fn new_0() -> Date;
3334
3335 /// Creates a JavaScript `Date` instance that represents
3336 /// a single moment in time. `Date` objects are based on a time value that is
3337 /// the number of milliseconds since 1 January 1970 UTC.
3338 ///
3339 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
3340 #[wasm_bindgen(constructor)]
3341 pub fn new_with_year_month(year: u32, month: i32) -> Date;
3342
3343 /// Creates a JavaScript `Date` instance that represents
3344 /// a single moment in time. `Date` objects are based on a time value that is
3345 /// the number of milliseconds since 1 January 1970 UTC.
3346 ///
3347 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
3348 #[wasm_bindgen(constructor)]
3349 pub fn new_with_year_month_day(year: u32, month: i32, day: i32) -> Date;
3350
3351 /// Creates a JavaScript `Date` instance that represents
3352 /// a single moment in time. `Date` objects are based on a time value that is
3353 /// the number of milliseconds since 1 January 1970 UTC.
3354 ///
3355 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
3356 #[wasm_bindgen(constructor)]
3357 pub fn new_with_year_month_day_hr(year: u32, month: i32, day: i32, hr: i32) -> Date;
3358
3359 /// Creates a JavaScript `Date` instance that represents
3360 /// a single moment in time. `Date` objects are based on a time value that is
3361 /// the number of milliseconds since 1 January 1970 UTC.
3362 ///
3363 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
3364 #[wasm_bindgen(constructor)]
3365 pub fn new_with_year_month_day_hr_min(
3366 year: u32,
3367 month: i32,
3368 day: i32,
3369 hr: i32,
3370 min: i32,
3371 ) -> Date;
3372
3373 /// Creates a JavaScript `Date` instance that represents
3374 /// a single moment in time. `Date` objects are based on a time value that is
3375 /// the number of milliseconds since 1 January 1970 UTC.
3376 ///
3377 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
3378 #[wasm_bindgen(constructor)]
3379 pub fn new_with_year_month_day_hr_min_sec(
3380 year: u32,
3381 month: i32,
3382 day: i32,
3383 hr: i32,
3384 min: i32,
3385 sec: i32,
3386 ) -> Date;
3387
3388 /// Creates a JavaScript `Date` instance that represents
3389 /// a single moment in time. `Date` objects are based on a time value that is
3390 /// the number of milliseconds since 1 January 1970 UTC.
3391 ///
3392 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
3393 #[wasm_bindgen(constructor)]
3394 pub fn new_with_year_month_day_hr_min_sec_milli(
3395 year: u32,
3396 month: i32,
3397 day: i32,
3398 hr: i32,
3399 min: i32,
3400 sec: i32,
3401 milli: i32,
3402 ) -> Date;
3403
3404 /// The `Date.now()` method returns the number of milliseconds
3405 /// elapsed since January 1, 1970 00:00:00 UTC.
3406 ///
3407 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/now)
3408 #[wasm_bindgen(static_method_of = Date)]
3409 pub fn now() -> f64;
3410
3411 /// The `Date.parse()` method parses a string representation of a date, and returns the number of milliseconds
3412 /// since January 1, 1970, 00:00:00 UTC or `NaN` if the string is unrecognized or, in some cases,
3413 /// contains illegal date values (e.g. 2015-02-31).
3414 ///
3415 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse)
3416 #[wasm_bindgen(static_method_of = Date)]
3417 pub fn parse(date: &str) -> f64;
3418
3419 /// The `setDate()` method sets the day of the Date object relative to the beginning of the currently set month.
3420 ///
3421 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setDate)
3422 #[wasm_bindgen(method, js_name = setDate)]
3423 pub fn set_date(this: &Date, day: u32) -> f64;
3424
3425 /// The `setFullYear()` method sets the full year for a specified date according to local time.
3426 /// Returns new timestamp.
3427 ///
3428 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setFullYear)
3429 #[wasm_bindgen(method, js_name = setFullYear)]
3430 pub fn set_full_year(this: &Date, year: u32) -> f64;
3431
3432 /// The `setFullYear()` method sets the full year for a specified date according to local time.
3433 /// Returns new timestamp.
3434 ///
3435 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setFullYear)
3436 #[wasm_bindgen(method, js_name = setFullYear)]
3437 pub fn set_full_year_with_month(this: &Date, year: u32, month: i32) -> f64;
3438
3439 /// The `setFullYear()` method sets the full year for a specified date according to local time.
3440 /// Returns new timestamp.
3441 ///
3442 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setFullYear)
3443 #[wasm_bindgen(method, js_name = setFullYear)]
3444 pub fn set_full_year_with_month_date(this: &Date, year: u32, month: i32, date: i32) -> f64;
3445
3446 /// The `setHours()` method sets the hours for a specified date according to local time,
3447 /// and returns the number of milliseconds since January 1, 1970 00:00:00 UTC until the time represented
3448 /// by the updated Date instance.
3449 ///
3450 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setHours)
3451 #[wasm_bindgen(method, js_name = setHours)]
3452 pub fn set_hours(this: &Date, hours: u32) -> f64;
3453
3454 /// The `setMilliseconds()` method sets the milliseconds for a specified date according to local time.
3455 ///
3456 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setMilliseconds)
3457 #[wasm_bindgen(method, js_name = setMilliseconds)]
3458 pub fn set_milliseconds(this: &Date, milliseconds: u32) -> f64;
3459
3460 /// The `setMinutes()` method sets the minutes for a specified date according to local time.
3461 ///
3462 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setMinutes)
3463 #[wasm_bindgen(method, js_name = setMinutes)]
3464 pub fn set_minutes(this: &Date, minutes: u32) -> f64;
3465
3466 /// The `setMonth()` method sets the month for a specified date according to the currently set year.
3467 ///
3468 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setMonth)
3469 #[wasm_bindgen(method, js_name = setMonth)]
3470 pub fn set_month(this: &Date, month: u32) -> f64;
3471
3472 /// The `setSeconds()` method sets the seconds for a specified date according to local time.
3473 ///
3474 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setSeconds)
3475 #[wasm_bindgen(method, js_name = setSeconds)]
3476 pub fn set_seconds(this: &Date, seconds: u32) -> f64;
3477
3478 /// The `setTime()` method sets the Date object to the time represented by a number of milliseconds
3479 /// since January 1, 1970, 00:00:00 UTC.
3480 ///
3481 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setTime)
3482 #[wasm_bindgen(method, js_name = setTime)]
3483 pub fn set_time(this: &Date, time: f64) -> f64;
3484
3485 /// The `setUTCDate()` method sets the day of the month for a specified date
3486 /// according to universal time.
3487 ///
3488 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCDate)
3489 #[wasm_bindgen(method, js_name = setUTCDate)]
3490 pub fn set_utc_date(this: &Date, day: u32) -> f64;
3491
3492 /// The `setUTCFullYear()` method sets the full year for a specified date according to universal time.
3493 ///
3494 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCFullYear)
3495 #[wasm_bindgen(method, js_name = setUTCFullYear)]
3496 pub fn set_utc_full_year(this: &Date, year: u32) -> f64;
3497
3498 /// The `setUTCFullYear()` method sets the full year for a specified date according to universal time.
3499 ///
3500 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCFullYear)
3501 #[wasm_bindgen(method, js_name = setUTCFullYear)]
3502 pub fn set_utc_full_year_with_month(this: &Date, year: u32, month: i32) -> f64;
3503
3504 /// The `setUTCFullYear()` method sets the full year for a specified date according to universal time.
3505 ///
3506 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCFullYear)
3507 #[wasm_bindgen(method, js_name = setUTCFullYear)]
3508 pub fn set_utc_full_year_with_month_date(this: &Date, year: u32, month: i32, date: i32) -> f64;
3509
3510 /// The `setUTCHours()` method sets the hour for a specified date according to universal time,
3511 /// and returns the number of milliseconds since January 1, 1970 00:00:00 UTC until the time
3512 /// represented by the updated Date instance.
3513 ///
3514 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCHours)
3515 #[wasm_bindgen(method, js_name = setUTCHours)]
3516 pub fn set_utc_hours(this: &Date, hours: u32) -> f64;
3517
3518 /// The `setUTCMilliseconds()` method sets the milliseconds for a specified date
3519 /// according to universal time.
3520 ///
3521 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCMilliseconds)
3522 #[wasm_bindgen(method, js_name = setUTCMilliseconds)]
3523 pub fn set_utc_milliseconds(this: &Date, milliseconds: u32) -> f64;
3524
3525 /// The `setUTCMinutes()` method sets the minutes for a specified date according to universal time.
3526 ///
3527 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCMinutes)
3528 #[wasm_bindgen(method, js_name = setUTCMinutes)]
3529 pub fn set_utc_minutes(this: &Date, minutes: u32) -> f64;
3530
3531 /// The `setUTCMonth()` method sets the month for a specified date according to universal time.
3532 ///
3533 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCMonth)
3534 #[wasm_bindgen(method, js_name = setUTCMonth)]
3535 pub fn set_utc_month(this: &Date, month: u32) -> f64;
3536
3537 /// The `setUTCSeconds()` method sets the seconds for a specified date according to universal time.
3538 ///
3539 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCSeconds)
3540 #[wasm_bindgen(method, js_name = setUTCSeconds)]
3541 pub fn set_utc_seconds(this: &Date, seconds: u32) -> f64;
3542
3543 /// The `toDateString()` method returns the date portion of a Date object
3544 /// in human readable form in American English.
3545 ///
3546 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toDateString)
3547 #[wasm_bindgen(method, js_name = toDateString)]
3548 pub fn to_date_string(this: &Date) -> JsString;
3549
3550 /// The `toISOString()` method returns a string in simplified extended ISO format (ISO
3551 /// 8601), which is always 24 or 27 characters long (YYYY-MM-DDTHH:mm:ss.sssZ or
3552 /// ±YYYYYY-MM-DDTHH:mm:ss.sssZ, respectively). The timezone is always zero UTC offset,
3553 /// as denoted by the suffix "Z"
3554 ///
3555 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString)
3556 #[wasm_bindgen(method, js_name = toISOString)]
3557 pub fn to_iso_string(this: &Date) -> JsString;
3558
3559 /// The `toJSON()` method returns a string representation of the Date object.
3560 ///
3561 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toJSON)
3562 #[wasm_bindgen(method, js_name = toJSON)]
3563 pub fn to_json(this: &Date) -> JsString;
3564
3565 /// The `toLocaleDateString()` method returns a string with a language sensitive
3566 /// representation of the date portion of this date. The new locales and options
3567 /// arguments let applications specify the language whose formatting conventions
3568 /// should be used and allow to customize the behavior of the function.
3569 /// In older implementations, which ignore the locales and options arguments,
3570 /// the locale used and the form of the string
3571 /// returned are entirely implementation dependent.
3572 ///
3573 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString)
3574 #[wasm_bindgen(method, js_name = toLocaleDateString)]
3575 pub fn to_locale_date_string(this: &Date, locale: &str, options: &JsValue) -> JsString;
3576
3577 /// The `toLocaleString()` method returns a string with a language sensitive
3578 /// representation of this date. The new locales and options arguments
3579 /// let applications specify the language whose formatting conventions
3580 /// should be used and customize the behavior of the function.
3581 /// In older implementations, which ignore the locales
3582 /// and options arguments, the locale used and the form of the string
3583 /// returned are entirely implementation dependent.
3584 ///
3585 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString)
3586 #[wasm_bindgen(method, js_name = toLocaleString)]
3587 pub fn to_locale_string(this: &Date, locale: &str, options: &JsValue) -> JsString;
3588
3589 /// The `toLocaleTimeString()` method returns a string with a language sensitive
3590 /// representation of the time portion of this date. The new locales and options
3591 /// arguments let applications specify the language whose formatting conventions should be
3592 /// used and customize the behavior of the function. In older implementations, which ignore
3593 /// the locales and options arguments, the locale used and the form of the string
3594 /// returned are entirely implementation dependent.
3595 ///
3596 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleTimeString)
3597 #[wasm_bindgen(method, js_name = toLocaleTimeString)]
3598 pub fn to_locale_time_string(this: &Date, locale: &str) -> JsString;
3599
3600 #[wasm_bindgen(method, js_name = toLocaleTimeString)]
3601 pub fn to_locale_time_string_with_options(
3602 this: &Date,
3603 locale: &str,
3604 options: &JsValue,
3605 ) -> JsString;
3606
3607 /// The `toString()` method returns a string representing
3608 /// the specified Date object.
3609 ///
3610 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toString)
3611 #[wasm_bindgen(method, js_name = toString)]
3612 pub fn to_string(this: &Date) -> JsString;
3613
3614 /// The `toTimeString()` method returns the time portion of a Date object in human
3615 /// readable form in American English.
3616 ///
3617 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toTimeString)
3618 #[wasm_bindgen(method, js_name = toTimeString)]
3619 pub fn to_time_string(this: &Date) -> JsString;
3620
3621 /// The `toUTCString()` method converts a date to a string,
3622 /// using the UTC time zone.
3623 ///
3624 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toUTCString)
3625 #[wasm_bindgen(method, js_name = toUTCString)]
3626 pub fn to_utc_string(this: &Date) -> JsString;
3627
3628 /// The `Date.UTC()` method accepts the same parameters as the
3629 /// longest form of the constructor, and returns the number of
3630 /// milliseconds in a `Date` object since January 1, 1970,
3631 /// 00:00:00, universal time.
3632 ///
3633 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/UTC)
3634 #[wasm_bindgen(static_method_of = Date, js_name = UTC)]
3635 pub fn utc(year: f64, month: f64) -> f64;
3636
3637 /// The `valueOf()` method returns the primitive value of
3638 /// a Date object.
3639 ///
3640 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/valueOf)
3641 #[wasm_bindgen(method, js_name = valueOf)]
3642 pub fn value_of(this: &Date) -> f64;
3643}
3644
3645// Object.
3646#[wasm_bindgen]
3647extern "C" {
3648 #[wasm_bindgen(typescript_type = "object")]
3649 #[derive(Clone, Debug)]
3650 pub type Object;
3651
3652 /// The `Object.assign()` method is used to copy the values of all enumerable
3653 /// own properties from one or more source objects to a target object. It
3654 /// will return the target object.
3655 ///
3656 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
3657 #[wasm_bindgen(static_method_of = Object)]
3658 pub fn assign(target: &Object, source: &Object) -> Object;
3659
3660 /// The `Object.assign()` method is used to copy the values of all enumerable
3661 /// own properties from one or more source objects to a target object. It
3662 /// will return the target object.
3663 ///
3664 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
3665 #[wasm_bindgen(static_method_of = Object, js_name = assign)]
3666 pub fn assign2(target: &Object, source1: &Object, source2: &Object) -> Object;
3667
3668 /// The `Object.assign()` method is used to copy the values of all enumerable
3669 /// own properties from one or more source objects to a target object. It
3670 /// will return the target object.
3671 ///
3672 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
3673 #[wasm_bindgen(static_method_of = Object, js_name = assign)]
3674 pub fn assign3(target: &Object, source1: &Object, source2: &Object, source3: &Object)
3675 -> Object;
3676
3677 /// The constructor property returns a reference to the `Object` constructor
3678 /// function that created the instance object.
3679 ///
3680 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/constructor)
3681 #[wasm_bindgen(method, getter)]
3682 pub fn constructor(this: &Object) -> Function;
3683
3684 /// The `Object.create()` method creates a new object, using an existing
3685 /// object to provide the newly created object's prototype.
3686 ///
3687 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/create)
3688 #[wasm_bindgen(static_method_of = Object)]
3689 pub fn create(prototype: &Object) -> Object;
3690
3691 /// The static method `Object.defineProperty()` defines a new
3692 /// property directly on an object, or modifies an existing
3693 /// property on an object, and returns the object.
3694 ///
3695 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty)
3696 #[wasm_bindgen(static_method_of = Object, js_name = defineProperty)]
3697 pub fn define_property(obj: &Object, prop: &JsValue, descriptor: &Object) -> Object;
3698
3699 /// The `Object.defineProperties()` method defines new or modifies
3700 /// existing properties directly on an object, returning the
3701 /// object.
3702 ///
3703 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperties)
3704 #[wasm_bindgen(static_method_of = Object, js_name = defineProperties)]
3705 pub fn define_properties(obj: &Object, props: &Object) -> Object;
3706
3707 /// The `Object.entries()` method returns an array of a given
3708 /// object's own enumerable property [key, value] pairs, in the
3709 /// same order as that provided by a for...in loop (the difference
3710 /// being that a for-in loop enumerates properties in the
3711 /// prototype chain as well).
3712 ///
3713 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries)
3714 #[wasm_bindgen(static_method_of = Object)]
3715 pub fn entries(object: &Object) -> Array;
3716
3717 /// The `Object.freeze()` method freezes an object: that is, prevents new
3718 /// properties from being added to it; prevents existing properties from
3719 /// being removed; and prevents existing properties, or their enumerability,
3720 /// configurability, or writability, from being changed, it also prevents
3721 /// the prototype from being changed. The method returns the passed object.
3722 ///
3723 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze)
3724 #[wasm_bindgen(static_method_of = Object)]
3725 pub fn freeze(value: &Object) -> Object;
3726
3727 /// The `Object.fromEntries()` method transforms a list of key-value pairs
3728 /// into an object.
3729 ///
3730 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/fromEntries)
3731 #[wasm_bindgen(static_method_of = Object, catch, js_name = fromEntries)]
3732 pub fn from_entries(iterable: &JsValue) -> Result<Object, JsValue>;
3733
3734 /// The `Object.getOwnPropertyDescriptor()` method returns a
3735 /// property descriptor for an own property (that is, one directly
3736 /// present on an object and not in the object's prototype chain)
3737 /// of a given object.
3738 ///
3739 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor)
3740 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptor)]
3741 pub fn get_own_property_descriptor(obj: &Object, prop: &JsValue) -> JsValue;
3742
3743 /// The `Object.getOwnPropertyDescriptors()` method returns all own
3744 /// property descriptors of a given object.
3745 ///
3746 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptors)
3747 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptors)]
3748 pub fn get_own_property_descriptors(obj: &Object) -> JsValue;
3749
3750 /// The `Object.getOwnPropertyNames()` method returns an array of
3751 /// all properties (including non-enumerable properties except for
3752 /// those which use Symbol) found directly upon a given object.
3753 ///
3754 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyNames)
3755 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyNames)]
3756 pub fn get_own_property_names(obj: &Object) -> Array;
3757
3758 /// The `Object.getOwnPropertySymbols()` method returns an array of
3759 /// all symbol properties found directly upon a given object.
3760 ///
3761 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertySymbols)
3762 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertySymbols)]
3763 pub fn get_own_property_symbols(obj: &Object) -> Array;
3764
3765 /// The `Object.getPrototypeOf()` method returns the prototype
3766 /// (i.e. the value of the internal [[Prototype]] property) of the
3767 /// specified object.
3768 ///
3769 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getPrototypeOf)
3770 #[wasm_bindgen(static_method_of = Object, js_name = getPrototypeOf)]
3771 pub fn get_prototype_of(obj: &JsValue) -> Object;
3772
3773 /// The `hasOwnProperty()` method returns a boolean indicating whether the
3774 /// object has the specified property as its own property (as opposed to
3775 /// inheriting it).
3776 ///
3777 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty)
3778 #[wasm_bindgen(method, js_name = hasOwnProperty)]
3779 pub fn has_own_property(this: &Object, property: &JsValue) -> bool;
3780
3781 /// The `Object.hasOwn()` method returns a boolean indicating whether the
3782 /// object passed in has the specified property as its own property (as
3783 /// opposed to inheriting it).
3784 ///
3785 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn)
3786 #[wasm_bindgen(static_method_of = Object, js_name = hasOwn)]
3787 pub fn has_own(instance: &Object, property: &JsValue) -> bool;
3788
3789 /// The `Object.is()` method determines whether two values are the same value.
3790 ///
3791 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is)
3792 #[wasm_bindgen(static_method_of = Object)]
3793 pub fn is(value_1: &JsValue, value_2: &JsValue) -> bool;
3794
3795 /// The `Object.isExtensible()` method determines if an object is extensible
3796 /// (whether it can have new properties added to it).
3797 ///
3798 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isExtensible)
3799 #[wasm_bindgen(static_method_of = Object, js_name = isExtensible)]
3800 pub fn is_extensible(object: &Object) -> bool;
3801
3802 /// The `Object.isFrozen()` determines if an object is frozen.
3803 ///
3804 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isFrozen)
3805 #[wasm_bindgen(static_method_of = Object, js_name = isFrozen)]
3806 pub fn is_frozen(object: &Object) -> bool;
3807
3808 /// The `Object.isSealed()` method determines if an object is sealed.
3809 ///
3810 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isSealed)
3811 #[wasm_bindgen(static_method_of = Object, js_name = isSealed)]
3812 pub fn is_sealed(object: &Object) -> bool;
3813
3814 /// The `isPrototypeOf()` method checks if an object exists in another
3815 /// object's prototype chain.
3816 ///
3817 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isPrototypeOf)
3818 #[wasm_bindgen(method, js_name = isPrototypeOf)]
3819 pub fn is_prototype_of(this: &Object, value: &JsValue) -> bool;
3820
3821 /// The `Object.keys()` method returns an array of a given object's property
3822 /// names, in the same order as we get with a normal loop.
3823 ///
3824 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys)
3825 #[wasm_bindgen(static_method_of = Object)]
3826 pub fn keys(object: &Object) -> Array;
3827
3828 /// The [`Object`] constructor creates an object wrapper.
3829 ///
3830 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)
3831 #[wasm_bindgen(constructor)]
3832 pub fn new() -> Object;
3833
3834 /// The `Object.preventExtensions()` method prevents new properties from
3835 /// ever being added to an object (i.e. prevents future extensions to the
3836 /// object).
3837 ///
3838 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/preventExtensions)
3839 #[wasm_bindgen(static_method_of = Object, js_name = preventExtensions)]
3840 pub fn prevent_extensions(object: &Object);
3841
3842 /// The `propertyIsEnumerable()` method returns a Boolean indicating
3843 /// whether the specified property is enumerable.
3844 ///
3845 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/propertyIsEnumerable)
3846 #[wasm_bindgen(method, js_name = propertyIsEnumerable)]
3847 pub fn property_is_enumerable(this: &Object, property: &JsValue) -> bool;
3848
3849 /// The `Object.seal()` method seals an object, preventing new properties
3850 /// from being added to it and marking all existing properties as
3851 /// non-configurable. Values of present properties can still be changed as
3852 /// long as they are writable.
3853 ///
3854 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/seal)
3855 #[wasm_bindgen(static_method_of = Object)]
3856 pub fn seal(value: &Object) -> Object;
3857
3858 /// The `Object.setPrototypeOf()` method sets the prototype (i.e., the
3859 /// internal `[[Prototype]]` property) of a specified object to another
3860 /// object or `null`.
3861 ///
3862 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/setPrototypeOf)
3863 #[wasm_bindgen(static_method_of = Object, js_name = setPrototypeOf)]
3864 pub fn set_prototype_of(object: &Object, prototype: &Object) -> Object;
3865
3866 /// The `toLocaleString()` method returns a string representing the object.
3867 /// This method is meant to be overridden by derived objects for
3868 /// locale-specific purposes.
3869 ///
3870 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toLocaleString)
3871 #[wasm_bindgen(method, js_name = toLocaleString)]
3872 pub fn to_locale_string(this: &Object) -> JsString;
3873
3874 /// The `toString()` method returns a string representing the object.
3875 ///
3876 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString)
3877 #[wasm_bindgen(method, js_name = toString)]
3878 pub fn to_string(this: &Object) -> JsString;
3879
3880 /// The `valueOf()` method returns the primitive value of the
3881 /// specified object.
3882 ///
3883 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf)
3884 #[wasm_bindgen(method, js_name = valueOf)]
3885 pub fn value_of(this: &Object) -> Object;
3886
3887 /// The `Object.values()` method returns an array of a given object's own
3888 /// enumerable property values, in the same order as that provided by a
3889 /// `for...in` loop (the difference being that a for-in loop enumerates
3890 /// properties in the prototype chain as well).
3891 ///
3892 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values)
3893 #[wasm_bindgen(static_method_of = Object)]
3894 pub fn values(object: &Object) -> Array;
3895}
3896
3897impl Object {
3898 /// Returns the `Object` value of this JS value if it's an instance of an
3899 /// object.
3900 ///
3901 /// If this JS value is not an instance of an object then this returns
3902 /// `None`.
3903 pub fn try_from(val: &JsValue) -> Option<&Object> {
3904 if val.is_object() {
3905 Some(val.unchecked_ref())
3906 } else {
3907 None
3908 }
3909 }
3910}
3911
3912impl PartialEq for Object {
3913 #[inline]
3914 fn eq(&self, other: &Object) -> bool {
3915 Object::is(self.as_ref(), other.as_ref())
3916 }
3917}
3918
3919impl Eq for Object {}
3920
3921impl Default for Object {
3922 fn default() -> Self {
3923 Self::new()
3924 }
3925}
3926
3927// Proxy
3928#[wasm_bindgen]
3929extern "C" {
3930 #[wasm_bindgen(typescript_type = "ProxyConstructor")]
3931 #[derive(Clone, Debug)]
3932 pub type Proxy;
3933
3934 /// The [`Proxy`] object is used to define custom behavior for fundamental
3935 /// operations (e.g. property lookup, assignment, enumeration, function
3936 /// invocation, etc).
3937 ///
3938 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy)
3939 #[wasm_bindgen(constructor)]
3940 pub fn new(target: &JsValue, handler: &Object) -> Proxy;
3941
3942 /// The `Proxy.revocable()` method is used to create a revocable [`Proxy`]
3943 /// object.
3944 ///
3945 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy/revocable)
3946 #[wasm_bindgen(static_method_of = Proxy)]
3947 pub fn revocable(target: &JsValue, handler: &Object) -> Object;
3948}
3949
3950// RangeError
3951#[wasm_bindgen]
3952extern "C" {
3953 /// The `RangeError` object indicates an error when a value is not in the set
3954 /// or range of allowed values.
3955 ///
3956 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError)
3957 #[wasm_bindgen(extends = Error, extends = Object, typescript_type = "RangeError")]
3958 #[derive(Clone, Debug, PartialEq, Eq)]
3959 pub type RangeError;
3960
3961 /// The `RangeError` object indicates an error when a value is not in the set
3962 /// or range of allowed values.
3963 ///
3964 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError)
3965 #[wasm_bindgen(constructor)]
3966 pub fn new(message: &str) -> RangeError;
3967}
3968
3969// ReferenceError
3970#[wasm_bindgen]
3971extern "C" {
3972 /// The `ReferenceError` object represents an error when a non-existent
3973 /// variable is referenced.
3974 ///
3975 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError)
3976 #[wasm_bindgen(extends = Error, extends = Object, typescript_type = "ReferenceError")]
3977 #[derive(Clone, Debug, PartialEq, Eq)]
3978 pub type ReferenceError;
3979
3980 /// The `ReferenceError` object represents an error when a non-existent
3981 /// variable is referenced.
3982 ///
3983 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError)
3984 #[wasm_bindgen(constructor)]
3985 pub fn new(message: &str) -> ReferenceError;
3986}
3987
3988#[allow(non_snake_case)]
3989pub mod Reflect {
3990 use super::*;
3991
3992 // Reflect
3993 #[wasm_bindgen]
3994 extern "C" {
3995 /// The static `Reflect.apply()` method calls a target function with
3996 /// arguments as specified.
3997 ///
3998 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/apply)
3999 #[wasm_bindgen(js_namespace = Reflect, catch)]
4000 pub fn apply(
4001 target: &Function,
4002 this_argument: &JsValue,
4003 arguments_list: &Array,
4004 ) -> Result<JsValue, JsValue>;
4005
4006 /// The static `Reflect.construct()` method acts like the new operator, but
4007 /// as a function. It is equivalent to calling `new target(...args)`. It
4008 /// gives also the added option to specify a different prototype.
4009 ///
4010 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/construct)
4011 #[wasm_bindgen(js_namespace = Reflect, catch)]
4012 pub fn construct(target: &Function, arguments_list: &Array) -> Result<JsValue, JsValue>;
4013
4014 /// The static `Reflect.construct()` method acts like the new operator, but
4015 /// as a function. It is equivalent to calling `new target(...args)`. It
4016 /// gives also the added option to specify a different prototype.
4017 ///
4018 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/construct)
4019 #[wasm_bindgen(js_namespace = Reflect, js_name = construct, catch)]
4020 pub fn construct_with_new_target(
4021 target: &Function,
4022 arguments_list: &Array,
4023 new_target: &Function,
4024 ) -> Result<JsValue, JsValue>;
4025
4026 /// The static `Reflect.defineProperty()` method is like
4027 /// `Object.defineProperty()` but returns a `Boolean`.
4028 ///
4029 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/defineProperty)
4030 #[wasm_bindgen(js_namespace = Reflect, js_name = defineProperty, catch)]
4031 pub fn define_property(
4032 target: &Object,
4033 property_key: &JsValue,
4034 attributes: &Object,
4035 ) -> Result<bool, JsValue>;
4036
4037 /// The static `Reflect.deleteProperty()` method allows to delete
4038 /// properties. It is like the `delete` operator as a function.
4039 ///
4040 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/deleteProperty)
4041 #[wasm_bindgen(js_namespace = Reflect, js_name = deleteProperty, catch)]
4042 pub fn delete_property(target: &Object, key: &JsValue) -> Result<bool, JsValue>;
4043
4044 /// The static `Reflect.get()` method works like getting a property from
4045 /// an object (`target[propertyKey]`) as a function.
4046 ///
4047 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/get)
4048 #[wasm_bindgen(js_namespace = Reflect, catch)]
4049 pub fn get(target: &JsValue, key: &JsValue) -> Result<JsValue, JsValue>;
4050
4051 /// The same as [`get`](fn.get.html)
4052 /// except the key is an `f64`, which is slightly faster.
4053 #[wasm_bindgen(js_namespace = Reflect, js_name = "get", catch)]
4054 pub fn get_f64(target: &JsValue, key: f64) -> Result<JsValue, JsValue>;
4055
4056 /// The same as [`get`](fn.get.html)
4057 /// except the key is a `u32`, which is slightly faster.
4058 #[wasm_bindgen(js_namespace = Reflect, js_name = "get", catch)]
4059 pub fn get_u32(target: &JsValue, key: u32) -> Result<JsValue, JsValue>;
4060
4061 /// The static `Reflect.getOwnPropertyDescriptor()` method is similar to
4062 /// `Object.getOwnPropertyDescriptor()`. It returns a property descriptor
4063 /// of the given property if it exists on the object, `undefined` otherwise.
4064 ///
4065 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getOwnPropertyDescriptor)
4066 #[wasm_bindgen(js_namespace = Reflect, js_name = getOwnPropertyDescriptor, catch)]
4067 pub fn get_own_property_descriptor(
4068 target: &Object,
4069 property_key: &JsValue,
4070 ) -> Result<JsValue, JsValue>;
4071
4072 /// The static `Reflect.getPrototypeOf()` method is almost the same
4073 /// method as `Object.getPrototypeOf()`. It returns the prototype
4074 /// (i.e. the value of the internal `[[Prototype]]` property) of
4075 /// the specified object.
4076 ///
4077 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getPrototypeOf)
4078 #[wasm_bindgen(js_namespace = Reflect, js_name = getPrototypeOf, catch)]
4079 pub fn get_prototype_of(target: &JsValue) -> Result<Object, JsValue>;
4080
4081 /// The static `Reflect.has()` method works like the in operator as a
4082 /// function.
4083 ///
4084 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/has)
4085 #[wasm_bindgen(js_namespace = Reflect, catch)]
4086 pub fn has(target: &JsValue, property_key: &JsValue) -> Result<bool, JsValue>;
4087
4088 /// The static `Reflect.isExtensible()` method determines if an object is
4089 /// extensible (whether it can have new properties added to it). It is
4090 /// similar to `Object.isExtensible()`, but with some differences.
4091 ///
4092 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/isExtensible)
4093 #[wasm_bindgen(js_namespace = Reflect, js_name = isExtensible, catch)]
4094 pub fn is_extensible(target: &Object) -> Result<bool, JsValue>;
4095
4096 /// The static `Reflect.ownKeys()` method returns an array of the
4097 /// target object's own property keys.
4098 ///
4099 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/ownKeys)
4100 #[wasm_bindgen(js_namespace = Reflect, js_name = ownKeys, catch)]
4101 pub fn own_keys(target: &JsValue) -> Result<Array, JsValue>;
4102
4103 /// The static `Reflect.preventExtensions()` method prevents new
4104 /// properties from ever being added to an object (i.e. prevents
4105 /// future extensions to the object). It is similar to
4106 /// `Object.preventExtensions()`, but with some differences.
4107 ///
4108 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/preventExtensions)
4109 #[wasm_bindgen(js_namespace = Reflect, js_name = preventExtensions, catch)]
4110 pub fn prevent_extensions(target: &Object) -> Result<bool, JsValue>;
4111
4112 /// The static `Reflect.set()` method works like setting a
4113 /// property on an object.
4114 ///
4115 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
4116 #[wasm_bindgen(js_namespace = Reflect, catch)]
4117 pub fn set(
4118 target: &JsValue,
4119 property_key: &JsValue,
4120 value: &JsValue,
4121 ) -> Result<bool, JsValue>;
4122
4123 /// The same as [`set`](fn.set.html)
4124 /// except the key is an `f64`, which is slightly faster.
4125 #[wasm_bindgen(js_namespace = Reflect, js_name = "set", catch)]
4126 pub fn set_f64(
4127 target: &JsValue,
4128 property_key: f64,
4129 value: &JsValue,
4130 ) -> Result<bool, JsValue>;
4131
4132 /// The same as [`set`](fn.set.html)
4133 /// except the key is a `u32`, which is slightly faster.
4134 #[wasm_bindgen(js_namespace = Reflect, js_name = "set", catch)]
4135 pub fn set_u32(
4136 target: &JsValue,
4137 property_key: u32,
4138 value: &JsValue,
4139 ) -> Result<bool, JsValue>;
4140
4141 /// The static `Reflect.set()` method works like setting a
4142 /// property on an object.
4143 ///
4144 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
4145 #[wasm_bindgen(js_namespace = Reflect, js_name = set, catch)]
4146 pub fn set_with_receiver(
4147 target: &JsValue,
4148 property_key: &JsValue,
4149 value: &JsValue,
4150 receiver: &JsValue,
4151 ) -> Result<bool, JsValue>;
4152
4153 /// The static `Reflect.setPrototypeOf()` method is the same
4154 /// method as `Object.setPrototypeOf()`. It sets the prototype
4155 /// (i.e., the internal `[[Prototype]]` property) of a specified
4156 /// object to another object or to null.
4157 ///
4158 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/setPrototypeOf)
4159 #[wasm_bindgen(js_namespace = Reflect, js_name = setPrototypeOf, catch)]
4160 pub fn set_prototype_of(target: &Object, prototype: &JsValue) -> Result<bool, JsValue>;
4161 }
4162}
4163
4164// RegExp
4165#[wasm_bindgen]
4166extern "C" {
4167 #[wasm_bindgen(extends = Object, typescript_type = "RegExp")]
4168 #[derive(Clone, Debug, PartialEq, Eq)]
4169 pub type RegExp;
4170
4171 /// The `exec()` method executes a search for a match in a specified
4172 /// string. Returns a result array, or null.
4173 ///
4174 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec)
4175 #[wasm_bindgen(method)]
4176 pub fn exec(this: &RegExp, text: &str) -> Option<Array>;
4177
4178 /// The flags property returns a string consisting of the flags of
4179 /// the current regular expression object.
4180 ///
4181 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/flags)
4182 #[wasm_bindgen(method, getter)]
4183 pub fn flags(this: &RegExp) -> JsString;
4184
4185 /// The global property indicates whether or not the "g" flag is
4186 /// used with the regular expression. global is a read-only
4187 /// property of an individual regular expression instance.
4188 ///
4189 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/global)
4190 #[wasm_bindgen(method, getter)]
4191 pub fn global(this: &RegExp) -> bool;
4192
4193 /// The ignoreCase property indicates whether or not the "i" flag
4194 /// is used with the regular expression. ignoreCase is a read-only
4195 /// property of an individual regular expression instance.
4196 ///
4197 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/ignoreCase)
4198 #[wasm_bindgen(method, getter, js_name = ignoreCase)]
4199 pub fn ignore_case(this: &RegExp) -> bool;
4200
4201 /// The non-standard input property is a static property of
4202 /// regular expressions that contains the string against which a
4203 /// regular expression is matched. RegExp.$_ is an alias for this
4204 /// property.
4205 ///
4206 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/input)
4207 #[wasm_bindgen(static_method_of = RegExp, getter)]
4208 pub fn input() -> JsString;
4209
4210 /// The lastIndex is a read/write integer property of regular expression
4211 /// instances that specifies the index at which to start the next match.
4212 ///
4213 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex)
4214 #[wasm_bindgen(structural, getter = lastIndex, method)]
4215 pub fn last_index(this: &RegExp) -> u32;
4216
4217 /// The lastIndex is a read/write integer property of regular expression
4218 /// instances that specifies the index at which to start the next match.
4219 ///
4220 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex)
4221 #[wasm_bindgen(structural, setter = lastIndex, method)]
4222 pub fn set_last_index(this: &RegExp, index: u32);
4223
4224 /// The non-standard lastMatch property is a static and read-only
4225 /// property of regular expressions that contains the last matched
4226 /// characters. `RegExp.$&` is an alias for this property.
4227 ///
4228 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastMatch)
4229 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = lastMatch)]
4230 pub fn last_match() -> JsString;
4231
4232 /// The non-standard lastParen property is a static and read-only
4233 /// property of regular expressions that contains the last
4234 /// parenthesized substring match, if any. `RegExp.$+` is an alias
4235 /// for this property.
4236 ///
4237 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastParen)
4238 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = lastParen)]
4239 pub fn last_paren() -> JsString;
4240
4241 /// The non-standard leftContext property is a static and
4242 /// read-only property of regular expressions that contains the
4243 /// substring preceding the most recent match. `RegExp.$`` is an
4244 /// alias for this property.
4245 ///
4246 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/leftContext)
4247 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = leftContext)]
4248 pub fn left_context() -> JsString;
4249
4250 /// The multiline property indicates whether or not the "m" flag
4251 /// is used with the regular expression. multiline is a read-only
4252 /// property of an individual regular expression instance.
4253 ///
4254 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/multiline)
4255 #[wasm_bindgen(method, getter)]
4256 pub fn multiline(this: &RegExp) -> bool;
4257
4258 /// The non-standard $1, $2, $3, $4, $5, $6, $7, $8, $9 properties
4259 /// are static and read-only properties of regular expressions
4260 /// that contain parenthesized substring matches.
4261 ///
4262 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/n)
4263 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$1")]
4264 pub fn n1() -> JsString;
4265 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$2")]
4266 pub fn n2() -> JsString;
4267 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$3")]
4268 pub fn n3() -> JsString;
4269 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$4")]
4270 pub fn n4() -> JsString;
4271 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$5")]
4272 pub fn n5() -> JsString;
4273 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$6")]
4274 pub fn n6() -> JsString;
4275 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$7")]
4276 pub fn n7() -> JsString;
4277 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$8")]
4278 pub fn n8() -> JsString;
4279 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$9")]
4280 pub fn n9() -> JsString;
4281
4282 /// The `RegExp` constructor creates a regular expression object for matching text with a pattern.
4283 ///
4284 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp)
4285 #[wasm_bindgen(constructor)]
4286 pub fn new(pattern: &str, flags: &str) -> RegExp;
4287 #[wasm_bindgen(constructor)]
4288 pub fn new_regexp(pattern: &RegExp, flags: &str) -> RegExp;
4289
4290 /// The non-standard rightContext property is a static and
4291 /// read-only property of regular expressions that contains the
4292 /// substring following the most recent match. `RegExp.$'` is an
4293 /// alias for this property.
4294 ///
4295 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/rightContext)
4296 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = rightContext)]
4297 pub fn right_context() -> JsString;
4298
4299 /// The source property returns a String containing the source
4300 /// text of the regexp object, and it doesn't contain the two
4301 /// forward slashes on both sides and any flags.
4302 ///
4303 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/source)
4304 #[wasm_bindgen(method, getter)]
4305 pub fn source(this: &RegExp) -> JsString;
4306
4307 /// The sticky property reflects whether or not the search is
4308 /// sticky (searches in strings only from the index indicated by
4309 /// the lastIndex property of this regular expression). sticky is
4310 /// a read-only property of an individual regular expression
4311 /// object.
4312 ///
4313 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/sticky)
4314 #[wasm_bindgen(method, getter)]
4315 pub fn sticky(this: &RegExp) -> bool;
4316
4317 /// The `test()` method executes a search for a match between a
4318 /// regular expression and a specified string. Returns true or
4319 /// false.
4320 ///
4321 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/test)
4322 #[wasm_bindgen(method)]
4323 pub fn test(this: &RegExp, text: &str) -> bool;
4324
4325 /// The `toString()` method returns a string representing the
4326 /// regular expression.
4327 ///
4328 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/toString)
4329 #[wasm_bindgen(method, js_name = toString)]
4330 pub fn to_string(this: &RegExp) -> JsString;
4331
4332 /// The unicode property indicates whether or not the "u" flag is
4333 /// used with a regular expression. unicode is a read-only
4334 /// property of an individual regular expression instance.
4335 ///
4336 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/unicode)
4337 #[wasm_bindgen(method, getter)]
4338 pub fn unicode(this: &RegExp) -> bool;
4339}
4340
4341// Set
4342#[wasm_bindgen]
4343extern "C" {
4344 #[wasm_bindgen(extends = Object, typescript_type = "Set<any>")]
4345 #[derive(Clone, Debug, PartialEq, Eq)]
4346 pub type Set;
4347
4348 /// The `add()` method appends a new element with a specified value to the
4349 /// end of a [`Set`] object.
4350 ///
4351 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/add)
4352 #[wasm_bindgen(method)]
4353 pub fn add(this: &Set, value: &JsValue) -> Set;
4354
4355 /// The `clear()` method removes all elements from a [`Set`] object.
4356 ///
4357 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/clear)
4358 #[wasm_bindgen(method)]
4359 pub fn clear(this: &Set);
4360
4361 /// The `delete()` method removes the specified element from a [`Set`]
4362 /// object.
4363 ///
4364 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/delete)
4365 #[wasm_bindgen(method)]
4366 pub fn delete(this: &Set, value: &JsValue) -> bool;
4367
4368 /// The `forEach()` method executes a provided function once for each value
4369 /// in the Set object, in insertion order.
4370 ///
4371 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/forEach)
4372 #[wasm_bindgen(method, js_name = forEach)]
4373 pub fn for_each(this: &Set, callback: &mut dyn FnMut(JsValue, JsValue, Set));
4374
4375 /// The `has()` method returns a boolean indicating whether an element with
4376 /// the specified value exists in a [`Set`] object or not.
4377 ///
4378 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/has)
4379 #[wasm_bindgen(method)]
4380 pub fn has(this: &Set, value: &JsValue) -> bool;
4381
4382 /// The [`Set`] object lets you store unique values of any type, whether
4383 /// primitive values or object references.
4384 ///
4385 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
4386 #[wasm_bindgen(constructor)]
4387 pub fn new(init: &JsValue) -> Set;
4388
4389 /// The size accessor property returns the number of elements in a [`Set`]
4390 /// object.
4391 ///
4392 /// [MDN documentation](https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Set/size)
4393 #[wasm_bindgen(method, getter, structural)]
4394 pub fn size(this: &Set) -> u32;
4395}
4396
4397impl Default for Set {
4398 fn default() -> Self {
4399 Self::new(&JsValue::UNDEFINED)
4400 }
4401}
4402
4403// SetIterator
4404#[wasm_bindgen]
4405extern "C" {
4406 /// The `entries()` method returns a new Iterator object that contains an
4407 /// array of [value, value] for each element in the Set object, in insertion
4408 /// order. For Set objects there is no key like in Map objects. However, to
4409 /// keep the API similar to the Map object, each entry has the same value
4410 /// for its key and value here, so that an array [value, value] is returned.
4411 ///
4412 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/entries)
4413 #[wasm_bindgen(method)]
4414 pub fn entries(set: &Set) -> Iterator;
4415
4416 /// The `keys()` method is an alias for this method (for similarity with
4417 /// Map objects); it behaves exactly the same and returns values
4418 /// of Set elements.
4419 ///
4420 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/values)
4421 #[wasm_bindgen(method)]
4422 pub fn keys(set: &Set) -> Iterator;
4423
4424 /// The `values()` method returns a new Iterator object that contains the
4425 /// values for each element in the Set object in insertion order.
4426 ///
4427 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/values)
4428 #[wasm_bindgen(method)]
4429 pub fn values(set: &Set) -> Iterator;
4430}
4431
4432// SyntaxError
4433#[wasm_bindgen]
4434extern "C" {
4435 /// A `SyntaxError` is thrown when the JavaScript engine encounters tokens or
4436 /// token order that does not conform to the syntax of the language when
4437 /// parsing code.
4438 ///
4439 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError)
4440 #[wasm_bindgen(extends = Error, extends = Object, typescript_type = "SyntaxError")]
4441 #[derive(Clone, Debug, PartialEq, Eq)]
4442 pub type SyntaxError;
4443
4444 /// A `SyntaxError` is thrown when the JavaScript engine encounters tokens or
4445 /// token order that does not conform to the syntax of the language when
4446 /// parsing code.
4447 ///
4448 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError)
4449 #[wasm_bindgen(constructor)]
4450 pub fn new(message: &str) -> SyntaxError;
4451}
4452
4453// TypeError
4454#[wasm_bindgen]
4455extern "C" {
4456 /// The `TypeError` object represents an error when a value is not of the
4457 /// expected type.
4458 ///
4459 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError)
4460 #[wasm_bindgen(extends = Error, extends = Object, typescript_type = "TypeError")]
4461 #[derive(Clone, Debug, PartialEq, Eq)]
4462 pub type TypeError;
4463
4464 /// The `TypeError` object represents an error when a value is not of the
4465 /// expected type.
4466 ///
4467 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError)
4468 #[wasm_bindgen(constructor)]
4469 pub fn new(message: &str) -> TypeError;
4470}
4471
4472// URIError
4473#[wasm_bindgen]
4474extern "C" {
4475 /// The `URIError` object represents an error when a global URI handling
4476 /// function was used in a wrong way.
4477 ///
4478 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError)
4479 #[wasm_bindgen(extends = Error, extends = Object, js_name = URIError, typescript_type = "URIError")]
4480 #[derive(Clone, Debug, PartialEq, Eq)]
4481 pub type UriError;
4482
4483 /// The `URIError` object represents an error when a global URI handling
4484 /// function was used in a wrong way.
4485 ///
4486 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError)
4487 #[wasm_bindgen(constructor, js_class = "URIError")]
4488 pub fn new(message: &str) -> UriError;
4489}
4490
4491// WeakMap
4492#[wasm_bindgen]
4493extern "C" {
4494 #[wasm_bindgen(extends = Object, typescript_type = "WeakMap<object, any>")]
4495 #[derive(Clone, Debug, PartialEq, Eq)]
4496 pub type WeakMap;
4497
4498 /// The [`WeakMap`] object is a collection of key/value pairs in which the
4499 /// keys are weakly referenced. The keys must be objects and the values can
4500 /// be arbitrary values.
4501 ///
4502 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap)
4503 #[wasm_bindgen(constructor)]
4504 pub fn new() -> WeakMap;
4505
4506 /// The `set()` method sets the value for the key in the [`WeakMap`] object.
4507 /// Returns the [`WeakMap`] object.
4508 ///
4509 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/set)
4510 #[wasm_bindgen(method, js_class = "WeakMap")]
4511 pub fn set(this: &WeakMap, key: &Object, value: &JsValue) -> WeakMap;
4512
4513 /// The `get()` method returns a specified by key element
4514 /// from a [`WeakMap`] object.
4515 ///
4516 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/get)
4517 #[wasm_bindgen(method)]
4518 pub fn get(this: &WeakMap, key: &Object) -> JsValue;
4519
4520 /// The `has()` method returns a boolean indicating whether an element with
4521 /// the specified key exists in the [`WeakMap`] object or not.
4522 ///
4523 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/has)
4524 #[wasm_bindgen(method)]
4525 pub fn has(this: &WeakMap, key: &Object) -> bool;
4526
4527 /// The `delete()` method removes the specified element from a [`WeakMap`]
4528 /// object.
4529 ///
4530 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/delete)
4531 #[wasm_bindgen(method)]
4532 pub fn delete(this: &WeakMap, key: &Object) -> bool;
4533}
4534
4535impl Default for WeakMap {
4536 fn default() -> Self {
4537 Self::new()
4538 }
4539}
4540
4541// WeakSet
4542#[wasm_bindgen]
4543extern "C" {
4544 #[wasm_bindgen(extends = Object, typescript_type = "WeakSet<object>")]
4545 #[derive(Clone, Debug, PartialEq, Eq)]
4546 pub type WeakSet;
4547
4548 /// The `WeakSet` object lets you store weakly held objects in a collection.
4549 ///
4550 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet)
4551 #[wasm_bindgen(constructor)]
4552 pub fn new() -> WeakSet;
4553
4554 /// The `has()` method returns a boolean indicating whether an object exists
4555 /// in a WeakSet or not.
4556 ///
4557 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet/has)
4558 #[wasm_bindgen(method)]
4559 pub fn has(this: &WeakSet, value: &Object) -> bool;
4560
4561 /// The `add()` method appends a new object to the end of a WeakSet object.
4562 ///
4563 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet/add)
4564 #[wasm_bindgen(method)]
4565 pub fn add(this: &WeakSet, value: &Object) -> WeakSet;
4566
4567 /// The `delete()` method removes the specified element from a WeakSet
4568 /// object.
4569 ///
4570 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet/delete)
4571 #[wasm_bindgen(method)]
4572 pub fn delete(this: &WeakSet, value: &Object) -> bool;
4573}
4574
4575impl Default for WeakSet {
4576 fn default() -> Self {
4577 Self::new()
4578 }
4579}
4580
4581// WeakRef
4582#[wasm_bindgen]
4583extern "C" {
4584 #[wasm_bindgen(extends = Object, typescript_type = "WeakRef<object>")]
4585 #[derive(Clone, Debug, PartialEq, Eq)]
4586 pub type WeakRef;
4587
4588 /// The `WeakRef` object contains a weak reference to an object. A weak
4589 /// reference to an object is a reference that does not prevent the object
4590 /// from being reclaimed by the garbage collector.
4591 ///
4592 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef)
4593 #[wasm_bindgen(constructor)]
4594 pub fn new(target: &Object) -> WeakRef;
4595
4596 /// Returns the `Object` this `WeakRef` points to, or `None` if the
4597 /// object has been garbage collected.
4598 ///
4599 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef/deref)
4600 #[wasm_bindgen(method)]
4601 pub fn deref(this: &WeakRef) -> Option<Object>;
4602}
4603
4604#[cfg(js_sys_unstable_apis)]
4605#[allow(non_snake_case)]
4606pub mod Temporal;
4607
4608#[allow(non_snake_case)]
4609pub mod WebAssembly {
4610 use super::*;
4611
4612 // WebAssembly
4613 #[wasm_bindgen]
4614 extern "C" {
4615 /// The `WebAssembly.compile()` function compiles a `WebAssembly.Module`
4616 /// from WebAssembly binary code. This function is useful if it is
4617 /// necessary to a compile a module before it can be instantiated
4618 /// (otherwise, the `WebAssembly.instantiate()` function should be used).
4619 ///
4620 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compile)
4621 #[wasm_bindgen(js_namespace = WebAssembly)]
4622 pub fn compile(buffer_source: &JsValue) -> Promise;
4623
4624 /// The `WebAssembly.compileStreaming()` function compiles a
4625 /// `WebAssembly.Module` module directly from a streamed underlying
4626 /// source. This function is useful if it is necessary to a compile a
4627 /// module before it can be instantiated (otherwise, the
4628 /// `WebAssembly.instantiateStreaming()` function should be used).
4629 ///
4630 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compileStreaming)
4631 #[wasm_bindgen(js_namespace = WebAssembly, js_name = compileStreaming)]
4632 pub fn compile_streaming(response: &Promise) -> Promise;
4633
4634 /// The `WebAssembly.instantiate()` function allows you to compile and
4635 /// instantiate WebAssembly code.
4636 ///
4637 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate)
4638 #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiate)]
4639 pub fn instantiate_buffer(buffer: &[u8], imports: &Object) -> Promise;
4640
4641 /// The `WebAssembly.instantiate()` function allows you to compile and
4642 /// instantiate WebAssembly code.
4643 ///
4644 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate)
4645 #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiate)]
4646 pub fn instantiate_module(module: &Module, imports: &Object) -> Promise;
4647
4648 /// The `WebAssembly.instantiateStreaming()` function compiles and
4649 /// instantiates a WebAssembly module directly from a streamed
4650 /// underlying source. This is the most efficient, optimized way to load
4651 /// Wasm code.
4652 ///
4653 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiateStreaming)
4654 #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiateStreaming)]
4655 pub fn instantiate_streaming(response: &Promise, imports: &Object) -> Promise;
4656
4657 /// The `WebAssembly.validate()` function validates a given typed
4658 /// array of WebAssembly binary code, returning whether the bytes
4659 /// form a valid Wasm module (`true`) or not (`false`).
4660 ///
4661 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/validate)
4662 #[wasm_bindgen(js_namespace = WebAssembly, catch)]
4663 pub fn validate(buffer_source: &JsValue) -> Result<bool, JsValue>;
4664 }
4665
4666 // WebAssembly.CompileError
4667 #[wasm_bindgen]
4668 extern "C" {
4669 /// The `WebAssembly.CompileError()` constructor creates a new
4670 /// WebAssembly `CompileError` object, which indicates an error during
4671 /// WebAssembly decoding or validation.
4672 ///
4673 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/CompileError)
4674 #[wasm_bindgen(extends = Error, js_namespace = WebAssembly, typescript_type = "WebAssembly.CompileError")]
4675 #[derive(Clone, Debug, PartialEq, Eq)]
4676 pub type CompileError;
4677
4678 /// The `WebAssembly.CompileError()` constructor creates a new
4679 /// WebAssembly `CompileError` object, which indicates an error during
4680 /// WebAssembly decoding or validation.
4681 ///
4682 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/CompileError)
4683 #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
4684 pub fn new(message: &str) -> CompileError;
4685 }
4686
4687 // WebAssembly.Instance
4688 #[wasm_bindgen]
4689 extern "C" {
4690 /// A `WebAssembly.Instance` object is a stateful, executable instance
4691 /// of a `WebAssembly.Module`. Instance objects contain all the exported
4692 /// WebAssembly functions that allow calling into WebAssembly code from
4693 /// JavaScript.
4694 ///
4695 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance)
4696 #[wasm_bindgen(extends = Object, js_namespace = WebAssembly, typescript_type = "WebAssembly.Instance")]
4697 #[derive(Clone, Debug, PartialEq, Eq)]
4698 pub type Instance;
4699
4700 /// The `WebAssembly.Instance()` constructor function can be called to
4701 /// synchronously instantiate a given `WebAssembly.Module`
4702 /// object. However, the primary way to get an `Instance` is through the
4703 /// asynchronous `WebAssembly.instantiateStreaming()` function.
4704 ///
4705 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance)
4706 #[wasm_bindgen(catch, constructor, js_namespace = WebAssembly)]
4707 pub fn new(module: &Module, imports: &Object) -> Result<Instance, JsValue>;
4708
4709 /// The `exports` readonly property of the `WebAssembly.Instance` object
4710 /// prototype returns an object containing as its members all the
4711 /// functions exported from the WebAssembly module instance, to allow
4712 /// them to be accessed and used by JavaScript.
4713 ///
4714 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance/exports)
4715 #[wasm_bindgen(getter, method, js_namespace = WebAssembly)]
4716 pub fn exports(this: &Instance) -> Object;
4717 }
4718
4719 // WebAssembly.LinkError
4720 #[wasm_bindgen]
4721 extern "C" {
4722 /// The `WebAssembly.LinkError()` constructor creates a new WebAssembly
4723 /// LinkError object, which indicates an error during module
4724 /// instantiation (besides traps from the start function).
4725 ///
4726 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/LinkError)
4727 #[wasm_bindgen(extends = Error, js_namespace = WebAssembly, typescript_type = "WebAssembly.LinkError")]
4728 #[derive(Clone, Debug, PartialEq, Eq)]
4729 pub type LinkError;
4730
4731 /// The `WebAssembly.LinkError()` constructor creates a new WebAssembly
4732 /// LinkError object, which indicates an error during module
4733 /// instantiation (besides traps from the start function).
4734 ///
4735 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/LinkError)
4736 #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
4737 pub fn new(message: &str) -> LinkError;
4738 }
4739
4740 // WebAssembly.RuntimeError
4741 #[wasm_bindgen]
4742 extern "C" {
4743 /// The `WebAssembly.RuntimeError()` constructor creates a new WebAssembly
4744 /// `RuntimeError` object — the type that is thrown whenever WebAssembly
4745 /// specifies a trap.
4746 ///
4747 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/RuntimeError)
4748 #[wasm_bindgen(extends = Error, js_namespace = WebAssembly, typescript_type = "WebAssembly.RuntimeError")]
4749 #[derive(Clone, Debug, PartialEq, Eq)]
4750 pub type RuntimeError;
4751
4752 /// The `WebAssembly.RuntimeError()` constructor creates a new WebAssembly
4753 /// `RuntimeError` object — the type that is thrown whenever WebAssembly
4754 /// specifies a trap.
4755 ///
4756 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/RuntimeError)
4757 #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
4758 pub fn new(message: &str) -> RuntimeError;
4759 }
4760
4761 // WebAssembly.Module
4762 #[wasm_bindgen]
4763 extern "C" {
4764 /// A `WebAssembly.Module` object contains stateless WebAssembly code
4765 /// that has already been compiled by the browser and can be
4766 /// efficiently shared with Workers, and instantiated multiple times.
4767 ///
4768 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module)
4769 #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Module")]
4770 #[derive(Clone, Debug, PartialEq, Eq)]
4771 pub type Module;
4772
4773 /// A `WebAssembly.Module` object contains stateless WebAssembly code
4774 /// that has already been compiled by the browser and can be
4775 /// efficiently shared with Workers, and instantiated multiple times.
4776 ///
4777 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module)
4778 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
4779 pub fn new(buffer_source: &JsValue) -> Result<Module, JsValue>;
4780
4781 /// The `WebAssembly.customSections()` function returns a copy of the
4782 /// contents of all custom sections in the given module with the given
4783 /// string name.
4784 ///
4785 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/customSections)
4786 #[wasm_bindgen(static_method_of = Module, js_namespace = WebAssembly, js_name = customSections)]
4787 pub fn custom_sections(module: &Module, sectionName: &str) -> Array;
4788
4789 /// The `WebAssembly.exports()` function returns an array containing
4790 /// descriptions of all the declared exports of the given `Module`.
4791 ///
4792 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/exports)
4793 #[wasm_bindgen(static_method_of = Module, js_namespace = WebAssembly)]
4794 pub fn exports(module: &Module) -> Array;
4795
4796 /// The `WebAssembly.imports()` function returns an array containing
4797 /// descriptions of all the declared imports of the given `Module`.
4798 ///
4799 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/imports)
4800 #[wasm_bindgen(static_method_of = Module, js_namespace = WebAssembly)]
4801 pub fn imports(module: &Module) -> Array;
4802 }
4803
4804 // WebAssembly.Table
4805 #[wasm_bindgen]
4806 extern "C" {
4807 /// The `WebAssembly.Table()` constructor creates a new `Table` object
4808 /// of the given size and element type.
4809 ///
4810 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table)
4811 #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Table")]
4812 #[derive(Clone, Debug, PartialEq, Eq)]
4813 pub type Table;
4814
4815 /// The `WebAssembly.Table()` constructor creates a new `Table` object
4816 /// of the given size and element type.
4817 ///
4818 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table)
4819 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
4820 pub fn new(table_descriptor: &Object) -> Result<Table, JsValue>;
4821
4822 /// The `WebAssembly.Table()` constructor creates a new `Table` object
4823 /// of the given size and element type.
4824 ///
4825 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table)
4826 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
4827 pub fn new_with_value(table_descriptor: &Object, value: JsValue) -> Result<Table, JsValue>;
4828
4829 /// The length prototype property of the `WebAssembly.Table` object
4830 /// returns the length of the table, i.e. the number of elements in the
4831 /// table.
4832 ///
4833 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/length)
4834 #[wasm_bindgen(method, getter, js_namespace = WebAssembly)]
4835 pub fn length(this: &Table) -> u32;
4836
4837 /// The `get()` prototype method of the `WebAssembly.Table()` object
4838 /// retrieves a function reference stored at a given index.
4839 ///
4840 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/get)
4841 #[wasm_bindgen(method, catch, js_namespace = WebAssembly)]
4842 pub fn get(this: &Table, index: u32) -> Result<Function, JsValue>;
4843
4844 /// The `get()` prototype method of the `WebAssembly.Table()` object
4845 /// retrieves a function reference stored at a given index.
4846 ///
4847 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/get)
4848 #[wasm_bindgen(method, catch, js_namespace = WebAssembly, js_name = get)]
4849 pub fn get_raw(this: &Table, index: u32) -> Result<JsValue, JsValue>;
4850
4851 /// The `grow()` prototype method of the `WebAssembly.Table` object
4852 /// increases the size of the `Table` instance by a specified number of
4853 /// elements.
4854 ///
4855 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/grow)
4856 #[wasm_bindgen(method, catch, js_namespace = WebAssembly)]
4857 pub fn grow(this: &Table, additional_capacity: u32) -> Result<u32, JsValue>;
4858
4859 /// The `grow()` prototype method of the `WebAssembly.Table` object
4860 /// increases the size of the `Table` instance by a specified number of
4861 /// elements.
4862 ///
4863 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/grow)
4864 #[wasm_bindgen(method, catch, js_namespace = WebAssembly, js_name = grow)]
4865 pub fn grow_with_value(
4866 this: &Table,
4867 additional_capacity: u32,
4868 value: JsValue,
4869 ) -> Result<u32, JsValue>;
4870
4871 /// The `set()` prototype method of the `WebAssembly.Table` object mutates a
4872 /// reference stored at a given index to a different value.
4873 ///
4874 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/set)
4875 #[wasm_bindgen(method, catch, js_namespace = WebAssembly)]
4876 pub fn set(this: &Table, index: u32, function: &Function) -> Result<(), JsValue>;
4877
4878 /// The `set()` prototype method of the `WebAssembly.Table` object mutates a
4879 /// reference stored at a given index to a different value.
4880 ///
4881 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/set)
4882 #[wasm_bindgen(method, catch, js_namespace = WebAssembly, js_name = set)]
4883 pub fn set_raw(this: &Table, index: u32, value: &JsValue) -> Result<(), JsValue>;
4884 }
4885
4886 // WebAssembly.Tag
4887 #[wasm_bindgen]
4888 extern "C" {
4889 /// The `WebAssembly.Tag()` constructor creates a new `Tag` object
4890 ///
4891 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Tag)
4892 #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Tag")]
4893 #[derive(Clone, Debug, PartialEq, Eq)]
4894 pub type Tag;
4895
4896 /// The `WebAssembly.Tag()` constructor creates a new `Tag` object
4897 ///
4898 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Tag)
4899 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
4900 pub fn new(tag_descriptor: &Object) -> Result<Tag, JsValue>;
4901 }
4902
4903 // WebAssembly.Exception
4904 #[wasm_bindgen]
4905 extern "C" {
4906 /// The `WebAssembly.Exception()` constructor creates a new `Exception` object
4907 ///
4908 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception)
4909 #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Exception")]
4910 #[derive(Clone, Debug, PartialEq, Eq)]
4911 pub type Exception;
4912
4913 /// The `WebAssembly.Exception()` constructor creates a new `Exception` object
4914 ///
4915 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception)
4916 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
4917 pub fn new(tag: &Tag, payload: &Array) -> Result<Exception, JsValue>;
4918
4919 /// The `WebAssembly.Exception()` constructor creates a new `Exception` object
4920 ///
4921 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception)
4922 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
4923 pub fn new_with_options(
4924 tag: &Tag,
4925 payload: &Array,
4926 options: &Object,
4927 ) -> Result<Exception, JsValue>;
4928
4929 /// The `is()` prototype method of the `WebAssembly.Exception` can be used to
4930 /// test if the Exception matches a given tag.
4931 ///
4932 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception/is)
4933 #[wasm_bindgen(method, js_namespace = WebAssembly)]
4934 pub fn is(this: &Exception, tag: &Tag) -> bool;
4935
4936 /// The `getArg()` prototype method of the `WebAssembly.Exception` can be used
4937 /// to get the value of a specified item in the exception's data arguments
4938 ///
4939 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception/getArg)
4940 #[wasm_bindgen(method, js_namespace = WebAssembly, js_name = getArg, catch)]
4941 pub fn get_arg(this: &Exception, tag: &Tag, index: u32) -> Result<JsValue, JsValue>;
4942 }
4943
4944 // WebAssembly.Global
4945 #[wasm_bindgen]
4946 extern "C" {
4947 /// The `WebAssembly.Global()` constructor creates a new `Global` object
4948 /// of the given type and value.
4949 ///
4950 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global)
4951 #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Global")]
4952 #[derive(Clone, Debug, PartialEq, Eq)]
4953 pub type Global;
4954
4955 /// The `WebAssembly.Global()` constructor creates a new `Global` object
4956 /// of the given type and value.
4957 ///
4958 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global)
4959 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
4960 pub fn new(global_descriptor: &Object, value: &JsValue) -> Result<Global, JsValue>;
4961
4962 /// The value prototype property of the `WebAssembly.Global` object
4963 /// returns the value of the global.
4964 ///
4965 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global)
4966 #[wasm_bindgen(method, getter, structural, js_namespace = WebAssembly)]
4967 pub fn value(this: &Global) -> JsValue;
4968 #[wasm_bindgen(method, setter = value, structural, js_namespace = WebAssembly)]
4969 pub fn set_value(this: &Global, value: &JsValue);
4970 }
4971
4972 // WebAssembly.Memory
4973 #[wasm_bindgen]
4974 extern "C" {
4975 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory)
4976 #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Memory")]
4977 #[derive(Clone, Debug, PartialEq, Eq)]
4978 pub type Memory;
4979
4980 /// The `WebAssembly.Memory()` constructor creates a new `Memory` object
4981 /// which is a resizable `ArrayBuffer` that holds the raw bytes of
4982 /// memory accessed by a WebAssembly `Instance`.
4983 ///
4984 /// A memory created by JavaScript or in WebAssembly code will be
4985 /// accessible and mutable from both JavaScript and WebAssembly.
4986 ///
4987 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory)
4988 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
4989 pub fn new(descriptor: &Object) -> Result<Memory, JsValue>;
4990
4991 /// An accessor property that returns the buffer contained in the
4992 /// memory.
4993 ///
4994 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory/buffer)
4995 #[wasm_bindgen(method, getter, js_namespace = WebAssembly)]
4996 pub fn buffer(this: &Memory) -> JsValue;
4997
4998 /// The `grow()` prototype method of the `Memory` object increases the
4999 /// size of the memory instance by a specified number of WebAssembly
5000 /// pages.
5001 ///
5002 /// Takes the number of pages to grow (64KiB in size) and returns the
5003 /// previous size of memory, in pages.
5004 ///
5005 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory/grow)
5006 #[wasm_bindgen(method, js_namespace = WebAssembly)]
5007 pub fn grow(this: &Memory, pages: u32) -> u32;
5008 }
5009}
5010
5011/// The `JSON` object contains methods for parsing [JavaScript Object
5012/// Notation (JSON)](https://json.org/) and converting values to JSON. It
5013/// can't be called or constructed, and aside from its two method
5014/// properties, it has no interesting functionality of its own.
5015#[allow(non_snake_case)]
5016pub mod JSON {
5017 use super::*;
5018
5019 // JSON
5020 #[wasm_bindgen]
5021 extern "C" {
5022 /// The `JSON.parse()` method parses a JSON string, constructing the
5023 /// JavaScript value or object described by the string.
5024 ///
5025 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse)
5026 #[wasm_bindgen(catch, js_namespace = JSON)]
5027 pub fn parse(text: &str) -> Result<JsValue, JsValue>;
5028
5029 /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
5030 ///
5031 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
5032 #[wasm_bindgen(catch, js_namespace = JSON)]
5033 pub fn stringify(obj: &JsValue) -> Result<JsString, JsValue>;
5034
5035 /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
5036 ///
5037 /// The `replacer` argument is a function that alters the behavior of the stringification
5038 /// process, or an array of String and Number objects that serve as a whitelist
5039 /// for selecting/filtering the properties of the value object to be included
5040 /// in the JSON string. If this value is null or not provided, all properties
5041 /// of the object are included in the resulting JSON string.
5042 ///
5043 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
5044 #[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
5045 pub fn stringify_with_replacer(
5046 obj: &JsValue,
5047 replacer: &JsValue,
5048 ) -> Result<JsString, JsValue>;
5049
5050 /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
5051 ///
5052 /// The `replacer` argument is a function that alters the behavior of the stringification
5053 /// process, or an array of String and Number objects that serve as a whitelist
5054 /// for selecting/filtering the properties of the value object to be included
5055 /// in the JSON string. If this value is null or not provided, all properties
5056 /// of the object are included in the resulting JSON string.
5057 ///
5058 /// The `space` argument is a String or Number object that's used to insert white space into
5059 /// the output JSON string for readability purposes. If this is a Number, it
5060 /// indicates the number of space characters to use as white space; this number
5061 /// is capped at 10 (if it is greater, the value is just 10). Values less than
5062 /// 1 indicate that no space should be used. If this is a String, the string
5063 /// (or the first 10 characters of the string, if it's longer than that) is
5064 /// used as white space. If this parameter is not provided (or is null), no
5065 /// white space is used.
5066 ///
5067 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
5068 #[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
5069 pub fn stringify_with_replacer_and_space(
5070 obj: &JsValue,
5071 replacer: &JsValue,
5072 space: &JsValue,
5073 ) -> Result<JsString, JsValue>;
5074
5075 }
5076}
5077
5078// JsString
5079#[wasm_bindgen]
5080extern "C" {
5081 #[wasm_bindgen(js_name = String, extends = Object, is_type_of = JsValue::is_string, typescript_type = "string")]
5082 #[derive(Clone, PartialEq, Eq)]
5083 pub type JsString;
5084
5085 /// The length property of a String object indicates the length of a string,
5086 /// in UTF-16 code units.
5087 ///
5088 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/length)
5089 #[wasm_bindgen(method, getter, structural)]
5090 pub fn length(this: &JsString) -> u32;
5091
5092 /// The 'at()' method returns a new string consisting of the single UTF-16
5093 /// code unit located at the specified offset into the string, counting from
5094 /// the end if it's negative.
5095 ///
5096 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/at)
5097 #[wasm_bindgen(method, js_class = "String")]
5098 pub fn at(this: &JsString, index: i32) -> Option<JsString>;
5099
5100 /// The String object's `charAt()` method returns a new string consisting of
5101 /// the single UTF-16 code unit located at the specified offset into the
5102 /// string.
5103 ///
5104 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charAt)
5105 #[wasm_bindgen(method, js_class = "String", js_name = charAt)]
5106 pub fn char_at(this: &JsString, index: u32) -> JsString;
5107
5108 /// The `charCodeAt()` method returns an integer between 0 and 65535
5109 /// representing the UTF-16 code unit at the given index (the UTF-16 code
5110 /// unit matches the Unicode code point for code points representable in a
5111 /// single UTF-16 code unit, but might also be the first code unit of a
5112 /// surrogate pair for code points not representable in a single UTF-16 code
5113 /// unit, e.g. Unicode code points > 0x10000). If you want the entire code
5114 /// point value, use `codePointAt()`.
5115 ///
5116 /// Returns `NaN` if index is out of range.
5117 ///
5118 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charCodeAt)
5119 #[wasm_bindgen(method, js_class = "String", js_name = charCodeAt)]
5120 pub fn char_code_at(this: &JsString, index: u32) -> f64;
5121
5122 /// The `codePointAt()` method returns a non-negative integer that is the
5123 /// Unicode code point value.
5124 ///
5125 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/codePointAt)
5126 #[wasm_bindgen(method, js_class = "String", js_name = codePointAt)]
5127 pub fn code_point_at(this: &JsString, pos: u32) -> JsValue;
5128
5129 /// The `concat()` method concatenates the string arguments to the calling
5130 /// string and returns a new string.
5131 ///
5132 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/concat)
5133 #[wasm_bindgen(method, js_class = "String")]
5134 pub fn concat(this: &JsString, string_2: &JsValue) -> JsString;
5135
5136 /// The `endsWith()` method determines whether a string ends with the characters of a
5137 /// specified string, returning true or false as appropriate.
5138 ///
5139 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith)
5140 #[wasm_bindgen(method, js_class = "String", js_name = endsWith)]
5141 pub fn ends_with(this: &JsString, search_string: &str, length: i32) -> bool;
5142
5143 /// The static `String.fromCharCode()` method returns a string created from
5144 /// the specified sequence of UTF-16 code units.
5145 ///
5146 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
5147 ///
5148 /// # Notes
5149 ///
5150 /// There are a few bindings to `from_char_code` in `js-sys`: `from_char_code1`, `from_char_code2`, etc...
5151 /// with different arities.
5152 ///
5153 /// Additionally, this function accepts `u16` for character codes, but
5154 /// fixing others requires a breaking change release
5155 /// (see https://github.com/wasm-bindgen/wasm-bindgen/issues/1460 for details).
5156 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode, variadic)]
5157 pub fn from_char_code(char_codes: &[u16]) -> JsString;
5158
5159 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
5160 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
5161 pub fn from_char_code1(a: u32) -> JsString;
5162
5163 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
5164 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
5165 pub fn from_char_code2(a: u32, b: u32) -> JsString;
5166
5167 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
5168 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
5169 pub fn from_char_code3(a: u32, b: u32, c: u32) -> JsString;
5170
5171 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
5172 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
5173 pub fn from_char_code4(a: u32, b: u32, c: u32, d: u32) -> JsString;
5174
5175 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
5176 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
5177 pub fn from_char_code5(a: u32, b: u32, c: u32, d: u32, e: u32) -> JsString;
5178
5179 /// The static `String.fromCodePoint()` method returns a string created by
5180 /// using the specified sequence of code points.
5181 ///
5182 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
5183 ///
5184 /// # Exceptions
5185 ///
5186 /// A RangeError is thrown if an invalid Unicode code point is given
5187 ///
5188 /// # Notes
5189 ///
5190 /// There are a few bindings to `from_code_point` in `js-sys`: `from_code_point1`, `from_code_point2`, etc...
5191 /// with different arities.
5192 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint, variadic)]
5193 pub fn from_code_point(code_points: &[u32]) -> Result<JsString, JsValue>;
5194
5195 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
5196 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
5197 pub fn from_code_point1(a: u32) -> Result<JsString, JsValue>;
5198
5199 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
5200 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
5201 pub fn from_code_point2(a: u32, b: u32) -> Result<JsString, JsValue>;
5202
5203 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
5204 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
5205 pub fn from_code_point3(a: u32, b: u32, c: u32) -> Result<JsString, JsValue>;
5206
5207 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
5208 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
5209 pub fn from_code_point4(a: u32, b: u32, c: u32, d: u32) -> Result<JsString, JsValue>;
5210
5211 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
5212 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
5213 pub fn from_code_point5(a: u32, b: u32, c: u32, d: u32, e: u32) -> Result<JsString, JsValue>;
5214
5215 /// The `includes()` method determines whether one string may be found
5216 /// within another string, returning true or false as appropriate.
5217 ///
5218 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes)
5219 #[wasm_bindgen(method, js_class = "String")]
5220 pub fn includes(this: &JsString, search_string: &str, position: i32) -> bool;
5221
5222 /// The `indexOf()` method returns the index within the calling String
5223 /// object of the first occurrence of the specified value, starting the
5224 /// search at fromIndex. Returns -1 if the value is not found.
5225 ///
5226 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf)
5227 #[wasm_bindgen(method, js_class = "String", js_name = indexOf)]
5228 pub fn index_of(this: &JsString, search_value: &str, from_index: i32) -> i32;
5229
5230 /// The `lastIndexOf()` method returns the index within the calling String
5231 /// object of the last occurrence of the specified value, searching
5232 /// backwards from fromIndex. Returns -1 if the value is not found.
5233 ///
5234 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/lastIndexOf)
5235 #[wasm_bindgen(method, js_class = "String", js_name = lastIndexOf)]
5236 pub fn last_index_of(this: &JsString, search_value: &str, from_index: i32) -> i32;
5237
5238 /// The `localeCompare()` method returns a number indicating whether
5239 /// a reference string comes before or after or is the same as
5240 /// the given string in sort order.
5241 ///
5242 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare)
5243 #[wasm_bindgen(method, js_class = "String", js_name = localeCompare)]
5244 pub fn locale_compare(
5245 this: &JsString,
5246 compare_string: &str,
5247 locales: &Array,
5248 options: &Object,
5249 ) -> i32;
5250
5251 /// The `match()` method retrieves the matches when matching a string against a regular expression.
5252 ///
5253 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match)
5254 #[wasm_bindgen(method, js_class = "String", js_name = match)]
5255 pub fn match_(this: &JsString, pattern: &RegExp) -> Option<Object>;
5256
5257 /// The `match_all()` method is similar to `match()`, but gives an iterator of `exec()` arrays, which preserve capture groups.
5258 ///
5259 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/matchAll)
5260 #[wasm_bindgen(method, js_class = "String", js_name = matchAll)]
5261 pub fn match_all(this: &JsString, pattern: &RegExp) -> Iterator;
5262
5263 /// The `normalize()` method returns the Unicode Normalization Form
5264 /// of a given string (if the value isn't a string, it will be converted to one first).
5265 ///
5266 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize)
5267 #[wasm_bindgen(method, js_class = "String")]
5268 pub fn normalize(this: &JsString, form: &str) -> JsString;
5269
5270 /// The `padEnd()` method pads the current string with a given string
5271 /// (repeated, if needed) so that the resulting string reaches a given
5272 /// length. The padding is applied from the end (right) of the current
5273 /// string.
5274 ///
5275 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padEnd)
5276 #[wasm_bindgen(method, js_class = "String", js_name = padEnd)]
5277 pub fn pad_end(this: &JsString, target_length: u32, pad_string: &str) -> JsString;
5278
5279 /// The `padStart()` method pads the current string with another string
5280 /// (repeated, if needed) so that the resulting string reaches the given
5281 /// length. The padding is applied from the start (left) of the current
5282 /// string.
5283 ///
5284 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padStart)
5285 #[wasm_bindgen(method, js_class = "String", js_name = padStart)]
5286 pub fn pad_start(this: &JsString, target_length: u32, pad_string: &str) -> JsString;
5287
5288 /// The `repeat()` method constructs and returns a new string which contains the specified
5289 /// number of copies of the string on which it was called, concatenated together.
5290 ///
5291 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat)
5292 #[wasm_bindgen(method, js_class = "String")]
5293 pub fn repeat(this: &JsString, count: i32) -> JsString;
5294
5295 /// The `replace()` method returns a new string with some or all matches of a pattern
5296 /// replaced by a replacement. The pattern can be a string or a RegExp, and
5297 /// the replacement can be a string or a function to be called for each match.
5298 ///
5299 /// Note: The original string will remain unchanged.
5300 ///
5301 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
5302 #[wasm_bindgen(method, js_class = "String")]
5303 pub fn replace(this: &JsString, pattern: &str, replacement: &str) -> JsString;
5304
5305 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
5306 #[wasm_bindgen(method, js_class = "String", js_name = replace)]
5307 pub fn replace_with_function(
5308 this: &JsString,
5309 pattern: &str,
5310 replacement: &Function,
5311 ) -> JsString;
5312
5313 #[wasm_bindgen(method, js_class = "String", js_name = replace)]
5314 pub fn replace_by_pattern(this: &JsString, pattern: &RegExp, replacement: &str) -> JsString;
5315
5316 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
5317 #[wasm_bindgen(method, js_class = "String", js_name = replace)]
5318 pub fn replace_by_pattern_with_function(
5319 this: &JsString,
5320 pattern: &RegExp,
5321 replacement: &Function,
5322 ) -> JsString;
5323
5324 /// The `replace_all()` method returns a new string with all matches of a pattern
5325 /// replaced by a replacement. The pattern can be a string or a global RegExp, and
5326 /// the replacement can be a string or a function to be called for each match.
5327 ///
5328 /// Note: The original string will remain unchanged.
5329 ///
5330 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)
5331 #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
5332 pub fn replace_all(this: &JsString, pattern: &str, replacement: &str) -> JsString;
5333
5334 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)
5335 #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
5336 pub fn replace_all_with_function(
5337 this: &JsString,
5338 pattern: &str,
5339 replacement: &Function,
5340 ) -> JsString;
5341
5342 #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
5343 pub fn replace_all_by_pattern(this: &JsString, pattern: &RegExp, replacement: &str)
5344 -> JsString;
5345
5346 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)
5347 #[wasm_bindgen(method, js_class = "String", js_name = replaceAll)]
5348 pub fn replace_all_by_pattern_with_function(
5349 this: &JsString,
5350 pattern: &RegExp,
5351 replacement: &Function,
5352 ) -> JsString;
5353
5354 /// The `search()` method executes a search for a match between
5355 /// a regular expression and this String object.
5356 ///
5357 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/search)
5358 #[wasm_bindgen(method, js_class = "String")]
5359 pub fn search(this: &JsString, pattern: &RegExp) -> i32;
5360
5361 /// The `slice()` method extracts a section of a string and returns it as a
5362 /// new string, without modifying the original string.
5363 ///
5364 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice)
5365 #[wasm_bindgen(method, js_class = "String")]
5366 pub fn slice(this: &JsString, start: u32, end: u32) -> JsString;
5367
5368 /// The `split()` method splits a String object into an array of strings by separating the string
5369 /// into substrings, using a specified separator string to determine where to make each split.
5370 ///
5371 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)
5372 #[wasm_bindgen(method, js_class = "String")]
5373 pub fn split(this: &JsString, separator: &str) -> Array;
5374
5375 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)
5376 #[wasm_bindgen(method, js_class = "String", js_name = split)]
5377 pub fn split_limit(this: &JsString, separator: &str, limit: u32) -> Array;
5378
5379 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)
5380 #[wasm_bindgen(method, js_class = "String", js_name = split)]
5381 pub fn split_by_pattern(this: &JsString, pattern: &RegExp) -> Array;
5382
5383 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)
5384 #[wasm_bindgen(method, js_class = "String", js_name = split)]
5385 pub fn split_by_pattern_limit(this: &JsString, pattern: &RegExp, limit: u32) -> Array;
5386
5387 /// The `startsWith()` method determines whether a string begins with the
5388 /// characters of a specified string, returning true or false as
5389 /// appropriate.
5390 ///
5391 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith)
5392 #[wasm_bindgen(method, js_class = "String", js_name = startsWith)]
5393 pub fn starts_with(this: &JsString, search_string: &str, position: u32) -> bool;
5394
5395 /// The `substring()` method returns the part of the string between the
5396 /// start and end indexes, or to the end of the string.
5397 ///
5398 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring)
5399 #[wasm_bindgen(method, js_class = "String")]
5400 pub fn substring(this: &JsString, index_start: u32, index_end: u32) -> JsString;
5401
5402 /// The `substr()` method returns the part of a string between
5403 /// the start index and a number of characters after it.
5404 ///
5405 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr)
5406 #[wasm_bindgen(method, js_class = "String")]
5407 pub fn substr(this: &JsString, start: i32, length: i32) -> JsString;
5408
5409 /// The `toLocaleLowerCase()` method returns the calling string value converted to lower case,
5410 /// according to any locale-specific case mappings.
5411 ///
5412 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLocaleLowerCase)
5413 #[wasm_bindgen(method, js_class = "String", js_name = toLocaleLowerCase)]
5414 pub fn to_locale_lower_case(this: &JsString, locale: Option<&str>) -> JsString;
5415
5416 /// The `toLocaleUpperCase()` method returns the calling string value converted to upper case,
5417 /// according to any locale-specific case mappings.
5418 ///
5419 /// [MDN documentation](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/String/toLocaleUpperCase)
5420 #[wasm_bindgen(method, js_class = "String", js_name = toLocaleUpperCase)]
5421 pub fn to_locale_upper_case(this: &JsString, locale: Option<&str>) -> JsString;
5422
5423 /// The `toLowerCase()` method returns the calling string value
5424 /// converted to lower case.
5425 ///
5426 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLowerCase)
5427 #[wasm_bindgen(method, js_class = "String", js_name = toLowerCase)]
5428 pub fn to_lower_case(this: &JsString) -> JsString;
5429
5430 /// The `toString()` method returns a string representing the specified
5431 /// object.
5432 ///
5433 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toString)
5434 #[wasm_bindgen(method, js_class = "String", js_name = toString)]
5435 pub fn to_string(this: &JsString) -> JsString;
5436
5437 /// The `toUpperCase()` method returns the calling string value converted to
5438 /// uppercase (the value will be converted to a string if it isn't one).
5439 ///
5440 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase)
5441 #[wasm_bindgen(method, js_class = "String", js_name = toUpperCase)]
5442 pub fn to_upper_case(this: &JsString) -> JsString;
5443
5444 /// The `trim()` method removes whitespace from both ends of a string.
5445 /// Whitespace in this context is all the whitespace characters (space, tab,
5446 /// no-break space, etc.) and all the line terminator characters (LF, CR,
5447 /// etc.).
5448 ///
5449 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trim)
5450 #[wasm_bindgen(method, js_class = "String")]
5451 pub fn trim(this: &JsString) -> JsString;
5452
5453 /// The `trimEnd()` method removes whitespace from the end of a string.
5454 /// `trimRight()` is an alias of this method.
5455 ///
5456 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimEnd)
5457 #[wasm_bindgen(method, js_class = "String", js_name = trimEnd)]
5458 pub fn trim_end(this: &JsString) -> JsString;
5459
5460 /// The `trimEnd()` method removes whitespace from the end of a string.
5461 /// `trimRight()` is an alias of this method.
5462 ///
5463 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimEnd)
5464 #[wasm_bindgen(method, js_class = "String", js_name = trimRight)]
5465 pub fn trim_right(this: &JsString) -> JsString;
5466
5467 /// The `trimStart()` method removes whitespace from the beginning of a
5468 /// string. `trimLeft()` is an alias of this method.
5469 ///
5470 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimStart)
5471 #[wasm_bindgen(method, js_class = "String", js_name = trimStart)]
5472 pub fn trim_start(this: &JsString) -> JsString;
5473
5474 /// The `trimStart()` method removes whitespace from the beginning of a
5475 /// string. `trimLeft()` is an alias of this method.
5476 ///
5477 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimStart)
5478 #[wasm_bindgen(method, js_class = "String", js_name = trimLeft)]
5479 pub fn trim_left(this: &JsString) -> JsString;
5480
5481 /// The `valueOf()` method returns the primitive value of a `String` object.
5482 ///
5483 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/valueOf)
5484 #[wasm_bindgen(method, js_class = "String", js_name = valueOf)]
5485 pub fn value_of(this: &JsString) -> JsString;
5486
5487 /// The static `raw()` method is a tag function of template literals,
5488 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
5489 ///
5490 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
5491 #[wasm_bindgen(catch, variadic, static_method_of = JsString, js_class = "String")]
5492 pub fn raw(call_site: &Object, substitutions: &Array) -> Result<JsString, JsValue>;
5493
5494 /// The static `raw()` method is a tag function of template literals,
5495 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
5496 ///
5497 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
5498 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
5499 pub fn raw_0(call_site: &Object) -> Result<JsString, JsValue>;
5500
5501 /// The static `raw()` method is a tag function of template literals,
5502 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
5503 ///
5504 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
5505 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
5506 pub fn raw_1(call_site: &Object, substitutions_1: &str) -> Result<JsString, JsValue>;
5507
5508 /// The static `raw()` method is a tag function of template literals,
5509 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
5510 ///
5511 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
5512 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
5513 pub fn raw_2(
5514 call_site: &Object,
5515 substitutions_1: &str,
5516 substitutions_2: &str,
5517 ) -> Result<JsString, JsValue>;
5518
5519 /// The static `raw()` method is a tag function of template literals,
5520 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
5521 ///
5522 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
5523 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
5524 pub fn raw_3(
5525 call_site: &Object,
5526 substitutions_1: &str,
5527 substitutions_2: &str,
5528 substitutions_3: &str,
5529 ) -> Result<JsString, JsValue>;
5530
5531 /// The static `raw()` method is a tag function of template literals,
5532 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
5533 ///
5534 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
5535 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
5536 pub fn raw_4(
5537 call_site: &Object,
5538 substitutions_1: &str,
5539 substitutions_2: &str,
5540 substitutions_3: &str,
5541 substitutions_4: &str,
5542 ) -> Result<JsString, JsValue>;
5543
5544 /// The static `raw()` method is a tag function of template literals,
5545 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
5546 ///
5547 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
5548 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
5549 pub fn raw_5(
5550 call_site: &Object,
5551 substitutions_1: &str,
5552 substitutions_2: &str,
5553 substitutions_3: &str,
5554 substitutions_4: &str,
5555 substitutions_5: &str,
5556 ) -> Result<JsString, JsValue>;
5557
5558 /// The static `raw()` method is a tag function of template literals,
5559 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
5560 ///
5561 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
5562 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
5563 pub fn raw_6(
5564 call_site: &Object,
5565 substitutions_1: &str,
5566 substitutions_2: &str,
5567 substitutions_3: &str,
5568 substitutions_4: &str,
5569 substitutions_5: &str,
5570 substitutions_6: &str,
5571 ) -> Result<JsString, JsValue>;
5572
5573 /// The static `raw()` method is a tag function of template literals,
5574 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
5575 ///
5576 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
5577 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
5578 pub fn raw_7(
5579 call_site: &Object,
5580 substitutions_1: &str,
5581 substitutions_2: &str,
5582 substitutions_3: &str,
5583 substitutions_4: &str,
5584 substitutions_5: &str,
5585 substitutions_6: &str,
5586 substitutions_7: &str,
5587 ) -> Result<JsString, JsValue>;
5588}
5589
5590impl JsString {
5591 /// Returns the `JsString` value of this JS value if it's an instance of a
5592 /// string.
5593 ///
5594 /// If this JS value is not an instance of a string then this returns
5595 /// `None`.
5596 #[deprecated(note = "recommended to use dyn_ref instead which is now equivalent")]
5597 pub fn try_from(val: &JsValue) -> Option<&JsString> {
5598 val.dyn_ref()
5599 }
5600
5601 /// Returns whether this string is a valid UTF-16 string.
5602 ///
5603 /// This is useful for learning whether `String::from(..)` will return a
5604 /// lossless representation of the JS string. If this string contains
5605 /// unpaired surrogates then `String::from` will succeed but it will be a
5606 /// lossy representation of the JS string because unpaired surrogates will
5607 /// become replacement characters.
5608 ///
5609 /// If this function returns `false` then to get a lossless representation
5610 /// of the string you'll need to manually use the `iter` method (or the
5611 /// `char_code_at` accessor) to view the raw character codes.
5612 ///
5613 /// For more information, see the documentation on [JS strings vs Rust
5614 /// strings][docs]
5615 ///
5616 /// [docs]: https://wasm-bindgen.github.io/wasm-bindgen/reference/types/str.html
5617 pub fn is_valid_utf16(&self) -> bool {
5618 core::char::decode_utf16(self.iter()).all(|i| i.is_ok())
5619 }
5620
5621 /// Returns an iterator over the `u16` character codes that make up this JS
5622 /// string.
5623 ///
5624 /// This method will call `char_code_at` for each code in this JS string,
5625 /// returning an iterator of the codes in sequence.
5626 pub fn iter(
5627 &self,
5628 ) -> impl ExactSizeIterator<Item = u16> + DoubleEndedIterator<Item = u16> + '_ {
5629 (0..self.length()).map(move |i| self.char_code_at(i) as u16)
5630 }
5631
5632 /// If this string consists of a single Unicode code point, then this method
5633 /// converts it into a Rust `char` without doing any allocations.
5634 ///
5635 /// If this JS value is not a valid UTF-8 or consists of more than a single
5636 /// codepoint, then this returns `None`.
5637 ///
5638 /// Note that a single Unicode code point might be represented as more than
5639 /// one code unit on the JavaScript side. For example, a JavaScript string
5640 /// `"\uD801\uDC37"` is actually a single Unicode code point U+10437 which
5641 /// corresponds to a character '𐐷'.
5642 pub fn as_char(&self) -> Option<char> {
5643 let len = self.length();
5644
5645 if len == 0 || len > 2 {
5646 return None;
5647 }
5648
5649 // This will be simplified when definitions are fixed:
5650 // https://github.com/wasm-bindgen/wasm-bindgen/issues/1362
5651 let cp = self.code_point_at(0).as_f64().unwrap_throw() as u32;
5652
5653 let c = core::char::from_u32(cp)?;
5654
5655 if c.len_utf16() as u32 == len {
5656 Some(c)
5657 } else {
5658 None
5659 }
5660 }
5661}
5662
5663impl PartialEq<str> for JsString {
5664 #[allow(clippy::cmp_owned)] // prevent infinite recursion
5665 fn eq(&self, other: &str) -> bool {
5666 String::from(self) == other
5667 }
5668}
5669
5670impl<'a> PartialEq<&'a str> for JsString {
5671 fn eq(&self, other: &&'a str) -> bool {
5672 <JsString as PartialEq<str>>::eq(self, other)
5673 }
5674}
5675
5676impl PartialEq<String> for JsString {
5677 fn eq(&self, other: &String) -> bool {
5678 <JsString as PartialEq<str>>::eq(self, other)
5679 }
5680}
5681
5682impl<'a> PartialEq<&'a String> for JsString {
5683 fn eq(&self, other: &&'a String) -> bool {
5684 <JsString as PartialEq<str>>::eq(self, other)
5685 }
5686}
5687
5688impl<'a> From<&'a str> for JsString {
5689 fn from(s: &'a str) -> Self {
5690 JsString::unchecked_from_js(JsValue::from_str(s))
5691 }
5692}
5693
5694impl From<String> for JsString {
5695 fn from(s: String) -> Self {
5696 From::from(&*s)
5697 }
5698}
5699
5700impl From<char> for JsString {
5701 #[inline]
5702 fn from(c: char) -> Self {
5703 JsString::from_code_point1(c as u32).unwrap_throw()
5704 }
5705}
5706
5707impl<'a> From<&'a JsString> for String {
5708 fn from(s: &'a JsString) -> Self {
5709 s.obj.as_string().unwrap_throw()
5710 }
5711}
5712
5713impl From<JsString> for String {
5714 fn from(s: JsString) -> Self {
5715 From::from(&s)
5716 }
5717}
5718
5719impl fmt::Debug for JsString {
5720 #[inline]
5721 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5722 fmt::Debug::fmt(&String::from(self), f)
5723 }
5724}
5725
5726impl fmt::Display for JsString {
5727 #[inline]
5728 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5729 fmt::Display::fmt(&String::from(self), f)
5730 }
5731}
5732
5733impl str::FromStr for JsString {
5734 type Err = convert::Infallible;
5735 fn from_str(s: &str) -> Result<Self, Self::Err> {
5736 Ok(JsString::from(s))
5737 }
5738}
5739
5740// Symbol
5741#[wasm_bindgen]
5742extern "C" {
5743 #[wasm_bindgen(is_type_of = JsValue::is_symbol, typescript_type = "Symbol")]
5744 #[derive(Clone, Debug)]
5745 pub type Symbol;
5746
5747 /// The `Symbol.hasInstance` well-known symbol is used to determine
5748 /// if a constructor object recognizes an object as its instance.
5749 /// The `instanceof` operator's behavior can be customized by this symbol.
5750 ///
5751 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/hasInstance)
5752 #[wasm_bindgen(static_method_of = Symbol, getter, structural, js_name = hasInstance)]
5753 pub fn has_instance() -> Symbol;
5754
5755 /// The `Symbol.isConcatSpreadable` well-known symbol is used to configure
5756 /// if an object should be flattened to its array elements when using the
5757 /// `Array.prototype.concat()` method.
5758 ///
5759 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/isConcatSpreadable)
5760 #[wasm_bindgen(static_method_of = Symbol, getter, structural, js_name = isConcatSpreadable)]
5761 pub fn is_concat_spreadable() -> Symbol;
5762
5763 /// The `Symbol.asyncIterator` well-known symbol specifies the default AsyncIterator for an object.
5764 /// If this property is set on an object, it is an async iterable and can be used in a `for await...of` loop.
5765 ///
5766 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/asyncIterator)
5767 #[wasm_bindgen(static_method_of = Symbol, getter, structural, js_name = asyncIterator)]
5768 pub fn async_iterator() -> Symbol;
5769
5770 /// The `Symbol.iterator` well-known symbol specifies the default iterator
5771 /// for an object. Used by `for...of`.
5772 ///
5773 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/iterator)
5774 #[wasm_bindgen(static_method_of = Symbol, getter, structural)]
5775 pub fn iterator() -> Symbol;
5776
5777 /// The `Symbol.match` well-known symbol specifies the matching of a regular
5778 /// expression against a string. This function is called by the
5779 /// `String.prototype.match()` method.
5780 ///
5781 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/match)
5782 #[wasm_bindgen(static_method_of = Symbol, getter, structural, js_name = match)]
5783 pub fn match_() -> Symbol;
5784
5785 /// The `Symbol.replace` well-known symbol specifies the method that
5786 /// replaces matched substrings of a string. This function is called by the
5787 /// `String.prototype.replace()` method.
5788 ///
5789 /// For more information, see `RegExp.prototype[@@replace]()` and
5790 /// `String.prototype.replace()`.
5791 ///
5792 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/replace)
5793 #[wasm_bindgen(static_method_of = Symbol, getter, structural)]
5794 pub fn replace() -> Symbol;
5795
5796 /// The `Symbol.search` well-known symbol specifies the method that returns
5797 /// the index within a string that matches the regular expression. This
5798 /// function is called by the `String.prototype.search()` method.
5799 ///
5800 /// For more information, see `RegExp.prototype[@@search]()` and
5801 /// `String.prototype.search()`.
5802 ///
5803 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/search)
5804 #[wasm_bindgen(static_method_of = Symbol, getter, structural)]
5805 pub fn search() -> Symbol;
5806
5807 /// The well-known symbol `Symbol.species` specifies a function-valued
5808 /// property that the constructor function uses to create derived objects.
5809 ///
5810 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/species)
5811 #[wasm_bindgen(static_method_of = Symbol, getter, structural)]
5812 pub fn species() -> Symbol;
5813
5814 /// The `Symbol.split` well-known symbol specifies the method that splits a
5815 /// string at the indices that match a regular expression. This function is
5816 /// called by the `String.prototype.split()` method.
5817 ///
5818 /// For more information, see `RegExp.prototype[@@split]()` and
5819 /// `String.prototype.split()`.
5820 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/split)
5821 #[wasm_bindgen(static_method_of = Symbol, getter, structural)]
5822 pub fn split() -> Symbol;
5823
5824 /// The `Symbol.toPrimitive` is a symbol that specifies a function valued
5825 /// property that is called to convert an object to a corresponding
5826 /// primitive value.
5827 ///
5828 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toPrimitive)
5829 #[wasm_bindgen(static_method_of = Symbol, getter, structural, js_name = toPrimitive)]
5830 pub fn to_primitive() -> Symbol;
5831
5832 /// The `Symbol.toStringTag` well-known symbol is a string valued property
5833 /// that is used in the creation of the default string description of an
5834 /// object. It is accessed internally by the `Object.prototype.toString()`
5835 /// method.
5836 ///
5837 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toString)
5838 #[wasm_bindgen(static_method_of = Symbol, getter, structural, js_name = toStringTag)]
5839 pub fn to_string_tag() -> Symbol;
5840
5841 /// The `Symbol.for(key)` method searches for existing symbols in a runtime-wide symbol registry with
5842 /// the given key and returns it if found.
5843 /// Otherwise a new symbol gets created in the global symbol registry with this key.
5844 ///
5845 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/for)
5846 #[wasm_bindgen(static_method_of = Symbol, js_name = for)]
5847 pub fn for_(key: &str) -> Symbol;
5848
5849 /// The `Symbol.keyFor(sym)` method retrieves a shared symbol key from the global symbol registry for the given symbol.
5850 ///
5851 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/keyFor)
5852 #[wasm_bindgen(static_method_of = Symbol, js_name = keyFor)]
5853 pub fn key_for(sym: &Symbol) -> JsValue;
5854
5855 /// The `toString()` method returns a string representing the specified Symbol object.
5856 ///
5857 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toString)
5858 #[wasm_bindgen(method, js_name = toString)]
5859 pub fn to_string(this: &Symbol) -> JsString;
5860
5861 /// The `Symbol.unscopables` well-known symbol is used to specify an object
5862 /// value of whose own and inherited property names are excluded from the
5863 /// with environment bindings of the associated object.
5864 ///
5865 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/unscopables)
5866 #[wasm_bindgen(static_method_of = Symbol, getter, structural)]
5867 pub fn unscopables() -> Symbol;
5868
5869 /// The `valueOf()` method returns the primitive value of a Symbol object.
5870 ///
5871 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/valueOf)
5872 #[wasm_bindgen(method, js_name = valueOf)]
5873 pub fn value_of(this: &Symbol) -> Symbol;
5874}
5875
5876#[allow(non_snake_case)]
5877pub mod Intl {
5878 use super::*;
5879
5880 // Intl
5881 #[wasm_bindgen]
5882 extern "C" {
5883 /// The `Intl.getCanonicalLocales()` method returns an array containing
5884 /// the canonical locale names. Duplicates will be omitted and elements
5885 /// will be validated as structurally valid language tags.
5886 ///
5887 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/getCanonicalLocales)
5888 #[wasm_bindgen(js_name = getCanonicalLocales, js_namespace = Intl)]
5889 pub fn get_canonical_locales(s: &JsValue) -> Array;
5890 }
5891
5892 // Intl.Collator
5893 #[wasm_bindgen]
5894 extern "C" {
5895 /// The `Intl.Collator` object is a constructor for collators, objects
5896 /// that enable language sensitive string comparison.
5897 ///
5898 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator)
5899 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.Collator")]
5900 #[derive(Clone, Debug)]
5901 pub type Collator;
5902
5903 /// The `Intl.Collator` object is a constructor for collators, objects
5904 /// that enable language sensitive string comparison.
5905 ///
5906 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator)
5907 #[wasm_bindgen(constructor, js_namespace = Intl)]
5908 pub fn new(locales: &Array, options: &Object) -> Collator;
5909
5910 /// The Intl.Collator.prototype.compare property returns a function that
5911 /// compares two strings according to the sort order of this Collator
5912 /// object.
5913 ///
5914 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/compare)
5915 #[wasm_bindgen(method, getter, js_class = "Intl.Collator")]
5916 pub fn compare(this: &Collator) -> Function;
5917
5918 /// The `Intl.Collator.prototype.resolvedOptions()` method returns a new
5919 /// object with properties reflecting the locale and collation options
5920 /// computed during initialization of this Collator object.
5921 ///
5922 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/resolvedOptions)
5923 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
5924 pub fn resolved_options(this: &Collator) -> Object;
5925
5926 /// The `Intl.Collator.supportedLocalesOf()` method returns an array
5927 /// containing those of the provided locales that are supported in
5928 /// collation without having to fall back to the runtime's default
5929 /// locale.
5930 ///
5931 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/supportedLocalesOf)
5932 #[wasm_bindgen(static_method_of = Collator, js_namespace = Intl, js_name = supportedLocalesOf)]
5933 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
5934 }
5935
5936 impl Default for Collator {
5937 fn default() -> Self {
5938 Self::new(
5939 &JsValue::UNDEFINED.unchecked_into(),
5940 &JsValue::UNDEFINED.unchecked_into(),
5941 )
5942 }
5943 }
5944
5945 // Intl.DateTimeFormat
5946 #[wasm_bindgen]
5947 extern "C" {
5948 /// The `Intl.DateTimeFormat` object is a constructor for objects
5949 /// that enable language-sensitive date and time formatting.
5950 ///
5951 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat)
5952 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.DateTimeFormat")]
5953 #[derive(Clone, Debug)]
5954 pub type DateTimeFormat;
5955
5956 /// The `Intl.DateTimeFormat` object is a constructor for objects
5957 /// that enable language-sensitive date and time formatting.
5958 ///
5959 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat)
5960 #[wasm_bindgen(constructor, js_namespace = Intl)]
5961 pub fn new(locales: &Array, options: &Object) -> DateTimeFormat;
5962
5963 /// The Intl.DateTimeFormat.prototype.format property returns a getter function that
5964 /// formats a date according to the locale and formatting options of this
5965 /// Intl.DateTimeFormat object.
5966 ///
5967 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/format)
5968 #[wasm_bindgen(method, getter, js_class = "Intl.DateTimeFormat")]
5969 pub fn format(this: &DateTimeFormat) -> Function;
5970
5971 /// The `Intl.DateTimeFormat.prototype.formatToParts()` method allows locale-aware
5972 /// formatting of strings produced by DateTimeFormat formatters.
5973 ///
5974 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/formatToParts)
5975 #[wasm_bindgen(method, js_class = "Intl.DateTimeFormat", js_name = formatToParts)]
5976 pub fn format_to_parts(this: &DateTimeFormat, date: &Date) -> Array;
5977
5978 /// The `Intl.DateTimeFormat.prototype.resolvedOptions()` method returns a new
5979 /// object with properties reflecting the locale and date and time formatting
5980 /// options computed during initialization of this DateTimeFormat object.
5981 ///
5982 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/resolvedOptions)
5983 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
5984 pub fn resolved_options(this: &DateTimeFormat) -> Object;
5985
5986 /// The `Intl.DateTimeFormat.supportedLocalesOf()` method returns an array
5987 /// containing those of the provided locales that are supported in date
5988 /// and time formatting without having to fall back to the runtime's default
5989 /// locale.
5990 ///
5991 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/supportedLocalesOf)
5992 #[wasm_bindgen(static_method_of = DateTimeFormat, js_namespace = Intl, js_name = supportedLocalesOf)]
5993 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
5994 }
5995
5996 impl Default for DateTimeFormat {
5997 fn default() -> Self {
5998 Self::new(
5999 &JsValue::UNDEFINED.unchecked_into(),
6000 &JsValue::UNDEFINED.unchecked_into(),
6001 )
6002 }
6003 }
6004
6005 // Intl.NumberFormat
6006 #[wasm_bindgen]
6007 extern "C" {
6008 /// The `Intl.NumberFormat` object is a constructor for objects
6009 /// that enable language sensitive number formatting.
6010 ///
6011 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat)
6012 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.NumberFormat")]
6013 #[derive(Clone, Debug)]
6014 pub type NumberFormat;
6015
6016 /// The `Intl.NumberFormat` object is a constructor for objects
6017 /// that enable language sensitive number formatting.
6018 ///
6019 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat)
6020 #[wasm_bindgen(constructor, js_namespace = Intl)]
6021 pub fn new(locales: &Array, options: &Object) -> NumberFormat;
6022
6023 /// The Intl.NumberFormat.prototype.format property returns a getter function that
6024 /// formats a number according to the locale and formatting options of this
6025 /// NumberFormat object.
6026 ///
6027 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/format)
6028 #[wasm_bindgen(method, getter, js_class = "Intl.NumberFormat")]
6029 pub fn format(this: &NumberFormat) -> Function;
6030
6031 /// The `Intl.Numberformat.prototype.formatToParts()` method allows locale-aware
6032 /// formatting of strings produced by NumberTimeFormat formatters.
6033 ///
6034 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/formatToParts)
6035 #[wasm_bindgen(method, js_class = "Intl.NumberFormat", js_name = formatToParts)]
6036 pub fn format_to_parts(this: &NumberFormat, number: f64) -> Array;
6037
6038 /// The `Intl.NumberFormat.prototype.resolvedOptions()` method returns a new
6039 /// object with properties reflecting the locale and number formatting
6040 /// options computed during initialization of this NumberFormat object.
6041 ///
6042 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/resolvedOptions)
6043 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
6044 pub fn resolved_options(this: &NumberFormat) -> Object;
6045
6046 /// The `Intl.NumberFormat.supportedLocalesOf()` method returns an array
6047 /// containing those of the provided locales that are supported in number
6048 /// formatting without having to fall back to the runtime's default locale.
6049 ///
6050 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/supportedLocalesOf)
6051 #[wasm_bindgen(static_method_of = NumberFormat, js_namespace = Intl, js_name = supportedLocalesOf)]
6052 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
6053 }
6054
6055 impl Default for NumberFormat {
6056 fn default() -> Self {
6057 Self::new(
6058 &JsValue::UNDEFINED.unchecked_into(),
6059 &JsValue::UNDEFINED.unchecked_into(),
6060 )
6061 }
6062 }
6063
6064 // Intl.PluralRules
6065 #[wasm_bindgen]
6066 extern "C" {
6067 /// The `Intl.PluralRules` object is a constructor for objects
6068 /// that enable plural sensitive formatting and plural language rules.
6069 ///
6070 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules)
6071 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.PluralRules")]
6072 #[derive(Clone, Debug)]
6073 pub type PluralRules;
6074
6075 /// The `Intl.PluralRules` object is a constructor for objects
6076 /// that enable plural sensitive formatting and plural language rules.
6077 ///
6078 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules)
6079 #[wasm_bindgen(constructor, js_namespace = Intl)]
6080 pub fn new(locales: &Array, options: &Object) -> PluralRules;
6081
6082 /// The `Intl.PluralRules.prototype.resolvedOptions()` method returns a new
6083 /// object with properties reflecting the locale and plural formatting
6084 /// options computed during initialization of this PluralRules object.
6085 ///
6086 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/resolvedOptions)
6087 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
6088 pub fn resolved_options(this: &PluralRules) -> Object;
6089
6090 /// The `Intl.PluralRules.prototype.select()` method returns a String indicating
6091 /// which plural rule to use for locale-aware formatting.
6092 ///
6093 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/select)
6094 #[wasm_bindgen(method, js_namespace = Intl)]
6095 pub fn select(this: &PluralRules, number: f64) -> JsString;
6096
6097 /// The `Intl.PluralRules.supportedLocalesOf()` method returns an array
6098 /// containing those of the provided locales that are supported in plural
6099 /// formatting without having to fall back to the runtime's default locale.
6100 ///
6101 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/supportedLocalesOf)
6102 #[wasm_bindgen(static_method_of = PluralRules, js_namespace = Intl, js_name = supportedLocalesOf)]
6103 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
6104 }
6105
6106 impl Default for PluralRules {
6107 fn default() -> Self {
6108 Self::new(
6109 &JsValue::UNDEFINED.unchecked_into(),
6110 &JsValue::UNDEFINED.unchecked_into(),
6111 )
6112 }
6113 }
6114
6115 // Intl.RelativeTimeFormat
6116 #[wasm_bindgen]
6117 extern "C" {
6118 /// The `Intl.RelativeTimeFormat` object is a constructor for objects
6119 /// that enable language-sensitive relative time formatting.
6120 ///
6121 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat)
6122 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.RelativeTimeFormat")]
6123 #[derive(Clone, Debug)]
6124 pub type RelativeTimeFormat;
6125
6126 /// The `Intl.RelativeTimeFormat` object is a constructor for objects
6127 /// that enable language-sensitive relative time formatting.
6128 ///
6129 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat)
6130 #[wasm_bindgen(constructor, js_namespace = Intl)]
6131 pub fn new(locales: &Array, options: &Object) -> RelativeTimeFormat;
6132
6133 /// The `Intl.RelativeTimeFormat.prototype.format` method formats a `value` and `unit`
6134 /// according to the locale and formatting options of this Intl.RelativeTimeFormat object.
6135 ///
6136 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/format)
6137 #[wasm_bindgen(method, js_class = "Intl.RelativeTimeFormat")]
6138 pub fn format(this: &RelativeTimeFormat, value: f64, unit: &str) -> JsString;
6139
6140 /// The `Intl.RelativeTimeFormat.prototype.formatToParts()` method returns an array of
6141 /// objects representing the relative time format in parts that can be used for custom locale-aware formatting.
6142 ///
6143 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/formatToParts)
6144 #[wasm_bindgen(method, js_class = "Intl.RelativeTimeFormat", js_name = formatToParts)]
6145 pub fn format_to_parts(this: &RelativeTimeFormat, value: f64, unit: &str) -> Array;
6146
6147 /// The `Intl.RelativeTimeFormat.prototype.resolvedOptions()` method returns a new
6148 /// object with properties reflecting the locale and relative time formatting
6149 /// options computed during initialization of this RelativeTimeFormat object.
6150 ///
6151 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/resolvedOptions)
6152 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
6153 pub fn resolved_options(this: &RelativeTimeFormat) -> Object;
6154
6155 /// The `Intl.RelativeTimeFormat.supportedLocalesOf()` method returns an array
6156 /// containing those of the provided locales that are supported in date and time
6157 /// formatting without having to fall back to the runtime's default locale.
6158 ///
6159 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RelativeTimeFormat/supportedLocalesOf)
6160 #[wasm_bindgen(static_method_of = RelativeTimeFormat, js_namespace = Intl, js_name = supportedLocalesOf)]
6161 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
6162 }
6163
6164 impl Default for RelativeTimeFormat {
6165 fn default() -> Self {
6166 Self::new(
6167 &JsValue::UNDEFINED.unchecked_into(),
6168 &JsValue::UNDEFINED.unchecked_into(),
6169 )
6170 }
6171 }
6172}
6173
6174// Promise
6175#[wasm_bindgen]
6176extern "C" {
6177 /// The `Promise` object represents the eventual completion (or failure) of
6178 /// an asynchronous operation, and its resulting value.
6179 ///
6180 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
6181 #[must_use]
6182 #[wasm_bindgen(extends = Object, typescript_type = "Promise<any>")]
6183 #[derive(Clone, Debug)]
6184 pub type Promise;
6185
6186 /// Creates a new `Promise` with the provided executor `cb`
6187 ///
6188 /// The `cb` is a function that is passed with the arguments `resolve` and
6189 /// `reject`. The `cb` function is executed immediately by the `Promise`
6190 /// implementation, passing `resolve` and `reject` functions (the executor
6191 /// is called before the `Promise` constructor even returns the created
6192 /// object). The `resolve` and `reject` functions, when called, resolve or
6193 /// reject the promise, respectively. The executor normally initiates
6194 /// some asynchronous work, and then, once that completes, either calls
6195 /// the `resolve` function to resolve the promise or else rejects it if an
6196 /// error occurred.
6197 ///
6198 /// If an error is thrown in the executor function, the promise is rejected.
6199 /// The return value of the executor is ignored.
6200 ///
6201 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
6202 #[wasm_bindgen(constructor)]
6203 pub fn new(cb: &mut dyn FnMut(Function, Function)) -> Promise;
6204
6205 /// The `Promise.all(iterable)` method returns a single `Promise` that
6206 /// resolves when all of the promises in the iterable argument have resolved
6207 /// or when the iterable argument contains no promises. It rejects with the
6208 /// reason of the first promise that rejects.
6209 ///
6210 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all)
6211 #[wasm_bindgen(static_method_of = Promise)]
6212 pub fn all(obj: &JsValue) -> Promise;
6213
6214 /// The `Promise.allSettled(iterable)` method returns a single `Promise` that
6215 /// resolves when all of the promises in the iterable argument have either
6216 /// fulfilled or rejected or when the iterable argument contains no promises.
6217 ///
6218 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled)
6219 #[wasm_bindgen(static_method_of = Promise, js_name = allSettled)]
6220 pub fn all_settled(obj: &JsValue) -> Promise;
6221
6222 /// The `Promise.any(iterable)` method returns a single `Promise` that
6223 /// resolves when any of the promises in the iterable argument have resolved
6224 /// or when the iterable argument contains no promises. It rejects with an
6225 /// `AggregateError` if all promises in the iterable rejected.
6226 ///
6227 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/any)
6228 #[wasm_bindgen(static_method_of = Promise)]
6229 pub fn any(obj: &JsValue) -> Promise;
6230
6231 /// The `Promise.race(iterable)` method returns a promise that resolves or
6232 /// rejects as soon as one of the promises in the iterable resolves or
6233 /// rejects, with the value or reason from that promise.
6234 ///
6235 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/race)
6236 #[wasm_bindgen(static_method_of = Promise)]
6237 pub fn race(obj: &JsValue) -> Promise;
6238
6239 /// The `Promise.reject(reason)` method returns a `Promise` object that is
6240 /// rejected with the given reason.
6241 ///
6242 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/reject)
6243 #[wasm_bindgen(static_method_of = Promise)]
6244 pub fn reject(obj: &JsValue) -> Promise;
6245
6246 /// The `Promise.resolve(value)` method returns a `Promise` object that is
6247 /// resolved with the given value. If the value is a promise, that promise
6248 /// is returned; if the value is a thenable (i.e. has a "then" method), the
6249 /// returned promise will "follow" that thenable, adopting its eventual
6250 /// state; otherwise the returned promise will be fulfilled with the value.
6251 ///
6252 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/resolve)
6253 #[wasm_bindgen(static_method_of = Promise)]
6254 pub fn resolve(obj: &JsValue) -> Promise;
6255
6256 /// The `catch()` method returns a `Promise` and deals with rejected cases
6257 /// only. It behaves the same as calling `Promise.prototype.then(undefined,
6258 /// onRejected)` (in fact, calling `obj.catch(onRejected)` internally calls
6259 /// `obj.then(undefined, onRejected)`).
6260 ///
6261 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch)
6262 #[wasm_bindgen(method)]
6263 pub fn catch(this: &Promise, cb: &Closure<dyn FnMut(JsValue)>) -> Promise;
6264
6265 /// The `then()` method returns a `Promise`. It takes up to two arguments:
6266 /// callback functions for the success and failure cases of the `Promise`.
6267 ///
6268 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then)
6269 #[wasm_bindgen(method)]
6270 pub fn then(this: &Promise, cb: &Closure<dyn FnMut(JsValue)>) -> Promise;
6271
6272 /// Same as `then`, only with both arguments provided.
6273 #[wasm_bindgen(method, js_name = then)]
6274 pub fn then2(
6275 this: &Promise,
6276 resolve: &Closure<dyn FnMut(JsValue)>,
6277 reject: &Closure<dyn FnMut(JsValue)>,
6278 ) -> Promise;
6279
6280 /// The `finally()` method returns a `Promise`. When the promise is settled,
6281 /// whether fulfilled or rejected, the specified callback function is
6282 /// executed. This provides a way for code that must be executed once the
6283 /// `Promise` has been dealt with to be run whether the promise was
6284 /// fulfilled successfully or rejected.
6285 ///
6286 /// This lets you avoid duplicating code in both the promise's `then()` and
6287 /// `catch()` handlers.
6288 ///
6289 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/finally)
6290 #[wasm_bindgen(method)]
6291 pub fn finally(this: &Promise, cb: &Closure<dyn FnMut()>) -> Promise;
6292}
6293
6294/// Returns a handle to the global scope object.
6295///
6296/// This allows access to the global properties and global names by accessing
6297/// the `Object` returned.
6298pub fn global() -> Object {
6299 use once_cell::unsync::Lazy;
6300
6301 struct Wrapper<T>(Lazy<T>);
6302
6303 #[cfg(not(target_feature = "atomics"))]
6304 unsafe impl<T> Sync for Wrapper<T> {}
6305
6306 #[cfg(not(target_feature = "atomics"))]
6307 unsafe impl<T> Send for Wrapper<T> {}
6308
6309 #[cfg_attr(target_feature = "atomics", thread_local)]
6310 static GLOBAL: Wrapper<Object> = Wrapper(Lazy::new(get_global_object));
6311
6312 return GLOBAL.0.clone();
6313
6314 fn get_global_object() -> Object {
6315 // Accessing the global object is not an easy thing to do, and what we
6316 // basically want is `globalThis` but we can't rely on that existing
6317 // everywhere. In the meantime we've got the fallbacks mentioned in:
6318 //
6319 // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis
6320 //
6321 // Note that this is pretty heavy code-size wise but it at least gets
6322 // the job largely done for now and avoids the `Function` constructor at
6323 // the end which triggers CSP errors.
6324 #[wasm_bindgen]
6325 extern "C" {
6326 type Global;
6327
6328 #[wasm_bindgen(thread_local_v2, js_name = globalThis)]
6329 static GLOBAL_THIS: Option<Object>;
6330
6331 #[wasm_bindgen(thread_local_v2, js_name = self)]
6332 static SELF: Option<Object>;
6333
6334 #[wasm_bindgen(thread_local_v2, js_name = window)]
6335 static WINDOW: Option<Object>;
6336
6337 #[wasm_bindgen(thread_local_v2, js_name = global)]
6338 static GLOBAL: Option<Object>;
6339 }
6340
6341 // The order is important: in Firefox Extension Content Scripts `globalThis`
6342 // is a Sandbox (not Window), so `globalThis` must be checked after `window`.
6343 let static_object = SELF
6344 .with(Option::clone)
6345 .or_else(|| WINDOW.with(Option::clone))
6346 .or_else(|| GLOBAL_THIS.with(Option::clone))
6347 .or_else(|| GLOBAL.with(Option::clone));
6348 if let Some(obj) = static_object {
6349 if !obj.is_undefined() {
6350 return obj;
6351 }
6352 }
6353
6354 // According to StackOverflow you can access the global object via:
6355 //
6356 // const global = Function('return this')();
6357 //
6358 // I think that's because the manufactured function isn't in "strict" mode.
6359 // It also turns out that non-strict functions will ignore `undefined`
6360 // values for `this` when using the `apply` function.
6361 //
6362 // As a result we use the equivalent of this snippet to get a handle to the
6363 // global object in a sort of roundabout way that should hopefully work in
6364 // all contexts like ESM, node, browsers, etc.
6365 let this = Function::new_no_args("return this")
6366 .call0(&JsValue::undefined())
6367 .ok();
6368
6369 // Note that we avoid `unwrap()` on `call0` to avoid code size bloat, we
6370 // just handle the `Err` case as returning a different object.
6371 debug_assert!(this.is_some());
6372 match this {
6373 Some(this) => this.unchecked_into(),
6374 None => JsValue::undefined().unchecked_into(),
6375 }
6376 }
6377}
6378
6379macro_rules! arrays {
6380 ($(#[doc = $ctor:literal] #[doc = $mdn:literal] $name:ident: $ty:ident,)*) => ($(
6381 #[wasm_bindgen]
6382 extern "C" {
6383 #[wasm_bindgen(extends = Object, typescript_type = $name)]
6384 #[derive(Clone, Debug)]
6385 pub type $name;
6386
6387 /// The
6388 #[doc = $ctor]
6389 /// constructor creates a new array.
6390 ///
6391 /// [MDN documentation](
6392 #[doc = $mdn]
6393 /// )
6394 #[wasm_bindgen(constructor)]
6395 pub fn new(constructor_arg: &JsValue) -> $name;
6396
6397 /// An
6398 #[doc = $ctor]
6399 /// which creates an array with an internal buffer large
6400 /// enough for `length` elements.
6401 ///
6402 /// [MDN documentation](
6403 #[doc = $mdn]
6404 /// )
6405 #[wasm_bindgen(constructor)]
6406 pub fn new_with_length(length: u32) -> $name;
6407
6408 /// An
6409 #[doc = $ctor]
6410 /// which creates an array from a Rust slice.
6411 ///
6412 /// [MDN documentation](
6413 #[doc = $mdn]
6414 /// )
6415 #[wasm_bindgen(constructor)]
6416 pub fn new_from_slice(slice: &[$ty]) -> $name;
6417
6418 /// An
6419 #[doc = $ctor]
6420 /// which creates an array with the given buffer but is a
6421 /// view starting at `byte_offset`.
6422 ///
6423 /// [MDN documentation](
6424 #[doc = $mdn]
6425 /// )
6426 #[wasm_bindgen(constructor)]
6427 pub fn new_with_byte_offset(buffer: &JsValue, byte_offset: u32) -> $name;
6428
6429 /// An
6430 #[doc = $ctor]
6431 /// which creates an array with the given buffer but is a
6432 /// view starting at `byte_offset` for `length` elements.
6433 ///
6434 /// [MDN documentation](
6435 #[doc = $mdn]
6436 /// )
6437 #[wasm_bindgen(constructor)]
6438 pub fn new_with_byte_offset_and_length(
6439 buffer: &JsValue,
6440 byte_offset: u32,
6441 length: u32,
6442 ) -> $name;
6443
6444 /// The `fill()` method fills all the elements of an array from a start index
6445 /// to an end index with a static value. The end index is not included.
6446 ///
6447 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/fill)
6448 #[wasm_bindgen(method)]
6449 pub fn fill(this: &$name, value: $ty, start: u32, end: u32) -> $name;
6450
6451 /// The buffer accessor property represents the `ArrayBuffer` referenced
6452 /// by a `TypedArray` at construction time.
6453 #[wasm_bindgen(getter, method)]
6454 pub fn buffer(this: &$name) -> ArrayBuffer;
6455
6456 /// The `subarray()` method returns a new `TypedArray` on the same
6457 /// `ArrayBuffer` store and with the same element types as for this
6458 /// `TypedArray` object.
6459 #[wasm_bindgen(method)]
6460 pub fn subarray(this: &$name, begin: u32, end: u32) -> $name;
6461
6462 /// The `slice()` method returns a shallow copy of a portion of a typed
6463 /// array into a new typed array object. This method has the same algorithm
6464 /// as `Array.prototype.slice()`.
6465 #[wasm_bindgen(method)]
6466 pub fn slice(this: &$name, begin: u32, end: u32) -> $name;
6467
6468 /// The `forEach()` method executes a provided function once per array
6469 /// element. This method has the same algorithm as
6470 /// `Array.prototype.forEach()`. `TypedArray` is one of the typed array
6471 /// types here.
6472 #[wasm_bindgen(method, js_name = forEach)]
6473 pub fn for_each(this: &$name, callback: &mut dyn FnMut($ty, u32, $name));
6474
6475 /// The length accessor property represents the length (in elements) of a
6476 /// typed array.
6477 #[wasm_bindgen(method, getter)]
6478 pub fn length(this: &$name) -> u32;
6479
6480 /// The byteLength accessor property represents the length (in bytes) of a
6481 /// typed array.
6482 #[wasm_bindgen(method, getter, js_name = byteLength)]
6483 pub fn byte_length(this: &$name) -> u32;
6484
6485 /// The byteOffset accessor property represents the offset (in bytes) of a
6486 /// typed array from the start of its `ArrayBuffer`.
6487 #[wasm_bindgen(method, getter, js_name = byteOffset)]
6488 pub fn byte_offset(this: &$name) -> u32;
6489
6490 /// The `set()` method stores multiple values in the typed array, reading
6491 /// input values from a specified array.
6492 #[wasm_bindgen(method)]
6493 pub fn set(this: &$name, src: &JsValue, offset: u32);
6494
6495 /// Gets the value at `idx`, counting from the end if negative.
6496 #[wasm_bindgen(method)]
6497 pub fn at(this: &$name, idx: i32) -> Option<$ty>;
6498
6499 /// The `copyWithin()` method shallow copies part of a typed array to another
6500 /// location in the same typed array and returns it, without modifying its size.
6501 ///
6502 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin)
6503 #[wasm_bindgen(method, js_name = copyWithin)]
6504 pub fn copy_within(this: &$name, target: i32, start: i32, end: i32) -> $name;
6505
6506 /// Gets the value at `idx`, equivalent to the javascript `my_var = arr[idx]`.
6507 #[wasm_bindgen(method, structural, indexing_getter)]
6508 pub fn get_index(this: &$name, idx: u32) -> $ty;
6509
6510 /// Sets the value at `idx`, equivalent to the javascript `arr[idx] = value`.
6511 #[wasm_bindgen(method, structural, indexing_setter)]
6512 pub fn set_index(this: &$name, idx: u32, value: $ty);
6513
6514 /// Copies the Rust slice's data to self.
6515 ///
6516 /// This method is not expected to be public. It requires the length of the
6517 /// TypedArray to be the same as the slice, use `self.copy_from(slice)` instead.
6518 #[wasm_bindgen(method, js_name = set)]
6519 fn copy_from_slice(this: &$name, slice: &[$ty]);
6520
6521 /// Copies this TypedArray's data to Rust slice;
6522 ///
6523 /// This method is not expected to be public. It requires the length of the
6524 /// TypedArray to be the same as the slice, use `self.copy_to(slice)` instead.
6525 ///
6526 /// # Workaround
6527 ///
6528 /// We actually need `slice.set(typed_array)` here, but since slice cannot be treated as
6529 /// `Uint8Array` on the Rust side, we use `Uint8Array.prototype.set.call`, which allows
6530 /// us to specify the `this` value inside the function.
6531 ///
6532 /// Therefore, `Uint8Array.prototype.set.call(slice, typed_array)` is equivalent to
6533 /// `slice.set(typed_array)`.
6534 #[wasm_bindgen(js_namespace = $name, js_name = "prototype.set.call")]
6535 fn copy_to_slice(slice: &mut [$ty], this: &$name);
6536 }
6537
6538 impl $name {
6539 /// Creates a JS typed array which is a view into wasm's linear
6540 /// memory at the slice specified.
6541 ///
6542 /// This function returns a new typed array which is a view into
6543 /// wasm's memory. This view does not copy the underlying data.
6544 ///
6545 /// # Safety
6546 ///
6547 /// Views into WebAssembly memory are only valid so long as the
6548 /// backing buffer isn't resized in JS. Once this function is called
6549 /// any future calls to `Box::new` (or malloc of any form) may cause
6550 /// the returned value here to be invalidated. Use with caution!
6551 ///
6552 /// Additionally the returned object can be safely mutated but the
6553 /// input slice isn't guaranteed to be mutable.
6554 ///
6555 /// Finally, the returned object is disconnected from the input
6556 /// slice's lifetime, so there's no guarantee that the data is read
6557 /// at the right time.
6558 pub unsafe fn view(rust: &[$ty]) -> $name {
6559 wasm_bindgen::__rt::wbg_cast(rust)
6560 }
6561
6562 /// Creates a JS typed array which is a view into wasm's linear
6563 /// memory at the specified pointer with specified length.
6564 ///
6565 /// This function returns a new typed array which is a view into
6566 /// wasm's memory. This view does not copy the underlying data.
6567 ///
6568 /// # Safety
6569 ///
6570 /// Views into WebAssembly memory are only valid so long as the
6571 /// backing buffer isn't resized in JS. Once this function is called
6572 /// any future calls to `Box::new` (or malloc of any form) may cause
6573 /// the returned value here to be invalidated. Use with caution!
6574 ///
6575 /// Additionally the returned object can be safely mutated,
6576 /// the changes are guaranteed to be reflected in the input array.
6577 pub unsafe fn view_mut_raw(ptr: *mut $ty, length: usize) -> $name {
6578 let slice = core::slice::from_raw_parts_mut(ptr, length);
6579 Self::view(slice)
6580 }
6581
6582 /// Copy the contents of this JS typed array into the destination
6583 /// Rust pointer.
6584 ///
6585 /// This function will efficiently copy the memory from a typed
6586 /// array into this Wasm module's own linear memory, initializing
6587 /// the memory destination provided.
6588 ///
6589 /// # Safety
6590 ///
6591 /// This function requires `dst` to point to a buffer
6592 /// large enough to fit this array's contents.
6593 pub unsafe fn raw_copy_to_ptr(&self, dst: *mut $ty) {
6594 let slice = core::slice::from_raw_parts_mut(dst, self.length() as usize);
6595 self.copy_to(slice);
6596 }
6597
6598 /// Copy the contents of this JS typed array into the destination
6599 /// Rust slice.
6600 ///
6601 /// This function will efficiently copy the memory from a typed
6602 /// array into this Wasm module's own linear memory, initializing
6603 /// the memory destination provided.
6604 ///
6605 /// # Panics
6606 ///
6607 /// This function will panic if this typed array's length is
6608 /// different than the length of the provided `dst` array.
6609 pub fn copy_to(&self, dst: &mut [$ty]) {
6610 core::assert_eq!(self.length() as usize, dst.len());
6611 $name::copy_to_slice(dst, self);
6612 }
6613
6614 /// Copy the contents of this JS typed array into the destination
6615 /// Rust slice.
6616 ///
6617 /// This function will efficiently copy the memory from a typed
6618 /// array into this Wasm module's own linear memory, initializing
6619 /// the memory destination provided.
6620 ///
6621 /// # Panics
6622 ///
6623 /// This function will panic if this typed array's length is
6624 /// different than the length of the provided `dst` array.
6625 pub fn copy_to_uninit<'dst>(&self, dst: &'dst mut [MaybeUninit<$ty>]) -> &'dst mut [$ty] {
6626 core::assert_eq!(self.length() as usize, dst.len());
6627 let dst = unsafe { &mut *(dst as *mut [MaybeUninit<$ty>] as *mut [$ty]) };
6628 self.copy_to(dst);
6629 dst
6630 }
6631
6632 /// Copy the contents of the source Rust slice into this
6633 /// JS typed array.
6634 ///
6635 /// This function will efficiently copy the memory from within
6636 /// the Wasm module's own linear memory to this typed array.
6637 ///
6638 /// # Panics
6639 ///
6640 /// This function will panic if this typed array's length is
6641 /// different than the length of the provided `src` array.
6642 pub fn copy_from(&self, src: &[$ty]) {
6643 core::assert_eq!(self.length() as usize, src.len());
6644 self.copy_from_slice(src);
6645 }
6646
6647 /// Efficiently copies the contents of this JS typed array into a new Vec.
6648 pub fn to_vec(&self) -> Vec<$ty> {
6649 let len = self.length() as usize;
6650 let mut output = Vec::with_capacity(len);
6651 // Safety: the capacity has been set
6652 unsafe {
6653 self.raw_copy_to_ptr(output.as_mut_ptr());
6654 output.set_len(len);
6655 }
6656 output
6657 }
6658 }
6659
6660 impl<'a> From<&'a [$ty]> for $name {
6661 #[inline]
6662 fn from(slice: &'a [$ty]) -> $name {
6663 // This is safe because the `new` function makes a copy if its argument is a TypedArray
6664 $name::new_from_slice(slice)
6665 }
6666 }
6667
6668 impl Default for $name {
6669 fn default() -> Self {
6670 Self::new(&JsValue::UNDEFINED.unchecked_into())
6671 }
6672 }
6673 )*);
6674}
6675
6676arrays! {
6677 /// `Int8Array()`
6678 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int8Array
6679 Int8Array: i8,
6680
6681 /// `Int16Array()`
6682 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int16Array
6683 Int16Array: i16,
6684
6685 /// `Int32Array()`
6686 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int32Array
6687 Int32Array: i32,
6688
6689 /// `Uint8Array()`
6690 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array
6691 Uint8Array: u8,
6692
6693 /// `Uint8ClampedArray()`
6694 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8ClampedArray
6695 Uint8ClampedArray: u8,
6696
6697 /// `Uint16Array()`
6698 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint16Array
6699 Uint16Array: u16,
6700
6701 /// `Uint32Array()`
6702 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint32Array
6703 Uint32Array: u32,
6704
6705 /// `Float32Array()`
6706 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array
6707 Float32Array: f32,
6708
6709 /// `Float64Array()`
6710 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float64Array
6711 Float64Array: f64,
6712
6713 /// `BigInt64Array()`
6714 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt64Array
6715 BigInt64Array: i64,
6716
6717 /// `BigUint64Array()`
6718 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigUint64Array
6719 BigUint64Array: u64,
6720}