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