| 1 | //! Bindings to JavaScript's standard, built-in objects, including their methods |
| 2 | //! and properties. |
| 3 | //! |
| 4 | //! This does *not* include any Web, Node, or any other JS environment |
| 5 | //! APIs. Only the things that are guaranteed to exist in the global scope by |
| 6 | //! the ECMAScript standard. |
| 7 | //! |
| 8 | //! <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects> |
| 9 | //! |
| 10 | //! ## A Note About `camelCase`, `snake_case`, and Naming Conventions |
| 11 | //! |
| 12 | //! JavaScript's global objects use `camelCase` naming conventions for functions |
| 13 | //! and methods, but Rust style is to use `snake_case`. These bindings expose |
| 14 | //! the Rust style `snake_case` name. Additionally, acronyms within a method |
| 15 | //! name are all lower case, where as in JavaScript they are all upper case. For |
| 16 | //! example, `decodeURI` in JavaScript is exposed as `decode_uri` in these |
| 17 | //! bindings. |
| 18 | |
| 19 | #![doc (html_root_url = "https://docs.rs/js-sys/0.2" )] |
| 20 | #![cfg_attr (not(feature = "std" ), no_std)] |
| 21 | #![cfg_attr (target_feature = "atomics" , feature(thread_local))] |
| 22 | |
| 23 | extern crate alloc; |
| 24 | |
| 25 | use alloc::string::String; |
| 26 | use alloc::vec::Vec; |
| 27 | use core::cmp::Ordering; |
| 28 | use core::convert::{self, Infallible, TryFrom}; |
| 29 | use core::f64; |
| 30 | use core::fmt; |
| 31 | use core::iter::{self, Product, Sum}; |
| 32 | use core::mem::{self, MaybeUninit}; |
| 33 | use core::ops::{Add, BitAnd, BitOr, BitXor, Div, Mul, Neg, Not, Rem, Shl, Shr, Sub}; |
| 34 | use core::str; |
| 35 | use core::str::FromStr; |
| 36 | |
| 37 | pub use wasm_bindgen; |
| 38 | use wasm_bindgen::prelude::*; |
| 39 | |
| 40 | // When adding new imports: |
| 41 | // |
| 42 | // * Keep imports in alphabetical order. |
| 43 | // |
| 44 | // * Rename imports with `js_name = ...` according to the note about `camelCase` |
| 45 | // and `snake_case` in the module's documentation above. |
| 46 | // |
| 47 | // * Include the one sentence summary of the import from the MDN link in the |
| 48 | // module's documentation above, and the MDN link itself. |
| 49 | // |
| 50 | // * If a function or method can throw an exception, make it catchable by adding |
| 51 | // `#[wasm_bindgen(catch)]`. |
| 52 | // |
| 53 | // * Add a new `#[test]` into the appropriate file in the |
| 54 | // `crates/js-sys/tests/wasm/` directory. If the imported function or method |
| 55 | // can throw an exception, make sure to also add test coverage for that case. |
| 56 | // |
| 57 | // * Arguments that are `JsValue`s or imported JavaScript types should be taken |
| 58 | // by reference. |
| 59 | |
| 60 | macro_rules! forward_deref_unop { |
| 61 | (impl $imp:ident, $method:ident for $t:ty) => { |
| 62 | impl $imp for $t { |
| 63 | type Output = <&'static $t as $imp>::Output; |
| 64 | |
| 65 | #[inline] |
| 66 | fn $method(self) -> Self::Output { |
| 67 | $imp::$method(&self) |
| 68 | } |
| 69 | } |
| 70 | }; |
| 71 | } |
| 72 | |
| 73 | macro_rules! forward_deref_binop { |
| 74 | (impl $imp:ident, $method:ident for $t:ty) => { |
| 75 | impl<'a> $imp<$t> for &'a $t { |
| 76 | type Output = <&'static $t as $imp<&'static $t>>::Output; |
| 77 | |
| 78 | #[inline] |
| 79 | fn $method(self, other: $t) -> Self::Output { |
| 80 | $imp::$method(self, &other) |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | impl $imp<&$t> for $t { |
| 85 | type Output = <&'static $t as $imp<&'static $t>>::Output; |
| 86 | |
| 87 | #[inline] |
| 88 | fn $method(self, other: &$t) -> Self::Output { |
| 89 | $imp::$method(&self, other) |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | impl $imp<$t> for $t { |
| 94 | type Output = <&'static $t as $imp<&'static $t>>::Output; |
| 95 | |
| 96 | #[inline] |
| 97 | fn $method(self, other: $t) -> Self::Output { |
| 98 | $imp::$method(&self, &other) |
| 99 | } |
| 100 | } |
| 101 | }; |
| 102 | } |
| 103 | |
| 104 | macro_rules! forward_js_unop { |
| 105 | (impl $imp:ident, $method:ident for $t:ty) => { |
| 106 | impl $imp for &$t { |
| 107 | type Output = $t; |
| 108 | |
| 109 | #[inline] |
| 110 | fn $method(self) -> Self::Output { |
| 111 | $imp::$method(JsValue::as_ref(self)).unchecked_into() |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | forward_deref_unop!(impl $imp, $method for $t); |
| 116 | }; |
| 117 | } |
| 118 | |
| 119 | macro_rules! forward_js_binop { |
| 120 | (impl $imp:ident, $method:ident for $t:ty) => { |
| 121 | impl $imp<&$t> for &$t { |
| 122 | type Output = $t; |
| 123 | |
| 124 | #[inline] |
| 125 | fn $method(self, other: &$t) -> Self::Output { |
| 126 | $imp::$method(JsValue::as_ref(self), JsValue::as_ref(other)).unchecked_into() |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | forward_deref_binop!(impl $imp, $method for $t); |
| 131 | }; |
| 132 | } |
| 133 | |
| 134 | macro_rules! sum_product { |
| 135 | ($($a:ident)*) => ($( |
| 136 | impl Sum for $a { |
| 137 | #[inline] |
| 138 | fn sum<I: iter::Iterator<Item=Self>>(iter: I) -> Self { |
| 139 | iter.fold( |
| 140 | $a::from(0), |
| 141 | |a, b| a + b, |
| 142 | ) |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | impl Product for $a { |
| 147 | #[inline] |
| 148 | fn product<I: iter::Iterator<Item=Self>>(iter: I) -> Self { |
| 149 | iter.fold( |
| 150 | $a::from(1), |
| 151 | |a, b| a * b, |
| 152 | ) |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | impl<'a> Sum<&'a $a> for $a { |
| 157 | fn sum<I: iter::Iterator<Item=&'a Self>>(iter: I) -> Self { |
| 158 | iter.fold( |
| 159 | $a::from(0), |
| 160 | |a, b| a + b, |
| 161 | ) |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | impl<'a> Product<&'a $a> for $a { |
| 166 | #[inline] |
| 167 | fn product<I: iter::Iterator<Item=&'a Self>>(iter: I) -> Self { |
| 168 | iter.fold( |
| 169 | $a::from(1), |
| 170 | |a, b| a * b, |
| 171 | ) |
| 172 | } |
| 173 | } |
| 174 | )*) |
| 175 | } |
| 176 | |
| 177 | macro_rules! partialord_ord { |
| 178 | ($t:ident) => { |
| 179 | impl PartialOrd for $t { |
| 180 | #[inline] |
| 181 | fn partial_cmp(&self, other: &Self) -> Option<Ordering> { |
| 182 | Some(self.cmp(other)) |
| 183 | } |
| 184 | |
| 185 | #[inline] |
| 186 | fn lt(&self, other: &Self) -> bool { |
| 187 | JsValue::as_ref(self).lt(JsValue::as_ref(other)) |
| 188 | } |
| 189 | |
| 190 | #[inline] |
| 191 | fn le(&self, other: &Self) -> bool { |
| 192 | JsValue::as_ref(self).le(JsValue::as_ref(other)) |
| 193 | } |
| 194 | |
| 195 | #[inline] |
| 196 | fn ge(&self, other: &Self) -> bool { |
| 197 | JsValue::as_ref(self).ge(JsValue::as_ref(other)) |
| 198 | } |
| 199 | |
| 200 | #[inline] |
| 201 | fn gt(&self, other: &Self) -> bool { |
| 202 | JsValue::as_ref(self).gt(JsValue::as_ref(other)) |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | impl Ord for $t { |
| 207 | #[inline] |
| 208 | fn cmp(&self, other: &Self) -> Ordering { |
| 209 | if self == other { |
| 210 | Ordering::Equal |
| 211 | } else if self.lt(other) { |
| 212 | Ordering::Less |
| 213 | } else { |
| 214 | Ordering::Greater |
| 215 | } |
| 216 | } |
| 217 | } |
| 218 | }; |
| 219 | } |
| 220 | |
| 221 | #[wasm_bindgen ] |
| 222 | unsafeextern "C" { |
| 223 | /// The `decodeURI()` function decodes a Uniform Resource Identifier (URI) |
| 224 | /// previously created by `encodeURI` or by a similar routine. |
| 225 | /// |
| 226 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURI) |
| 227 | #[wasm_bindgen (catch, js_name = decodeURI)] |
| 228 | pub unsafefn decode_uri(encoded: &str) -> Result<JsString, JsValue>; |
| 229 | |
| 230 | /// The `decodeURIComponent()` function decodes a Uniform Resource Identifier (URI) component |
| 231 | /// previously created by `encodeURIComponent` or by a similar routine. |
| 232 | /// |
| 233 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURIComponent) |
| 234 | #[wasm_bindgen (catch, js_name = decodeURIComponent)] |
| 235 | pub unsafefn decode_uri_component(encoded: &str) -> Result<JsString, JsValue>; |
| 236 | |
| 237 | /// The `encodeURI()` function encodes a Uniform Resource Identifier (URI) |
| 238 | /// by replacing each instance of certain characters by one, two, three, or |
| 239 | /// four escape sequences representing the UTF-8 encoding of the character |
| 240 | /// (will only be four escape sequences for characters composed of two |
| 241 | /// "surrogate" characters). |
| 242 | /// |
| 243 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURI) |
| 244 | #[wasm_bindgen (js_name = encodeURI)] |
| 245 | pub unsafefn encode_uri(decoded: &str) -> JsString; |
| 246 | |
| 247 | /// The `encodeURIComponent()` function encodes a Uniform Resource Identifier (URI) component |
| 248 | /// by replacing each instance of certain characters by one, two, three, or four escape sequences |
| 249 | /// representing the UTF-8 encoding of the character |
| 250 | /// (will only be four escape sequences for characters composed of two "surrogate" characters). |
| 251 | /// |
| 252 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent) |
| 253 | #[wasm_bindgen (js_name = encodeURIComponent)] |
| 254 | pub unsafefn encode_uri_component(decoded: &str) -> JsString; |
| 255 | |
| 256 | /// The `eval()` function evaluates JavaScript code represented as a string. |
| 257 | /// |
| 258 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval) |
| 259 | #[wasm_bindgen (catch)] |
| 260 | pub unsafefn eval(js_source_text: &str) -> Result<JsValue, JsValue>; |
| 261 | |
| 262 | /// The global `isFinite()` function determines whether the passed value is a finite number. |
| 263 | /// If needed, the parameter is first converted to a number. |
| 264 | /// |
| 265 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isFinite) |
| 266 | #[wasm_bindgen (js_name = isFinite)] |
| 267 | pub unsafefn is_finite(value: &JsValue) -> bool; |
| 268 | |
| 269 | /// The `parseInt()` function parses a string argument and returns an integer |
| 270 | /// of the specified radix (the base in mathematical numeral systems), or NaN on error. |
| 271 | /// |
| 272 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt) |
| 273 | #[wasm_bindgen (js_name = parseInt)] |
| 274 | pub unsafefn parse_int(text: &str, radix: u8) -> f64; |
| 275 | |
| 276 | /// The `parseFloat()` function parses an argument and returns a floating point number, |
| 277 | /// or NaN on error. |
| 278 | /// |
| 279 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseFloat) |
| 280 | #[wasm_bindgen (js_name = parseFloat)] |
| 281 | pub unsafefn parse_float(text: &str) -> f64; |
| 282 | |
| 283 | /// The `escape()` function computes a new string in which certain characters have been |
| 284 | /// replaced by a hexadecimal escape sequence. |
| 285 | /// |
| 286 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/escape) |
| 287 | #[wasm_bindgen ] |
| 288 | pub unsafefn escape(string: &str) -> JsString; |
| 289 | |
| 290 | /// The `unescape()` function computes a new string in which hexadecimal escape |
| 291 | /// sequences are replaced with the character that it represents. The escape sequences might |
| 292 | /// be introduced by a function like `escape`. Usually, `decodeURI` or `decodeURIComponent` |
| 293 | /// are preferred over `unescape`. |
| 294 | /// |
| 295 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/unescape) |
| 296 | #[wasm_bindgen ] |
| 297 | pub unsafefn unescape(string: &str) -> JsString; |
| 298 | } |
| 299 | |
| 300 | // Array |
| 301 | #[wasm_bindgen ] |
| 302 | unsafeextern "C" { |
| 303 | #[wasm_bindgen (extends = Object, is_type_of = Array::is_array, typescript_type = "Array<any>" )] |
| 304 | #[derive (Clone, Debug, PartialEq, Eq)] |
| 305 | pub type Array; |
| 306 | |
| 307 | /// Creates a new empty array. |
| 308 | #[wasm_bindgen (constructor)] |
| 309 | pub unsafefn new() -> Array; |
| 310 | |
| 311 | /// Creates a new array with the specified length (elements are initialized to `undefined`). |
| 312 | #[wasm_bindgen (constructor)] |
| 313 | pub unsafefn new_with_length(len: u32) -> Array; |
| 314 | |
| 315 | /// Retrieves the element at the index, counting from the end if negative |
| 316 | /// (returns `undefined` if the index is out of range). |
| 317 | #[wasm_bindgen (method)] |
| 318 | pub unsafefn at(this: &Array, index: i32) -> JsValue; |
| 319 | |
| 320 | /// Retrieves the element at the index (returns `undefined` if the index is out of range). |
| 321 | #[wasm_bindgen (method, structural, indexing_getter)] |
| 322 | pub unsafefn get(this: &Array, index: u32) -> JsValue; |
| 323 | |
| 324 | /// Sets the element at the index (auto-enlarges the array if the index is out of range). |
| 325 | #[wasm_bindgen (method, structural, indexing_setter)] |
| 326 | pub unsafefn set(this: &Array, index: u32, value: JsValue); |
| 327 | |
| 328 | /// Deletes the element at the index (does nothing if the index is out of range). |
| 329 | /// |
| 330 | /// The element at the index is set to `undefined`. |
| 331 | /// |
| 332 | /// This does not resize the array, the array will still be the same length. |
| 333 | #[wasm_bindgen (method, structural, indexing_deleter)] |
| 334 | pub unsafefn delete(this: &Array, index: u32); |
| 335 | |
| 336 | /// The `Array.from()` method creates a new, shallow-copied `Array` instance |
| 337 | /// from an array-like or iterable object. |
| 338 | #[wasm_bindgen (static_method_of = Array)] |
| 339 | pub unsafefn from(val: &JsValue) -> Array; |
| 340 | |
| 341 | /// The `copyWithin()` method shallow copies part of an array to another |
| 342 | /// location in the same array and returns it, without modifying its size. |
| 343 | /// |
| 344 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin) |
| 345 | #[wasm_bindgen (method, js_name = copyWithin)] |
| 346 | pub unsafefn copy_within(this: &Array, target: i32, start: i32, end: i32) -> Array; |
| 347 | |
| 348 | /// The `concat()` method is used to merge two or more arrays. This method |
| 349 | /// does not change the existing arrays, but instead returns a new array. |
| 350 | /// |
| 351 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat) |
| 352 | #[wasm_bindgen (method)] |
| 353 | pub unsafefn concat(this: &Array, array: &Array) -> Array; |
| 354 | |
| 355 | /// The `every()` method tests whether all elements in the array pass the test |
| 356 | /// implemented by the provided function. |
| 357 | /// |
| 358 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every) |
| 359 | #[wasm_bindgen (method)] |
| 360 | pub unsafefn every(this: &Array, predicate: &mut dyn FnMut(JsValue, u32, Array) -> bool) -> bool; |
| 361 | |
| 362 | /// The `fill()` method fills all the elements of an array from a start index |
| 363 | /// to an end index with a static value. The end index is not included. |
| 364 | /// |
| 365 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill) |
| 366 | #[wasm_bindgen (method)] |
| 367 | pub unsafefn fill(this: &Array, value: &JsValue, start: u32, end: u32) -> Array; |
| 368 | |
| 369 | /// The `filter()` method creates a new array with all elements that pass the |
| 370 | /// test implemented by the provided function. |
| 371 | /// |
| 372 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter) |
| 373 | #[wasm_bindgen (method)] |
| 374 | pub unsafefn filter(this: &Array, predicate: &mut dyn FnMut(JsValue, u32, Array) -> bool) -> Array; |
| 375 | |
| 376 | /// The `find()` method returns the value of the first element in the array that satisfies |
| 377 | /// the provided testing function. Otherwise `undefined` is returned. |
| 378 | /// |
| 379 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find) |
| 380 | #[wasm_bindgen (method)] |
| 381 | pub unsafefn find(this: &Array, predicate: &mut dyn FnMut(JsValue, u32, Array) -> bool) -> JsValue; |
| 382 | |
| 383 | /// The `findIndex()` method returns the index of the first element in the array that |
| 384 | /// satisfies the provided testing function. Otherwise -1 is returned. |
| 385 | /// |
| 386 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex) |
| 387 | #[wasm_bindgen (method, js_name = findIndex)] |
| 388 | pub unsafefn find_index(this: &Array, predicate: &mut dyn FnMut(JsValue, u32, Array) -> bool) -> i32; |
| 389 | |
| 390 | /// The `findLast()` method of Array instances iterates the array in reverse order |
| 391 | /// and returns the value of the first element that satisfies the provided testing function. |
| 392 | /// If no elements satisfy the testing function, undefined is returned. |
| 393 | /// |
| 394 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLast) |
| 395 | #[wasm_bindgen (method, js_name = findLast)] |
| 396 | pub unsafefn find_last( |
| 397 | this: &Array, |
| 398 | predicate: &mut dyn FnMut(JsValue, u32, Array) -> bool, |
| 399 | ) -> JsValue; |
| 400 | |
| 401 | /// The `findLastIndex()` method of Array instances iterates the array in reverse order |
| 402 | /// and returns the index of the first element that satisfies the provided testing function. |
| 403 | /// If no elements satisfy the testing function, -1 is returned. |
| 404 | /// |
| 405 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLastIndex) |
| 406 | #[wasm_bindgen (method, js_name = findLastIndex)] |
| 407 | pub unsafefn find_last_index( |
| 408 | this: &Array, |
| 409 | predicate: &mut dyn FnMut(JsValue, u32, Array) -> bool, |
| 410 | ) -> i32; |
| 411 | |
| 412 | /// The `flat()` method creates a new array with all sub-array elements concatenated into it |
| 413 | /// recursively up to the specified depth. |
| 414 | /// |
| 415 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat) |
| 416 | #[wasm_bindgen (method)] |
| 417 | pub unsafefn flat(this: &Array, depth: i32) -> Array; |
| 418 | |
| 419 | /// The `flatMap()` method first maps each element using a mapping function, then flattens |
| 420 | /// the result into a new array. |
| 421 | /// |
| 422 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap) |
| 423 | #[wasm_bindgen (method, js_name = flatMap)] |
| 424 | pub unsafefn flat_map( |
| 425 | this: &Array, |
| 426 | callback: &mut dyn FnMut(JsValue, u32, Array) -> Vec<JsValue>, |
| 427 | ) -> Array; |
| 428 | |
| 429 | /// The `forEach()` method executes a provided function once for each array element. |
| 430 | /// |
| 431 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach) |
| 432 | #[wasm_bindgen (method, js_name = forEach)] |
| 433 | pub unsafefn for_each(this: &Array, callback: &mut dyn FnMut(JsValue, u32, Array)); |
| 434 | |
| 435 | /// The `includes()` method determines whether an array includes a certain |
| 436 | /// element, returning true or false as appropriate. |
| 437 | /// |
| 438 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes) |
| 439 | #[wasm_bindgen (method)] |
| 440 | pub unsafefn includes(this: &Array, value: &JsValue, from_index: i32) -> bool; |
| 441 | |
| 442 | /// The `indexOf()` method returns the first index at which a given element |
| 443 | /// can be found in the array, or -1 if it is not present. |
| 444 | /// |
| 445 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf) |
| 446 | #[wasm_bindgen (method, js_name = indexOf)] |
| 447 | pub unsafefn index_of(this: &Array, value: &JsValue, from_index: i32) -> i32; |
| 448 | |
| 449 | /// The `Array.isArray()` method determines whether the passed value is an Array. |
| 450 | /// |
| 451 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray) |
| 452 | #[wasm_bindgen (static_method_of = Array, js_name = isArray)] |
| 453 | pub unsafefn is_array(value: &JsValue) -> bool; |
| 454 | |
| 455 | /// The `join()` method joins all elements of an array (or an array-like object) |
| 456 | /// into a string and returns this string. |
| 457 | /// |
| 458 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join) |
| 459 | #[wasm_bindgen (method)] |
| 460 | pub unsafefn join(this: &Array, delimiter: &str) -> JsString; |
| 461 | |
| 462 | /// The `lastIndexOf()` method returns the last index at which a given element |
| 463 | /// can be found in the array, or -1 if it is not present. The array is |
| 464 | /// searched backwards, starting at fromIndex. |
| 465 | /// |
| 466 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/lastIndexOf) |
| 467 | #[wasm_bindgen (method, js_name = lastIndexOf)] |
| 468 | pub unsafefn last_index_of(this: &Array, value: &JsValue, from_index: i32) -> i32; |
| 469 | |
| 470 | /// The length property of an object which is an instance of type Array |
| 471 | /// sets or returns the number of elements in that array. The value is an |
| 472 | /// unsigned, 32-bit integer that is always numerically greater than the |
| 473 | /// highest index in the array. |
| 474 | /// |
| 475 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/length) |
| 476 | #[wasm_bindgen (method, getter, structural)] |
| 477 | pub unsafefn length(this: &Array) -> u32; |
| 478 | |
| 479 | /// Sets the length of the array. |
| 480 | /// |
| 481 | /// If it is set to less than the current length of the array, it will |
| 482 | /// shrink the array. |
| 483 | /// |
| 484 | /// If it is set to more than the current length of the array, it will |
| 485 | /// increase the length of the array, filling the new space with empty |
| 486 | /// slots. |
| 487 | /// |
| 488 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/length) |
| 489 | #[wasm_bindgen (method, setter)] |
| 490 | pub unsafefn set_length(this: &Array, value: u32); |
| 491 | |
| 492 | /// `map()` calls a provided callback function once for each element in an array, |
| 493 | /// in order, and constructs a new array from the results. callback is invoked |
| 494 | /// only for indexes of the array which have assigned values, including undefined. |
| 495 | /// It is not called for missing elements of the array (that is, indexes that have |
| 496 | /// never been set, which have been deleted or which have never been assigned a value). |
| 497 | /// |
| 498 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) |
| 499 | #[wasm_bindgen (method)] |
| 500 | pub unsafefn map(this: &Array, predicate: &mut dyn FnMut(JsValue, u32, Array) -> JsValue) -> Array; |
| 501 | |
| 502 | /// The `Array.of()` method creates a new Array instance with a variable |
| 503 | /// number of arguments, regardless of number or type of the arguments. |
| 504 | /// |
| 505 | /// The difference between `Array.of()` and the `Array` constructor is in the |
| 506 | /// handling of integer arguments: `Array.of(7)` creates an array with a single |
| 507 | /// element, `7`, whereas `Array(7)` creates an empty array with a `length` |
| 508 | /// property of `7` (Note: this implies an array of 7 empty slots, not slots |
| 509 | /// with actual undefined values). |
| 510 | /// |
| 511 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of) |
| 512 | /// |
| 513 | /// # Notes |
| 514 | /// |
| 515 | /// There are a few bindings to `of` in `js-sys`: `of1`, `of2`, etc... |
| 516 | /// with different arities. |
| 517 | #[wasm_bindgen (static_method_of = Array, js_name = of)] |
| 518 | pub unsafefn of1(a: &JsValue) -> Array; |
| 519 | |
| 520 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of) |
| 521 | #[wasm_bindgen (static_method_of = Array, js_name = of)] |
| 522 | pub unsafefn of2(a: &JsValue, b: &JsValue) -> Array; |
| 523 | |
| 524 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of) |
| 525 | #[wasm_bindgen (static_method_of = Array, js_name = of)] |
| 526 | pub unsafefn of3(a: &JsValue, b: &JsValue, c: &JsValue) -> Array; |
| 527 | |
| 528 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of) |
| 529 | #[wasm_bindgen (static_method_of = Array, js_name = of)] |
| 530 | pub unsafefn of4(a: &JsValue, b: &JsValue, c: &JsValue, d: &JsValue) -> Array; |
| 531 | |
| 532 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of) |
| 533 | #[wasm_bindgen (static_method_of = Array, js_name = of)] |
| 534 | pub unsafefn of5(a: &JsValue, b: &JsValue, c: &JsValue, d: &JsValue, e: &JsValue) -> Array; |
| 535 | |
| 536 | /// The `pop()` method removes the last element from an array and returns that |
| 537 | /// element. This method changes the length of the array. |
| 538 | /// |
| 539 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pop) |
| 540 | #[wasm_bindgen (method)] |
| 541 | pub unsafefn pop(this: &Array) -> JsValue; |
| 542 | |
| 543 | /// The `push()` method adds one or more elements to the end of an array and |
| 544 | /// returns the new length of the array. |
| 545 | /// |
| 546 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push) |
| 547 | #[wasm_bindgen (method)] |
| 548 | pub unsafefn push(this: &Array, value: &JsValue) -> u32; |
| 549 | |
| 550 | /// The `reduce()` method applies a function against an accumulator and each element in |
| 551 | /// the array (from left to right) to reduce it to a single value. |
| 552 | /// |
| 553 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce) |
| 554 | #[wasm_bindgen (method)] |
| 555 | pub unsafefn reduce( |
| 556 | this: &Array, |
| 557 | predicate: &mut dyn FnMut(JsValue, JsValue, u32, Array) -> JsValue, |
| 558 | initial_value: &JsValue, |
| 559 | ) -> JsValue; |
| 560 | |
| 561 | /// The `reduceRight()` method applies a function against an accumulator and each value |
| 562 | /// of the array (from right-to-left) to reduce it to a single value. |
| 563 | /// |
| 564 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/ReduceRight) |
| 565 | #[wasm_bindgen (method, js_name = reduceRight)] |
| 566 | pub unsafefn reduce_right( |
| 567 | this: &Array, |
| 568 | predicate: &mut dyn FnMut(JsValue, JsValue, u32, Array) -> JsValue, |
| 569 | initial_value: &JsValue, |
| 570 | ) -> JsValue; |
| 571 | |
| 572 | /// The `reverse()` method reverses an array in place. The first array |
| 573 | /// element becomes the last, and the last array element becomes the first. |
| 574 | /// |
| 575 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse) |
| 576 | #[wasm_bindgen (method)] |
| 577 | pub unsafefn reverse(this: &Array) -> Array; |
| 578 | |
| 579 | /// The `shift()` method removes the first element from an array and returns |
| 580 | /// that removed element. This method changes the length of the array. |
| 581 | /// |
| 582 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift) |
| 583 | #[wasm_bindgen (method)] |
| 584 | pub unsafefn shift(this: &Array) -> JsValue; |
| 585 | |
| 586 | /// The `slice()` method returns a shallow copy of a portion of an array into |
| 587 | /// a new array object selected from begin to end (end not included). |
| 588 | /// The original array will not be modified. |
| 589 | /// |
| 590 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice) |
| 591 | #[wasm_bindgen (method)] |
| 592 | pub unsafefn slice(this: &Array, start: u32, end: u32) -> Array; |
| 593 | |
| 594 | /// The `some()` method tests whether at least one element in the array passes the test implemented |
| 595 | /// by the provided function. |
| 596 | /// Note: This method returns false for any condition put on an empty array. |
| 597 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some) |
| 598 | #[wasm_bindgen (method)] |
| 599 | pub unsafefn some(this: &Array, predicate: &mut dyn FnMut(JsValue) -> bool) -> bool; |
| 600 | |
| 601 | /// The `sort()` method sorts the elements of an array in place and returns |
| 602 | /// the array. The sort is not necessarily stable. The default sort |
| 603 | /// order is according to string Unicode code points. |
| 604 | /// |
| 605 | /// The time and space complexity of the sort cannot be guaranteed as it |
| 606 | /// is implementation dependent. |
| 607 | /// |
| 608 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort) |
| 609 | #[wasm_bindgen (method)] |
| 610 | pub unsafefn sort(this: &Array) -> Array; |
| 611 | |
| 612 | /// The `splice()` method changes the contents of an array by removing existing elements and/or |
| 613 | /// adding new elements. |
| 614 | /// |
| 615 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice) |
| 616 | #[wasm_bindgen (method)] |
| 617 | pub unsafefn splice(this: &Array, start: u32, delete_count: u32, item: &JsValue) -> Array; |
| 618 | |
| 619 | /// The `toLocaleString()` method returns a string representing the elements of the array. |
| 620 | /// The elements are converted to Strings using their toLocaleString methods and these |
| 621 | /// Strings are separated by a locale-specific String (such as a comma “,”). |
| 622 | /// |
| 623 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toLocaleString) |
| 624 | #[wasm_bindgen (method, js_name = toLocaleString)] |
| 625 | pub unsafefn to_locale_string(this: &Array, locales: &JsValue, options: &JsValue) -> JsString; |
| 626 | |
| 627 | /// The `toString()` method returns a string representing the specified array |
| 628 | /// and its elements. |
| 629 | /// |
| 630 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toString) |
| 631 | #[wasm_bindgen (method, js_name = toString)] |
| 632 | pub unsafefn to_string(this: &Array) -> JsString; |
| 633 | |
| 634 | /// The `unshift()` method adds one or more elements to the beginning of an |
| 635 | /// array and returns the new length of the array. |
| 636 | /// |
| 637 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift) |
| 638 | #[wasm_bindgen (method)] |
| 639 | pub unsafefn unshift(this: &Array, value: &JsValue) -> u32; |
| 640 | } |
| 641 | |
| 642 | /// Iterator returned by `Array::into_iter` |
| 643 | #[derive (Debug, Clone)] |
| 644 | pub struct ArrayIntoIter { |
| 645 | range: core::ops::Range<u32>, |
| 646 | array: Array, |
| 647 | } |
| 648 | |
| 649 | impl core::iter::Iterator for ArrayIntoIter { |
| 650 | type Item = JsValue; |
| 651 | |
| 652 | fn next(&mut self) -> Option<Self::Item> { |
| 653 | let index = self.range.next()?; |
| 654 | Some(self.array.get(index)) |
| 655 | } |
| 656 | |
| 657 | #[inline ] |
| 658 | fn size_hint(&self) -> (usize, Option<usize>) { |
| 659 | self.range.size_hint() |
| 660 | } |
| 661 | |
| 662 | #[inline ] |
| 663 | fn count(self) -> usize |
| 664 | where |
| 665 | Self: Sized, |
| 666 | { |
| 667 | self.range.count() |
| 668 | } |
| 669 | |
| 670 | #[inline ] |
| 671 | fn last(self) -> Option<Self::Item> |
| 672 | where |
| 673 | Self: Sized, |
| 674 | { |
| 675 | let Self { range, array } = self; |
| 676 | range.last().map(|index| array.get(index)) |
| 677 | } |
| 678 | |
| 679 | #[inline ] |
| 680 | fn nth(&mut self, n: usize) -> Option<Self::Item> { |
| 681 | self.range.nth(n).map(|index| self.array.get(index)) |
| 682 | } |
| 683 | } |
| 684 | |
| 685 | impl core::iter::DoubleEndedIterator for ArrayIntoIter { |
| 686 | fn next_back(&mut self) -> Option<Self::Item> { |
| 687 | let index: u32 = self.range.next_back()?; |
| 688 | Some(self.array.get(index)) |
| 689 | } |
| 690 | |
| 691 | fn nth_back(&mut self, n: usize) -> Option<Self::Item> { |
| 692 | self.range.nth_back(n).map(|index: u32| self.array.get(index)) |
| 693 | } |
| 694 | } |
| 695 | |
| 696 | impl core::iter::FusedIterator for ArrayIntoIter {} |
| 697 | |
| 698 | impl core::iter::ExactSizeIterator for ArrayIntoIter {} |
| 699 | |
| 700 | /// Iterator returned by `Array::iter` |
| 701 | #[derive (Debug, Clone)] |
| 702 | pub struct ArrayIter<'a> { |
| 703 | range: core::ops::Range<u32>, |
| 704 | array: &'a Array, |
| 705 | } |
| 706 | |
| 707 | impl core::iter::Iterator for ArrayIter<'_> { |
| 708 | type Item = JsValue; |
| 709 | |
| 710 | fn next(&mut self) -> Option<Self::Item> { |
| 711 | let index = self.range.next()?; |
| 712 | Some(self.array.get(index)) |
| 713 | } |
| 714 | |
| 715 | #[inline ] |
| 716 | fn size_hint(&self) -> (usize, Option<usize>) { |
| 717 | self.range.size_hint() |
| 718 | } |
| 719 | |
| 720 | #[inline ] |
| 721 | fn count(self) -> usize |
| 722 | where |
| 723 | Self: Sized, |
| 724 | { |
| 725 | self.range.count() |
| 726 | } |
| 727 | |
| 728 | #[inline ] |
| 729 | fn last(self) -> Option<Self::Item> |
| 730 | where |
| 731 | Self: Sized, |
| 732 | { |
| 733 | let Self { range, array } = self; |
| 734 | range.last().map(|index| array.get(index)) |
| 735 | } |
| 736 | |
| 737 | #[inline ] |
| 738 | fn nth(&mut self, n: usize) -> Option<Self::Item> { |
| 739 | self.range.nth(n).map(|index| self.array.get(index)) |
| 740 | } |
| 741 | } |
| 742 | |
| 743 | impl core::iter::DoubleEndedIterator for ArrayIter<'_> { |
| 744 | fn next_back(&mut self) -> Option<Self::Item> { |
| 745 | let index: u32 = self.range.next_back()?; |
| 746 | Some(self.array.get(index)) |
| 747 | } |
| 748 | |
| 749 | fn nth_back(&mut self, n: usize) -> Option<Self::Item> { |
| 750 | self.range.nth_back(n).map(|index: u32| self.array.get(index)) |
| 751 | } |
| 752 | } |
| 753 | |
| 754 | impl core::iter::FusedIterator for ArrayIter<'_> {} |
| 755 | |
| 756 | impl core::iter::ExactSizeIterator for ArrayIter<'_> {} |
| 757 | |
| 758 | impl Array { |
| 759 | /// Returns an iterator over the values of the JS array. |
| 760 | pub fn iter(&self) -> ArrayIter<'_> { |
| 761 | ArrayIter { |
| 762 | range: 0..self.length(), |
| 763 | array: self, |
| 764 | } |
| 765 | } |
| 766 | |
| 767 | /// Converts the JS array into a new Vec. |
| 768 | pub fn to_vec(&self) -> Vec<JsValue> { |
| 769 | let len: i32 = self.length(); |
| 770 | |
| 771 | let mut output: Vec = Vec::with_capacity(len as usize); |
| 772 | |
| 773 | for i: i32 in 0..len { |
| 774 | output.push(self.get(i)); |
| 775 | } |
| 776 | |
| 777 | output |
| 778 | } |
| 779 | } |
| 780 | |
| 781 | impl core::iter::IntoIterator for Array { |
| 782 | type Item = JsValue; |
| 783 | type IntoIter = ArrayIntoIter; |
| 784 | |
| 785 | fn into_iter(self) -> Self::IntoIter { |
| 786 | ArrayIntoIter { |
| 787 | range: 0..self.length(), |
| 788 | array: self, |
| 789 | } |
| 790 | } |
| 791 | } |
| 792 | |
| 793 | // TODO pre-initialize the Array with the correct length using TrustedLen |
| 794 | impl<A> core::iter::FromIterator<A> for Array |
| 795 | where |
| 796 | A: AsRef<JsValue>, |
| 797 | { |
| 798 | fn from_iter<T>(iter: T) -> Array |
| 799 | where |
| 800 | T: IntoIterator<Item = A>, |
| 801 | { |
| 802 | let mut out: Array = Array::new(); |
| 803 | out.extend(iter); |
| 804 | out |
| 805 | } |
| 806 | } |
| 807 | |
| 808 | impl<A> core::iter::Extend<A> for Array |
| 809 | where |
| 810 | A: AsRef<JsValue>, |
| 811 | { |
| 812 | fn extend<T>(&mut self, iter: T) |
| 813 | where |
| 814 | T: IntoIterator<Item = A>, |
| 815 | { |
| 816 | for value: A in iter { |
| 817 | self.push(value.as_ref()); |
| 818 | } |
| 819 | } |
| 820 | } |
| 821 | |
| 822 | impl Default for Array { |
| 823 | fn default() -> Self { |
| 824 | Self::new() |
| 825 | } |
| 826 | } |
| 827 | |
| 828 | // ArrayBuffer |
| 829 | #[wasm_bindgen ] |
| 830 | unsafeextern "C" { |
| 831 | #[wasm_bindgen (extends = Object, typescript_type = "ArrayBuffer" )] |
| 832 | #[derive (Clone, Debug, PartialEq, Eq)] |
| 833 | pub type ArrayBuffer; |
| 834 | |
| 835 | /// The `ArrayBuffer` object is used to represent a generic, |
| 836 | /// fixed-length raw binary data buffer. You cannot directly |
| 837 | /// manipulate the contents of an `ArrayBuffer`; instead, you |
| 838 | /// create one of the typed array objects or a `DataView` object |
| 839 | /// which represents the buffer in a specific format, and use that |
| 840 | /// to read and write the contents of the buffer. |
| 841 | /// |
| 842 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer) |
| 843 | #[wasm_bindgen (constructor)] |
| 844 | pub unsafefn new(length: u32) -> ArrayBuffer; |
| 845 | |
| 846 | /// The byteLength property of an object which is an instance of type ArrayBuffer |
| 847 | /// it's an accessor property whose set accessor function is undefined, |
| 848 | /// meaning that you can only read this property. |
| 849 | /// The value is established when the array is constructed and cannot be changed. |
| 850 | /// This property returns 0 if this ArrayBuffer has been detached. |
| 851 | /// |
| 852 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/byteLength) |
| 853 | #[wasm_bindgen (method, getter, js_name = byteLength)] |
| 854 | pub unsafefn byte_length(this: &ArrayBuffer) -> u32; |
| 855 | |
| 856 | /// The `isView()` method returns true if arg is one of the `ArrayBuffer` |
| 857 | /// views, such as typed array objects or a DataView; false otherwise. |
| 858 | /// |
| 859 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/isView) |
| 860 | #[wasm_bindgen (static_method_of = ArrayBuffer, js_name = isView)] |
| 861 | pub unsafefn is_view(value: &JsValue) -> bool; |
| 862 | |
| 863 | /// The `slice()` method returns a new `ArrayBuffer` whose contents |
| 864 | /// are a copy of this `ArrayBuffer`'s bytes from begin, inclusive, |
| 865 | /// up to end, exclusive. |
| 866 | /// |
| 867 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/slice) |
| 868 | #[wasm_bindgen (method)] |
| 869 | pub unsafefn slice(this: &ArrayBuffer, begin: u32) -> ArrayBuffer; |
| 870 | |
| 871 | /// Like `slice()` but with the `end` argument. |
| 872 | /// |
| 873 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/slice) |
| 874 | #[wasm_bindgen (method, js_name = slice)] |
| 875 | pub unsafefn slice_with_end(this: &ArrayBuffer, begin: u32, end: u32) -> ArrayBuffer; |
| 876 | } |
| 877 | |
| 878 | // SharedArrayBuffer |
| 879 | #[wasm_bindgen ] |
| 880 | unsafeextern "C" { |
| 881 | #[wasm_bindgen (extends = Object, typescript_type = "SharedArrayBuffer" )] |
| 882 | #[derive (Clone, Debug)] |
| 883 | pub type SharedArrayBuffer; |
| 884 | |
| 885 | /// The `SharedArrayBuffer` object is used to represent a generic, |
| 886 | /// fixed-length raw binary data buffer, similar to the `ArrayBuffer` |
| 887 | /// object, but in a way that they can be used to create views |
| 888 | /// on shared memory. Unlike an `ArrayBuffer`, a `SharedArrayBuffer` |
| 889 | /// cannot become detached. |
| 890 | /// |
| 891 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer) |
| 892 | #[wasm_bindgen (constructor)] |
| 893 | pub unsafefn new(length: u32) -> SharedArrayBuffer; |
| 894 | |
| 895 | /// The byteLength accessor property represents the length of |
| 896 | /// an `SharedArrayBuffer` in bytes. This is established when |
| 897 | /// the `SharedArrayBuffer` is constructed and cannot be changed. |
| 898 | /// |
| 899 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/byteLength) |
| 900 | #[wasm_bindgen (method, getter, js_name = byteLength)] |
| 901 | pub unsafefn byte_length(this: &SharedArrayBuffer) -> u32; |
| 902 | |
| 903 | /// The `slice()` method returns a new `SharedArrayBuffer` whose contents |
| 904 | /// are a copy of this `SharedArrayBuffer`'s bytes from begin, inclusive, |
| 905 | /// up to end, exclusive. |
| 906 | /// |
| 907 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/slice) |
| 908 | #[wasm_bindgen (method)] |
| 909 | pub unsafefn slice(this: &SharedArrayBuffer, begin: u32) -> SharedArrayBuffer; |
| 910 | |
| 911 | /// Like `slice()` but with the `end` argument. |
| 912 | /// |
| 913 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/slice) |
| 914 | #[wasm_bindgen (method, js_name = slice)] |
| 915 | pub unsafefn slice_with_end(this: &SharedArrayBuffer, begin: u32, end: u32) -> SharedArrayBuffer; |
| 916 | } |
| 917 | |
| 918 | // Array Iterator |
| 919 | #[wasm_bindgen ] |
| 920 | unsafeextern "C" { |
| 921 | /// The `keys()` method returns a new Array Iterator object that contains the |
| 922 | /// keys for each index in the array. |
| 923 | /// |
| 924 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/keys) |
| 925 | #[wasm_bindgen (method)] |
| 926 | pub unsafefn keys(this: &Array) -> Iterator; |
| 927 | |
| 928 | /// The `entries()` method returns a new Array Iterator object that contains |
| 929 | /// the key/value pairs for each index in the array. |
| 930 | /// |
| 931 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries) |
| 932 | #[wasm_bindgen (method)] |
| 933 | pub unsafefn entries(this: &Array) -> Iterator; |
| 934 | |
| 935 | /// The `values()` method returns a new Array Iterator object that |
| 936 | /// contains the values for each index in the array. |
| 937 | /// |
| 938 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/values) |
| 939 | #[wasm_bindgen (method)] |
| 940 | pub unsafefn values(this: &Array) -> Iterator; |
| 941 | } |
| 942 | |
| 943 | /// The `Atomics` object provides atomic operations as static methods. |
| 944 | /// They are used with `SharedArrayBuffer` objects. |
| 945 | /// |
| 946 | /// The Atomic operations are installed on an `Atomics` module. Unlike |
| 947 | /// the other global objects, `Atomics` is not a constructor. You cannot |
| 948 | /// use it with a new operator or invoke the `Atomics` object as a |
| 949 | /// function. All properties and methods of `Atomics` are static |
| 950 | /// (as is the case with the Math object, for example). |
| 951 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics) |
| 952 | #[allow (non_snake_case)] |
| 953 | pub mod Atomics { |
| 954 | use super::*; |
| 955 | |
| 956 | #[wasm_bindgen ] |
| 957 | extern "C" { |
| 958 | /// The static `Atomics.add()` method adds a given value at a given |
| 959 | /// position in the array and returns the old value at that position. |
| 960 | /// This atomic operation guarantees that no other write happens |
| 961 | /// until the modified value is written back. |
| 962 | /// |
| 963 | /// You should use `add_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`. |
| 964 | /// |
| 965 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/add) |
| 966 | #[wasm_bindgen (js_namespace = Atomics, catch)] |
| 967 | pub fn add(typed_array: &JsValue, index: u32, value: i32) -> Result<i32, JsValue>; |
| 968 | |
| 969 | /// The static `Atomics.add()` method adds a given value at a given |
| 970 | /// position in the array and returns the old value at that position. |
| 971 | /// This atomic operation guarantees that no other write happens |
| 972 | /// until the modified value is written back. |
| 973 | /// |
| 974 | /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`. |
| 975 | /// |
| 976 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/add) |
| 977 | #[wasm_bindgen (js_namespace = Atomics, catch, js_name = add)] |
| 978 | pub fn add_bigint(typed_array: &JsValue, index: u32, value: i64) -> Result<i64, JsValue>; |
| 979 | |
| 980 | /// The static `Atomics.and()` method computes a bitwise AND with a given |
| 981 | /// value at a given position in the array, and returns the old value |
| 982 | /// at that position. |
| 983 | /// This atomic operation guarantees that no other write happens |
| 984 | /// until the modified value is written back. |
| 985 | /// |
| 986 | /// You should use `and_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`. |
| 987 | /// |
| 988 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/and) |
| 989 | #[wasm_bindgen (js_namespace = Atomics, catch)] |
| 990 | pub fn and(typed_array: &JsValue, index: u32, value: i32) -> Result<i32, JsValue>; |
| 991 | |
| 992 | /// The static `Atomics.and()` method computes a bitwise AND with a given |
| 993 | /// value at a given position in the array, and returns the old value |
| 994 | /// at that position. |
| 995 | /// This atomic operation guarantees that no other write happens |
| 996 | /// until the modified value is written back. |
| 997 | /// |
| 998 | /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`. |
| 999 | /// |
| 1000 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/and) |
| 1001 | #[wasm_bindgen (js_namespace = Atomics, catch, js_name = and)] |
| 1002 | pub fn and_bigint(typed_array: &JsValue, index: u32, value: i64) -> Result<i64, JsValue>; |
| 1003 | |
| 1004 | /// The static `Atomics.compareExchange()` method exchanges a given |
| 1005 | /// replacement value at a given position in the array, if a given expected |
| 1006 | /// value equals the old value. It returns the old value at that position |
| 1007 | /// whether it was equal to the expected value or not. |
| 1008 | /// This atomic operation guarantees that no other write happens |
| 1009 | /// until the modified value is written back. |
| 1010 | /// |
| 1011 | /// You should use `compare_exchange_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`. |
| 1012 | /// |
| 1013 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/compareExchange) |
| 1014 | #[wasm_bindgen (js_namespace = Atomics, catch, js_name = compareExchange)] |
| 1015 | pub fn compare_exchange( |
| 1016 | typed_array: &JsValue, |
| 1017 | index: u32, |
| 1018 | expected_value: i32, |
| 1019 | replacement_value: i32, |
| 1020 | ) -> Result<i32, JsValue>; |
| 1021 | |
| 1022 | /// The static `Atomics.compareExchange()` method exchanges a given |
| 1023 | /// replacement value at a given position in the array, if a given expected |
| 1024 | /// value equals the old value. It returns the old value at that position |
| 1025 | /// whether it was equal to the expected value or not. |
| 1026 | /// This atomic operation guarantees that no other write happens |
| 1027 | /// until the modified value is written back. |
| 1028 | /// |
| 1029 | /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`. |
| 1030 | /// |
| 1031 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/compareExchange) |
| 1032 | #[wasm_bindgen (js_namespace = Atomics, catch, js_name = compareExchange)] |
| 1033 | pub fn compare_exchange_bigint( |
| 1034 | typed_array: &JsValue, |
| 1035 | index: u32, |
| 1036 | expected_value: i64, |
| 1037 | replacement_value: i64, |
| 1038 | ) -> Result<i64, JsValue>; |
| 1039 | |
| 1040 | /// The static `Atomics.exchange()` method stores a given value at a given |
| 1041 | /// position in the array and returns the old value at that position. |
| 1042 | /// This atomic operation guarantees that no other write happens |
| 1043 | /// until the modified value is written back. |
| 1044 | /// |
| 1045 | /// You should use `exchange_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`. |
| 1046 | /// |
| 1047 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/exchange) |
| 1048 | #[wasm_bindgen (js_namespace = Atomics, catch)] |
| 1049 | pub fn exchange(typed_array: &JsValue, index: u32, value: i32) -> Result<i32, JsValue>; |
| 1050 | |
| 1051 | /// The static `Atomics.exchange()` method stores a given value at a given |
| 1052 | /// position in the array and returns the old value at that position. |
| 1053 | /// This atomic operation guarantees that no other write happens |
| 1054 | /// until the modified value is written back. |
| 1055 | /// |
| 1056 | /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`. |
| 1057 | /// |
| 1058 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/exchange) |
| 1059 | #[wasm_bindgen (js_namespace = Atomics, catch, js_name = exchange)] |
| 1060 | pub fn exchange_bigint( |
| 1061 | typed_array: &JsValue, |
| 1062 | index: u32, |
| 1063 | value: i64, |
| 1064 | ) -> Result<i64, JsValue>; |
| 1065 | |
| 1066 | /// The static `Atomics.isLockFree()` method is used to determine |
| 1067 | /// whether to use locks or atomic operations. It returns true, |
| 1068 | /// if the given size is one of the `BYTES_PER_ELEMENT` property |
| 1069 | /// of integer `TypedArray` types. |
| 1070 | /// |
| 1071 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/isLockFree) |
| 1072 | #[wasm_bindgen (js_namespace = Atomics, js_name = isLockFree)] |
| 1073 | pub fn is_lock_free(size: u32) -> bool; |
| 1074 | |
| 1075 | /// The static `Atomics.load()` method returns a value at a given |
| 1076 | /// position in the array. |
| 1077 | /// |
| 1078 | /// You should use `load_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`. |
| 1079 | /// |
| 1080 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/load) |
| 1081 | #[wasm_bindgen (js_namespace = Atomics, catch)] |
| 1082 | pub fn load(typed_array: &JsValue, index: u32) -> Result<i32, JsValue>; |
| 1083 | |
| 1084 | /// The static `Atomics.load()` method returns a value at a given |
| 1085 | /// position in the array. |
| 1086 | /// |
| 1087 | /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`. |
| 1088 | /// |
| 1089 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/load) |
| 1090 | #[wasm_bindgen (js_namespace = Atomics, catch, js_name = load)] |
| 1091 | pub fn load_bigint(typed_array: &JsValue, index: i64) -> Result<i64, JsValue>; |
| 1092 | |
| 1093 | /// The static `Atomics.notify()` method notifies up some agents that |
| 1094 | /// are sleeping in the wait queue. |
| 1095 | /// Note: This operation works with a shared `Int32Array` only. |
| 1096 | /// If `count` is not provided, notifies all the agents in the queue. |
| 1097 | /// |
| 1098 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/notify) |
| 1099 | #[wasm_bindgen (js_namespace = Atomics, catch)] |
| 1100 | pub fn notify(typed_array: &Int32Array, index: u32) -> Result<u32, JsValue>; |
| 1101 | |
| 1102 | /// Notifies up to `count` agents in the wait queue. |
| 1103 | #[wasm_bindgen (js_namespace = Atomics, catch, js_name = notify)] |
| 1104 | pub fn notify_with_count( |
| 1105 | typed_array: &Int32Array, |
| 1106 | index: u32, |
| 1107 | count: u32, |
| 1108 | ) -> Result<u32, JsValue>; |
| 1109 | |
| 1110 | /// The static `Atomics.or()` method computes a bitwise OR with a given value |
| 1111 | /// at a given position in the array, and returns the old value at that position. |
| 1112 | /// This atomic operation guarantees that no other write happens |
| 1113 | /// until the modified value is written back. |
| 1114 | /// |
| 1115 | /// You should use `or_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`. |
| 1116 | /// |
| 1117 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/or) |
| 1118 | #[wasm_bindgen (js_namespace = Atomics, catch)] |
| 1119 | pub fn or(typed_array: &JsValue, index: u32, value: i32) -> Result<i32, JsValue>; |
| 1120 | |
| 1121 | /// The static `Atomics.or()` method computes a bitwise OR with a given value |
| 1122 | /// at a given position in the array, and returns the old value at that position. |
| 1123 | /// This atomic operation guarantees that no other write happens |
| 1124 | /// until the modified value is written back. |
| 1125 | /// |
| 1126 | /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`. |
| 1127 | /// |
| 1128 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/or) |
| 1129 | #[wasm_bindgen (js_namespace = Atomics, catch, js_name = or)] |
| 1130 | pub fn or_bigint(typed_array: &JsValue, index: u32, value: i64) -> Result<i64, JsValue>; |
| 1131 | |
| 1132 | /// The static `Atomics.store()` method stores a given value at the given |
| 1133 | /// position in the array and returns that value. |
| 1134 | /// |
| 1135 | /// You should use `store_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`. |
| 1136 | /// |
| 1137 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/store) |
| 1138 | #[wasm_bindgen (js_namespace = Atomics, catch)] |
| 1139 | pub fn store(typed_array: &JsValue, index: u32, value: i32) -> Result<i32, JsValue>; |
| 1140 | |
| 1141 | /// The static `Atomics.store()` method stores a given value at the given |
| 1142 | /// position in the array and returns that value. |
| 1143 | /// |
| 1144 | /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`. |
| 1145 | /// |
| 1146 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/store) |
| 1147 | #[wasm_bindgen (js_namespace = Atomics, catch, js_name = store)] |
| 1148 | pub fn store_bigint(typed_array: &JsValue, index: u32, value: i64) -> Result<i64, JsValue>; |
| 1149 | |
| 1150 | /// The static `Atomics.sub()` method subtracts a given value at a |
| 1151 | /// given position in the array and returns the old value at that position. |
| 1152 | /// This atomic operation guarantees that no other write happens |
| 1153 | /// until the modified value is written back. |
| 1154 | /// |
| 1155 | /// You should use `sub_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`. |
| 1156 | /// |
| 1157 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/sub) |
| 1158 | #[wasm_bindgen (js_namespace = Atomics, catch)] |
| 1159 | pub fn sub(typed_array: &JsValue, index: u32, value: i32) -> Result<i32, JsValue>; |
| 1160 | |
| 1161 | /// The static `Atomics.sub()` method subtracts a given value at a |
| 1162 | /// given position in the array and returns the old value at that position. |
| 1163 | /// This atomic operation guarantees that no other write happens |
| 1164 | /// until the modified value is written back. |
| 1165 | /// |
| 1166 | /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`. |
| 1167 | /// |
| 1168 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/sub) |
| 1169 | #[wasm_bindgen (js_namespace = Atomics, catch, js_name = sub)] |
| 1170 | pub fn sub_bigint(typed_array: &JsValue, index: u32, value: i64) -> Result<i64, JsValue>; |
| 1171 | |
| 1172 | /// The static `Atomics.wait()` method verifies that a given |
| 1173 | /// position in an `Int32Array` still contains a given value |
| 1174 | /// and if so sleeps, awaiting a wakeup or a timeout. |
| 1175 | /// It returns a string which is either "ok", "not-equal", or "timed-out". |
| 1176 | /// Note: This operation only works with a shared `Int32Array` |
| 1177 | /// and may not be allowed on the main thread. |
| 1178 | /// |
| 1179 | /// You should use `wait_bigint` to operate on a `BigInt64Array`. |
| 1180 | /// |
| 1181 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait) |
| 1182 | #[wasm_bindgen (js_namespace = Atomics, catch)] |
| 1183 | pub fn wait(typed_array: &Int32Array, index: u32, value: i32) -> Result<JsString, JsValue>; |
| 1184 | |
| 1185 | /// The static `Atomics.wait()` method verifies that a given |
| 1186 | /// position in an `BigInt64Array` still contains a given value |
| 1187 | /// and if so sleeps, awaiting a wakeup or a timeout. |
| 1188 | /// It returns a string which is either "ok", "not-equal", or "timed-out". |
| 1189 | /// Note: This operation only works with a shared `BigInt64Array` |
| 1190 | /// and may not be allowed on the main thread. |
| 1191 | /// |
| 1192 | /// You should use `wait` to operate on a `Int32Array`. |
| 1193 | /// |
| 1194 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait) |
| 1195 | #[wasm_bindgen (js_namespace = Atomics, catch, js_name = wait)] |
| 1196 | pub fn wait_bigint( |
| 1197 | typed_array: &BigInt64Array, |
| 1198 | index: u32, |
| 1199 | value: i64, |
| 1200 | ) -> Result<JsString, JsValue>; |
| 1201 | |
| 1202 | /// Like `wait()`, but with timeout |
| 1203 | /// |
| 1204 | /// You should use `wait_with_timeout_bigint` to operate on a `BigInt64Array`. |
| 1205 | /// |
| 1206 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait) |
| 1207 | #[wasm_bindgen (js_namespace = Atomics, catch, js_name = wait)] |
| 1208 | pub fn wait_with_timeout( |
| 1209 | typed_array: &Int32Array, |
| 1210 | index: u32, |
| 1211 | value: i32, |
| 1212 | timeout: f64, |
| 1213 | ) -> Result<JsString, JsValue>; |
| 1214 | |
| 1215 | /// Like `wait()`, but with timeout |
| 1216 | /// |
| 1217 | /// You should use `wait_with_timeout` to operate on a `Int32Array`. |
| 1218 | /// |
| 1219 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait) |
| 1220 | #[wasm_bindgen (js_namespace = Atomics, catch, js_name = wait)] |
| 1221 | pub fn wait_with_timeout_bigint( |
| 1222 | typed_array: &BigInt64Array, |
| 1223 | index: u32, |
| 1224 | value: i64, |
| 1225 | timeout: f64, |
| 1226 | ) -> Result<JsString, JsValue>; |
| 1227 | |
| 1228 | /// The static `Atomics.waitAsync()` method verifies that a given position in an |
| 1229 | /// `Int32Array` still contains a given value and if so sleeps, awaiting a |
| 1230 | /// wakeup or a timeout. It returns an object with two properties. The first |
| 1231 | /// property `async` is a boolean which if true indicates that the second |
| 1232 | /// property `value` is a promise. If `async` is false then value is a string |
| 1233 | /// whether equal to either "not-equal" or "timed-out". |
| 1234 | /// Note: This operation only works with a shared `Int32Array` and may be used |
| 1235 | /// on the main thread. |
| 1236 | /// |
| 1237 | /// You should use `wait_async_bigint` to operate on a `BigInt64Array`. |
| 1238 | /// |
| 1239 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/waitAsync) |
| 1240 | #[wasm_bindgen (js_namespace = Atomics, catch, js_name = waitAsync)] |
| 1241 | pub fn wait_async( |
| 1242 | typed_array: &Int32Array, |
| 1243 | index: u32, |
| 1244 | value: i32, |
| 1245 | ) -> Result<Object, JsValue>; |
| 1246 | |
| 1247 | /// The static `Atomics.waitAsync()` method verifies that a given position in an |
| 1248 | /// `Int32Array` still contains a given value and if so sleeps, awaiting a |
| 1249 | /// wakeup or a timeout. It returns an object with two properties. The first |
| 1250 | /// property `async` is a boolean which if true indicates that the second |
| 1251 | /// property `value` is a promise. If `async` is false then value is a string |
| 1252 | /// whether equal to either "not-equal" or "timed-out". |
| 1253 | /// Note: This operation only works with a shared `BigInt64Array` and may be used |
| 1254 | /// on the main thread. |
| 1255 | /// |
| 1256 | /// You should use `wait_async` to operate on a `Int32Array`. |
| 1257 | /// |
| 1258 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/waitAsync) |
| 1259 | #[wasm_bindgen (js_namespace = Atomics, catch, js_name = waitAsync)] |
| 1260 | pub fn wait_async_bigint( |
| 1261 | typed_array: &BigInt64Array, |
| 1262 | index: u32, |
| 1263 | value: i64, |
| 1264 | ) -> Result<Object, JsValue>; |
| 1265 | |
| 1266 | /// Like `waitAsync()`, but with timeout |
| 1267 | /// |
| 1268 | /// You should use `wait_async_with_timeout_bigint` to operate on a `BigInt64Array`. |
| 1269 | /// |
| 1270 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/waitAsync) |
| 1271 | #[wasm_bindgen (js_namespace = Atomics, catch, js_name = waitAsync)] |
| 1272 | pub fn wait_async_with_timeout( |
| 1273 | typed_array: &Int32Array, |
| 1274 | index: u32, |
| 1275 | value: i32, |
| 1276 | timeout: f64, |
| 1277 | ) -> Result<Object, JsValue>; |
| 1278 | |
| 1279 | /// Like `waitAsync()`, but with timeout |
| 1280 | /// |
| 1281 | /// You should use `wait_async_with_timeout` to operate on a `Int32Array`. |
| 1282 | /// |
| 1283 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/waitAsync) |
| 1284 | #[wasm_bindgen (js_namespace = Atomics, catch, js_name = waitAsync)] |
| 1285 | pub fn wait_async_with_timeout_bigint( |
| 1286 | typed_array: &BigInt64Array, |
| 1287 | index: u32, |
| 1288 | value: i64, |
| 1289 | timeout: f64, |
| 1290 | ) -> Result<Object, JsValue>; |
| 1291 | |
| 1292 | /// The static `Atomics.xor()` method computes a bitwise XOR |
| 1293 | /// with a given value at a given position in the array, |
| 1294 | /// and returns the old value at that position. |
| 1295 | /// This atomic operation guarantees that no other write happens |
| 1296 | /// until the modified value is written back. |
| 1297 | /// |
| 1298 | /// You should use `xor_bigint` to operate on a `BigInt64Array` or a `BigUint64Array`. |
| 1299 | /// |
| 1300 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/xor) |
| 1301 | #[wasm_bindgen (js_namespace = Atomics, catch)] |
| 1302 | pub fn xor(typed_array: &JsValue, index: u32, value: i32) -> Result<i32, JsValue>; |
| 1303 | |
| 1304 | /// The static `Atomics.xor()` method computes a bitwise XOR |
| 1305 | /// with a given value at a given position in the array, |
| 1306 | /// and returns the old value at that position. |
| 1307 | /// This atomic operation guarantees that no other write happens |
| 1308 | /// until the modified value is written back. |
| 1309 | /// |
| 1310 | /// This method is used to operate on a `BigInt64Array` or a `BigUint64Array`. |
| 1311 | /// |
| 1312 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/xor) |
| 1313 | #[wasm_bindgen (js_namespace = Atomics, catch, js_name = xor)] |
| 1314 | pub fn xor_bigint(typed_array: &JsValue, index: u32, value: i64) -> Result<i64, JsValue>; |
| 1315 | } |
| 1316 | } |
| 1317 | |
| 1318 | // BigInt |
| 1319 | #[wasm_bindgen ] |
| 1320 | unsafeextern "C" { |
| 1321 | #[wasm_bindgen (extends = Object, is_type_of = |v| v.is_bigint(), typescript_type = "bigint" )] |
| 1322 | #[derive (Clone, PartialEq, Eq)] |
| 1323 | pub type BigInt; |
| 1324 | |
| 1325 | #[wasm_bindgen (catch, js_name = BigInt)] |
| 1326 | unsafefn new_bigint(value: &JsValue) -> Result<BigInt, Error>; |
| 1327 | |
| 1328 | #[wasm_bindgen (js_name = BigInt)] |
| 1329 | unsafefn new_bigint_unchecked(value: &JsValue) -> BigInt; |
| 1330 | |
| 1331 | /// Clamps a BigInt value to a signed integer value, and returns that value. |
| 1332 | /// |
| 1333 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/asIntN) |
| 1334 | #[wasm_bindgen (static_method_of = BigInt, js_name = asIntN)] |
| 1335 | pub unsafefn as_int_n(bits: f64, bigint: &BigInt) -> BigInt; |
| 1336 | |
| 1337 | /// Clamps a BigInt value to an unsigned integer value, and returns that value. |
| 1338 | /// |
| 1339 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/asUintN) |
| 1340 | #[wasm_bindgen (static_method_of = BigInt, js_name = asUintN)] |
| 1341 | pub unsafefn as_uint_n(bits: f64, bigint: &BigInt) -> BigInt; |
| 1342 | |
| 1343 | /// Returns a string with a language-sensitive representation of this BigInt value. Overrides the [`Object.prototype.toLocaleString()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/toLocaleString) method. |
| 1344 | /// |
| 1345 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/toLocaleString) |
| 1346 | #[wasm_bindgen (method, js_name = toLocaleString)] |
| 1347 | pub unsafefn to_locale_string(this: &BigInt, locales: &JsValue, options: &JsValue) -> JsString; |
| 1348 | |
| 1349 | /// Returns a string representing this BigInt value in the specified radix (base). Overrides the [`Object.prototype.toString()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString) method. |
| 1350 | /// |
| 1351 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/toString) |
| 1352 | #[wasm_bindgen (catch, method, js_name = toString)] |
| 1353 | pub unsafefn to_string(this: &BigInt, radix: u8) -> Result<JsString, RangeError>; |
| 1354 | |
| 1355 | #[wasm_bindgen (method, js_name = toString)] |
| 1356 | unsafefn to_string_unchecked(this: &BigInt, radix: u8) -> String; |
| 1357 | |
| 1358 | /// Returns this BigInt value. Overrides the [`Object.prototype.valueOf()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf) method. |
| 1359 | /// |
| 1360 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/valueOf) |
| 1361 | #[wasm_bindgen (method, js_name = valueOf)] |
| 1362 | pub unsafefn value_of(this: &BigInt, radix: u8) -> BigInt; |
| 1363 | } |
| 1364 | |
| 1365 | impl BigInt { |
| 1366 | /// Creates a new BigInt value. |
| 1367 | /// |
| 1368 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt/BigInt) |
| 1369 | #[inline ] |
| 1370 | pub fn new(value: &JsValue) -> Result<BigInt, Error> { |
| 1371 | new_bigint(value) |
| 1372 | } |
| 1373 | |
| 1374 | /// Applies the binary `/` JS operator on two `BigInt`s, catching and returning any `RangeError` thrown. |
| 1375 | /// |
| 1376 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Division) |
| 1377 | pub fn checked_div(&self, rhs: &Self) -> Result<Self, RangeError> { |
| 1378 | let result = JsValue::as_ref(self).checked_div(JsValue::as_ref(rhs)); |
| 1379 | |
| 1380 | if result.is_instance_of::<RangeError>() { |
| 1381 | Err(result.unchecked_into()) |
| 1382 | } else { |
| 1383 | Ok(result.unchecked_into()) |
| 1384 | } |
| 1385 | } |
| 1386 | |
| 1387 | /// Applies the binary `**` JS operator on the two `BigInt`s. |
| 1388 | /// |
| 1389 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Exponentiation) |
| 1390 | #[inline ] |
| 1391 | pub fn pow(&self, rhs: &Self) -> Self { |
| 1392 | JsValue::as_ref(self) |
| 1393 | .pow(JsValue::as_ref(rhs)) |
| 1394 | .unchecked_into() |
| 1395 | } |
| 1396 | |
| 1397 | /// Returns a tuple of this [`BigInt`]'s absolute value along with a |
| 1398 | /// [`bool`] indicating whether the [`BigInt`] was negative. |
| 1399 | fn abs(&self) -> (Self, bool) { |
| 1400 | if self < &BigInt::from(0) { |
| 1401 | (-self, true) |
| 1402 | } else { |
| 1403 | (self.clone(), false) |
| 1404 | } |
| 1405 | } |
| 1406 | } |
| 1407 | |
| 1408 | macro_rules! bigint_from { |
| 1409 | ($($x:ident)*) => ($( |
| 1410 | impl From<$x> for BigInt { |
| 1411 | #[inline] |
| 1412 | fn from(x: $x) -> BigInt { |
| 1413 | new_bigint_unchecked(&JsValue::from(x)) |
| 1414 | } |
| 1415 | } |
| 1416 | |
| 1417 | impl PartialEq<$x> for BigInt { |
| 1418 | #[inline] |
| 1419 | fn eq(&self, other: &$x) -> bool { |
| 1420 | JsValue::from(self) == JsValue::from(BigInt::from(*other)) |
| 1421 | } |
| 1422 | } |
| 1423 | )*) |
| 1424 | } |
| 1425 | bigint_from!(i8 u8 i16 u16 i32 u32 isize usize); |
| 1426 | |
| 1427 | macro_rules! bigint_from_big { |
| 1428 | ($($x:ident)*) => ($( |
| 1429 | impl From<$x> for BigInt { |
| 1430 | #[inline] |
| 1431 | fn from(x: $x) -> BigInt { |
| 1432 | JsValue::from(x).unchecked_into() |
| 1433 | } |
| 1434 | } |
| 1435 | |
| 1436 | impl PartialEq<$x> for BigInt { |
| 1437 | #[inline] |
| 1438 | fn eq(&self, other: &$x) -> bool { |
| 1439 | self == &BigInt::from(*other) |
| 1440 | } |
| 1441 | } |
| 1442 | |
| 1443 | impl TryFrom<BigInt> for $x { |
| 1444 | type Error = BigInt; |
| 1445 | |
| 1446 | #[inline] |
| 1447 | fn try_from(x: BigInt) -> Result<Self, BigInt> { |
| 1448 | Self::try_from(JsValue::from(x)).map_err(JsCast::unchecked_into) |
| 1449 | } |
| 1450 | } |
| 1451 | )*) |
| 1452 | } |
| 1453 | bigint_from_big!(i64 u64 i128 u128); |
| 1454 | |
| 1455 | impl PartialEq<Number> for BigInt { |
| 1456 | #[inline ] |
| 1457 | fn eq(&self, other: &Number) -> bool { |
| 1458 | JsValue::as_ref(self).loose_eq(JsValue::as_ref(self:other)) |
| 1459 | } |
| 1460 | } |
| 1461 | |
| 1462 | impl Not for &BigInt { |
| 1463 | type Output = BigInt; |
| 1464 | |
| 1465 | #[inline ] |
| 1466 | fn not(self) -> Self::Output { |
| 1467 | JsValue::as_ref(self).bit_not().unchecked_into() |
| 1468 | } |
| 1469 | } |
| 1470 | |
| 1471 | forward_deref_unop!(impl Not, not for BigInt); |
| 1472 | forward_js_unop!(impl Neg, neg for BigInt); |
| 1473 | forward_js_binop!(impl BitAnd, bitand for BigInt); |
| 1474 | forward_js_binop!(impl BitOr, bitor for BigInt); |
| 1475 | forward_js_binop!(impl BitXor, bitxor for BigInt); |
| 1476 | forward_js_binop!(impl Shl, shl for BigInt); |
| 1477 | forward_js_binop!(impl Shr, shr for BigInt); |
| 1478 | forward_js_binop!(impl Add, add for BigInt); |
| 1479 | forward_js_binop!(impl Sub, sub for BigInt); |
| 1480 | forward_js_binop!(impl Div, div for BigInt); |
| 1481 | forward_js_binop!(impl Mul, mul for BigInt); |
| 1482 | forward_js_binop!(impl Rem, rem for BigInt); |
| 1483 | sum_product!(BigInt); |
| 1484 | |
| 1485 | partialord_ord!(BigInt); |
| 1486 | |
| 1487 | impl Default for BigInt { |
| 1488 | fn default() -> Self { |
| 1489 | BigInt::from(i32::default()) |
| 1490 | } |
| 1491 | } |
| 1492 | |
| 1493 | impl FromStr for BigInt { |
| 1494 | type Err = Error; |
| 1495 | |
| 1496 | #[inline ] |
| 1497 | fn from_str(s: &str) -> Result<Self, Self::Err> { |
| 1498 | BigInt::new(&s.into()) |
| 1499 | } |
| 1500 | } |
| 1501 | |
| 1502 | impl fmt::Debug for BigInt { |
| 1503 | #[inline ] |
| 1504 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 1505 | fmt::Display::fmt(self, f) |
| 1506 | } |
| 1507 | } |
| 1508 | |
| 1509 | impl fmt::Display for BigInt { |
| 1510 | #[inline ] |
| 1511 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 1512 | let (abs: BigInt, is_neg: bool) = self.abs(); |
| 1513 | f.pad_integral(!is_neg, prefix:"" , &abs.to_string_unchecked(10)) |
| 1514 | } |
| 1515 | } |
| 1516 | |
| 1517 | impl fmt::Binary for BigInt { |
| 1518 | #[inline ] |
| 1519 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 1520 | let (abs: BigInt, is_neg: bool) = self.abs(); |
| 1521 | f.pad_integral(!is_neg, prefix:"0b" , &abs.to_string_unchecked(2)) |
| 1522 | } |
| 1523 | } |
| 1524 | |
| 1525 | impl fmt::Octal for BigInt { |
| 1526 | #[inline ] |
| 1527 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 1528 | let (abs: BigInt, is_neg: bool) = self.abs(); |
| 1529 | f.pad_integral(!is_neg, prefix:"0o" , &abs.to_string_unchecked(8)) |
| 1530 | } |
| 1531 | } |
| 1532 | |
| 1533 | impl fmt::LowerHex for BigInt { |
| 1534 | #[inline ] |
| 1535 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 1536 | let (abs: BigInt, is_neg: bool) = self.abs(); |
| 1537 | f.pad_integral(!is_neg, prefix:"0x" , &abs.to_string_unchecked(16)) |
| 1538 | } |
| 1539 | } |
| 1540 | |
| 1541 | impl fmt::UpperHex for BigInt { |
| 1542 | #[inline ] |
| 1543 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 1544 | let (abs: BigInt, is_neg: bool) = self.abs(); |
| 1545 | let mut s: String = abs.to_string_unchecked(16); |
| 1546 | s.make_ascii_uppercase(); |
| 1547 | f.pad_integral(!is_neg, prefix:"0x" , &s) |
| 1548 | } |
| 1549 | } |
| 1550 | |
| 1551 | // Boolean |
| 1552 | #[wasm_bindgen ] |
| 1553 | unsafeextern "C" { |
| 1554 | #[wasm_bindgen (extends = Object, is_type_of = |v| v.as_bool().is_some(), typescript_type = "boolean" )] |
| 1555 | #[derive (Clone, PartialEq, Eq)] |
| 1556 | pub type Boolean; |
| 1557 | |
| 1558 | /// The `Boolean()` constructor creates an object wrapper for a boolean value. |
| 1559 | /// |
| 1560 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean) |
| 1561 | #[wasm_bindgen (constructor)] |
| 1562 | #[deprecated (note = "recommended to use `Boolean::from` instead" )] |
| 1563 | #[allow (deprecated)] |
| 1564 | pub unsafefn new(value: &JsValue) -> Boolean; |
| 1565 | |
| 1566 | /// The `valueOf()` method returns the primitive value of a `Boolean` object. |
| 1567 | /// |
| 1568 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean/valueOf) |
| 1569 | #[wasm_bindgen (method, js_name = valueOf)] |
| 1570 | pub unsafefn value_of(this: &Boolean) -> bool; |
| 1571 | } |
| 1572 | |
| 1573 | impl From<bool> for Boolean { |
| 1574 | #[inline ] |
| 1575 | fn from(b: bool) -> Boolean { |
| 1576 | Boolean::unchecked_from_js(JsValue::from(b)) |
| 1577 | } |
| 1578 | } |
| 1579 | |
| 1580 | impl From<Boolean> for bool { |
| 1581 | #[inline ] |
| 1582 | fn from(b: Boolean) -> bool { |
| 1583 | b.value_of() |
| 1584 | } |
| 1585 | } |
| 1586 | |
| 1587 | impl PartialEq<bool> for Boolean { |
| 1588 | #[inline ] |
| 1589 | fn eq(&self, other: &bool) -> bool { |
| 1590 | self.value_of() == *other |
| 1591 | } |
| 1592 | } |
| 1593 | |
| 1594 | impl fmt::Debug for Boolean { |
| 1595 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
| 1596 | fmt::Debug::fmt(&self.value_of(), f) |
| 1597 | } |
| 1598 | } |
| 1599 | |
| 1600 | impl fmt::Display for Boolean { |
| 1601 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
| 1602 | fmt::Display::fmt(&self.value_of(), f) |
| 1603 | } |
| 1604 | } |
| 1605 | |
| 1606 | impl Default for Boolean { |
| 1607 | fn default() -> Self { |
| 1608 | Self::from(bool::default()) |
| 1609 | } |
| 1610 | } |
| 1611 | |
| 1612 | impl Not for &Boolean { |
| 1613 | type Output = Boolean; |
| 1614 | |
| 1615 | #[inline ] |
| 1616 | fn not(self) -> Self::Output { |
| 1617 | (!JsValue::as_ref(self)).into() |
| 1618 | } |
| 1619 | } |
| 1620 | |
| 1621 | forward_deref_unop!(impl Not, not for Boolean); |
| 1622 | |
| 1623 | partialord_ord!(Boolean); |
| 1624 | |
| 1625 | // DataView |
| 1626 | #[wasm_bindgen ] |
| 1627 | unsafeextern "C" { |
| 1628 | #[wasm_bindgen (extends = Object, typescript_type = "DataView" )] |
| 1629 | #[derive (Clone, Debug, PartialEq, Eq)] |
| 1630 | pub type DataView; |
| 1631 | |
| 1632 | /// The `DataView` view provides a low-level interface for reading and |
| 1633 | /// writing multiple number types in an `ArrayBuffer` irrespective of the |
| 1634 | /// platform's endianness. |
| 1635 | /// |
| 1636 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView) |
| 1637 | #[wasm_bindgen (constructor)] |
| 1638 | pub unsafefn new(buffer: &ArrayBuffer, byteOffset: usize, byteLength: usize) -> DataView; |
| 1639 | |
| 1640 | /// The `DataView` view provides a low-level interface for reading and |
| 1641 | /// writing multiple number types in an `ArrayBuffer` irrespective of the |
| 1642 | /// platform's endianness. |
| 1643 | /// |
| 1644 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView) |
| 1645 | #[wasm_bindgen (constructor)] |
| 1646 | pub unsafefn new_with_shared_array_buffer( |
| 1647 | buffer: &SharedArrayBuffer, |
| 1648 | byteOffset: usize, |
| 1649 | byteLength: usize, |
| 1650 | ) -> DataView; |
| 1651 | |
| 1652 | /// The ArrayBuffer referenced by this view. Fixed at construction time and thus read only. |
| 1653 | /// |
| 1654 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/buffer) |
| 1655 | #[wasm_bindgen (method, getter, structural)] |
| 1656 | pub unsafefn buffer(this: &DataView) -> ArrayBuffer; |
| 1657 | |
| 1658 | /// The length (in bytes) of this view from the start of its ArrayBuffer. |
| 1659 | /// Fixed at construction time and thus read only. |
| 1660 | /// |
| 1661 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/byteLength) |
| 1662 | #[wasm_bindgen (method, getter, structural, js_name = byteLength)] |
| 1663 | pub unsafefn byte_length(this: &DataView) -> usize; |
| 1664 | |
| 1665 | /// The offset (in bytes) of this view from the start of its ArrayBuffer. |
| 1666 | /// Fixed at construction time and thus read only. |
| 1667 | /// |
| 1668 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/byteOffset) |
| 1669 | #[wasm_bindgen (method, getter, structural, js_name = byteOffset)] |
| 1670 | pub unsafefn byte_offset(this: &DataView) -> usize; |
| 1671 | |
| 1672 | /// The `getInt8()` method gets a signed 8-bit integer (byte) at the |
| 1673 | /// specified byte offset from the start of the DataView. |
| 1674 | /// |
| 1675 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt8) |
| 1676 | #[wasm_bindgen (method, js_name = getInt8)] |
| 1677 | pub unsafefn get_int8(this: &DataView, byte_offset: usize) -> i8; |
| 1678 | |
| 1679 | /// The `getUint8()` method gets a unsigned 8-bit integer (byte) at the specified |
| 1680 | /// byte offset from the start of the DataView. |
| 1681 | /// |
| 1682 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint8) |
| 1683 | #[wasm_bindgen (method, js_name = getUint8)] |
| 1684 | pub unsafefn get_uint8(this: &DataView, byte_offset: usize) -> u8; |
| 1685 | |
| 1686 | /// The `getInt16()` method gets a signed 16-bit integer (short) at the specified |
| 1687 | /// byte offset from the start of the DataView. |
| 1688 | /// |
| 1689 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt16) |
| 1690 | #[wasm_bindgen (method, js_name = getInt16)] |
| 1691 | pub unsafefn get_int16(this: &DataView, byte_offset: usize) -> i16; |
| 1692 | |
| 1693 | /// The `getInt16()` method gets a signed 16-bit integer (short) at the specified |
| 1694 | /// byte offset from the start of the DataView. |
| 1695 | /// |
| 1696 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt16) |
| 1697 | #[wasm_bindgen (method, js_name = getInt16)] |
| 1698 | pub unsafefn get_int16_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> i16; |
| 1699 | |
| 1700 | /// The `getUint16()` method gets an unsigned 16-bit integer (unsigned short) at the specified |
| 1701 | /// byte offset from the start of the view. |
| 1702 | /// |
| 1703 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint16) |
| 1704 | #[wasm_bindgen (method, js_name = getUint16)] |
| 1705 | pub unsafefn get_uint16(this: &DataView, byte_offset: usize) -> u16; |
| 1706 | |
| 1707 | /// The `getUint16()` method gets an unsigned 16-bit integer (unsigned short) at the specified |
| 1708 | /// byte offset from the start of the view. |
| 1709 | /// |
| 1710 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint16) |
| 1711 | #[wasm_bindgen (method, js_name = getUint16)] |
| 1712 | pub unsafefn get_uint16_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> u16; |
| 1713 | |
| 1714 | /// The `getInt32()` method gets a signed 32-bit integer (long) at the specified |
| 1715 | /// byte offset from the start of the DataView. |
| 1716 | /// |
| 1717 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt32) |
| 1718 | #[wasm_bindgen (method, js_name = getInt32)] |
| 1719 | pub unsafefn get_int32(this: &DataView, byte_offset: usize) -> i32; |
| 1720 | |
| 1721 | /// The `getInt32()` method gets a signed 32-bit integer (long) at the specified |
| 1722 | /// byte offset from the start of the DataView. |
| 1723 | /// |
| 1724 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt32) |
| 1725 | #[wasm_bindgen (method, js_name = getInt32)] |
| 1726 | pub unsafefn get_int32_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> i32; |
| 1727 | |
| 1728 | /// The `getUint32()` method gets an unsigned 32-bit integer (unsigned long) at the specified |
| 1729 | /// byte offset from the start of the view. |
| 1730 | /// |
| 1731 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint32) |
| 1732 | #[wasm_bindgen (method, js_name = getUint32)] |
| 1733 | pub unsafefn get_uint32(this: &DataView, byte_offset: usize) -> u32; |
| 1734 | |
| 1735 | /// The `getUint32()` method gets an unsigned 32-bit integer (unsigned long) at the specified |
| 1736 | /// byte offset from the start of the view. |
| 1737 | /// |
| 1738 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint32) |
| 1739 | #[wasm_bindgen (method, js_name = getUint32)] |
| 1740 | pub unsafefn get_uint32_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> u32; |
| 1741 | |
| 1742 | /// The `getFloat32()` method gets a signed 32-bit float (float) at the specified |
| 1743 | /// byte offset from the start of the DataView. |
| 1744 | /// |
| 1745 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat32) |
| 1746 | #[wasm_bindgen (method, js_name = getFloat32)] |
| 1747 | pub unsafefn get_float32(this: &DataView, byte_offset: usize) -> f32; |
| 1748 | |
| 1749 | /// The `getFloat32()` method gets a signed 32-bit float (float) at the specified |
| 1750 | /// byte offset from the start of the DataView. |
| 1751 | /// |
| 1752 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat32) |
| 1753 | #[wasm_bindgen (method, js_name = getFloat32)] |
| 1754 | pub unsafefn get_float32_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> f32; |
| 1755 | |
| 1756 | /// The `getFloat64()` method gets a signed 64-bit float (double) at the specified |
| 1757 | /// byte offset from the start of the DataView. |
| 1758 | /// |
| 1759 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat64) |
| 1760 | #[wasm_bindgen (method, js_name = getFloat64)] |
| 1761 | pub unsafefn get_float64(this: &DataView, byte_offset: usize) -> f64; |
| 1762 | |
| 1763 | /// The `getFloat64()` method gets a signed 64-bit float (double) at the specified |
| 1764 | /// byte offset from the start of the DataView. |
| 1765 | /// |
| 1766 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat64) |
| 1767 | #[wasm_bindgen (method, js_name = getFloat64)] |
| 1768 | pub unsafefn get_float64_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> f64; |
| 1769 | |
| 1770 | /// The `setInt8()` method stores a signed 8-bit integer (byte) value at the |
| 1771 | /// specified byte offset from the start of the DataView. |
| 1772 | /// |
| 1773 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt8) |
| 1774 | #[wasm_bindgen (method, js_name = setInt8)] |
| 1775 | pub unsafefn set_int8(this: &DataView, byte_offset: usize, value: i8); |
| 1776 | |
| 1777 | /// The `setUint8()` method stores an unsigned 8-bit integer (byte) value at the |
| 1778 | /// specified byte offset from the start of the DataView. |
| 1779 | /// |
| 1780 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint8) |
| 1781 | #[wasm_bindgen (method, js_name = setUint8)] |
| 1782 | pub unsafefn set_uint8(this: &DataView, byte_offset: usize, value: u8); |
| 1783 | |
| 1784 | /// The `setInt16()` method stores a signed 16-bit integer (short) value at the |
| 1785 | /// specified byte offset from the start of the DataView. |
| 1786 | /// |
| 1787 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt16) |
| 1788 | #[wasm_bindgen (method, js_name = setInt16)] |
| 1789 | pub unsafefn set_int16(this: &DataView, byte_offset: usize, value: i16); |
| 1790 | |
| 1791 | /// The `setInt16()` method stores a signed 16-bit integer (short) value at the |
| 1792 | /// specified byte offset from the start of the DataView. |
| 1793 | /// |
| 1794 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt16) |
| 1795 | #[wasm_bindgen (method, js_name = setInt16)] |
| 1796 | pub unsafefn set_int16_endian(this: &DataView, byte_offset: usize, value: i16, little_endian: bool); |
| 1797 | |
| 1798 | /// The `setUint16()` method stores an unsigned 16-bit integer (unsigned short) value at the |
| 1799 | /// specified byte offset from the start of the DataView. |
| 1800 | /// |
| 1801 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint16) |
| 1802 | #[wasm_bindgen (method, js_name = setUint16)] |
| 1803 | pub unsafefn set_uint16(this: &DataView, byte_offset: usize, value: u16); |
| 1804 | |
| 1805 | /// The `setUint16()` method stores an unsigned 16-bit integer (unsigned short) value at the |
| 1806 | /// specified byte offset from the start of the DataView. |
| 1807 | /// |
| 1808 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint16) |
| 1809 | #[wasm_bindgen (method, js_name = setUint16)] |
| 1810 | pub unsafefn set_uint16_endian(this: &DataView, byte_offset: usize, value: u16, little_endian: bool); |
| 1811 | |
| 1812 | /// The `setInt32()` method stores a signed 32-bit integer (long) value at the |
| 1813 | /// specified byte offset from the start of the DataView. |
| 1814 | /// |
| 1815 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt32) |
| 1816 | #[wasm_bindgen (method, js_name = setInt32)] |
| 1817 | pub unsafefn set_int32(this: &DataView, byte_offset: usize, value: i32); |
| 1818 | |
| 1819 | /// The `setInt32()` method stores a signed 32-bit integer (long) value at the |
| 1820 | /// specified byte offset from the start of the DataView. |
| 1821 | /// |
| 1822 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt32) |
| 1823 | #[wasm_bindgen (method, js_name = setInt32)] |
| 1824 | pub unsafefn set_int32_endian(this: &DataView, byte_offset: usize, value: i32, little_endian: bool); |
| 1825 | |
| 1826 | /// The `setUint32()` method stores an unsigned 32-bit integer (unsigned long) value at the |
| 1827 | /// specified byte offset from the start of the DataView. |
| 1828 | /// |
| 1829 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint32) |
| 1830 | #[wasm_bindgen (method, js_name = setUint32)] |
| 1831 | pub unsafefn set_uint32(this: &DataView, byte_offset: usize, value: u32); |
| 1832 | |
| 1833 | /// The `setUint32()` method stores an unsigned 32-bit integer (unsigned long) value at the |
| 1834 | /// specified byte offset from the start of the DataView. |
| 1835 | /// |
| 1836 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint32) |
| 1837 | #[wasm_bindgen (method, js_name = setUint32)] |
| 1838 | pub unsafefn set_uint32_endian(this: &DataView, byte_offset: usize, value: u32, little_endian: bool); |
| 1839 | |
| 1840 | /// The `setFloat32()` method stores a signed 32-bit float (float) value at the |
| 1841 | /// specified byte offset from the start of the DataView. |
| 1842 | /// |
| 1843 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat32) |
| 1844 | #[wasm_bindgen (method, js_name = setFloat32)] |
| 1845 | pub unsafefn set_float32(this: &DataView, byte_offset: usize, value: f32); |
| 1846 | |
| 1847 | /// The `setFloat32()` method stores a signed 32-bit float (float) value at the |
| 1848 | /// specified byte offset from the start of the DataView. |
| 1849 | /// |
| 1850 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat32) |
| 1851 | #[wasm_bindgen (method, js_name = setFloat32)] |
| 1852 | pub unsafefn set_float32_endian(this: &DataView, byte_offset: usize, value: f32, little_endian: bool); |
| 1853 | |
| 1854 | /// The `setFloat64()` method stores a signed 64-bit float (double) value at the |
| 1855 | /// specified byte offset from the start of the DataView. |
| 1856 | /// |
| 1857 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat64) |
| 1858 | #[wasm_bindgen (method, js_name = setFloat64)] |
| 1859 | pub unsafefn set_float64(this: &DataView, byte_offset: usize, value: f64); |
| 1860 | |
| 1861 | /// The `setFloat64()` method stores a signed 64-bit float (double) value at the |
| 1862 | /// specified byte offset from the start of the DataView. |
| 1863 | /// |
| 1864 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat64) |
| 1865 | #[wasm_bindgen (method, js_name = setFloat64)] |
| 1866 | pub unsafefn set_float64_endian(this: &DataView, byte_offset: usize, value: f64, little_endian: bool); |
| 1867 | } |
| 1868 | |
| 1869 | // Error |
| 1870 | #[wasm_bindgen ] |
| 1871 | unsafeextern "C" { |
| 1872 | #[wasm_bindgen (extends = Object, typescript_type = "Error" )] |
| 1873 | #[derive (Clone, Debug, PartialEq, Eq)] |
| 1874 | pub type Error; |
| 1875 | |
| 1876 | /// The Error constructor creates an error object. |
| 1877 | /// Instances of Error objects are thrown when runtime errors occur. |
| 1878 | /// The Error object can also be used as a base object for user-defined exceptions. |
| 1879 | /// See below for standard built-in error types. |
| 1880 | /// |
| 1881 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) |
| 1882 | #[wasm_bindgen (constructor)] |
| 1883 | pub unsafefn new(message: &str) -> Error; |
| 1884 | #[wasm_bindgen (constructor)] |
| 1885 | pub unsafefn new_with_options(message: &str, options: &Object) -> Error; |
| 1886 | |
| 1887 | /// The cause property is the underlying cause of the error. |
| 1888 | /// Usually this is used to add context to re-thrown errors. |
| 1889 | /// |
| 1890 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error#differentiate_between_similar_errors) |
| 1891 | #[wasm_bindgen (method, getter, structural)] |
| 1892 | pub unsafefn cause(this: &Error) -> JsValue; |
| 1893 | #[wasm_bindgen (method, setter, structural)] |
| 1894 | pub unsafefn set_cause(this: &Error, cause: &JsValue); |
| 1895 | |
| 1896 | /// The message property is a human-readable description of the error. |
| 1897 | /// |
| 1898 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/message) |
| 1899 | #[wasm_bindgen (method, getter, structural)] |
| 1900 | pub unsafefn message(this: &Error) -> JsString; |
| 1901 | #[wasm_bindgen (method, setter, structural)] |
| 1902 | pub unsafefn set_message(this: &Error, message: &str); |
| 1903 | |
| 1904 | /// The name property represents a name for the type of error. The initial value is "Error". |
| 1905 | /// |
| 1906 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/name) |
| 1907 | #[wasm_bindgen (method, getter, structural)] |
| 1908 | pub unsafefn name(this: &Error) -> JsString; |
| 1909 | #[wasm_bindgen (method, setter, structural)] |
| 1910 | pub unsafefn set_name(this: &Error, name: &str); |
| 1911 | |
| 1912 | /// The `toString()` method returns a string representing the specified Error object |
| 1913 | /// |
| 1914 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/toString) |
| 1915 | #[wasm_bindgen (method, js_name = toString)] |
| 1916 | pub unsafefn to_string(this: &Error) -> JsString; |
| 1917 | } |
| 1918 | |
| 1919 | partialord_ord!(JsString); |
| 1920 | |
| 1921 | // EvalError |
| 1922 | #[wasm_bindgen ] |
| 1923 | unsafeextern "C" { |
| 1924 | #[wasm_bindgen (extends = Object, extends = Error, typescript_type = "EvalError" )] |
| 1925 | #[derive (Clone, Debug, PartialEq, Eq)] |
| 1926 | pub type EvalError; |
| 1927 | |
| 1928 | /// The EvalError object indicates an error regarding the global eval() function. This |
| 1929 | /// exception is not thrown by JavaScript anymore, however the EvalError object remains for |
| 1930 | /// compatibility. |
| 1931 | /// |
| 1932 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/EvalError) |
| 1933 | #[wasm_bindgen (constructor)] |
| 1934 | pub unsafefn new(message: &str) -> EvalError; |
| 1935 | } |
| 1936 | |
| 1937 | // Function |
| 1938 | #[wasm_bindgen ] |
| 1939 | unsafeextern "C" { |
| 1940 | #[wasm_bindgen (extends = Object, is_type_of = JsValue::is_function, typescript_type = "Function" )] |
| 1941 | #[derive (Clone, Debug, PartialEq, Eq)] |
| 1942 | pub type Function; |
| 1943 | |
| 1944 | /// The `Function` constructor creates a new `Function` object. Calling the |
| 1945 | /// constructor directly can create functions dynamically, but suffers from |
| 1946 | /// security and similar (but far less significant) performance issues |
| 1947 | /// similar to `eval`. However, unlike `eval`, the `Function` constructor |
| 1948 | /// allows executing code in the global scope, prompting better programming |
| 1949 | /// habits and allowing for more efficient code minification. |
| 1950 | /// |
| 1951 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function) |
| 1952 | #[wasm_bindgen (constructor)] |
| 1953 | pub unsafefn new_with_args(args: &str, body: &str) -> Function; |
| 1954 | |
| 1955 | /// The `Function` constructor creates a new `Function` object. Calling the |
| 1956 | /// constructor directly can create functions dynamically, but suffers from |
| 1957 | /// security and similar (but far less significant) performance issues |
| 1958 | /// similar to `eval`. However, unlike `eval`, the `Function` constructor |
| 1959 | /// allows executing code in the global scope, prompting better programming |
| 1960 | /// habits and allowing for more efficient code minification. |
| 1961 | /// |
| 1962 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function) |
| 1963 | #[wasm_bindgen (constructor)] |
| 1964 | pub unsafefn new_no_args(body: &str) -> Function; |
| 1965 | |
| 1966 | /// The `apply()` method calls a function with a given this value, and arguments provided as an array |
| 1967 | /// (or an array-like object). |
| 1968 | /// |
| 1969 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply) |
| 1970 | #[wasm_bindgen (method, catch)] |
| 1971 | pub unsafefn apply(this: &Function, context: &JsValue, args: &Array) -> Result<JsValue, JsValue>; |
| 1972 | |
| 1973 | /// The `call()` method calls a function with a given this value and |
| 1974 | /// arguments provided individually. |
| 1975 | /// |
| 1976 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call) |
| 1977 | #[wasm_bindgen (method, catch, js_name = call)] |
| 1978 | pub unsafefn call0(this: &Function, context: &JsValue) -> Result<JsValue, JsValue>; |
| 1979 | |
| 1980 | /// The `call()` method calls a function with a given this value and |
| 1981 | /// arguments provided individually. |
| 1982 | /// |
| 1983 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call) |
| 1984 | #[wasm_bindgen (method, catch, js_name = call)] |
| 1985 | pub unsafefn call1(this: &Function, context: &JsValue, arg1: &JsValue) -> Result<JsValue, JsValue>; |
| 1986 | |
| 1987 | /// The `call()` method calls a function with a given this value and |
| 1988 | /// arguments provided individually. |
| 1989 | /// |
| 1990 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call) |
| 1991 | #[wasm_bindgen (method, catch, js_name = call)] |
| 1992 | pub unsafefn call2( |
| 1993 | this: &Function, |
| 1994 | context: &JsValue, |
| 1995 | arg1: &JsValue, |
| 1996 | arg2: &JsValue, |
| 1997 | ) -> Result<JsValue, JsValue>; |
| 1998 | |
| 1999 | /// The `call()` method calls a function with a given this value and |
| 2000 | /// arguments provided individually. |
| 2001 | /// |
| 2002 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call) |
| 2003 | #[wasm_bindgen (method, catch, js_name = call)] |
| 2004 | pub unsafefn call3( |
| 2005 | this: &Function, |
| 2006 | context: &JsValue, |
| 2007 | arg1: &JsValue, |
| 2008 | arg2: &JsValue, |
| 2009 | arg3: &JsValue, |
| 2010 | ) -> Result<JsValue, JsValue>; |
| 2011 | |
| 2012 | /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value, |
| 2013 | /// with a given sequence of arguments preceding any provided when the new function is called. |
| 2014 | /// |
| 2015 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind) |
| 2016 | #[wasm_bindgen (method, js_name = bind)] |
| 2017 | pub unsafefn bind(this: &Function, context: &JsValue) -> Function; |
| 2018 | |
| 2019 | /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value, |
| 2020 | /// with a given sequence of arguments preceding any provided when the new function is called. |
| 2021 | /// |
| 2022 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind) |
| 2023 | #[wasm_bindgen (method, js_name = bind)] |
| 2024 | pub unsafefn bind0(this: &Function, context: &JsValue) -> Function; |
| 2025 | |
| 2026 | /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value, |
| 2027 | /// with a given sequence of arguments preceding any provided when the new function is called. |
| 2028 | /// |
| 2029 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind) |
| 2030 | #[wasm_bindgen (method, js_name = bind)] |
| 2031 | pub unsafefn bind1(this: &Function, context: &JsValue, arg1: &JsValue) -> Function; |
| 2032 | |
| 2033 | /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value, |
| 2034 | /// with a given sequence of arguments preceding any provided when the new function is called. |
| 2035 | /// |
| 2036 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind) |
| 2037 | #[wasm_bindgen (method, js_name = bind)] |
| 2038 | pub unsafefn bind2(this: &Function, context: &JsValue, arg1: &JsValue, arg2: &JsValue) -> Function; |
| 2039 | |
| 2040 | /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value, |
| 2041 | /// with a given sequence of arguments preceding any provided when the new function is called. |
| 2042 | /// |
| 2043 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind) |
| 2044 | #[wasm_bindgen (method, js_name = bind)] |
| 2045 | pub unsafefn bind3( |
| 2046 | this: &Function, |
| 2047 | context: &JsValue, |
| 2048 | arg1: &JsValue, |
| 2049 | arg2: &JsValue, |
| 2050 | arg3: &JsValue, |
| 2051 | ) -> Function; |
| 2052 | |
| 2053 | /// The length property indicates the number of arguments expected by the function. |
| 2054 | /// |
| 2055 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/length) |
| 2056 | #[wasm_bindgen (method, getter, structural)] |
| 2057 | pub unsafefn length(this: &Function) -> u32; |
| 2058 | |
| 2059 | /// A Function object's read-only name property indicates the function's |
| 2060 | /// name as specified when it was created or "anonymous" for functions |
| 2061 | /// created anonymously. |
| 2062 | /// |
| 2063 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name) |
| 2064 | #[wasm_bindgen (method, getter, structural)] |
| 2065 | pub unsafefn name(this: &Function) -> JsString; |
| 2066 | |
| 2067 | /// The `toString()` method returns a string representing the source code of the function. |
| 2068 | /// |
| 2069 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/toString) |
| 2070 | #[wasm_bindgen (method, js_name = toString)] |
| 2071 | pub unsafefn to_string(this: &Function) -> JsString; |
| 2072 | } |
| 2073 | |
| 2074 | impl Function { |
| 2075 | /// Returns the `Function` value of this JS value if it's an instance of a |
| 2076 | /// function. |
| 2077 | /// |
| 2078 | /// If this JS value is not an instance of a function then this returns |
| 2079 | /// `None`. |
| 2080 | #[deprecated (note = "recommended to use dyn_ref instead which is now equivalent" )] |
| 2081 | pub fn try_from(val: &JsValue) -> Option<&Function> { |
| 2082 | val.dyn_ref() |
| 2083 | } |
| 2084 | } |
| 2085 | |
| 2086 | impl Default for Function { |
| 2087 | fn default() -> Self { |
| 2088 | Self::new_no_args("" ) |
| 2089 | } |
| 2090 | } |
| 2091 | |
| 2092 | // Generator |
| 2093 | #[wasm_bindgen ] |
| 2094 | unsafeextern "C" { |
| 2095 | #[wasm_bindgen (extends = Object, typescript_type = "Generator<any, any, any>" )] |
| 2096 | #[derive (Clone, Debug, PartialEq, Eq)] |
| 2097 | pub type Generator; |
| 2098 | |
| 2099 | /// The `next()` method returns an object with two properties done and value. |
| 2100 | /// You can also provide a parameter to the next method to send a value to the generator. |
| 2101 | /// |
| 2102 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/next) |
| 2103 | #[wasm_bindgen (method, structural, catch)] |
| 2104 | pub unsafefn next(this: &Generator, value: &JsValue) -> Result<JsValue, JsValue>; |
| 2105 | |
| 2106 | /// The `return()` method returns the given value and finishes the generator. |
| 2107 | /// |
| 2108 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/return) |
| 2109 | #[wasm_bindgen (method, structural, js_name = return)] |
| 2110 | pub unsafefn return_(this: &Generator, value: &JsValue) -> JsValue; |
| 2111 | |
| 2112 | /// The `throw()` method resumes the execution of a generator by throwing an error into it |
| 2113 | /// and returns an object with two properties done and value. |
| 2114 | /// |
| 2115 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/throw) |
| 2116 | #[wasm_bindgen (method, structural, catch)] |
| 2117 | pub unsafefn throw(this: &Generator, error: &Error) -> Result<JsValue, JsValue>; |
| 2118 | } |
| 2119 | |
| 2120 | // Map |
| 2121 | #[wasm_bindgen ] |
| 2122 | unsafeextern "C" { |
| 2123 | #[wasm_bindgen (extends = Object, typescript_type = "Map<any, any>" )] |
| 2124 | #[derive (Clone, Debug, PartialEq, Eq)] |
| 2125 | pub type Map; |
| 2126 | |
| 2127 | /// The `clear()` method removes all elements from a Map object. |
| 2128 | /// |
| 2129 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/clear) |
| 2130 | #[wasm_bindgen (method)] |
| 2131 | pub unsafefn clear(this: &Map); |
| 2132 | |
| 2133 | /// The `delete()` method removes the specified element from a Map object. |
| 2134 | /// |
| 2135 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/delete) |
| 2136 | #[wasm_bindgen (method)] |
| 2137 | pub unsafefn delete(this: &Map, key: &JsValue) -> bool; |
| 2138 | |
| 2139 | /// The `forEach()` method executes a provided function once per each |
| 2140 | /// key/value pair in the Map object, in insertion order. |
| 2141 | /// Note that in Javascript land the `Key` and `Value` are reversed compared to normal expectations: |
| 2142 | /// # Examples |
| 2143 | /// ``` |
| 2144 | /// let js_map = Map::new(); |
| 2145 | /// js_map.for_each(&mut |value, key| { |
| 2146 | /// // Do something here... |
| 2147 | /// }) |
| 2148 | /// ``` |
| 2149 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/forEach) |
| 2150 | #[wasm_bindgen (method, js_name = forEach)] |
| 2151 | pub unsafefn for_each(this: &Map, callback: &mut dyn FnMut(JsValue, JsValue)); |
| 2152 | |
| 2153 | /// The `get()` method returns a specified element from a Map object. |
| 2154 | /// |
| 2155 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get) |
| 2156 | #[wasm_bindgen (method)] |
| 2157 | pub unsafefn get(this: &Map, key: &JsValue) -> JsValue; |
| 2158 | |
| 2159 | /// The `has()` method returns a boolean indicating whether an element with |
| 2160 | /// the specified key exists or not. |
| 2161 | /// |
| 2162 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/has) |
| 2163 | #[wasm_bindgen (method)] |
| 2164 | pub unsafefn has(this: &Map, key: &JsValue) -> bool; |
| 2165 | |
| 2166 | /// The Map object holds key-value pairs. Any value (both objects and |
| 2167 | /// primitive values) maybe used as either a key or a value. |
| 2168 | /// |
| 2169 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) |
| 2170 | #[wasm_bindgen (constructor)] |
| 2171 | pub unsafefn new() -> Map; |
| 2172 | |
| 2173 | /// The `set()` method adds or updates an element with a specified key |
| 2174 | /// and value to a Map object. |
| 2175 | /// |
| 2176 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/set) |
| 2177 | #[wasm_bindgen (method)] |
| 2178 | pub unsafefn set(this: &Map, key: &JsValue, value: &JsValue) -> Map; |
| 2179 | |
| 2180 | /// The value of size is an integer representing how many entries |
| 2181 | /// the Map object has. A set accessor function for size is undefined; |
| 2182 | /// you can not change this property. |
| 2183 | /// |
| 2184 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/size) |
| 2185 | #[wasm_bindgen (method, getter, structural)] |
| 2186 | pub unsafefn size(this: &Map) -> u32; |
| 2187 | } |
| 2188 | |
| 2189 | impl Default for Map { |
| 2190 | fn default() -> Self { |
| 2191 | Self::new() |
| 2192 | } |
| 2193 | } |
| 2194 | |
| 2195 | // Map Iterator |
| 2196 | #[wasm_bindgen ] |
| 2197 | unsafeextern "C" { |
| 2198 | /// The `entries()` method returns a new Iterator object that contains |
| 2199 | /// the [key, value] pairs for each element in the Map object in |
| 2200 | /// insertion order. |
| 2201 | /// |
| 2202 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries) |
| 2203 | #[wasm_bindgen (method)] |
| 2204 | pub unsafefn entries(this: &Map) -> Iterator; |
| 2205 | |
| 2206 | /// The `keys()` method returns a new Iterator object that contains the |
| 2207 | /// keys for each element in the Map object in insertion order. |
| 2208 | /// |
| 2209 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/keys) |
| 2210 | #[wasm_bindgen (method)] |
| 2211 | pub unsafefn keys(this: &Map) -> Iterator; |
| 2212 | |
| 2213 | /// The `values()` method returns a new Iterator object that contains the |
| 2214 | /// values for each element in the Map object in insertion order. |
| 2215 | /// |
| 2216 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/values) |
| 2217 | #[wasm_bindgen (method)] |
| 2218 | pub unsafefn values(this: &Map) -> Iterator; |
| 2219 | } |
| 2220 | |
| 2221 | // Iterator |
| 2222 | #[wasm_bindgen ] |
| 2223 | unsafeextern "C" { |
| 2224 | /// Any object that conforms to the JS iterator protocol. For example, |
| 2225 | /// something returned by `myArray[Symbol.iterator]()`. |
| 2226 | /// |
| 2227 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols) |
| 2228 | #[derive (Clone, Debug)] |
| 2229 | #[wasm_bindgen (is_type_of = Iterator::looks_like_iterator, typescript_type = "Iterator<any>" )] |
| 2230 | pub type Iterator; |
| 2231 | |
| 2232 | /// The `next()` method always has to return an object with appropriate |
| 2233 | /// properties including done and value. If a non-object value gets returned |
| 2234 | /// (such as false or undefined), a TypeError ("iterator.next() returned a |
| 2235 | /// non-object value") will be thrown. |
| 2236 | #[wasm_bindgen (catch, method, structural)] |
| 2237 | pub unsafefn next(this: &Iterator) -> Result<IteratorNext, JsValue>; |
| 2238 | } |
| 2239 | |
| 2240 | impl Iterator { |
| 2241 | fn looks_like_iterator(it: &JsValue) -> bool { |
| 2242 | #[wasm_bindgen ] |
| 2243 | unsafeextern "C" { |
| 2244 | type MaybeIterator; |
| 2245 | |
| 2246 | #[wasm_bindgen (method, getter)] |
| 2247 | unsafefn next(this: &MaybeIterator) -> JsValue; |
| 2248 | } |
| 2249 | |
| 2250 | if !it.is_object() { |
| 2251 | return false; |
| 2252 | } |
| 2253 | |
| 2254 | let it: &MaybeIterator = it.unchecked_ref::<MaybeIterator>(); |
| 2255 | |
| 2256 | it.next().is_function() |
| 2257 | } |
| 2258 | } |
| 2259 | |
| 2260 | // Async Iterator |
| 2261 | #[wasm_bindgen ] |
| 2262 | unsafeextern "C" { |
| 2263 | /// Any object that conforms to the JS async iterator protocol. For example, |
| 2264 | /// something returned by `myObject[Symbol.asyncIterator]()`. |
| 2265 | /// |
| 2266 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of) |
| 2267 | #[derive (Clone, Debug)] |
| 2268 | #[wasm_bindgen (is_type_of = Iterator::looks_like_iterator, typescript_type = "AsyncIterator<any>" )] |
| 2269 | pub type AsyncIterator; |
| 2270 | |
| 2271 | /// The `next()` method always has to return a Promise which resolves to an object |
| 2272 | /// with appropriate properties including done and value. If a non-object value |
| 2273 | /// gets returned (such as false or undefined), a TypeError ("iterator.next() |
| 2274 | /// returned a non-object value") will be thrown. |
| 2275 | #[wasm_bindgen (catch, method, structural)] |
| 2276 | pub unsafefn next(this: &AsyncIterator) -> Result<Promise, JsValue>; |
| 2277 | } |
| 2278 | |
| 2279 | /// An iterator over the JS `Symbol.iterator` iteration protocol. |
| 2280 | /// |
| 2281 | /// Use the `IntoIterator for &js_sys::Iterator` implementation to create this. |
| 2282 | pub struct Iter<'a> { |
| 2283 | js: &'a Iterator, |
| 2284 | state: IterState, |
| 2285 | } |
| 2286 | |
| 2287 | /// An iterator over the JS `Symbol.iterator` iteration protocol. |
| 2288 | /// |
| 2289 | /// Use the `IntoIterator for js_sys::Iterator` implementation to create this. |
| 2290 | pub struct IntoIter { |
| 2291 | js: Iterator, |
| 2292 | state: IterState, |
| 2293 | } |
| 2294 | |
| 2295 | struct IterState { |
| 2296 | done: bool, |
| 2297 | } |
| 2298 | |
| 2299 | impl<'a> IntoIterator for &'a Iterator { |
| 2300 | type Item = Result<JsValue, JsValue>; |
| 2301 | type IntoIter = Iter<'a>; |
| 2302 | |
| 2303 | fn into_iter(self) -> Iter<'a> { |
| 2304 | Iter { |
| 2305 | js: self, |
| 2306 | state: IterState::new(), |
| 2307 | } |
| 2308 | } |
| 2309 | } |
| 2310 | |
| 2311 | impl core::iter::Iterator for Iter<'_> { |
| 2312 | type Item = Result<JsValue, JsValue>; |
| 2313 | |
| 2314 | fn next(&mut self) -> Option<Self::Item> { |
| 2315 | self.state.next(self.js) |
| 2316 | } |
| 2317 | } |
| 2318 | |
| 2319 | impl IntoIterator for Iterator { |
| 2320 | type Item = Result<JsValue, JsValue>; |
| 2321 | type IntoIter = IntoIter; |
| 2322 | |
| 2323 | fn into_iter(self) -> IntoIter { |
| 2324 | IntoIter { |
| 2325 | js: self, |
| 2326 | state: IterState::new(), |
| 2327 | } |
| 2328 | } |
| 2329 | } |
| 2330 | |
| 2331 | impl core::iter::Iterator for IntoIter { |
| 2332 | type Item = Result<JsValue, JsValue>; |
| 2333 | |
| 2334 | fn next(&mut self) -> Option<Self::Item> { |
| 2335 | self.state.next(&self.js) |
| 2336 | } |
| 2337 | } |
| 2338 | |
| 2339 | impl IterState { |
| 2340 | fn new() -> IterState { |
| 2341 | IterState { done: false } |
| 2342 | } |
| 2343 | |
| 2344 | fn next(&mut self, js: &Iterator) -> Option<Result<JsValue, JsValue>> { |
| 2345 | if self.done { |
| 2346 | return None; |
| 2347 | } |
| 2348 | let next: ! = match js.next() { |
| 2349 | Ok(val: !) => val, |
| 2350 | Err(e: JsValue) => { |
| 2351 | self.done = true; |
| 2352 | return Some(Err(e)); |
| 2353 | } |
| 2354 | }; |
| 2355 | if next.done() { |
| 2356 | self.done = true; |
| 2357 | None |
| 2358 | } else { |
| 2359 | Some(Ok(next.value())) |
| 2360 | } |
| 2361 | } |
| 2362 | } |
| 2363 | |
| 2364 | /// Create an iterator over `val` using the JS iteration protocol and |
| 2365 | /// `Symbol.iterator`. |
| 2366 | pub fn try_iter(val: &JsValue) -> Result<Option<IntoIter>, JsValue> { |
| 2367 | let iter_sym = Symbol::iterator(); |
| 2368 | let iter_fn: JsValue = Reflect::get(target:val, key:iter_sym.as_ref())?; |
| 2369 | |
| 2370 | let iter_fn: Function = match iter_fn.dyn_into() { |
| 2371 | Ok(iter_fn: Function) => iter_fn, |
| 2372 | Err(_) => return Ok(None), |
| 2373 | }; |
| 2374 | |
| 2375 | let it: Iterator = match iter_fn.call0(val)?.dyn_into() { |
| 2376 | Ok(it: Iterator) => it, |
| 2377 | Err(_) => return Ok(None), |
| 2378 | }; |
| 2379 | |
| 2380 | Ok(Some(it.into_iter())) |
| 2381 | } |
| 2382 | |
| 2383 | // IteratorNext |
| 2384 | #[wasm_bindgen ] |
| 2385 | unsafeextern "C" { |
| 2386 | /// The result of calling `next()` on a JS iterator. |
| 2387 | /// |
| 2388 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols) |
| 2389 | #[wasm_bindgen (extends = Object, typescript_type = "IteratorResult<any>" )] |
| 2390 | #[derive (Clone, Debug, PartialEq, Eq)] |
| 2391 | pub type IteratorNext; |
| 2392 | |
| 2393 | /// Has the value `true` if the iterator is past the end of the iterated |
| 2394 | /// sequence. In this case value optionally specifies the return value of |
| 2395 | /// the iterator. |
| 2396 | /// |
| 2397 | /// Has the value `false` if the iterator was able to produce the next value |
| 2398 | /// in the sequence. This is equivalent of not specifying the done property |
| 2399 | /// altogether. |
| 2400 | #[wasm_bindgen (method, getter, structural)] |
| 2401 | pub unsafefn done(this: &IteratorNext) -> bool; |
| 2402 | |
| 2403 | /// Any JavaScript value returned by the iterator. Can be omitted when done |
| 2404 | /// is true. |
| 2405 | #[wasm_bindgen (method, getter, structural)] |
| 2406 | pub unsafefn value(this: &IteratorNext) -> JsValue; |
| 2407 | } |
| 2408 | |
| 2409 | #[allow (non_snake_case)] |
| 2410 | pub mod Math { |
| 2411 | use super::*; |
| 2412 | |
| 2413 | // Math |
| 2414 | #[wasm_bindgen ] |
| 2415 | extern "C" { |
| 2416 | /// The `Math.abs()` function returns the absolute value of a number, that is |
| 2417 | /// Math.abs(x) = |x| |
| 2418 | /// |
| 2419 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/abs) |
| 2420 | #[wasm_bindgen (js_namespace = Math)] |
| 2421 | pub fn abs(x: f64) -> f64; |
| 2422 | |
| 2423 | /// The `Math.acos()` function returns the arccosine (in radians) of a |
| 2424 | /// number, that is ∀x∊[-1;1] |
| 2425 | /// Math.acos(x) = arccos(x) = the unique y∊[0;π] such that cos(y)=x |
| 2426 | /// |
| 2427 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/acos) |
| 2428 | #[wasm_bindgen (js_namespace = Math)] |
| 2429 | pub fn acos(x: f64) -> f64; |
| 2430 | |
| 2431 | /// The `Math.acosh()` function returns the hyperbolic arc-cosine of a |
| 2432 | /// number, that is ∀x ≥ 1 |
| 2433 | /// Math.acosh(x) = arcosh(x) = the unique y ≥ 0 such that cosh(y) = x |
| 2434 | /// |
| 2435 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/acosh) |
| 2436 | #[wasm_bindgen (js_namespace = Math)] |
| 2437 | pub fn acosh(x: f64) -> f64; |
| 2438 | |
| 2439 | /// The `Math.asin()` function returns the arcsine (in radians) of a |
| 2440 | /// number, that is ∀x ∊ [-1;1] |
| 2441 | /// Math.asin(x) = arcsin(x) = the unique y∊[-π2;π2] such that sin(y) = x |
| 2442 | /// |
| 2443 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/asin) |
| 2444 | #[wasm_bindgen (js_namespace = Math)] |
| 2445 | pub fn asin(x: f64) -> f64; |
| 2446 | |
| 2447 | /// The `Math.asinh()` function returns the hyperbolic arcsine of a |
| 2448 | /// number, that is Math.asinh(x) = arsinh(x) = the unique y such that sinh(y) = x |
| 2449 | /// |
| 2450 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/asinh) |
| 2451 | #[wasm_bindgen (js_namespace = Math)] |
| 2452 | pub fn asinh(x: f64) -> f64; |
| 2453 | |
| 2454 | /// The `Math.atan()` function returns the arctangent (in radians) of a |
| 2455 | /// number, that is Math.atan(x) = arctan(x) = the unique y ∊ [-π2;π2]such that |
| 2456 | /// tan(y) = x |
| 2457 | #[wasm_bindgen (js_namespace = Math)] |
| 2458 | pub fn atan(x: f64) -> f64; |
| 2459 | |
| 2460 | /// The `Math.atan2()` function returns the arctangent of the quotient of |
| 2461 | /// its arguments. |
| 2462 | /// |
| 2463 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/atan2) |
| 2464 | #[wasm_bindgen (js_namespace = Math)] |
| 2465 | pub fn atan2(y: f64, x: f64) -> f64; |
| 2466 | |
| 2467 | /// The `Math.atanh()` function returns the hyperbolic arctangent of a number, |
| 2468 | /// that is ∀x ∊ (-1,1), Math.atanh(x) = arctanh(x) = the unique y such that |
| 2469 | /// tanh(y) = x |
| 2470 | /// |
| 2471 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/atanh) |
| 2472 | #[wasm_bindgen (js_namespace = Math)] |
| 2473 | pub fn atanh(x: f64) -> f64; |
| 2474 | |
| 2475 | /// The `Math.cbrt() `function returns the cube root of a number, that is |
| 2476 | /// Math.cbrt(x) = ∛x = the unique y such that y^3 = x |
| 2477 | /// |
| 2478 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/cbrt) |
| 2479 | #[wasm_bindgen (js_namespace = Math)] |
| 2480 | pub fn cbrt(x: f64) -> f64; |
| 2481 | |
| 2482 | /// The `Math.ceil()` function returns the smallest integer greater than |
| 2483 | /// or equal to a given number. |
| 2484 | /// |
| 2485 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/ceil) |
| 2486 | #[wasm_bindgen (js_namespace = Math)] |
| 2487 | pub fn ceil(x: f64) -> f64; |
| 2488 | |
| 2489 | /// The `Math.clz32()` function returns the number of leading zero bits in |
| 2490 | /// the 32-bit binary representation of a number. |
| 2491 | /// |
| 2492 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/clz32) |
| 2493 | #[wasm_bindgen (js_namespace = Math)] |
| 2494 | pub fn clz32(x: i32) -> u32; |
| 2495 | |
| 2496 | /// The `Math.cos()` static function returns the cosine of the specified angle, |
| 2497 | /// which must be specified in radians. This value is length(adjacent)/length(hypotenuse). |
| 2498 | /// |
| 2499 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/cos) |
| 2500 | #[wasm_bindgen (js_namespace = Math)] |
| 2501 | pub fn cos(x: f64) -> f64; |
| 2502 | |
| 2503 | /// The `Math.cosh()` function returns the hyperbolic cosine of a number, |
| 2504 | /// that can be expressed using the constant e. |
| 2505 | /// |
| 2506 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/cosh) |
| 2507 | #[wasm_bindgen (js_namespace = Math)] |
| 2508 | pub fn cosh(x: f64) -> f64; |
| 2509 | |
| 2510 | /// The `Math.exp()` function returns e^x, where x is the argument, and e is Euler's number |
| 2511 | /// (also known as Napier's constant), the base of the natural logarithms. |
| 2512 | /// |
| 2513 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/exp) |
| 2514 | #[wasm_bindgen (js_namespace = Math)] |
| 2515 | pub fn exp(x: f64) -> f64; |
| 2516 | |
| 2517 | /// The `Math.expm1()` function returns e^x - 1, where x is the argument, and e the base of the |
| 2518 | /// natural logarithms. |
| 2519 | /// |
| 2520 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/expm1) |
| 2521 | #[wasm_bindgen (js_namespace = Math)] |
| 2522 | pub fn expm1(x: f64) -> f64; |
| 2523 | |
| 2524 | /// The `Math.floor()` function returns the largest integer less than or |
| 2525 | /// equal to a given number. |
| 2526 | /// |
| 2527 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/floor) |
| 2528 | #[wasm_bindgen (js_namespace = Math)] |
| 2529 | pub fn floor(x: f64) -> f64; |
| 2530 | |
| 2531 | /// The `Math.fround()` function returns the nearest 32-bit single precision float representation |
| 2532 | /// of a Number. |
| 2533 | /// |
| 2534 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/fround) |
| 2535 | #[wasm_bindgen (js_namespace = Math)] |
| 2536 | pub fn fround(x: f64) -> f32; |
| 2537 | |
| 2538 | /// The `Math.hypot()` function returns the square root of the sum of squares of its arguments. |
| 2539 | /// |
| 2540 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/hypot) |
| 2541 | #[wasm_bindgen (js_namespace = Math)] |
| 2542 | pub fn hypot(x: f64, y: f64) -> f64; |
| 2543 | |
| 2544 | /// The `Math.imul()` function returns the result of the C-like 32-bit multiplication of the |
| 2545 | /// two parameters. |
| 2546 | /// |
| 2547 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/imul) |
| 2548 | #[wasm_bindgen (js_namespace = Math)] |
| 2549 | pub fn imul(x: i32, y: i32) -> i32; |
| 2550 | |
| 2551 | /// The `Math.log()` function returns the natural logarithm (base e) of a number. |
| 2552 | /// The JavaScript `Math.log()` function is equivalent to ln(x) in mathematics. |
| 2553 | /// |
| 2554 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log) |
| 2555 | #[wasm_bindgen (js_namespace = Math)] |
| 2556 | pub fn log(x: f64) -> f64; |
| 2557 | |
| 2558 | /// The `Math.log10()` function returns the base 10 logarithm of a number. |
| 2559 | /// |
| 2560 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log10) |
| 2561 | #[wasm_bindgen (js_namespace = Math)] |
| 2562 | pub fn log10(x: f64) -> f64; |
| 2563 | |
| 2564 | /// The `Math.log1p()` function returns the natural logarithm (base e) of 1 + a number. |
| 2565 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log1p) |
| 2566 | #[wasm_bindgen (js_namespace = Math)] |
| 2567 | pub fn log1p(x: f64) -> f64; |
| 2568 | |
| 2569 | /// The `Math.log2()` function returns the base 2 logarithm of a number. |
| 2570 | /// |
| 2571 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log2) |
| 2572 | #[wasm_bindgen (js_namespace = Math)] |
| 2573 | pub fn log2(x: f64) -> f64; |
| 2574 | |
| 2575 | /// The `Math.max()` function returns the largest of two numbers. |
| 2576 | /// |
| 2577 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/max) |
| 2578 | #[wasm_bindgen (js_namespace = Math)] |
| 2579 | pub fn max(x: f64, y: f64) -> f64; |
| 2580 | |
| 2581 | /// The static function `Math.min()` returns the lowest-valued number passed into it. |
| 2582 | /// |
| 2583 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/min) |
| 2584 | #[wasm_bindgen (js_namespace = Math)] |
| 2585 | pub fn min(x: f64, y: f64) -> f64; |
| 2586 | |
| 2587 | /// The `Math.pow()` function returns the base to the exponent power, that is, base^exponent. |
| 2588 | /// |
| 2589 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/pow) |
| 2590 | #[wasm_bindgen (js_namespace = Math)] |
| 2591 | pub fn pow(base: f64, exponent: f64) -> f64; |
| 2592 | |
| 2593 | /// The `Math.random()` function returns a floating-point, pseudo-random number |
| 2594 | /// in the range 0–1 (inclusive of 0, but not 1) with approximately uniform distribution |
| 2595 | /// over that range — which you can then scale to your desired range. |
| 2596 | /// The implementation selects the initial seed to the random number generation algorithm; |
| 2597 | /// it cannot be chosen or reset by the user. |
| 2598 | /// |
| 2599 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random) |
| 2600 | #[wasm_bindgen (js_namespace = Math)] |
| 2601 | pub fn random() -> f64; |
| 2602 | |
| 2603 | /// The `Math.round()` function returns the value of a number rounded to the nearest integer. |
| 2604 | /// |
| 2605 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round) |
| 2606 | #[wasm_bindgen (js_namespace = Math)] |
| 2607 | pub fn round(x: f64) -> f64; |
| 2608 | |
| 2609 | /// The `Math.sign()` function returns the sign of a number, indicating whether the number is |
| 2610 | /// positive, negative or zero. |
| 2611 | /// |
| 2612 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign) |
| 2613 | #[wasm_bindgen (js_namespace = Math)] |
| 2614 | pub fn sign(x: f64) -> f64; |
| 2615 | |
| 2616 | /// The `Math.sin()` function returns the sine of a number. |
| 2617 | /// |
| 2618 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sin) |
| 2619 | #[wasm_bindgen (js_namespace = Math)] |
| 2620 | pub fn sin(x: f64) -> f64; |
| 2621 | |
| 2622 | /// The `Math.sinh()` function returns the hyperbolic sine of a number, that can be expressed |
| 2623 | /// using the constant e: Math.sinh(x) = (e^x - e^-x)/2 |
| 2624 | /// |
| 2625 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sinh) |
| 2626 | #[wasm_bindgen (js_namespace = Math)] |
| 2627 | pub fn sinh(x: f64) -> f64; |
| 2628 | |
| 2629 | /// The `Math.sqrt()` function returns the square root of a number, that is |
| 2630 | /// ∀x ≥ 0, Math.sqrt(x) = √x = the unique y ≥ 0 such that y^2 = x |
| 2631 | /// |
| 2632 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sqrt) |
| 2633 | #[wasm_bindgen (js_namespace = Math)] |
| 2634 | pub fn sqrt(x: f64) -> f64; |
| 2635 | |
| 2636 | /// The `Math.tan()` function returns the tangent of a number. |
| 2637 | /// |
| 2638 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/tan) |
| 2639 | #[wasm_bindgen (js_namespace = Math)] |
| 2640 | pub fn tan(x: f64) -> f64; |
| 2641 | |
| 2642 | /// The `Math.tanh()` function returns the hyperbolic tangent of a number, that is |
| 2643 | /// tanh x = sinh x / cosh x = (e^x - e^-x)/(e^x + e^-x) = (e^2x - 1)/(e^2x + 1) |
| 2644 | /// |
| 2645 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/tanh) |
| 2646 | #[wasm_bindgen (js_namespace = Math)] |
| 2647 | pub fn tanh(x: f64) -> f64; |
| 2648 | |
| 2649 | /// The `Math.trunc()` function returns the integer part of a number by removing any fractional |
| 2650 | /// digits. |
| 2651 | /// |
| 2652 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/trunc) |
| 2653 | #[wasm_bindgen (js_namespace = Math)] |
| 2654 | pub fn trunc(x: f64) -> f64; |
| 2655 | } |
| 2656 | } |
| 2657 | |
| 2658 | // Number. |
| 2659 | #[wasm_bindgen ] |
| 2660 | unsafeextern "C" { |
| 2661 | #[wasm_bindgen (extends = Object, is_type_of = |v| v.as_f64().is_some(), typescript_type = "number" )] |
| 2662 | #[derive (Clone, PartialEq)] |
| 2663 | pub type Number; |
| 2664 | |
| 2665 | /// The `Number.isFinite()` method determines whether the passed value is a finite number. |
| 2666 | /// |
| 2667 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isFinite) |
| 2668 | #[wasm_bindgen (static_method_of = Number, js_name = isFinite)] |
| 2669 | pub unsafefn is_finite(value: &JsValue) -> bool; |
| 2670 | |
| 2671 | /// The `Number.isInteger()` method determines whether the passed value is an integer. |
| 2672 | /// |
| 2673 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isInteger) |
| 2674 | #[wasm_bindgen (static_method_of = Number, js_name = isInteger)] |
| 2675 | pub unsafefn is_integer(value: &JsValue) -> bool; |
| 2676 | |
| 2677 | /// The `Number.isNaN()` method determines whether the passed value is `NaN` and its type is Number. |
| 2678 | /// It is a more robust version of the original, global isNaN(). |
| 2679 | /// |
| 2680 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isNaN) |
| 2681 | #[wasm_bindgen (static_method_of = Number, js_name = isNaN)] |
| 2682 | pub unsafefn is_nan(value: &JsValue) -> bool; |
| 2683 | |
| 2684 | /// The `Number.isSafeInteger()` method determines whether the provided value is a number |
| 2685 | /// that is a safe integer. |
| 2686 | /// |
| 2687 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isSafeInteger) |
| 2688 | #[wasm_bindgen (static_method_of = Number, js_name = isSafeInteger)] |
| 2689 | pub unsafefn is_safe_integer(value: &JsValue) -> bool; |
| 2690 | |
| 2691 | /// The `Number` JavaScript object is a wrapper object allowing |
| 2692 | /// you to work with numerical values. A `Number` object is |
| 2693 | /// created using the `Number()` constructor. |
| 2694 | /// |
| 2695 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) |
| 2696 | #[wasm_bindgen (constructor)] |
| 2697 | #[deprecated (note = "recommended to use `Number::from` instead" )] |
| 2698 | #[allow (deprecated)] |
| 2699 | pub unsafefn new(value: &JsValue) -> Number; |
| 2700 | |
| 2701 | #[wasm_bindgen (constructor)] |
| 2702 | unsafefn new_from_str(value: &str) -> Number; |
| 2703 | |
| 2704 | /// The `Number.parseInt()` method parses a string argument and returns an |
| 2705 | /// integer of the specified radix or base. |
| 2706 | /// |
| 2707 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/parseInt) |
| 2708 | #[wasm_bindgen (static_method_of = Number, js_name = parseInt)] |
| 2709 | pub unsafefn parse_int(text: &str, radix: u8) -> f64; |
| 2710 | |
| 2711 | /// The `Number.parseFloat()` method parses a string argument and returns a |
| 2712 | /// floating point number. |
| 2713 | /// |
| 2714 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/parseFloat) |
| 2715 | #[wasm_bindgen (static_method_of = Number, js_name = parseFloat)] |
| 2716 | pub unsafefn parse_float(text: &str) -> f64; |
| 2717 | |
| 2718 | /// The `toLocaleString()` method returns a string with a language sensitive |
| 2719 | /// representation of this number. |
| 2720 | /// |
| 2721 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString) |
| 2722 | #[wasm_bindgen (method, js_name = toLocaleString)] |
| 2723 | pub unsafefn to_locale_string(this: &Number, locale: &str) -> JsString; |
| 2724 | |
| 2725 | /// The `toPrecision()` method returns a string representing the Number |
| 2726 | /// object to the specified precision. |
| 2727 | /// |
| 2728 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision) |
| 2729 | #[wasm_bindgen (catch, method, js_name = toPrecision)] |
| 2730 | pub unsafefn to_precision(this: &Number, precision: u8) -> Result<JsString, JsValue>; |
| 2731 | |
| 2732 | /// The `toFixed()` method returns a string representing the Number |
| 2733 | /// object using fixed-point notation. |
| 2734 | /// |
| 2735 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed) |
| 2736 | #[wasm_bindgen (catch, method, js_name = toFixed)] |
| 2737 | pub unsafefn to_fixed(this: &Number, digits: u8) -> Result<JsString, JsValue>; |
| 2738 | |
| 2739 | /// The `toExponential()` method returns a string representing the Number |
| 2740 | /// object in exponential notation. |
| 2741 | /// |
| 2742 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toExponential) |
| 2743 | #[wasm_bindgen (catch, method, js_name = toExponential)] |
| 2744 | pub unsafefn to_exponential(this: &Number, fraction_digits: u8) -> Result<JsString, JsValue>; |
| 2745 | |
| 2746 | /// The `toString()` method returns a string representing the |
| 2747 | /// specified Number object. |
| 2748 | /// |
| 2749 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString) |
| 2750 | #[wasm_bindgen (catch, method, js_name = toString)] |
| 2751 | pub unsafefn to_string(this: &Number, radix: u8) -> Result<JsString, JsValue>; |
| 2752 | |
| 2753 | /// The `valueOf()` method returns the wrapped primitive value of |
| 2754 | /// a Number object. |
| 2755 | /// |
| 2756 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/valueOf) |
| 2757 | #[wasm_bindgen (method, js_name = valueOf)] |
| 2758 | pub unsafefn value_of(this: &Number) -> f64; |
| 2759 | } |
| 2760 | |
| 2761 | impl Number { |
| 2762 | /// The smallest interval between two representable numbers. |
| 2763 | /// |
| 2764 | /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/EPSILON) |
| 2765 | pub const EPSILON: f64 = f64::EPSILON; |
| 2766 | /// The maximum safe integer in JavaScript (2^53 - 1). |
| 2767 | /// |
| 2768 | /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER) |
| 2769 | pub const MAX_SAFE_INTEGER: f64 = 9007199254740991.0; |
| 2770 | /// The largest positive representable number. |
| 2771 | /// |
| 2772 | /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_VALUE) |
| 2773 | pub const MAX_VALUE: f64 = f64::MAX; |
| 2774 | /// The minimum safe integer in JavaScript (-(2^53 - 1)). |
| 2775 | /// |
| 2776 | /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MIN_SAFE_INTEGER) |
| 2777 | pub const MIN_SAFE_INTEGER: f64 = -9007199254740991.0; |
| 2778 | /// The smallest positive representable number—that is, the positive number closest to zero |
| 2779 | /// (without actually being zero). |
| 2780 | /// |
| 2781 | /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MIN_VALUE) |
| 2782 | // Cannot use f64::MIN_POSITIVE since that is the smallest **normal** positive number. |
| 2783 | pub const MIN_VALUE: f64 = 5E-324; |
| 2784 | /// Special "Not a Number" value. |
| 2785 | /// |
| 2786 | /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/NaN) |
| 2787 | pub const NAN: f64 = f64::NAN; |
| 2788 | /// Special value representing negative infinity. Returned on overflow. |
| 2789 | /// |
| 2790 | /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/NEGATIVE_INFINITY) |
| 2791 | pub const NEGATIVE_INFINITY: f64 = f64::NEG_INFINITY; |
| 2792 | /// Special value representing infinity. Returned on overflow. |
| 2793 | /// |
| 2794 | /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/POSITIVE_INFINITY) |
| 2795 | pub const POSITIVE_INFINITY: f64 = f64::INFINITY; |
| 2796 | |
| 2797 | /// Applies the binary `**` JS operator on the two `Number`s. |
| 2798 | /// |
| 2799 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Exponentiation) |
| 2800 | #[inline ] |
| 2801 | pub fn pow(&self, rhs: &Self) -> Self { |
| 2802 | JsValue::as_ref(self) |
| 2803 | .pow(JsValue::as_ref(rhs)) |
| 2804 | .unchecked_into() |
| 2805 | } |
| 2806 | |
| 2807 | /// Applies the binary `>>>` JS operator on the two `Number`s. |
| 2808 | /// |
| 2809 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Unsigned_right_shift) |
| 2810 | #[inline ] |
| 2811 | pub fn unsigned_shr(&self, rhs: &Self) -> Self { |
| 2812 | Number::from(JsValue::as_ref(self).unsigned_shr(JsValue::as_ref(rhs))) |
| 2813 | } |
| 2814 | } |
| 2815 | |
| 2816 | macro_rules! number_from { |
| 2817 | ($($x:ident)*) => ($( |
| 2818 | impl From<$x> for Number { |
| 2819 | #[inline] |
| 2820 | fn from(x: $x) -> Number { |
| 2821 | Number::unchecked_from_js(JsValue::from(x)) |
| 2822 | } |
| 2823 | } |
| 2824 | |
| 2825 | impl PartialEq<$x> for Number { |
| 2826 | #[inline] |
| 2827 | fn eq(&self, other: &$x) -> bool { |
| 2828 | self.value_of() == f64::from(*other) |
| 2829 | } |
| 2830 | } |
| 2831 | )*) |
| 2832 | } |
| 2833 | number_from!(i8 u8 i16 u16 i32 u32 f32 f64); |
| 2834 | |
| 2835 | /// The error type returned when a checked integral type conversion fails. |
| 2836 | #[derive (Debug, Copy, Clone, PartialEq, Eq)] |
| 2837 | pub struct TryFromIntError(()); |
| 2838 | |
| 2839 | impl fmt::Display for TryFromIntError { |
| 2840 | fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 2841 | fmt.write_str(data:"out of range integral type conversion attempted" ) |
| 2842 | } |
| 2843 | } |
| 2844 | |
| 2845 | #[cfg (feature = "std" )] |
| 2846 | impl std::error::Error for TryFromIntError {} |
| 2847 | |
| 2848 | macro_rules! number_try_from { |
| 2849 | ($($x:ident)*) => ($( |
| 2850 | impl TryFrom<$x> for Number { |
| 2851 | type Error = TryFromIntError; |
| 2852 | |
| 2853 | #[inline] |
| 2854 | fn try_from(x: $x) -> Result<Number, Self::Error> { |
| 2855 | let x_f64 = x as f64; |
| 2856 | if (Number::MIN_SAFE_INTEGER..=Number::MAX_SAFE_INTEGER).contains(&x_f64) { |
| 2857 | Ok(Number::from(x_f64)) |
| 2858 | } else { |
| 2859 | Err(TryFromIntError(())) |
| 2860 | } |
| 2861 | } |
| 2862 | } |
| 2863 | )*) |
| 2864 | } |
| 2865 | number_try_from!(i64 u64 i128 u128); |
| 2866 | |
| 2867 | // TODO: add this on the next major version, when blanket impl is removed |
| 2868 | /* |
| 2869 | impl convert::TryFrom<JsValue> for Number { |
| 2870 | type Error = Error; |
| 2871 | |
| 2872 | fn try_from(value: JsValue) -> Result<Self, Self::Error> { |
| 2873 | return match f64::try_from(value) { |
| 2874 | Ok(num) => Ok(Number::from(num)), |
| 2875 | Err(jsval) => Err(jsval.unchecked_into()) |
| 2876 | } |
| 2877 | } |
| 2878 | } |
| 2879 | */ |
| 2880 | |
| 2881 | impl From<&Number> for f64 { |
| 2882 | #[inline ] |
| 2883 | fn from(n: &Number) -> f64 { |
| 2884 | n.value_of() |
| 2885 | } |
| 2886 | } |
| 2887 | |
| 2888 | impl From<Number> for f64 { |
| 2889 | #[inline ] |
| 2890 | fn from(n: Number) -> f64 { |
| 2891 | <f64 as From<&'_ Number>>::from(&n) |
| 2892 | } |
| 2893 | } |
| 2894 | |
| 2895 | impl fmt::Debug for Number { |
| 2896 | #[inline ] |
| 2897 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
| 2898 | fmt::Debug::fmt(&self.value_of(), f) |
| 2899 | } |
| 2900 | } |
| 2901 | |
| 2902 | impl fmt::Display for Number { |
| 2903 | #[inline ] |
| 2904 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
| 2905 | fmt::Display::fmt(&self.value_of(), f) |
| 2906 | } |
| 2907 | } |
| 2908 | |
| 2909 | impl Default for Number { |
| 2910 | fn default() -> Self { |
| 2911 | Self::from(f64::default()) |
| 2912 | } |
| 2913 | } |
| 2914 | |
| 2915 | impl PartialEq<BigInt> for Number { |
| 2916 | #[inline ] |
| 2917 | fn eq(&self, other: &BigInt) -> bool { |
| 2918 | JsValue::as_ref(self).loose_eq(JsValue::as_ref(self:other)) |
| 2919 | } |
| 2920 | } |
| 2921 | |
| 2922 | impl Not for &Number { |
| 2923 | type Output = BigInt; |
| 2924 | |
| 2925 | #[inline ] |
| 2926 | fn not(self) -> Self::Output { |
| 2927 | JsValue::as_ref(self).bit_not().unchecked_into() |
| 2928 | } |
| 2929 | } |
| 2930 | |
| 2931 | forward_deref_unop!(impl Not, not for Number); |
| 2932 | forward_js_unop!(impl Neg, neg for Number); |
| 2933 | forward_js_binop!(impl BitAnd, bitand for Number); |
| 2934 | forward_js_binop!(impl BitOr, bitor for Number); |
| 2935 | forward_js_binop!(impl BitXor, bitxor for Number); |
| 2936 | forward_js_binop!(impl Shl, shl for Number); |
| 2937 | forward_js_binop!(impl Shr, shr for Number); |
| 2938 | forward_js_binop!(impl Add, add for Number); |
| 2939 | forward_js_binop!(impl Sub, sub for Number); |
| 2940 | forward_js_binop!(impl Div, div for Number); |
| 2941 | forward_js_binop!(impl Mul, mul for Number); |
| 2942 | forward_js_binop!(impl Rem, rem for Number); |
| 2943 | |
| 2944 | sum_product!(Number); |
| 2945 | |
| 2946 | impl PartialOrd for Number { |
| 2947 | #[inline ] |
| 2948 | fn partial_cmp(&self, other: &Self) -> Option<Ordering> { |
| 2949 | if Number::is_nan(self) || Number::is_nan(other) { |
| 2950 | None |
| 2951 | } else if self == other { |
| 2952 | Some(Ordering::Equal) |
| 2953 | } else if self.lt(other) { |
| 2954 | Some(Ordering::Less) |
| 2955 | } else { |
| 2956 | Some(Ordering::Greater) |
| 2957 | } |
| 2958 | } |
| 2959 | |
| 2960 | #[inline ] |
| 2961 | fn lt(&self, other: &Self) -> bool { |
| 2962 | JsValue::as_ref(self).lt(JsValue::as_ref(other)) |
| 2963 | } |
| 2964 | |
| 2965 | #[inline ] |
| 2966 | fn le(&self, other: &Self) -> bool { |
| 2967 | JsValue::as_ref(self).le(JsValue::as_ref(other)) |
| 2968 | } |
| 2969 | |
| 2970 | #[inline ] |
| 2971 | fn ge(&self, other: &Self) -> bool { |
| 2972 | JsValue::as_ref(self).ge(JsValue::as_ref(other)) |
| 2973 | } |
| 2974 | |
| 2975 | #[inline ] |
| 2976 | fn gt(&self, other: &Self) -> bool { |
| 2977 | JsValue::as_ref(self).gt(JsValue::as_ref(other)) |
| 2978 | } |
| 2979 | } |
| 2980 | |
| 2981 | impl FromStr for Number { |
| 2982 | type Err = Infallible; |
| 2983 | |
| 2984 | #[allow (deprecated)] |
| 2985 | #[inline ] |
| 2986 | fn from_str(s: &str) -> Result<Self, Self::Err> { |
| 2987 | Ok(Number::new_from_str(s)) |
| 2988 | } |
| 2989 | } |
| 2990 | |
| 2991 | // Date. |
| 2992 | #[wasm_bindgen ] |
| 2993 | unsafeextern "C" { |
| 2994 | #[wasm_bindgen (extends = Object, typescript_type = "Date" )] |
| 2995 | #[derive (Clone, Debug, PartialEq, Eq)] |
| 2996 | pub type Date; |
| 2997 | |
| 2998 | /// The `getDate()` method returns the day of the month for the |
| 2999 | /// specified date according to local time. |
| 3000 | /// |
| 3001 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getDate) |
| 3002 | #[wasm_bindgen (method, js_name = getDate)] |
| 3003 | pub unsafefn get_date(this: &Date) -> u32; |
| 3004 | |
| 3005 | /// The `getDay()` method returns the day of the week for the specified date according to local time, |
| 3006 | /// where 0 represents Sunday. For the day of the month see getDate(). |
| 3007 | /// |
| 3008 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getDay) |
| 3009 | #[wasm_bindgen (method, js_name = getDay)] |
| 3010 | pub unsafefn get_day(this: &Date) -> u32; |
| 3011 | |
| 3012 | /// The `getFullYear()` method returns the year of the specified date according to local time. |
| 3013 | /// |
| 3014 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getFullYear) |
| 3015 | #[wasm_bindgen (method, js_name = getFullYear)] |
| 3016 | pub unsafefn get_full_year(this: &Date) -> u32; |
| 3017 | |
| 3018 | /// The `getHours()` method returns the hour for the specified date, according to local time. |
| 3019 | /// |
| 3020 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getHours) |
| 3021 | #[wasm_bindgen (method, js_name = getHours)] |
| 3022 | pub unsafefn get_hours(this: &Date) -> u32; |
| 3023 | |
| 3024 | /// The `getMilliseconds()` method returns the milliseconds in the specified date according to local time. |
| 3025 | /// |
| 3026 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMilliseconds) |
| 3027 | #[wasm_bindgen (method, js_name = getMilliseconds)] |
| 3028 | pub unsafefn get_milliseconds(this: &Date) -> u32; |
| 3029 | |
| 3030 | /// The `getMinutes()` method returns the minutes in the specified date according to local time. |
| 3031 | /// |
| 3032 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMinutes) |
| 3033 | #[wasm_bindgen (method, js_name = getMinutes)] |
| 3034 | pub unsafefn get_minutes(this: &Date) -> u32; |
| 3035 | |
| 3036 | /// The `getMonth()` method returns the month in the specified date according to local time, |
| 3037 | /// as a zero-based value (where zero indicates the first month of the year). |
| 3038 | /// |
| 3039 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMonth) |
| 3040 | #[wasm_bindgen (method, js_name = getMonth)] |
| 3041 | pub unsafefn get_month(this: &Date) -> u32; |
| 3042 | |
| 3043 | /// The `getSeconds()` method returns the seconds in the specified date according to local time. |
| 3044 | /// |
| 3045 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getSeconds) |
| 3046 | #[wasm_bindgen (method, js_name = getSeconds)] |
| 3047 | pub unsafefn get_seconds(this: &Date) -> u32; |
| 3048 | |
| 3049 | /// The `getTime()` method returns the numeric value corresponding to the time for 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/getTime) |
| 3053 | #[wasm_bindgen (method, js_name = getTime)] |
| 3054 | pub unsafefn get_time(this: &Date) -> f64; |
| 3055 | |
| 3056 | /// The `getTimezoneOffset()` method returns the time zone difference, in minutes, |
| 3057 | /// from current locale (host system settings) to UTC. |
| 3058 | /// |
| 3059 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTimezoneOffset) |
| 3060 | #[wasm_bindgen (method, js_name = getTimezoneOffset)] |
| 3061 | pub unsafefn get_timezone_offset(this: &Date) -> f64; |
| 3062 | |
| 3063 | /// The `getUTCDate()` method returns the day (date) of the month in the specified date |
| 3064 | /// according to universal time. |
| 3065 | /// |
| 3066 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCDate) |
| 3067 | #[wasm_bindgen (method, js_name = getUTCDate)] |
| 3068 | pub unsafefn get_utc_date(this: &Date) -> u32; |
| 3069 | |
| 3070 | /// The `getUTCDay()` method returns the day of the week in the specified date according to universal time, |
| 3071 | /// where 0 represents Sunday. |
| 3072 | /// |
| 3073 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCDay) |
| 3074 | #[wasm_bindgen (method, js_name = getUTCDay)] |
| 3075 | pub unsafefn get_utc_day(this: &Date) -> u32; |
| 3076 | |
| 3077 | /// The `getUTCFullYear()` method returns the year in the specified date according to universal time. |
| 3078 | /// |
| 3079 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCFullYear) |
| 3080 | #[wasm_bindgen (method, js_name = getUTCFullYear)] |
| 3081 | pub unsafefn get_utc_full_year(this: &Date) -> u32; |
| 3082 | |
| 3083 | /// The `getUTCHours()` method returns the hours in the specified date according to universal time. |
| 3084 | /// |
| 3085 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCHours) |
| 3086 | #[wasm_bindgen (method, js_name = getUTCHours)] |
| 3087 | pub unsafefn get_utc_hours(this: &Date) -> u32; |
| 3088 | |
| 3089 | /// The `getUTCMilliseconds()` method returns the milliseconds in the specified date |
| 3090 | /// according to universal time. |
| 3091 | /// |
| 3092 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCMilliseconds) |
| 3093 | #[wasm_bindgen (method, js_name = getUTCMilliseconds)] |
| 3094 | pub unsafefn get_utc_milliseconds(this: &Date) -> u32; |
| 3095 | |
| 3096 | /// The `getUTCMinutes()` method returns the minutes in the specified date according to universal time. |
| 3097 | /// |
| 3098 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCMinutes) |
| 3099 | #[wasm_bindgen (method, js_name = getUTCMinutes)] |
| 3100 | pub unsafefn get_utc_minutes(this: &Date) -> u32; |
| 3101 | |
| 3102 | /// The `getUTCMonth()` returns the month of the specified date according to universal time, |
| 3103 | /// as a zero-based value (where zero indicates the first month of the year). |
| 3104 | /// |
| 3105 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCMonth) |
| 3106 | #[wasm_bindgen (method, js_name = getUTCMonth)] |
| 3107 | pub unsafefn get_utc_month(this: &Date) -> u32; |
| 3108 | |
| 3109 | /// The `getUTCSeconds()` method returns the seconds in the specified date according to universal time. |
| 3110 | /// |
| 3111 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCSeconds) |
| 3112 | #[wasm_bindgen (method, js_name = getUTCSeconds)] |
| 3113 | pub unsafefn get_utc_seconds(this: &Date) -> u32; |
| 3114 | |
| 3115 | /// Creates a JavaScript `Date` instance that represents |
| 3116 | /// a single moment in time. `Date` objects are based on a time value that is |
| 3117 | /// the number of milliseconds since 1 January 1970 UTC. |
| 3118 | /// |
| 3119 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) |
| 3120 | #[wasm_bindgen (constructor)] |
| 3121 | pub unsafefn new(init: &JsValue) -> Date; |
| 3122 | |
| 3123 | /// Creates a JavaScript `Date` instance that represents the current moment in |
| 3124 | /// time. |
| 3125 | /// |
| 3126 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) |
| 3127 | #[wasm_bindgen (constructor)] |
| 3128 | pub unsafefn new_0() -> Date; |
| 3129 | |
| 3130 | /// Creates a JavaScript `Date` instance that represents |
| 3131 | /// a single moment in time. `Date` objects are based on a time value that is |
| 3132 | /// the number of milliseconds since 1 January 1970 UTC. |
| 3133 | /// |
| 3134 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) |
| 3135 | #[wasm_bindgen (constructor)] |
| 3136 | pub unsafefn new_with_year_month(year: u32, month: i32) -> Date; |
| 3137 | |
| 3138 | /// Creates a JavaScript `Date` instance that represents |
| 3139 | /// a single moment in time. `Date` objects are based on a time value that is |
| 3140 | /// the number of milliseconds since 1 January 1970 UTC. |
| 3141 | /// |
| 3142 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) |
| 3143 | #[wasm_bindgen (constructor)] |
| 3144 | pub unsafefn new_with_year_month_day(year: u32, month: i32, day: i32) -> Date; |
| 3145 | |
| 3146 | /// Creates a JavaScript `Date` instance that represents |
| 3147 | /// a single moment in time. `Date` objects are based on a time value that is |
| 3148 | /// the number of milliseconds since 1 January 1970 UTC. |
| 3149 | /// |
| 3150 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) |
| 3151 | #[wasm_bindgen (constructor)] |
| 3152 | pub unsafefn new_with_year_month_day_hr(year: u32, month: i32, day: i32, hr: i32) -> Date; |
| 3153 | |
| 3154 | /// Creates a JavaScript `Date` instance that represents |
| 3155 | /// a single moment in time. `Date` objects are based on a time value that is |
| 3156 | /// the number of milliseconds since 1 January 1970 UTC. |
| 3157 | /// |
| 3158 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) |
| 3159 | #[wasm_bindgen (constructor)] |
| 3160 | pub unsafefn new_with_year_month_day_hr_min( |
| 3161 | year: u32, |
| 3162 | month: i32, |
| 3163 | day: i32, |
| 3164 | hr: i32, |
| 3165 | min: i32, |
| 3166 | ) -> Date; |
| 3167 | |
| 3168 | /// Creates a JavaScript `Date` instance that represents |
| 3169 | /// a single moment in time. `Date` objects are based on a time value that is |
| 3170 | /// the number of milliseconds since 1 January 1970 UTC. |
| 3171 | /// |
| 3172 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) |
| 3173 | #[wasm_bindgen (constructor)] |
| 3174 | pub unsafefn new_with_year_month_day_hr_min_sec( |
| 3175 | year: u32, |
| 3176 | month: i32, |
| 3177 | day: i32, |
| 3178 | hr: i32, |
| 3179 | min: i32, |
| 3180 | sec: i32, |
| 3181 | ) -> Date; |
| 3182 | |
| 3183 | /// Creates a JavaScript `Date` instance that represents |
| 3184 | /// a single moment in time. `Date` objects are based on a time value that is |
| 3185 | /// the number of milliseconds since 1 January 1970 UTC. |
| 3186 | /// |
| 3187 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) |
| 3188 | #[wasm_bindgen (constructor)] |
| 3189 | pub unsafefn new_with_year_month_day_hr_min_sec_milli( |
| 3190 | year: u32, |
| 3191 | month: i32, |
| 3192 | day: i32, |
| 3193 | hr: i32, |
| 3194 | min: i32, |
| 3195 | sec: i32, |
| 3196 | milli: i32, |
| 3197 | ) -> Date; |
| 3198 | |
| 3199 | /// The `Date.now()` method returns the number of milliseconds |
| 3200 | /// elapsed since January 1, 1970 00:00:00 UTC. |
| 3201 | /// |
| 3202 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/now) |
| 3203 | #[wasm_bindgen (static_method_of = Date)] |
| 3204 | pub unsafefn now() -> f64; |
| 3205 | |
| 3206 | /// The `Date.parse()` method parses a string representation of a date, and returns the number of milliseconds |
| 3207 | /// since January 1, 1970, 00:00:00 UTC or `NaN` if the string is unrecognized or, in some cases, |
| 3208 | /// contains illegal date values (e.g. 2015-02-31). |
| 3209 | /// |
| 3210 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse) |
| 3211 | #[wasm_bindgen (static_method_of = Date)] |
| 3212 | pub unsafefn parse(date: &str) -> f64; |
| 3213 | |
| 3214 | /// The `setDate()` method sets the day of the Date object relative to the beginning of the currently set month. |
| 3215 | /// |
| 3216 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setDate) |
| 3217 | #[wasm_bindgen (method, js_name = setDate)] |
| 3218 | pub unsafefn set_date(this: &Date, day: u32) -> f64; |
| 3219 | |
| 3220 | /// The `setFullYear()` method sets the full year for a specified date according to local time. |
| 3221 | /// Returns new timestamp. |
| 3222 | /// |
| 3223 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setFullYear) |
| 3224 | #[wasm_bindgen (method, js_name = setFullYear)] |
| 3225 | pub unsafefn set_full_year(this: &Date, year: u32) -> f64; |
| 3226 | |
| 3227 | /// The `setFullYear()` method sets the full year for a specified date according to local time. |
| 3228 | /// Returns new timestamp. |
| 3229 | /// |
| 3230 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setFullYear) |
| 3231 | #[wasm_bindgen (method, js_name = setFullYear)] |
| 3232 | pub unsafefn set_full_year_with_month(this: &Date, year: u32, month: i32) -> f64; |
| 3233 | |
| 3234 | /// The `setFullYear()` method sets the full year for a specified date according to local time. |
| 3235 | /// Returns new timestamp. |
| 3236 | /// |
| 3237 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setFullYear) |
| 3238 | #[wasm_bindgen (method, js_name = setFullYear)] |
| 3239 | pub unsafefn set_full_year_with_month_date(this: &Date, year: u32, month: i32, date: i32) -> f64; |
| 3240 | |
| 3241 | /// The `setHours()` method sets the hours for a specified date according to local time, |
| 3242 | /// and returns the number of milliseconds since January 1, 1970 00:00:00 UTC until the time represented |
| 3243 | /// by the updated Date instance. |
| 3244 | /// |
| 3245 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setHours) |
| 3246 | #[wasm_bindgen (method, js_name = setHours)] |
| 3247 | pub unsafefn set_hours(this: &Date, hours: u32) -> f64; |
| 3248 | |
| 3249 | /// The `setMilliseconds()` method sets the milliseconds for a specified date according to local time. |
| 3250 | /// |
| 3251 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setMilliseconds) |
| 3252 | #[wasm_bindgen (method, js_name = setMilliseconds)] |
| 3253 | pub unsafefn set_milliseconds(this: &Date, milliseconds: u32) -> f64; |
| 3254 | |
| 3255 | /// The `setMinutes()` method sets the minutes for a specified date according to local time. |
| 3256 | /// |
| 3257 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setMinutes) |
| 3258 | #[wasm_bindgen (method, js_name = setMinutes)] |
| 3259 | pub unsafefn set_minutes(this: &Date, minutes: u32) -> f64; |
| 3260 | |
| 3261 | /// The `setMonth()` method sets the month for a specified date according to the currently set year. |
| 3262 | /// |
| 3263 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setMonth) |
| 3264 | #[wasm_bindgen (method, js_name = setMonth)] |
| 3265 | pub unsafefn set_month(this: &Date, month: u32) -> f64; |
| 3266 | |
| 3267 | /// The `setSeconds()` method sets the seconds for a specified date according to local time. |
| 3268 | /// |
| 3269 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setSeconds) |
| 3270 | #[wasm_bindgen (method, js_name = setSeconds)] |
| 3271 | pub unsafefn set_seconds(this: &Date, seconds: u32) -> f64; |
| 3272 | |
| 3273 | /// The `setTime()` method sets the Date object to the time represented by a number of milliseconds |
| 3274 | /// since January 1, 1970, 00:00:00 UTC. |
| 3275 | /// |
| 3276 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setTime) |
| 3277 | #[wasm_bindgen (method, js_name = setTime)] |
| 3278 | pub unsafefn set_time(this: &Date, time: f64) -> f64; |
| 3279 | |
| 3280 | /// The `setUTCDate()` method sets the day of the month for a specified date |
| 3281 | /// according to universal time. |
| 3282 | /// |
| 3283 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCDate) |
| 3284 | #[wasm_bindgen (method, js_name = setUTCDate)] |
| 3285 | pub unsafefn set_utc_date(this: &Date, day: u32) -> f64; |
| 3286 | |
| 3287 | /// The `setUTCFullYear()` method sets the full year for a specified date according to universal time. |
| 3288 | /// |
| 3289 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCFullYear) |
| 3290 | #[wasm_bindgen (method, js_name = setUTCFullYear)] |
| 3291 | pub unsafefn set_utc_full_year(this: &Date, year: u32) -> f64; |
| 3292 | |
| 3293 | /// The `setUTCFullYear()` method sets the full year for a specified date according to universal time. |
| 3294 | /// |
| 3295 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCFullYear) |
| 3296 | #[wasm_bindgen (method, js_name = setUTCFullYear)] |
| 3297 | pub unsafefn set_utc_full_year_with_month(this: &Date, year: u32, month: i32) -> f64; |
| 3298 | |
| 3299 | /// The `setUTCFullYear()` method sets the full year for a specified date according to universal time. |
| 3300 | /// |
| 3301 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCFullYear) |
| 3302 | #[wasm_bindgen (method, js_name = setUTCFullYear)] |
| 3303 | pub unsafefn set_utc_full_year_with_month_date(this: &Date, year: u32, month: i32, date: i32) -> f64; |
| 3304 | |
| 3305 | /// The `setUTCHours()` method sets the hour for a specified date according to universal time, |
| 3306 | /// and returns the number of milliseconds since January 1, 1970 00:00:00 UTC until the time |
| 3307 | /// represented by the updated Date instance. |
| 3308 | /// |
| 3309 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCHours) |
| 3310 | #[wasm_bindgen (method, js_name = setUTCHours)] |
| 3311 | pub unsafefn set_utc_hours(this: &Date, hours: u32) -> f64; |
| 3312 | |
| 3313 | /// The `setUTCMilliseconds()` method sets the milliseconds for a specified date |
| 3314 | /// according to universal time. |
| 3315 | /// |
| 3316 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCMilliseconds) |
| 3317 | #[wasm_bindgen (method, js_name = setUTCMilliseconds)] |
| 3318 | pub unsafefn set_utc_milliseconds(this: &Date, milliseconds: u32) -> f64; |
| 3319 | |
| 3320 | /// The `setUTCMinutes()` method sets the minutes for a specified date according to universal time. |
| 3321 | /// |
| 3322 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCMinutes) |
| 3323 | #[wasm_bindgen (method, js_name = setUTCMinutes)] |
| 3324 | pub unsafefn set_utc_minutes(this: &Date, minutes: u32) -> f64; |
| 3325 | |
| 3326 | /// The `setUTCMonth()` method sets the month for a specified date according to universal time. |
| 3327 | /// |
| 3328 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCMonth) |
| 3329 | #[wasm_bindgen (method, js_name = setUTCMonth)] |
| 3330 | pub unsafefn set_utc_month(this: &Date, month: u32) -> f64; |
| 3331 | |
| 3332 | /// The `setUTCSeconds()` method sets the seconds for a specified date according to universal time. |
| 3333 | /// |
| 3334 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCSeconds) |
| 3335 | #[wasm_bindgen (method, js_name = setUTCSeconds)] |
| 3336 | pub unsafefn set_utc_seconds(this: &Date, seconds: u32) -> f64; |
| 3337 | |
| 3338 | /// The `toDateString()` method returns the date portion of a Date object |
| 3339 | /// in human readable form in American English. |
| 3340 | /// |
| 3341 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toDateString) |
| 3342 | #[wasm_bindgen (method, js_name = toDateString)] |
| 3343 | pub unsafefn to_date_string(this: &Date) -> JsString; |
| 3344 | |
| 3345 | /// The `toISOString()` method returns a string in simplified extended ISO format (ISO |
| 3346 | /// 8601), which is always 24 or 27 characters long (YYYY-MM-DDTHH:mm:ss.sssZ or |
| 3347 | /// ±YYYYYY-MM-DDTHH:mm:ss.sssZ, respectively). The timezone is always zero UTC offset, |
| 3348 | /// as denoted by the suffix "Z" |
| 3349 | /// |
| 3350 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString) |
| 3351 | #[wasm_bindgen (method, js_name = toISOString)] |
| 3352 | pub unsafefn to_iso_string(this: &Date) -> JsString; |
| 3353 | |
| 3354 | /// The `toJSON()` method returns a string representation of the Date object. |
| 3355 | /// |
| 3356 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toJSON) |
| 3357 | #[wasm_bindgen (method, js_name = toJSON)] |
| 3358 | pub unsafefn to_json(this: &Date) -> JsString; |
| 3359 | |
| 3360 | /// The `toLocaleDateString()` method returns a string with a language sensitive |
| 3361 | /// representation of the date portion of this date. The new locales and options |
| 3362 | /// arguments let applications specify the language whose formatting conventions |
| 3363 | /// should be used and allow to customize the behavior of the function. |
| 3364 | /// In older implementations, which ignore the locales and options arguments, |
| 3365 | /// the locale used and the form of the string |
| 3366 | /// returned are entirely implementation dependent. |
| 3367 | /// |
| 3368 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString) |
| 3369 | #[wasm_bindgen (method, js_name = toLocaleDateString)] |
| 3370 | pub unsafefn to_locale_date_string(this: &Date, locale: &str, options: &JsValue) -> JsString; |
| 3371 | |
| 3372 | /// The `toLocaleString()` method returns a string with a language sensitive |
| 3373 | /// representation of this date. The new locales and options arguments |
| 3374 | /// let applications specify the language whose formatting conventions |
| 3375 | /// should be used and customize the behavior of the function. |
| 3376 | /// In older implementations, which ignore the locales |
| 3377 | /// and options arguments, the locale used and the form of the string |
| 3378 | /// returned are entirely implementation dependent. |
| 3379 | /// |
| 3380 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString) |
| 3381 | #[wasm_bindgen (method, js_name = toLocaleString)] |
| 3382 | pub unsafefn to_locale_string(this: &Date, locale: &str, options: &JsValue) -> JsString; |
| 3383 | |
| 3384 | /// The `toLocaleTimeString()` method returns a string with a language sensitive |
| 3385 | /// representation of the time portion of this date. The new locales and options |
| 3386 | /// arguments let applications specify the language whose formatting conventions should be |
| 3387 | /// used and customize the behavior of the function. In older implementations, which ignore |
| 3388 | /// the locales and options arguments, the locale used and the form of the string |
| 3389 | /// returned are entirely implementation dependent. |
| 3390 | /// |
| 3391 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleTimeString) |
| 3392 | #[wasm_bindgen (method, js_name = toLocaleTimeString)] |
| 3393 | pub unsafefn to_locale_time_string(this: &Date, locale: &str) -> JsString; |
| 3394 | |
| 3395 | #[wasm_bindgen (method, js_name = toLocaleTimeString)] |
| 3396 | pub unsafefn to_locale_time_string_with_options( |
| 3397 | this: &Date, |
| 3398 | locale: &str, |
| 3399 | options: &JsValue, |
| 3400 | ) -> JsString; |
| 3401 | |
| 3402 | /// The `toString()` method returns a string representing |
| 3403 | /// the specified Date object. |
| 3404 | /// |
| 3405 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toString) |
| 3406 | #[wasm_bindgen (method, js_name = toString)] |
| 3407 | pub unsafefn to_string(this: &Date) -> JsString; |
| 3408 | |
| 3409 | /// The `toTimeString()` method returns the time portion of a Date object in human |
| 3410 | /// readable form in American English. |
| 3411 | /// |
| 3412 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toTimeString) |
| 3413 | #[wasm_bindgen (method, js_name = toTimeString)] |
| 3414 | pub unsafefn to_time_string(this: &Date) -> JsString; |
| 3415 | |
| 3416 | /// The `toUTCString()` method converts a date to a string, |
| 3417 | /// using the UTC time zone. |
| 3418 | /// |
| 3419 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toUTCString) |
| 3420 | #[wasm_bindgen (method, js_name = toUTCString)] |
| 3421 | pub unsafefn to_utc_string(this: &Date) -> JsString; |
| 3422 | |
| 3423 | /// The `Date.UTC()` method accepts the same parameters as the |
| 3424 | /// longest form of the constructor, and returns the number of |
| 3425 | /// milliseconds in a `Date` object since January 1, 1970, |
| 3426 | /// 00:00:00, universal time. |
| 3427 | /// |
| 3428 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/UTC) |
| 3429 | #[wasm_bindgen (static_method_of = Date, js_name = UTC)] |
| 3430 | pub unsafefn utc(year: f64, month: f64) -> f64; |
| 3431 | |
| 3432 | /// The `valueOf()` method returns the primitive value of |
| 3433 | /// a Date object. |
| 3434 | /// |
| 3435 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/valueOf) |
| 3436 | #[wasm_bindgen (method, js_name = valueOf)] |
| 3437 | pub unsafefn value_of(this: &Date) -> f64; |
| 3438 | } |
| 3439 | |
| 3440 | // Object. |
| 3441 | #[wasm_bindgen ] |
| 3442 | unsafeextern "C" { |
| 3443 | #[wasm_bindgen (typescript_type = "object" )] |
| 3444 | #[derive (Clone, Debug)] |
| 3445 | pub type Object; |
| 3446 | |
| 3447 | /// The `Object.assign()` method is used to copy the values of all enumerable |
| 3448 | /// own properties from one or more source objects to a target object. It |
| 3449 | /// will return the target object. |
| 3450 | /// |
| 3451 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign) |
| 3452 | #[wasm_bindgen (static_method_of = Object)] |
| 3453 | pub unsafefn assign(target: &Object, source: &Object) -> Object; |
| 3454 | |
| 3455 | /// The `Object.assign()` method is used to copy the values of all enumerable |
| 3456 | /// own properties from one or more source objects to a target object. It |
| 3457 | /// will return the target object. |
| 3458 | /// |
| 3459 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign) |
| 3460 | #[wasm_bindgen (static_method_of = Object, js_name = assign)] |
| 3461 | pub unsafefn assign2(target: &Object, source1: &Object, source2: &Object) -> Object; |
| 3462 | |
| 3463 | /// The `Object.assign()` method is used to copy the values of all enumerable |
| 3464 | /// own properties from one or more source objects to a target object. It |
| 3465 | /// will return the target object. |
| 3466 | /// |
| 3467 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign) |
| 3468 | #[wasm_bindgen (static_method_of = Object, js_name = assign)] |
| 3469 | pub unsafefn assign3(target: &Object, source1: &Object, source2: &Object, source3: &Object) |
| 3470 | -> Object; |
| 3471 | |
| 3472 | /// The constructor property returns a reference to the `Object` constructor |
| 3473 | /// function that created the instance object. |
| 3474 | /// |
| 3475 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/constructor) |
| 3476 | #[wasm_bindgen (method, getter)] |
| 3477 | pub unsafefn constructor(this: &Object) -> Function; |
| 3478 | |
| 3479 | /// The `Object.create()` method creates a new object, using an existing |
| 3480 | /// object to provide the newly created object's prototype. |
| 3481 | /// |
| 3482 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/create) |
| 3483 | #[wasm_bindgen (static_method_of = Object)] |
| 3484 | pub unsafefn create(prototype: &Object) -> Object; |
| 3485 | |
| 3486 | /// The static method `Object.defineProperty()` defines a new |
| 3487 | /// property directly on an object, or modifies an existing |
| 3488 | /// property on an object, and returns the object. |
| 3489 | /// |
| 3490 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty) |
| 3491 | #[wasm_bindgen (static_method_of = Object, js_name = defineProperty)] |
| 3492 | pub unsafefn define_property(obj: &Object, prop: &JsValue, descriptor: &Object) -> Object; |
| 3493 | |
| 3494 | /// The `Object.defineProperties()` method defines new or modifies |
| 3495 | /// existing properties directly on an object, returning the |
| 3496 | /// object. |
| 3497 | /// |
| 3498 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperties) |
| 3499 | #[wasm_bindgen (static_method_of = Object, js_name = defineProperties)] |
| 3500 | pub unsafefn define_properties(obj: &Object, props: &Object) -> Object; |
| 3501 | |
| 3502 | /// The `Object.entries()` method returns an array of a given |
| 3503 | /// object's own enumerable property [key, value] pairs, in the |
| 3504 | /// same order as that provided by a for...in loop (the difference |
| 3505 | /// being that a for-in loop enumerates properties in the |
| 3506 | /// prototype chain as well). |
| 3507 | /// |
| 3508 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries) |
| 3509 | #[wasm_bindgen (static_method_of = Object)] |
| 3510 | pub unsafefn entries(object: &Object) -> Array; |
| 3511 | |
| 3512 | /// The `Object.freeze()` method freezes an object: that is, prevents new |
| 3513 | /// properties from being added to it; prevents existing properties from |
| 3514 | /// being removed; and prevents existing properties, or their enumerability, |
| 3515 | /// configurability, or writability, from being changed, it also prevents |
| 3516 | /// the prototype from being changed. The method returns the passed object. |
| 3517 | /// |
| 3518 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze) |
| 3519 | #[wasm_bindgen (static_method_of = Object)] |
| 3520 | pub unsafefn freeze(value: &Object) -> Object; |
| 3521 | |
| 3522 | /// The `Object.fromEntries()` method transforms a list of key-value pairs |
| 3523 | /// into an object. |
| 3524 | /// |
| 3525 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/fromEntries) |
| 3526 | #[wasm_bindgen (static_method_of = Object, catch, js_name = fromEntries)] |
| 3527 | pub unsafefn from_entries(iterable: &JsValue) -> Result<Object, JsValue>; |
| 3528 | |
| 3529 | /// The `Object.getOwnPropertyDescriptor()` method returns a |
| 3530 | /// property descriptor for an own property (that is, one directly |
| 3531 | /// present on an object and not in the object's prototype chain) |
| 3532 | /// of a given object. |
| 3533 | /// |
| 3534 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor) |
| 3535 | #[wasm_bindgen (static_method_of = Object, js_name = getOwnPropertyDescriptor)] |
| 3536 | pub unsafefn get_own_property_descriptor(obj: &Object, prop: &JsValue) -> JsValue; |
| 3537 | |
| 3538 | /// The `Object.getOwnPropertyDescriptors()` method returns all own |
| 3539 | /// property descriptors of a given object. |
| 3540 | /// |
| 3541 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptors) |
| 3542 | #[wasm_bindgen (static_method_of = Object, js_name = getOwnPropertyDescriptors)] |
| 3543 | pub unsafefn get_own_property_descriptors(obj: &Object) -> JsValue; |
| 3544 | |
| 3545 | /// The `Object.getOwnPropertyNames()` method returns an array of |
| 3546 | /// all properties (including non-enumerable properties except for |
| 3547 | /// those which use Symbol) found directly upon a given object. |
| 3548 | /// |
| 3549 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyNames) |
| 3550 | #[wasm_bindgen (static_method_of = Object, js_name = getOwnPropertyNames)] |
| 3551 | pub unsafefn get_own_property_names(obj: &Object) -> Array; |
| 3552 | |
| 3553 | /// The `Object.getOwnPropertySymbols()` method returns an array of |
| 3554 | /// all symbol properties found directly upon a given object. |
| 3555 | /// |
| 3556 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertySymbols) |
| 3557 | #[wasm_bindgen (static_method_of = Object, js_name = getOwnPropertySymbols)] |
| 3558 | pub unsafefn get_own_property_symbols(obj: &Object) -> Array; |
| 3559 | |
| 3560 | /// The `Object.getPrototypeOf()` method returns the prototype |
| 3561 | /// (i.e. the value of the internal [[Prototype]] property) of the |
| 3562 | /// specified object. |
| 3563 | /// |
| 3564 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getPrototypeOf) |
| 3565 | #[wasm_bindgen (static_method_of = Object, js_name = getPrototypeOf)] |
| 3566 | pub unsafefn get_prototype_of(obj: &JsValue) -> Object; |
| 3567 | |
| 3568 | /// The `hasOwnProperty()` method returns a boolean indicating whether the |
| 3569 | /// object has the specified property as its own property (as opposed to |
| 3570 | /// inheriting it). |
| 3571 | /// |
| 3572 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty) |
| 3573 | #[wasm_bindgen (method, js_name = hasOwnProperty)] |
| 3574 | pub unsafefn has_own_property(this: &Object, property: &JsValue) -> bool; |
| 3575 | |
| 3576 | /// The `Object.hasOwn()` method returns a boolean indicating whether the |
| 3577 | /// object passed in has the specified property as its own property (as |
| 3578 | /// opposed to inheriting it). |
| 3579 | /// |
| 3580 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn) |
| 3581 | #[wasm_bindgen (static_method_of = Object, js_name = hasOwn)] |
| 3582 | pub unsafefn has_own(instance: &Object, property: &JsValue) -> bool; |
| 3583 | |
| 3584 | /// The `Object.is()` method determines whether two values are the same value. |
| 3585 | /// |
| 3586 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is) |
| 3587 | #[wasm_bindgen (static_method_of = Object)] |
| 3588 | pub unsafefn is(value_1: &JsValue, value_2: &JsValue) -> bool; |
| 3589 | |
| 3590 | /// The `Object.isExtensible()` method determines if an object is extensible |
| 3591 | /// (whether it can have new properties added to it). |
| 3592 | /// |
| 3593 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isExtensible) |
| 3594 | #[wasm_bindgen (static_method_of = Object, js_name = isExtensible)] |
| 3595 | pub unsafefn is_extensible(object: &Object) -> bool; |
| 3596 | |
| 3597 | /// The `Object.isFrozen()` determines if an object is frozen. |
| 3598 | /// |
| 3599 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isFrozen) |
| 3600 | #[wasm_bindgen (static_method_of = Object, js_name = isFrozen)] |
| 3601 | pub unsafefn is_frozen(object: &Object) -> bool; |
| 3602 | |
| 3603 | /// The `Object.isSealed()` method determines if an object is sealed. |
| 3604 | /// |
| 3605 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isSealed) |
| 3606 | #[wasm_bindgen (static_method_of = Object, js_name = isSealed)] |
| 3607 | pub unsafefn is_sealed(object: &Object) -> bool; |
| 3608 | |
| 3609 | /// The `isPrototypeOf()` method checks if an object exists in another |
| 3610 | /// object's prototype chain. |
| 3611 | /// |
| 3612 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isPrototypeOf) |
| 3613 | #[wasm_bindgen (method, js_name = isPrototypeOf)] |
| 3614 | pub unsafefn is_prototype_of(this: &Object, value: &JsValue) -> bool; |
| 3615 | |
| 3616 | /// The `Object.keys()` method returns an array of a given object's property |
| 3617 | /// names, in the same order as we get with a normal loop. |
| 3618 | /// |
| 3619 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys) |
| 3620 | #[wasm_bindgen (static_method_of = Object)] |
| 3621 | pub unsafefn keys(object: &Object) -> Array; |
| 3622 | |
| 3623 | /// The [`Object`] constructor creates an object wrapper. |
| 3624 | /// |
| 3625 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) |
| 3626 | #[wasm_bindgen (constructor)] |
| 3627 | pub unsafefn new() -> Object; |
| 3628 | |
| 3629 | /// The `Object.preventExtensions()` method prevents new properties from |
| 3630 | /// ever being added to an object (i.e. prevents future extensions to the |
| 3631 | /// object). |
| 3632 | /// |
| 3633 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/preventExtensions) |
| 3634 | #[wasm_bindgen (static_method_of = Object, js_name = preventExtensions)] |
| 3635 | pub unsafefn prevent_extensions(object: &Object); |
| 3636 | |
| 3637 | /// The `propertyIsEnumerable()` method returns a Boolean indicating |
| 3638 | /// whether the specified property is enumerable. |
| 3639 | /// |
| 3640 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/propertyIsEnumerable) |
| 3641 | #[wasm_bindgen (method, js_name = propertyIsEnumerable)] |
| 3642 | pub unsafefn property_is_enumerable(this: &Object, property: &JsValue) -> bool; |
| 3643 | |
| 3644 | /// The `Object.seal()` method seals an object, preventing new properties |
| 3645 | /// from being added to it and marking all existing properties as |
| 3646 | /// non-configurable. Values of present properties can still be changed as |
| 3647 | /// long as they are writable. |
| 3648 | /// |
| 3649 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/seal) |
| 3650 | #[wasm_bindgen (static_method_of = Object)] |
| 3651 | pub unsafefn seal(value: &Object) -> Object; |
| 3652 | |
| 3653 | /// The `Object.setPrototypeOf()` method sets the prototype (i.e., the |
| 3654 | /// internal `[[Prototype]]` property) of a specified object to another |
| 3655 | /// object or `null`. |
| 3656 | /// |
| 3657 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/setPrototypeOf) |
| 3658 | #[wasm_bindgen (static_method_of = Object, js_name = setPrototypeOf)] |
| 3659 | pub unsafefn set_prototype_of(object: &Object, prototype: &Object) -> Object; |
| 3660 | |
| 3661 | /// The `toLocaleString()` method returns a string representing the object. |
| 3662 | /// This method is meant to be overridden by derived objects for |
| 3663 | /// locale-specific purposes. |
| 3664 | /// |
| 3665 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toLocaleString) |
| 3666 | #[wasm_bindgen (method, js_name = toLocaleString)] |
| 3667 | pub unsafefn to_locale_string(this: &Object) -> JsString; |
| 3668 | |
| 3669 | /// The `toString()` method returns a string representing the object. |
| 3670 | /// |
| 3671 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString) |
| 3672 | #[wasm_bindgen (method, js_name = toString)] |
| 3673 | pub unsafefn to_string(this: &Object) -> JsString; |
| 3674 | |
| 3675 | /// The `valueOf()` method returns the primitive value of the |
| 3676 | /// specified object. |
| 3677 | /// |
| 3678 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf) |
| 3679 | #[wasm_bindgen (method, js_name = valueOf)] |
| 3680 | pub unsafefn value_of(this: &Object) -> Object; |
| 3681 | |
| 3682 | /// The `Object.values()` method returns an array of a given object's own |
| 3683 | /// enumerable property values, in the same order as that provided by a |
| 3684 | /// `for...in` loop (the difference being that a for-in loop enumerates |
| 3685 | /// properties in the prototype chain as well). |
| 3686 | /// |
| 3687 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values) |
| 3688 | #[wasm_bindgen (static_method_of = Object)] |
| 3689 | pub unsafefn values(object: &Object) -> Array; |
| 3690 | } |
| 3691 | |
| 3692 | impl Object { |
| 3693 | /// Returns the `Object` value of this JS value if it's an instance of an |
| 3694 | /// object. |
| 3695 | /// |
| 3696 | /// If this JS value is not an instance of an object then this returns |
| 3697 | /// `None`. |
| 3698 | pub fn try_from(val: &JsValue) -> Option<&Object> { |
| 3699 | if val.is_object() { |
| 3700 | Some(val.unchecked_ref()) |
| 3701 | } else { |
| 3702 | None |
| 3703 | } |
| 3704 | } |
| 3705 | } |
| 3706 | |
| 3707 | impl PartialEq for Object { |
| 3708 | #[inline ] |
| 3709 | fn eq(&self, other: &Object) -> bool { |
| 3710 | Object::is(self.as_ref(), other.as_ref()) |
| 3711 | } |
| 3712 | } |
| 3713 | |
| 3714 | impl Eq for Object {} |
| 3715 | |
| 3716 | impl Default for Object { |
| 3717 | fn default() -> Self { |
| 3718 | Self::new() |
| 3719 | } |
| 3720 | } |
| 3721 | |
| 3722 | // Proxy |
| 3723 | #[wasm_bindgen ] |
| 3724 | unsafeextern "C" { |
| 3725 | #[wasm_bindgen (typescript_type = "ProxyConstructor" )] |
| 3726 | #[derive (Clone, Debug)] |
| 3727 | pub type Proxy; |
| 3728 | |
| 3729 | /// The [`Proxy`] object is used to define custom behavior for fundamental |
| 3730 | /// operations (e.g. property lookup, assignment, enumeration, function |
| 3731 | /// invocation, etc). |
| 3732 | /// |
| 3733 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy) |
| 3734 | #[wasm_bindgen (constructor)] |
| 3735 | pub unsafefn new(target: &JsValue, handler: &Object) -> Proxy; |
| 3736 | |
| 3737 | /// The `Proxy.revocable()` method is used to create a revocable [`Proxy`] |
| 3738 | /// object. |
| 3739 | /// |
| 3740 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy/revocable) |
| 3741 | #[wasm_bindgen (static_method_of = Proxy)] |
| 3742 | pub unsafefn revocable(target: &JsValue, handler: &Object) -> Object; |
| 3743 | } |
| 3744 | |
| 3745 | // RangeError |
| 3746 | #[wasm_bindgen ] |
| 3747 | unsafeextern "C" { |
| 3748 | /// The `RangeError` object indicates an error when a value is not in the set |
| 3749 | /// or range of allowed values. |
| 3750 | /// |
| 3751 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError) |
| 3752 | #[wasm_bindgen (extends = Error, extends = Object, typescript_type = "RangeError" )] |
| 3753 | #[derive (Clone, Debug, PartialEq, Eq)] |
| 3754 | pub type RangeError; |
| 3755 | |
| 3756 | /// The `RangeError` object indicates an error when a value is not in the set |
| 3757 | /// or range of allowed values. |
| 3758 | /// |
| 3759 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError) |
| 3760 | #[wasm_bindgen (constructor)] |
| 3761 | pub unsafefn new(message: &str) -> RangeError; |
| 3762 | } |
| 3763 | |
| 3764 | // ReferenceError |
| 3765 | #[wasm_bindgen ] |
| 3766 | unsafeextern "C" { |
| 3767 | /// The `ReferenceError` object represents an error when a non-existent |
| 3768 | /// variable is referenced. |
| 3769 | /// |
| 3770 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError) |
| 3771 | #[wasm_bindgen (extends = Error, extends = Object, typescript_type = "ReferenceError" )] |
| 3772 | #[derive (Clone, Debug, PartialEq, Eq)] |
| 3773 | pub type ReferenceError; |
| 3774 | |
| 3775 | /// The `ReferenceError` object represents an error when a non-existent |
| 3776 | /// variable is referenced. |
| 3777 | /// |
| 3778 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError) |
| 3779 | #[wasm_bindgen (constructor)] |
| 3780 | pub unsafefn new(message: &str) -> ReferenceError; |
| 3781 | } |
| 3782 | |
| 3783 | #[allow (non_snake_case)] |
| 3784 | pub mod Reflect { |
| 3785 | use super::*; |
| 3786 | |
| 3787 | // Reflect |
| 3788 | #[wasm_bindgen ] |
| 3789 | extern "C" { |
| 3790 | /// The static `Reflect.apply()` method calls a target function with |
| 3791 | /// arguments as specified. |
| 3792 | /// |
| 3793 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/apply) |
| 3794 | #[wasm_bindgen (js_namespace = Reflect, catch)] |
| 3795 | pub fn apply( |
| 3796 | target: &Function, |
| 3797 | this_argument: &JsValue, |
| 3798 | arguments_list: &Array, |
| 3799 | ) -> Result<JsValue, JsValue>; |
| 3800 | |
| 3801 | /// The static `Reflect.construct()` method acts like the new operator, but |
| 3802 | /// as a function. It is equivalent to calling `new target(...args)`. It |
| 3803 | /// gives also the added option to specify a different prototype. |
| 3804 | /// |
| 3805 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/construct) |
| 3806 | #[wasm_bindgen (js_namespace = Reflect, catch)] |
| 3807 | pub fn construct(target: &Function, arguments_list: &Array) -> Result<JsValue, JsValue>; |
| 3808 | |
| 3809 | /// The static `Reflect.construct()` method acts like the new operator, but |
| 3810 | /// as a function. It is equivalent to calling `new target(...args)`. It |
| 3811 | /// gives also the added option to specify a different prototype. |
| 3812 | /// |
| 3813 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/construct) |
| 3814 | #[wasm_bindgen (js_namespace = Reflect, js_name = construct, catch)] |
| 3815 | pub fn construct_with_new_target( |
| 3816 | target: &Function, |
| 3817 | arguments_list: &Array, |
| 3818 | new_target: &Function, |
| 3819 | ) -> Result<JsValue, JsValue>; |
| 3820 | |
| 3821 | /// The static `Reflect.defineProperty()` method is like |
| 3822 | /// `Object.defineProperty()` but returns a `Boolean`. |
| 3823 | /// |
| 3824 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/defineProperty) |
| 3825 | #[wasm_bindgen (js_namespace = Reflect, js_name = defineProperty, catch)] |
| 3826 | pub fn define_property( |
| 3827 | target: &Object, |
| 3828 | property_key: &JsValue, |
| 3829 | attributes: &Object, |
| 3830 | ) -> Result<bool, JsValue>; |
| 3831 | |
| 3832 | /// The static `Reflect.deleteProperty()` method allows to delete |
| 3833 | /// properties. It is like the `delete` operator as a function. |
| 3834 | /// |
| 3835 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/deleteProperty) |
| 3836 | #[wasm_bindgen (js_namespace = Reflect, js_name = deleteProperty, catch)] |
| 3837 | pub fn delete_property(target: &Object, key: &JsValue) -> Result<bool, JsValue>; |
| 3838 | |
| 3839 | /// The static `Reflect.get()` method works like getting a property from |
| 3840 | /// an object (`target[propertyKey]`) as a function. |
| 3841 | /// |
| 3842 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/get) |
| 3843 | #[wasm_bindgen (js_namespace = Reflect, catch)] |
| 3844 | pub fn get(target: &JsValue, key: &JsValue) -> Result<JsValue, JsValue>; |
| 3845 | |
| 3846 | /// The same as [`get`](fn.get.html) |
| 3847 | /// except the key is an `f64`, which is slightly faster. |
| 3848 | #[wasm_bindgen (js_namespace = Reflect, js_name = "get" , catch)] |
| 3849 | pub fn get_f64(target: &JsValue, key: f64) -> Result<JsValue, JsValue>; |
| 3850 | |
| 3851 | /// The same as [`get`](fn.get.html) |
| 3852 | /// except the key is a `u32`, which is slightly faster. |
| 3853 | #[wasm_bindgen (js_namespace = Reflect, js_name = "get" , catch)] |
| 3854 | pub fn get_u32(target: &JsValue, key: u32) -> Result<JsValue, JsValue>; |
| 3855 | |
| 3856 | /// The static `Reflect.getOwnPropertyDescriptor()` method is similar to |
| 3857 | /// `Object.getOwnPropertyDescriptor()`. It returns a property descriptor |
| 3858 | /// of the given property if it exists on the object, `undefined` otherwise. |
| 3859 | /// |
| 3860 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getOwnPropertyDescriptor) |
| 3861 | #[wasm_bindgen (js_namespace = Reflect, js_name = getOwnPropertyDescriptor, catch)] |
| 3862 | pub fn get_own_property_descriptor( |
| 3863 | target: &Object, |
| 3864 | property_key: &JsValue, |
| 3865 | ) -> Result<JsValue, JsValue>; |
| 3866 | |
| 3867 | /// The static `Reflect.getPrototypeOf()` method is almost the same |
| 3868 | /// method as `Object.getPrototypeOf()`. It returns the prototype |
| 3869 | /// (i.e. the value of the internal `[[Prototype]]` property) of |
| 3870 | /// the specified object. |
| 3871 | /// |
| 3872 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getPrototypeOf) |
| 3873 | #[wasm_bindgen (js_namespace = Reflect, js_name = getPrototypeOf, catch)] |
| 3874 | pub fn get_prototype_of(target: &JsValue) -> Result<Object, JsValue>; |
| 3875 | |
| 3876 | /// The static `Reflect.has()` method works like the in operator as a |
| 3877 | /// function. |
| 3878 | /// |
| 3879 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/has) |
| 3880 | #[wasm_bindgen (js_namespace = Reflect, catch)] |
| 3881 | pub fn has(target: &JsValue, property_key: &JsValue) -> Result<bool, JsValue>; |
| 3882 | |
| 3883 | /// The static `Reflect.isExtensible()` method determines if an object is |
| 3884 | /// extensible (whether it can have new properties added to it). It is |
| 3885 | /// similar to `Object.isExtensible()`, but with some differences. |
| 3886 | /// |
| 3887 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/isExtensible) |
| 3888 | #[wasm_bindgen (js_namespace = Reflect, js_name = isExtensible, catch)] |
| 3889 | pub fn is_extensible(target: &Object) -> Result<bool, JsValue>; |
| 3890 | |
| 3891 | /// The static `Reflect.ownKeys()` method returns an array of the |
| 3892 | /// target object's own property keys. |
| 3893 | /// |
| 3894 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/ownKeys) |
| 3895 | #[wasm_bindgen (js_namespace = Reflect, js_name = ownKeys, catch)] |
| 3896 | pub fn own_keys(target: &JsValue) -> Result<Array, JsValue>; |
| 3897 | |
| 3898 | /// The static `Reflect.preventExtensions()` method prevents new |
| 3899 | /// properties from ever being added to an object (i.e. prevents |
| 3900 | /// future extensions to the object). It is similar to |
| 3901 | /// `Object.preventExtensions()`, but with some differences. |
| 3902 | /// |
| 3903 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/preventExtensions) |
| 3904 | #[wasm_bindgen (js_namespace = Reflect, js_name = preventExtensions, catch)] |
| 3905 | pub fn prevent_extensions(target: &Object) -> Result<bool, JsValue>; |
| 3906 | |
| 3907 | /// The static `Reflect.set()` method works like setting a |
| 3908 | /// property on an object. |
| 3909 | /// |
| 3910 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set) |
| 3911 | #[wasm_bindgen (js_namespace = Reflect, catch)] |
| 3912 | pub fn set( |
| 3913 | target: &JsValue, |
| 3914 | property_key: &JsValue, |
| 3915 | value: &JsValue, |
| 3916 | ) -> Result<bool, JsValue>; |
| 3917 | |
| 3918 | /// The same as [`set`](fn.set.html) |
| 3919 | /// except the key is an `f64`, which is slightly faster. |
| 3920 | #[wasm_bindgen (js_namespace = Reflect, js_name = "set" , catch)] |
| 3921 | pub fn set_f64( |
| 3922 | target: &JsValue, |
| 3923 | property_key: f64, |
| 3924 | value: &JsValue, |
| 3925 | ) -> Result<bool, JsValue>; |
| 3926 | |
| 3927 | /// The same as [`set`](fn.set.html) |
| 3928 | /// except the key is a `u32`, which is slightly faster. |
| 3929 | #[wasm_bindgen (js_namespace = Reflect, js_name = "set" , catch)] |
| 3930 | pub fn set_u32( |
| 3931 | target: &JsValue, |
| 3932 | property_key: u32, |
| 3933 | value: &JsValue, |
| 3934 | ) -> Result<bool, JsValue>; |
| 3935 | |
| 3936 | /// The static `Reflect.set()` method works like setting a |
| 3937 | /// property on an object. |
| 3938 | /// |
| 3939 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set) |
| 3940 | #[wasm_bindgen (js_namespace = Reflect, js_name = set, catch)] |
| 3941 | pub fn set_with_receiver( |
| 3942 | target: &JsValue, |
| 3943 | property_key: &JsValue, |
| 3944 | value: &JsValue, |
| 3945 | receiver: &JsValue, |
| 3946 | ) -> Result<bool, JsValue>; |
| 3947 | |
| 3948 | /// The static `Reflect.setPrototypeOf()` method is the same |
| 3949 | /// method as `Object.setPrototypeOf()`. It sets the prototype |
| 3950 | /// (i.e., the internal `[[Prototype]]` property) of a specified |
| 3951 | /// object to another object or to null. |
| 3952 | /// |
| 3953 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/setPrototypeOf) |
| 3954 | #[wasm_bindgen (js_namespace = Reflect, js_name = setPrototypeOf, catch)] |
| 3955 | pub fn set_prototype_of(target: &Object, prototype: &JsValue) -> Result<bool, JsValue>; |
| 3956 | } |
| 3957 | } |
| 3958 | |
| 3959 | // RegExp |
| 3960 | #[wasm_bindgen ] |
| 3961 | unsafeextern "C" { |
| 3962 | #[wasm_bindgen (extends = Object, typescript_type = "RegExp" )] |
| 3963 | #[derive (Clone, Debug, PartialEq, Eq)] |
| 3964 | pub type RegExp; |
| 3965 | |
| 3966 | /// The `exec()` method executes a search for a match in a specified |
| 3967 | /// string. Returns a result array, or null. |
| 3968 | /// |
| 3969 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec) |
| 3970 | #[wasm_bindgen (method)] |
| 3971 | pub unsafefn exec(this: &RegExp, text: &str) -> Option<Array>; |
| 3972 | |
| 3973 | /// The flags property returns a string consisting of the flags of |
| 3974 | /// the current regular expression object. |
| 3975 | /// |
| 3976 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/flags) |
| 3977 | #[wasm_bindgen (method, getter)] |
| 3978 | pub unsafefn flags(this: &RegExp) -> JsString; |
| 3979 | |
| 3980 | /// The global property indicates whether or not the "g" flag is |
| 3981 | /// used with the regular expression. global is a read-only |
| 3982 | /// property of an individual regular expression instance. |
| 3983 | /// |
| 3984 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/global) |
| 3985 | #[wasm_bindgen (method, getter)] |
| 3986 | pub unsafefn global(this: &RegExp) -> bool; |
| 3987 | |
| 3988 | /// The ignoreCase property indicates whether or not the "i" flag |
| 3989 | /// is used with the regular expression. ignoreCase is a read-only |
| 3990 | /// property of an individual regular expression instance. |
| 3991 | /// |
| 3992 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/ignoreCase) |
| 3993 | #[wasm_bindgen (method, getter, js_name = ignoreCase)] |
| 3994 | pub unsafefn ignore_case(this: &RegExp) -> bool; |
| 3995 | |
| 3996 | /// The non-standard input property is a static property of |
| 3997 | /// regular expressions that contains the string against which a |
| 3998 | /// regular expression is matched. RegExp.$_ is an alias for this |
| 3999 | /// property. |
| 4000 | /// |
| 4001 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/input) |
| 4002 | #[wasm_bindgen (static_method_of = RegExp, getter)] |
| 4003 | pub unsafefn input() -> JsString; |
| 4004 | |
| 4005 | /// The lastIndex is a read/write integer property of regular expression |
| 4006 | /// instances that specifies the index at which to start the next match. |
| 4007 | /// |
| 4008 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex) |
| 4009 | #[wasm_bindgen (structural, getter = lastIndex, method)] |
| 4010 | pub unsafefn last_index(this: &RegExp) -> u32; |
| 4011 | |
| 4012 | /// The lastIndex is a read/write integer property of regular expression |
| 4013 | /// instances that specifies the index at which to start the next match. |
| 4014 | /// |
| 4015 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex) |
| 4016 | #[wasm_bindgen (structural, setter = lastIndex, method)] |
| 4017 | pub unsafefn set_last_index(this: &RegExp, index: u32); |
| 4018 | |
| 4019 | /// The non-standard lastMatch property is a static and read-only |
| 4020 | /// property of regular expressions that contains the last matched |
| 4021 | /// characters. `RegExp.$&` is an alias for this property. |
| 4022 | /// |
| 4023 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastMatch) |
| 4024 | #[wasm_bindgen (static_method_of = RegExp, getter, js_name = lastMatch)] |
| 4025 | pub unsafefn last_match() -> JsString; |
| 4026 | |
| 4027 | /// The non-standard lastParen property is a static and read-only |
| 4028 | /// property of regular expressions that contains the last |
| 4029 | /// parenthesized substring match, if any. `RegExp.$+` is an alias |
| 4030 | /// for this property. |
| 4031 | /// |
| 4032 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastParen) |
| 4033 | #[wasm_bindgen (static_method_of = RegExp, getter, js_name = lastParen)] |
| 4034 | pub unsafefn last_paren() -> JsString; |
| 4035 | |
| 4036 | /// The non-standard leftContext property is a static and |
| 4037 | /// read-only property of regular expressions that contains the |
| 4038 | /// substring preceding the most recent match. `RegExp.$`` is an |
| 4039 | /// alias for this property. |
| 4040 | /// |
| 4041 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/leftContext) |
| 4042 | #[wasm_bindgen (static_method_of = RegExp, getter, js_name = leftContext)] |
| 4043 | pub unsafefn left_context() -> JsString; |
| 4044 | |
| 4045 | /// The multiline property indicates whether or not the "m" flag |
| 4046 | /// is used with the regular expression. multiline is a read-only |
| 4047 | /// property of an individual regular expression instance. |
| 4048 | /// |
| 4049 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/multiline) |
| 4050 | #[wasm_bindgen (method, getter)] |
| 4051 | pub unsafefn multiline(this: &RegExp) -> bool; |
| 4052 | |
| 4053 | /// The non-standard $1, $2, $3, $4, $5, $6, $7, $8, $9 properties |
| 4054 | /// are static and read-only properties of regular expressions |
| 4055 | /// that contain parenthesized substring matches. |
| 4056 | /// |
| 4057 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/n) |
| 4058 | #[wasm_bindgen (static_method_of = RegExp, getter, js_name = "$1" )] |
| 4059 | pub unsafefn n1() -> JsString; |
| 4060 | #[wasm_bindgen (static_method_of = RegExp, getter, js_name = "$2" )] |
| 4061 | pub unsafefn n2() -> JsString; |
| 4062 | #[wasm_bindgen (static_method_of = RegExp, getter, js_name = "$3" )] |
| 4063 | pub unsafefn n3() -> JsString; |
| 4064 | #[wasm_bindgen (static_method_of = RegExp, getter, js_name = "$4" )] |
| 4065 | pub unsafefn n4() -> JsString; |
| 4066 | #[wasm_bindgen (static_method_of = RegExp, getter, js_name = "$5" )] |
| 4067 | pub unsafefn n5() -> JsString; |
| 4068 | #[wasm_bindgen (static_method_of = RegExp, getter, js_name = "$6" )] |
| 4069 | pub unsafefn n6() -> JsString; |
| 4070 | #[wasm_bindgen (static_method_of = RegExp, getter, js_name = "$7" )] |
| 4071 | pub unsafefn n7() -> JsString; |
| 4072 | #[wasm_bindgen (static_method_of = RegExp, getter, js_name = "$8" )] |
| 4073 | pub unsafefn n8() -> JsString; |
| 4074 | #[wasm_bindgen (static_method_of = RegExp, getter, js_name = "$9" )] |
| 4075 | pub unsafefn n9() -> JsString; |
| 4076 | |
| 4077 | /// The `RegExp` constructor creates a regular expression object for matching text with a pattern. |
| 4078 | /// |
| 4079 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp) |
| 4080 | #[wasm_bindgen (constructor)] |
| 4081 | pub unsafefn new(pattern: &str, flags: &str) -> RegExp; |
| 4082 | #[wasm_bindgen (constructor)] |
| 4083 | pub unsafefn new_regexp(pattern: &RegExp, flags: &str) -> RegExp; |
| 4084 | |
| 4085 | /// The non-standard rightContext property is a static and |
| 4086 | /// read-only property of regular expressions that contains the |
| 4087 | /// substring following the most recent match. `RegExp.$'` is an |
| 4088 | /// alias for this property. |
| 4089 | /// |
| 4090 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/rightContext) |
| 4091 | #[wasm_bindgen (static_method_of = RegExp, getter, js_name = rightContext)] |
| 4092 | pub unsafefn right_context() -> JsString; |
| 4093 | |
| 4094 | /// The source property returns a String containing the source |
| 4095 | /// text of the regexp object, and it doesn't contain the two |
| 4096 | /// forward slashes on both sides and any flags. |
| 4097 | /// |
| 4098 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/source) |
| 4099 | #[wasm_bindgen (method, getter)] |
| 4100 | pub unsafefn source(this: &RegExp) -> JsString; |
| 4101 | |
| 4102 | /// The sticky property reflects whether or not the search is |
| 4103 | /// sticky (searches in strings only from the index indicated by |
| 4104 | /// the lastIndex property of this regular expression). sticky is |
| 4105 | /// a read-only property of an individual regular expression |
| 4106 | /// object. |
| 4107 | /// |
| 4108 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/sticky) |
| 4109 | #[wasm_bindgen (method, getter)] |
| 4110 | pub unsafefn sticky(this: &RegExp) -> bool; |
| 4111 | |
| 4112 | /// The `test()` method executes a search for a match between a |
| 4113 | /// regular expression and a specified string. Returns true or |
| 4114 | /// false. |
| 4115 | /// |
| 4116 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/test) |
| 4117 | #[wasm_bindgen (method)] |
| 4118 | pub unsafefn test(this: &RegExp, text: &str) -> bool; |
| 4119 | |
| 4120 | /// The `toString()` method returns a string representing the |
| 4121 | /// regular expression. |
| 4122 | /// |
| 4123 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/toString) |
| 4124 | #[wasm_bindgen (method, js_name = toString)] |
| 4125 | pub unsafefn to_string(this: &RegExp) -> JsString; |
| 4126 | |
| 4127 | /// The unicode property indicates whether or not the "u" flag is |
| 4128 | /// used with a regular expression. unicode is a read-only |
| 4129 | /// property of an individual regular expression instance. |
| 4130 | /// |
| 4131 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/unicode) |
| 4132 | #[wasm_bindgen (method, getter)] |
| 4133 | pub unsafefn unicode(this: &RegExp) -> bool; |
| 4134 | } |
| 4135 | |
| 4136 | // Set |
| 4137 | #[wasm_bindgen ] |
| 4138 | unsafeextern "C" { |
| 4139 | #[wasm_bindgen (extends = Object, typescript_type = "Set<any>" )] |
| 4140 | #[derive (Clone, Debug, PartialEq, Eq)] |
| 4141 | pub type Set; |
| 4142 | |
| 4143 | /// The `add()` method appends a new element with a specified value to the |
| 4144 | /// end of a [`Set`] object. |
| 4145 | /// |
| 4146 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/add) |
| 4147 | #[wasm_bindgen (method)] |
| 4148 | pub unsafefn add(this: &Set, value: &JsValue) -> Set; |
| 4149 | |
| 4150 | /// The `clear()` method removes all elements from a [`Set`] object. |
| 4151 | /// |
| 4152 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/clear) |
| 4153 | #[wasm_bindgen (method)] |
| 4154 | pub unsafefn clear(this: &Set); |
| 4155 | |
| 4156 | /// The `delete()` method removes the specified element from a [`Set`] |
| 4157 | /// object. |
| 4158 | /// |
| 4159 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/delete) |
| 4160 | #[wasm_bindgen (method)] |
| 4161 | pub unsafefn delete(this: &Set, value: &JsValue) -> bool; |
| 4162 | |
| 4163 | /// The `forEach()` method executes a provided function once for each value |
| 4164 | /// in the Set object, in insertion order. |
| 4165 | /// |
| 4166 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/forEach) |
| 4167 | #[wasm_bindgen (method, js_name = forEach)] |
| 4168 | pub unsafefn for_each(this: &Set, callback: &mut dyn FnMut(JsValue, JsValue, Set)); |
| 4169 | |
| 4170 | /// The `has()` method returns a boolean indicating whether an element with |
| 4171 | /// the specified value exists in a [`Set`] object or not. |
| 4172 | /// |
| 4173 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/has) |
| 4174 | #[wasm_bindgen (method)] |
| 4175 | pub unsafefn has(this: &Set, value: &JsValue) -> bool; |
| 4176 | |
| 4177 | /// The [`Set`] object lets you store unique values of any type, whether |
| 4178 | /// primitive values or object references. |
| 4179 | /// |
| 4180 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set) |
| 4181 | #[wasm_bindgen (constructor)] |
| 4182 | pub unsafefn new(init: &JsValue) -> Set; |
| 4183 | |
| 4184 | /// The size accessor property returns the number of elements in a [`Set`] |
| 4185 | /// object. |
| 4186 | /// |
| 4187 | /// [MDN documentation](https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Set/size) |
| 4188 | #[wasm_bindgen (method, getter, structural)] |
| 4189 | pub unsafefn size(this: &Set) -> u32; |
| 4190 | } |
| 4191 | |
| 4192 | impl Default for Set { |
| 4193 | fn default() -> Self { |
| 4194 | Self::new(&JsValue::UNDEFINED) |
| 4195 | } |
| 4196 | } |
| 4197 | |
| 4198 | // SetIterator |
| 4199 | #[wasm_bindgen ] |
| 4200 | unsafeextern "C" { |
| 4201 | /// The `entries()` method returns a new Iterator object that contains an |
| 4202 | /// array of [value, value] for each element in the Set object, in insertion |
| 4203 | /// order. For Set objects there is no key like in Map objects. However, to |
| 4204 | /// keep the API similar to the Map object, each entry has the same value |
| 4205 | /// for its key and value here, so that an array [value, value] is returned. |
| 4206 | /// |
| 4207 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/entries) |
| 4208 | #[wasm_bindgen (method)] |
| 4209 | pub unsafefn entries(set: &Set) -> Iterator; |
| 4210 | |
| 4211 | /// The `keys()` method is an alias for this method (for similarity with |
| 4212 | /// Map objects); it behaves exactly the same and returns values |
| 4213 | /// of Set elements. |
| 4214 | /// |
| 4215 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/values) |
| 4216 | #[wasm_bindgen (method)] |
| 4217 | pub unsafefn keys(set: &Set) -> Iterator; |
| 4218 | |
| 4219 | /// The `values()` method returns a new Iterator object that contains the |
| 4220 | /// values for each element in the Set object in insertion order. |
| 4221 | /// |
| 4222 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/values) |
| 4223 | #[wasm_bindgen (method)] |
| 4224 | pub unsafefn values(set: &Set) -> Iterator; |
| 4225 | } |
| 4226 | |
| 4227 | // SyntaxError |
| 4228 | #[wasm_bindgen ] |
| 4229 | unsafeextern "C" { |
| 4230 | /// A `SyntaxError` is thrown when the JavaScript engine encounters tokens or |
| 4231 | /// token order that does not conform to the syntax of the language when |
| 4232 | /// parsing code. |
| 4233 | /// |
| 4234 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError) |
| 4235 | #[wasm_bindgen (extends = Error, extends = Object, typescript_type = "SyntaxError" )] |
| 4236 | #[derive (Clone, Debug, PartialEq, Eq)] |
| 4237 | pub type SyntaxError; |
| 4238 | |
| 4239 | /// A `SyntaxError` is thrown when the JavaScript engine encounters tokens or |
| 4240 | /// token order that does not conform to the syntax of the language when |
| 4241 | /// parsing code. |
| 4242 | /// |
| 4243 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError) |
| 4244 | #[wasm_bindgen (constructor)] |
| 4245 | pub unsafefn new(message: &str) -> SyntaxError; |
| 4246 | } |
| 4247 | |
| 4248 | // TypeError |
| 4249 | #[wasm_bindgen ] |
| 4250 | unsafeextern "C" { |
| 4251 | /// The `TypeError` object represents an error when a value is not of the |
| 4252 | /// expected type. |
| 4253 | /// |
| 4254 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError) |
| 4255 | #[wasm_bindgen (extends = Error, extends = Object, typescript_type = "TypeError" )] |
| 4256 | #[derive (Clone, Debug, PartialEq, Eq)] |
| 4257 | pub type TypeError; |
| 4258 | |
| 4259 | /// The `TypeError` object represents an error when a value is not of the |
| 4260 | /// expected type. |
| 4261 | /// |
| 4262 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError) |
| 4263 | #[wasm_bindgen (constructor)] |
| 4264 | pub unsafefn new(message: &str) -> TypeError; |
| 4265 | } |
| 4266 | |
| 4267 | // URIError |
| 4268 | #[wasm_bindgen ] |
| 4269 | unsafeextern "C" { |
| 4270 | /// The `URIError` object represents an error when a global URI handling |
| 4271 | /// function was used in a wrong way. |
| 4272 | /// |
| 4273 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError) |
| 4274 | #[wasm_bindgen (extends = Error, extends = Object, js_name = URIError, typescript_type = "URIError" )] |
| 4275 | #[derive (Clone, Debug, PartialEq, Eq)] |
| 4276 | pub type UriError; |
| 4277 | |
| 4278 | /// The `URIError` object represents an error when a global URI handling |
| 4279 | /// function was used in a wrong way. |
| 4280 | /// |
| 4281 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError) |
| 4282 | #[wasm_bindgen (constructor, js_class = "URIError" )] |
| 4283 | pub unsafefn new(message: &str) -> UriError; |
| 4284 | } |
| 4285 | |
| 4286 | // WeakMap |
| 4287 | #[wasm_bindgen ] |
| 4288 | unsafeextern "C" { |
| 4289 | #[wasm_bindgen (extends = Object, typescript_type = "WeakMap<object, any>" )] |
| 4290 | #[derive (Clone, Debug, PartialEq, Eq)] |
| 4291 | pub type WeakMap; |
| 4292 | |
| 4293 | /// The [`WeakMap`] object is a collection of key/value pairs in which the |
| 4294 | /// keys are weakly referenced. The keys must be objects and the values can |
| 4295 | /// be arbitrary values. |
| 4296 | /// |
| 4297 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap) |
| 4298 | #[wasm_bindgen (constructor)] |
| 4299 | pub unsafefn new() -> WeakMap; |
| 4300 | |
| 4301 | /// The `set()` method sets the value for the key in the [`WeakMap`] object. |
| 4302 | /// Returns the [`WeakMap`] object. |
| 4303 | /// |
| 4304 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/set) |
| 4305 | #[wasm_bindgen (method, js_class = "WeakMap" )] |
| 4306 | pub unsafefn set(this: &WeakMap, key: &Object, value: &JsValue) -> WeakMap; |
| 4307 | |
| 4308 | /// The `get()` method returns a specified by key element |
| 4309 | /// from a [`WeakMap`] object. |
| 4310 | /// |
| 4311 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/get) |
| 4312 | #[wasm_bindgen (method)] |
| 4313 | pub unsafefn get(this: &WeakMap, key: &Object) -> JsValue; |
| 4314 | |
| 4315 | /// The `has()` method returns a boolean indicating whether an element with |
| 4316 | /// the specified key exists in the [`WeakMap`] object or not. |
| 4317 | /// |
| 4318 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/has) |
| 4319 | #[wasm_bindgen (method)] |
| 4320 | pub unsafefn has(this: &WeakMap, key: &Object) -> bool; |
| 4321 | |
| 4322 | /// The `delete()` method removes the specified element from a [`WeakMap`] |
| 4323 | /// object. |
| 4324 | /// |
| 4325 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/delete) |
| 4326 | #[wasm_bindgen (method)] |
| 4327 | pub unsafefn delete(this: &WeakMap, key: &Object) -> bool; |
| 4328 | } |
| 4329 | |
| 4330 | impl Default for WeakMap { |
| 4331 | fn default() -> Self { |
| 4332 | Self::new() |
| 4333 | } |
| 4334 | } |
| 4335 | |
| 4336 | // WeakSet |
| 4337 | #[wasm_bindgen ] |
| 4338 | unsafeextern "C" { |
| 4339 | #[wasm_bindgen (extends = Object, typescript_type = "WeakSet<object>" )] |
| 4340 | #[derive (Clone, Debug, PartialEq, Eq)] |
| 4341 | pub type WeakSet; |
| 4342 | |
| 4343 | /// The `WeakSet` object lets you store weakly held objects in a collection. |
| 4344 | /// |
| 4345 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet) |
| 4346 | #[wasm_bindgen (constructor)] |
| 4347 | pub unsafefn new() -> WeakSet; |
| 4348 | |
| 4349 | /// The `has()` method returns a boolean indicating whether an object exists |
| 4350 | /// in a WeakSet or not. |
| 4351 | /// |
| 4352 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet/has) |
| 4353 | #[wasm_bindgen (method)] |
| 4354 | pub unsafefn has(this: &WeakSet, value: &Object) -> bool; |
| 4355 | |
| 4356 | /// The `add()` method appends a new object to the end of a WeakSet object. |
| 4357 | /// |
| 4358 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet/add) |
| 4359 | #[wasm_bindgen (method)] |
| 4360 | pub unsafefn add(this: &WeakSet, value: &Object) -> WeakSet; |
| 4361 | |
| 4362 | /// The `delete()` method removes the specified element from a WeakSet |
| 4363 | /// object. |
| 4364 | /// |
| 4365 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet/delete) |
| 4366 | #[wasm_bindgen (method)] |
| 4367 | pub unsafefn delete(this: &WeakSet, value: &Object) -> bool; |
| 4368 | } |
| 4369 | |
| 4370 | impl Default for WeakSet { |
| 4371 | fn default() -> Self { |
| 4372 | Self::new() |
| 4373 | } |
| 4374 | } |
| 4375 | |
| 4376 | #[cfg (js_sys_unstable_apis)] |
| 4377 | #[allow (non_snake_case)] |
| 4378 | pub mod Temporal; |
| 4379 | |
| 4380 | #[allow (non_snake_case)] |
| 4381 | pub mod WebAssembly { |
| 4382 | use super::*; |
| 4383 | |
| 4384 | // WebAssembly |
| 4385 | #[wasm_bindgen ] |
| 4386 | extern "C" { |
| 4387 | /// The `WebAssembly.compile()` function compiles a `WebAssembly.Module` |
| 4388 | /// from WebAssembly binary code. This function is useful if it is |
| 4389 | /// necessary to a compile a module before it can be instantiated |
| 4390 | /// (otherwise, the `WebAssembly.instantiate()` function should be used). |
| 4391 | /// |
| 4392 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compile) |
| 4393 | #[wasm_bindgen (js_namespace = WebAssembly)] |
| 4394 | pub fn compile(buffer_source: &JsValue) -> Promise; |
| 4395 | |
| 4396 | /// The `WebAssembly.compileStreaming()` function compiles a |
| 4397 | /// `WebAssembly.Module` module directly from a streamed underlying |
| 4398 | /// source. This function is useful if it is necessary to a compile a |
| 4399 | /// module before it can be instantiated (otherwise, the |
| 4400 | /// `WebAssembly.instantiateStreaming()` function should be used). |
| 4401 | /// |
| 4402 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compileStreaming) |
| 4403 | #[wasm_bindgen (js_namespace = WebAssembly, js_name = compileStreaming)] |
| 4404 | pub fn compile_streaming(response: &Promise) -> Promise; |
| 4405 | |
| 4406 | /// The `WebAssembly.instantiate()` function allows you to compile and |
| 4407 | /// instantiate WebAssembly code. |
| 4408 | /// |
| 4409 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate) |
| 4410 | #[wasm_bindgen (js_namespace = WebAssembly, js_name = instantiate)] |
| 4411 | pub fn instantiate_buffer(buffer: &[u8], imports: &Object) -> Promise; |
| 4412 | |
| 4413 | /// The `WebAssembly.instantiate()` function allows you to compile and |
| 4414 | /// instantiate WebAssembly code. |
| 4415 | /// |
| 4416 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate) |
| 4417 | #[wasm_bindgen (js_namespace = WebAssembly, js_name = instantiate)] |
| 4418 | pub fn instantiate_module(module: &Module, imports: &Object) -> Promise; |
| 4419 | |
| 4420 | /// The `WebAssembly.instantiateStreaming()` function compiles and |
| 4421 | /// instantiates a WebAssembly module directly from a streamed |
| 4422 | /// underlying source. This is the most efficient, optimized way to load |
| 4423 | /// Wasm code. |
| 4424 | /// |
| 4425 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiateStreaming) |
| 4426 | #[wasm_bindgen (js_namespace = WebAssembly, js_name = instantiateStreaming)] |
| 4427 | pub fn instantiate_streaming(response: &Promise, imports: &Object) -> Promise; |
| 4428 | |
| 4429 | /// The `WebAssembly.validate()` function validates a given typed |
| 4430 | /// array of WebAssembly binary code, returning whether the bytes |
| 4431 | /// form a valid Wasm module (`true`) or not (`false`). |
| 4432 | /// |
| 4433 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/validate) |
| 4434 | #[wasm_bindgen (js_namespace = WebAssembly, catch)] |
| 4435 | pub fn validate(buffer_source: &JsValue) -> Result<bool, JsValue>; |
| 4436 | } |
| 4437 | |
| 4438 | // WebAssembly.CompileError |
| 4439 | #[wasm_bindgen ] |
| 4440 | extern "C" { |
| 4441 | /// The `WebAssembly.CompileError()` constructor creates a new |
| 4442 | /// WebAssembly `CompileError` object, which indicates an error during |
| 4443 | /// WebAssembly decoding or validation. |
| 4444 | /// |
| 4445 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/CompileError) |
| 4446 | #[wasm_bindgen (extends = Error, js_namespace = WebAssembly, typescript_type = "WebAssembly.CompileError" )] |
| 4447 | #[derive (Clone, Debug, PartialEq, Eq)] |
| 4448 | pub type CompileError; |
| 4449 | |
| 4450 | /// The `WebAssembly.CompileError()` constructor creates a new |
| 4451 | /// WebAssembly `CompileError` object, which indicates an error during |
| 4452 | /// WebAssembly decoding or validation. |
| 4453 | /// |
| 4454 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/CompileError) |
| 4455 | #[wasm_bindgen (constructor, js_namespace = WebAssembly)] |
| 4456 | pub fn new(message: &str) -> CompileError; |
| 4457 | } |
| 4458 | |
| 4459 | // WebAssembly.Instance |
| 4460 | #[wasm_bindgen ] |
| 4461 | extern "C" { |
| 4462 | /// A `WebAssembly.Instance` object is a stateful, executable instance |
| 4463 | /// of a `WebAssembly.Module`. Instance objects contain all the exported |
| 4464 | /// WebAssembly functions that allow calling into WebAssembly code from |
| 4465 | /// JavaScript. |
| 4466 | /// |
| 4467 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance) |
| 4468 | #[wasm_bindgen (extends = Object, js_namespace = WebAssembly, typescript_type = "WebAssembly.Instance" )] |
| 4469 | #[derive (Clone, Debug, PartialEq, Eq)] |
| 4470 | pub type Instance; |
| 4471 | |
| 4472 | /// The `WebAssembly.Instance()` constructor function can be called to |
| 4473 | /// synchronously instantiate a given `WebAssembly.Module` |
| 4474 | /// object. However, the primary way to get an `Instance` is through the |
| 4475 | /// asynchronous `WebAssembly.instantiateStreaming()` function. |
| 4476 | /// |
| 4477 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance) |
| 4478 | #[wasm_bindgen (catch, constructor, js_namespace = WebAssembly)] |
| 4479 | pub fn new(module: &Module, imports: &Object) -> Result<Instance, JsValue>; |
| 4480 | |
| 4481 | /// The `exports` readonly property of the `WebAssembly.Instance` object |
| 4482 | /// prototype returns an object containing as its members all the |
| 4483 | /// functions exported from the WebAssembly module instance, to allow |
| 4484 | /// them to be accessed and used by JavaScript. |
| 4485 | /// |
| 4486 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance/exports) |
| 4487 | #[wasm_bindgen (getter, method, js_namespace = WebAssembly)] |
| 4488 | pub fn exports(this: &Instance) -> Object; |
| 4489 | } |
| 4490 | |
| 4491 | // WebAssembly.LinkError |
| 4492 | #[wasm_bindgen ] |
| 4493 | extern "C" { |
| 4494 | /// The `WebAssembly.LinkError()` constructor creates a new WebAssembly |
| 4495 | /// LinkError object, which indicates an error during module |
| 4496 | /// instantiation (besides traps from the start function). |
| 4497 | /// |
| 4498 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/LinkError) |
| 4499 | #[wasm_bindgen (extends = Error, js_namespace = WebAssembly, typescript_type = "WebAssembly.LinkError" )] |
| 4500 | #[derive (Clone, Debug, PartialEq, Eq)] |
| 4501 | pub type LinkError; |
| 4502 | |
| 4503 | /// The `WebAssembly.LinkError()` constructor creates a new WebAssembly |
| 4504 | /// LinkError object, which indicates an error during module |
| 4505 | /// instantiation (besides traps from the start function). |
| 4506 | /// |
| 4507 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/LinkError) |
| 4508 | #[wasm_bindgen (constructor, js_namespace = WebAssembly)] |
| 4509 | pub fn new(message: &str) -> LinkError; |
| 4510 | } |
| 4511 | |
| 4512 | // WebAssembly.RuntimeError |
| 4513 | #[wasm_bindgen ] |
| 4514 | extern "C" { |
| 4515 | /// The `WebAssembly.RuntimeError()` constructor creates a new WebAssembly |
| 4516 | /// `RuntimeError` object — the type that is thrown whenever WebAssembly |
| 4517 | /// specifies a trap. |
| 4518 | /// |
| 4519 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/RuntimeError) |
| 4520 | #[wasm_bindgen (extends = Error, js_namespace = WebAssembly, typescript_type = "WebAssembly.RuntimeError" )] |
| 4521 | #[derive (Clone, Debug, PartialEq, Eq)] |
| 4522 | pub type RuntimeError; |
| 4523 | |
| 4524 | /// The `WebAssembly.RuntimeError()` constructor creates a new WebAssembly |
| 4525 | /// `RuntimeError` object — the type that is thrown whenever WebAssembly |
| 4526 | /// specifies a trap. |
| 4527 | /// |
| 4528 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/RuntimeError) |
| 4529 | #[wasm_bindgen (constructor, js_namespace = WebAssembly)] |
| 4530 | pub fn new(message: &str) -> RuntimeError; |
| 4531 | } |
| 4532 | |
| 4533 | // WebAssembly.Module |
| 4534 | #[wasm_bindgen ] |
| 4535 | extern "C" { |
| 4536 | /// A `WebAssembly.Module` object contains stateless WebAssembly code |
| 4537 | /// that has already been compiled by the browser and can be |
| 4538 | /// efficiently shared with Workers, and instantiated multiple times. |
| 4539 | /// |
| 4540 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module) |
| 4541 | #[wasm_bindgen (js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Module" )] |
| 4542 | #[derive (Clone, Debug, PartialEq, Eq)] |
| 4543 | pub type Module; |
| 4544 | |
| 4545 | /// A `WebAssembly.Module` object contains stateless WebAssembly code |
| 4546 | /// that has already been compiled by the browser and can be |
| 4547 | /// efficiently shared with Workers, and instantiated multiple times. |
| 4548 | /// |
| 4549 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module) |
| 4550 | #[wasm_bindgen (constructor, js_namespace = WebAssembly, catch)] |
| 4551 | pub fn new(buffer_source: &JsValue) -> Result<Module, JsValue>; |
| 4552 | |
| 4553 | /// The `WebAssembly.customSections()` function returns a copy of the |
| 4554 | /// contents of all custom sections in the given module with the given |
| 4555 | /// string name. |
| 4556 | /// |
| 4557 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/customSections) |
| 4558 | #[wasm_bindgen (static_method_of = Module, js_namespace = WebAssembly, js_name = customSections)] |
| 4559 | pub fn custom_sections(module: &Module, sectionName: &str) -> Array; |
| 4560 | |
| 4561 | /// The `WebAssembly.exports()` function returns an array containing |
| 4562 | /// descriptions of all the declared exports of the given `Module`. |
| 4563 | /// |
| 4564 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/exports) |
| 4565 | #[wasm_bindgen (static_method_of = Module, js_namespace = WebAssembly)] |
| 4566 | pub fn exports(module: &Module) -> Array; |
| 4567 | |
| 4568 | /// The `WebAssembly.imports()` function returns an array containing |
| 4569 | /// descriptions of all the declared imports of the given `Module`. |
| 4570 | /// |
| 4571 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/imports) |
| 4572 | #[wasm_bindgen (static_method_of = Module, js_namespace = WebAssembly)] |
| 4573 | pub fn imports(module: &Module) -> Array; |
| 4574 | } |
| 4575 | |
| 4576 | // WebAssembly.Table |
| 4577 | #[wasm_bindgen ] |
| 4578 | extern "C" { |
| 4579 | /// The `WebAssembly.Table()` constructor creates a new `Table` object |
| 4580 | /// of the given size and element type. |
| 4581 | /// |
| 4582 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table) |
| 4583 | #[wasm_bindgen (js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Table" )] |
| 4584 | #[derive (Clone, Debug, PartialEq, Eq)] |
| 4585 | pub type Table; |
| 4586 | |
| 4587 | /// The `WebAssembly.Table()` constructor creates a new `Table` object |
| 4588 | /// of the given size and element type. |
| 4589 | /// |
| 4590 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table) |
| 4591 | #[wasm_bindgen (constructor, js_namespace = WebAssembly, catch)] |
| 4592 | pub fn new(table_descriptor: &Object) -> Result<Table, JsValue>; |
| 4593 | |
| 4594 | /// The length prototype property of the `WebAssembly.Table` object |
| 4595 | /// returns the length of the table, i.e. the number of elements in the |
| 4596 | /// table. |
| 4597 | /// |
| 4598 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/length) |
| 4599 | #[wasm_bindgen (method, getter, js_namespace = WebAssembly)] |
| 4600 | pub fn length(this: &Table) -> u32; |
| 4601 | |
| 4602 | /// The `get()` prototype method of the `WebAssembly.Table()` object |
| 4603 | /// retrieves a function reference stored at a given index. |
| 4604 | /// |
| 4605 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/get) |
| 4606 | #[wasm_bindgen (method, catch, js_namespace = WebAssembly)] |
| 4607 | pub fn get(this: &Table, index: u32) -> Result<Function, JsValue>; |
| 4608 | |
| 4609 | /// The `grow()` prototype method of the `WebAssembly.Table` object |
| 4610 | /// increases the size of the `Table` instance by a specified number of |
| 4611 | /// elements. |
| 4612 | /// |
| 4613 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/grow) |
| 4614 | #[wasm_bindgen (method, catch, js_namespace = WebAssembly)] |
| 4615 | pub fn grow(this: &Table, additional_capacity: u32) -> Result<u32, JsValue>; |
| 4616 | |
| 4617 | /// The `set()` prototype method of the `WebAssembly.Table` object mutates a |
| 4618 | /// reference stored at a given index to a different value. |
| 4619 | /// |
| 4620 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/set) |
| 4621 | #[wasm_bindgen (method, catch, js_namespace = WebAssembly)] |
| 4622 | pub fn set(this: &Table, index: u32, function: &Function) -> Result<(), JsValue>; |
| 4623 | } |
| 4624 | |
| 4625 | // WebAssembly.Tag |
| 4626 | #[wasm_bindgen ] |
| 4627 | extern "C" { |
| 4628 | /// The `WebAssembly.Tag()` constructor creates a new `Tag` object |
| 4629 | /// |
| 4630 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Tag) |
| 4631 | #[wasm_bindgen (js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Tag" )] |
| 4632 | #[derive (Clone, Debug, PartialEq, Eq)] |
| 4633 | pub type Tag; |
| 4634 | |
| 4635 | /// The `WebAssembly.Tag()` constructor creates a new `Tag` object |
| 4636 | /// |
| 4637 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Tag) |
| 4638 | #[wasm_bindgen (constructor, js_namespace = WebAssembly, catch)] |
| 4639 | pub fn new(tag_descriptor: &Object) -> Result<Tag, JsValue>; |
| 4640 | } |
| 4641 | |
| 4642 | // WebAssembly.Exception |
| 4643 | #[wasm_bindgen ] |
| 4644 | extern "C" { |
| 4645 | /// The `WebAssembly.Exception()` constructor creates a new `Exception` object |
| 4646 | /// |
| 4647 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception) |
| 4648 | #[wasm_bindgen (js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Exception" )] |
| 4649 | #[derive (Clone, Debug, PartialEq, Eq)] |
| 4650 | pub type Exception; |
| 4651 | |
| 4652 | /// The `WebAssembly.Exception()` constructor creates a new `Exception` object |
| 4653 | /// |
| 4654 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception) |
| 4655 | #[wasm_bindgen (constructor, js_namespace = WebAssembly, catch)] |
| 4656 | pub fn new(tag: &Tag, payload: &Array) -> Result<Exception, JsValue>; |
| 4657 | |
| 4658 | /// The `WebAssembly.Exception()` constructor creates a new `Exception` object |
| 4659 | /// |
| 4660 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception) |
| 4661 | #[wasm_bindgen (constructor, js_namespace = WebAssembly, catch)] |
| 4662 | pub fn new_with_options( |
| 4663 | tag: &Tag, |
| 4664 | payload: &Array, |
| 4665 | options: &Object, |
| 4666 | ) -> Result<Exception, JsValue>; |
| 4667 | |
| 4668 | /// The `is()` prototype method of the `WebAssembly.Exception` can be used to |
| 4669 | /// test if the Exception matches a given tag. |
| 4670 | /// |
| 4671 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception/is) |
| 4672 | #[wasm_bindgen (method, js_namespace = WebAssembly)] |
| 4673 | pub fn is(this: &Exception, tag: &Tag) -> bool; |
| 4674 | |
| 4675 | /// The `getArg()` prototype method of the `WebAssembly.Exception` can be used |
| 4676 | /// to get the value of a specified item in the exception's data arguments |
| 4677 | /// |
| 4678 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Exception/getArg) |
| 4679 | #[wasm_bindgen (method, js_namespace = WebAssembly, js_name = getArg, catch)] |
| 4680 | pub fn get_arg(this: &Exception, tag: &Tag, index: u32) -> Result<JsValue, JsValue>; |
| 4681 | } |
| 4682 | |
| 4683 | // WebAssembly.Global |
| 4684 | #[wasm_bindgen ] |
| 4685 | extern "C" { |
| 4686 | /// The `WebAssembly.Global()` constructor creates a new `Global` object |
| 4687 | /// of the given type and value. |
| 4688 | /// |
| 4689 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global) |
| 4690 | #[wasm_bindgen (js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Global" )] |
| 4691 | #[derive (Clone, Debug, PartialEq, Eq)] |
| 4692 | pub type Global; |
| 4693 | |
| 4694 | /// The `WebAssembly.Global()` constructor creates a new `Global` object |
| 4695 | /// of the given type and value. |
| 4696 | /// |
| 4697 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global) |
| 4698 | #[wasm_bindgen (constructor, js_namespace = WebAssembly, catch)] |
| 4699 | pub fn new(global_descriptor: &Object, value: &JsValue) -> Result<Global, JsValue>; |
| 4700 | |
| 4701 | /// The value prototype property of the `WebAssembly.Global` object |
| 4702 | /// returns the value of the global. |
| 4703 | /// |
| 4704 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global) |
| 4705 | #[wasm_bindgen (method, getter, structural, js_namespace = WebAssembly)] |
| 4706 | pub fn value(this: &Global) -> JsValue; |
| 4707 | #[wasm_bindgen (method, setter = value, structural, js_namespace = WebAssembly)] |
| 4708 | pub fn set_value(this: &Global, value: &JsValue); |
| 4709 | } |
| 4710 | |
| 4711 | // WebAssembly.Memory |
| 4712 | #[wasm_bindgen ] |
| 4713 | extern "C" { |
| 4714 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory) |
| 4715 | #[wasm_bindgen (js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Memory" )] |
| 4716 | #[derive (Clone, Debug, PartialEq, Eq)] |
| 4717 | pub type Memory; |
| 4718 | |
| 4719 | /// The `WebAssembly.Memory()` constructor creates a new `Memory` object |
| 4720 | /// which is a resizable `ArrayBuffer` that holds the raw bytes of |
| 4721 | /// memory accessed by a WebAssembly `Instance`. |
| 4722 | /// |
| 4723 | /// A memory created by JavaScript or in WebAssembly code will be |
| 4724 | /// accessible and mutable from both JavaScript and WebAssembly. |
| 4725 | /// |
| 4726 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory) |
| 4727 | #[wasm_bindgen (constructor, js_namespace = WebAssembly, catch)] |
| 4728 | pub fn new(descriptor: &Object) -> Result<Memory, JsValue>; |
| 4729 | |
| 4730 | /// An accessor property that returns the buffer contained in the |
| 4731 | /// memory. |
| 4732 | /// |
| 4733 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory/buffer) |
| 4734 | #[wasm_bindgen (method, getter, js_namespace = WebAssembly)] |
| 4735 | pub fn buffer(this: &Memory) -> JsValue; |
| 4736 | |
| 4737 | /// The `grow()` prototype method of the `Memory` object increases the |
| 4738 | /// size of the memory instance by a specified number of WebAssembly |
| 4739 | /// pages. |
| 4740 | /// |
| 4741 | /// Takes the number of pages to grow (64KiB in size) and returns the |
| 4742 | /// previous size of memory, in pages. |
| 4743 | /// |
| 4744 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory/grow) |
| 4745 | #[wasm_bindgen (method, js_namespace = WebAssembly)] |
| 4746 | pub fn grow(this: &Memory, pages: u32) -> u32; |
| 4747 | } |
| 4748 | } |
| 4749 | |
| 4750 | /// The `JSON` object contains methods for parsing [JavaScript Object |
| 4751 | /// Notation (JSON)](https://json.org/) and converting values to JSON. It |
| 4752 | /// can't be called or constructed, and aside from its two method |
| 4753 | /// properties, it has no interesting functionality of its own. |
| 4754 | #[allow (non_snake_case)] |
| 4755 | pub mod JSON { |
| 4756 | use super::*; |
| 4757 | |
| 4758 | // JSON |
| 4759 | #[wasm_bindgen ] |
| 4760 | extern "C" { |
| 4761 | /// The `JSON.parse()` method parses a JSON string, constructing the |
| 4762 | /// JavaScript value or object described by the string. |
| 4763 | /// |
| 4764 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse) |
| 4765 | #[wasm_bindgen (catch, js_namespace = JSON)] |
| 4766 | pub fn parse(text: &str) -> Result<JsValue, JsValue>; |
| 4767 | |
| 4768 | /// The `JSON.stringify()` method converts a JavaScript value to a JSON string. |
| 4769 | /// |
| 4770 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify) |
| 4771 | #[wasm_bindgen (catch, js_namespace = JSON)] |
| 4772 | pub fn stringify(obj: &JsValue) -> Result<JsString, JsValue>; |
| 4773 | |
| 4774 | /// The `JSON.stringify()` method converts a JavaScript value to a JSON string. |
| 4775 | /// |
| 4776 | /// The `replacer` argument is a function that alters the behavior of the stringification |
| 4777 | /// process, or an array of String and Number objects that serve as a whitelist |
| 4778 | /// for selecting/filtering the properties of the value object to be included |
| 4779 | /// in the JSON string. If this value is null or not provided, all properties |
| 4780 | /// of the object are included in the resulting JSON string. |
| 4781 | /// |
| 4782 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify) |
| 4783 | #[wasm_bindgen (catch, js_namespace = JSON, js_name = stringify)] |
| 4784 | pub fn stringify_with_replacer( |
| 4785 | obj: &JsValue, |
| 4786 | replacer: &JsValue, |
| 4787 | ) -> Result<JsString, JsValue>; |
| 4788 | |
| 4789 | /// The `JSON.stringify()` method converts a JavaScript value to a JSON string. |
| 4790 | /// |
| 4791 | /// The `replacer` argument is a function that alters the behavior of the stringification |
| 4792 | /// process, or an array of String and Number objects that serve as a whitelist |
| 4793 | /// for selecting/filtering the properties of the value object to be included |
| 4794 | /// in the JSON string. If this value is null or not provided, all properties |
| 4795 | /// of the object are included in the resulting JSON string. |
| 4796 | /// |
| 4797 | /// The `space` argument is a String or Number object that's used to insert white space into |
| 4798 | /// the output JSON string for readability purposes. If this is a Number, it |
| 4799 | /// indicates the number of space characters to use as white space; this number |
| 4800 | /// is capped at 10 (if it is greater, the value is just 10). Values less than |
| 4801 | /// 1 indicate that no space should be used. If this is a String, the string |
| 4802 | /// (or the first 10 characters of the string, if it's longer than that) is |
| 4803 | /// used as white space. If this parameter is not provided (or is null), no |
| 4804 | /// white space is used. |
| 4805 | /// |
| 4806 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify) |
| 4807 | #[wasm_bindgen (catch, js_namespace = JSON, js_name = stringify)] |
| 4808 | pub fn stringify_with_replacer_and_space( |
| 4809 | obj: &JsValue, |
| 4810 | replacer: &JsValue, |
| 4811 | space: &JsValue, |
| 4812 | ) -> Result<JsString, JsValue>; |
| 4813 | |
| 4814 | } |
| 4815 | } |
| 4816 | |
| 4817 | // JsString |
| 4818 | #[wasm_bindgen ] |
| 4819 | unsafeextern "C" { |
| 4820 | #[wasm_bindgen (js_name = String, extends = Object, is_type_of = JsValue::is_string, typescript_type = "string" )] |
| 4821 | #[derive (Clone, PartialEq, Eq)] |
| 4822 | pub type JsString; |
| 4823 | |
| 4824 | /// The length property of a String object indicates the length of a string, |
| 4825 | /// in UTF-16 code units. |
| 4826 | /// |
| 4827 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/length) |
| 4828 | #[wasm_bindgen (method, getter, structural)] |
| 4829 | pub unsafefn length(this: &JsString) -> u32; |
| 4830 | |
| 4831 | /// The 'at()' method returns a new string consisting of the single UTF-16 |
| 4832 | /// code unit located at the specified offset into the string, counting from |
| 4833 | /// the end if it's negative. |
| 4834 | /// |
| 4835 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/at) |
| 4836 | #[wasm_bindgen (method, js_class = "String" )] |
| 4837 | pub unsafefn at(this: &JsString, index: i32) -> Option<JsString>; |
| 4838 | |
| 4839 | /// The String object's `charAt()` method returns a new string consisting of |
| 4840 | /// the single UTF-16 code unit located at the specified offset into the |
| 4841 | /// string. |
| 4842 | /// |
| 4843 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charAt) |
| 4844 | #[wasm_bindgen (method, js_class = "String" , js_name = charAt)] |
| 4845 | pub unsafefn char_at(this: &JsString, index: u32) -> JsString; |
| 4846 | |
| 4847 | /// The `charCodeAt()` method returns an integer between 0 and 65535 |
| 4848 | /// representing the UTF-16 code unit at the given index (the UTF-16 code |
| 4849 | /// unit matches the Unicode code point for code points representable in a |
| 4850 | /// single UTF-16 code unit, but might also be the first code unit of a |
| 4851 | /// surrogate pair for code points not representable in a single UTF-16 code |
| 4852 | /// unit, e.g. Unicode code points > 0x10000). If you want the entire code |
| 4853 | /// point value, use `codePointAt()`. |
| 4854 | /// |
| 4855 | /// Returns `NaN` if index is out of range. |
| 4856 | /// |
| 4857 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charCodeAt) |
| 4858 | #[wasm_bindgen (method, js_class = "String" , js_name = charCodeAt)] |
| 4859 | pub unsafefn char_code_at(this: &JsString, index: u32) -> f64; |
| 4860 | |
| 4861 | /// The `codePointAt()` method returns a non-negative integer that is the |
| 4862 | /// Unicode code point value. |
| 4863 | /// |
| 4864 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/codePointAt) |
| 4865 | #[wasm_bindgen (method, js_class = "String" , js_name = codePointAt)] |
| 4866 | pub unsafefn code_point_at(this: &JsString, pos: u32) -> JsValue; |
| 4867 | |
| 4868 | /// The `concat()` method concatenates the string arguments to the calling |
| 4869 | /// string and returns a new string. |
| 4870 | /// |
| 4871 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/concat) |
| 4872 | #[wasm_bindgen (method, js_class = "String" )] |
| 4873 | pub unsafefn concat(this: &JsString, string_2: &JsValue) -> JsString; |
| 4874 | |
| 4875 | /// The `endsWith()` method determines whether a string ends with the characters of a |
| 4876 | /// specified string, returning true or false as appropriate. |
| 4877 | /// |
| 4878 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith) |
| 4879 | #[wasm_bindgen (method, js_class = "String" , js_name = endsWith)] |
| 4880 | pub unsafefn ends_with(this: &JsString, search_string: &str, length: i32) -> bool; |
| 4881 | |
| 4882 | /// The static `String.fromCharCode()` method returns a string created from |
| 4883 | /// the specified sequence of UTF-16 code units. |
| 4884 | /// |
| 4885 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode) |
| 4886 | /// |
| 4887 | /// # Notes |
| 4888 | /// |
| 4889 | /// There are a few bindings to `from_char_code` in `js-sys`: `from_char_code1`, `from_char_code2`, etc... |
| 4890 | /// with different arities. |
| 4891 | /// |
| 4892 | /// Additionally, this function accepts `u16` for character codes, but |
| 4893 | /// fixing others requires a breaking change release |
| 4894 | /// (see https://github.com/rustwasm/wasm-bindgen/issues/1460 for details). |
| 4895 | #[wasm_bindgen (static_method_of = JsString, js_class = "String" , js_name = fromCharCode, variadic)] |
| 4896 | pub unsafefn from_char_code(char_codes: &[u16]) -> JsString; |
| 4897 | |
| 4898 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode) |
| 4899 | #[wasm_bindgen (static_method_of = JsString, js_class = "String" , js_name = fromCharCode)] |
| 4900 | pub unsafefn from_char_code1(a: u32) -> JsString; |
| 4901 | |
| 4902 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode) |
| 4903 | #[wasm_bindgen (static_method_of = JsString, js_class = "String" , js_name = fromCharCode)] |
| 4904 | pub unsafefn from_char_code2(a: u32, b: u32) -> JsString; |
| 4905 | |
| 4906 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode) |
| 4907 | #[wasm_bindgen (static_method_of = JsString, js_class = "String" , js_name = fromCharCode)] |
| 4908 | pub unsafefn from_char_code3(a: u32, b: u32, c: u32) -> JsString; |
| 4909 | |
| 4910 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode) |
| 4911 | #[wasm_bindgen (static_method_of = JsString, js_class = "String" , js_name = fromCharCode)] |
| 4912 | pub unsafefn from_char_code4(a: u32, b: u32, c: u32, d: u32) -> JsString; |
| 4913 | |
| 4914 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode) |
| 4915 | #[wasm_bindgen (static_method_of = JsString, js_class = "String" , js_name = fromCharCode)] |
| 4916 | pub unsafefn from_char_code5(a: u32, b: u32, c: u32, d: u32, e: u32) -> JsString; |
| 4917 | |
| 4918 | /// The static `String.fromCodePoint()` method returns a string created by |
| 4919 | /// using the specified sequence of code points. |
| 4920 | /// |
| 4921 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint) |
| 4922 | /// |
| 4923 | /// # Exceptions |
| 4924 | /// |
| 4925 | /// A RangeError is thrown if an invalid Unicode code point is given |
| 4926 | /// |
| 4927 | /// # Notes |
| 4928 | /// |
| 4929 | /// There are a few bindings to `from_code_point` in `js-sys`: `from_code_point1`, `from_code_point2`, etc... |
| 4930 | /// with different arities. |
| 4931 | #[wasm_bindgen (catch, static_method_of = JsString, js_class = "String" , js_name = fromCodePoint, variadic)] |
| 4932 | pub unsafefn from_code_point(code_points: &[u32]) -> Result<JsString, JsValue>; |
| 4933 | |
| 4934 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint) |
| 4935 | #[wasm_bindgen (catch, static_method_of = JsString, js_class = "String" , js_name = fromCodePoint)] |
| 4936 | pub unsafefn from_code_point1(a: u32) -> Result<JsString, JsValue>; |
| 4937 | |
| 4938 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint) |
| 4939 | #[wasm_bindgen (catch, static_method_of = JsString, js_class = "String" , js_name = fromCodePoint)] |
| 4940 | pub unsafefn from_code_point2(a: u32, b: u32) -> Result<JsString, JsValue>; |
| 4941 | |
| 4942 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint) |
| 4943 | #[wasm_bindgen (catch, static_method_of = JsString, js_class = "String" , js_name = fromCodePoint)] |
| 4944 | pub unsafefn from_code_point3(a: u32, b: u32, c: u32) -> Result<JsString, JsValue>; |
| 4945 | |
| 4946 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint) |
| 4947 | #[wasm_bindgen (catch, static_method_of = JsString, js_class = "String" , js_name = fromCodePoint)] |
| 4948 | pub unsafefn from_code_point4(a: u32, b: u32, c: u32, d: u32) -> Result<JsString, JsValue>; |
| 4949 | |
| 4950 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint) |
| 4951 | #[wasm_bindgen (catch, static_method_of = JsString, js_class = "String" , js_name = fromCodePoint)] |
| 4952 | pub unsafefn from_code_point5(a: u32, b: u32, c: u32, d: u32, e: u32) -> Result<JsString, JsValue>; |
| 4953 | |
| 4954 | /// The `includes()` method determines whether one string may be found |
| 4955 | /// within another string, returning true or false as appropriate. |
| 4956 | /// |
| 4957 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes) |
| 4958 | #[wasm_bindgen (method, js_class = "String" )] |
| 4959 | pub unsafefn includes(this: &JsString, search_string: &str, position: i32) -> bool; |
| 4960 | |
| 4961 | /// The `indexOf()` method returns the index within the calling String |
| 4962 | /// object of the first occurrence of the specified value, starting the |
| 4963 | /// search at fromIndex. Returns -1 if the value is not found. |
| 4964 | /// |
| 4965 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf) |
| 4966 | #[wasm_bindgen (method, js_class = "String" , js_name = indexOf)] |
| 4967 | pub unsafefn index_of(this: &JsString, search_value: &str, from_index: i32) -> i32; |
| 4968 | |
| 4969 | /// The `lastIndexOf()` method returns the index within the calling String |
| 4970 | /// object of the last occurrence of the specified value, searching |
| 4971 | /// backwards from fromIndex. Returns -1 if the value is not found. |
| 4972 | /// |
| 4973 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/lastIndexOf) |
| 4974 | #[wasm_bindgen (method, js_class = "String" , js_name = lastIndexOf)] |
| 4975 | pub unsafefn last_index_of(this: &JsString, search_value: &str, from_index: i32) -> i32; |
| 4976 | |
| 4977 | /// The `localeCompare()` method returns a number indicating whether |
| 4978 | /// a reference string comes before or after or is the same as |
| 4979 | /// the given string in sort order. |
| 4980 | /// |
| 4981 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare) |
| 4982 | #[wasm_bindgen (method, js_class = "String" , js_name = localeCompare)] |
| 4983 | pub unsafefn locale_compare( |
| 4984 | this: &JsString, |
| 4985 | compare_string: &str, |
| 4986 | locales: &Array, |
| 4987 | options: &Object, |
| 4988 | ) -> i32; |
| 4989 | |
| 4990 | /// The `match()` method retrieves the matches when matching a string against a regular expression. |
| 4991 | /// |
| 4992 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match) |
| 4993 | #[wasm_bindgen (method, js_class = "String" , js_name = match)] |
| 4994 | pub unsafefn match_(this: &JsString, pattern: &RegExp) -> Option<Object>; |
| 4995 | |
| 4996 | /// The `match_all()` method is similar to `match()`, but gives an iterator of `exec()` arrays, which preserve capture groups. |
| 4997 | /// |
| 4998 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/matchAll) |
| 4999 | #[wasm_bindgen (method, js_class = "String" , js_name = matchAll)] |
| 5000 | pub unsafefn match_all(this: &JsString, pattern: &RegExp) -> Iterator; |
| 5001 | |
| 5002 | /// The `normalize()` method returns the Unicode Normalization Form |
| 5003 | /// of a given string (if the value isn't a string, it will be converted to one first). |
| 5004 | /// |
| 5005 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize) |
| 5006 | #[wasm_bindgen (method, js_class = "String" )] |
| 5007 | pub unsafefn normalize(this: &JsString, form: &str) -> JsString; |
| 5008 | |
| 5009 | /// The `padEnd()` method pads the current string with a given string |
| 5010 | /// (repeated, if needed) so that the resulting string reaches a given |
| 5011 | /// length. The padding is applied from the end (right) of the current |
| 5012 | /// string. |
| 5013 | /// |
| 5014 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padEnd) |
| 5015 | #[wasm_bindgen (method, js_class = "String" , js_name = padEnd)] |
| 5016 | pub unsafefn pad_end(this: &JsString, target_length: u32, pad_string: &str) -> JsString; |
| 5017 | |
| 5018 | /// The `padStart()` method pads the current string with another string |
| 5019 | /// (repeated, if needed) so that the resulting string reaches the given |
| 5020 | /// length. The padding is applied from the start (left) of the current |
| 5021 | /// string. |
| 5022 | /// |
| 5023 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padStart) |
| 5024 | #[wasm_bindgen (method, js_class = "String" , js_name = padStart)] |
| 5025 | pub unsafefn pad_start(this: &JsString, target_length: u32, pad_string: &str) -> JsString; |
| 5026 | |
| 5027 | /// The `repeat()` method constructs and returns a new string which contains the specified |
| 5028 | /// number of copies of the string on which it was called, concatenated together. |
| 5029 | /// |
| 5030 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat) |
| 5031 | #[wasm_bindgen (method, js_class = "String" )] |
| 5032 | pub unsafefn repeat(this: &JsString, count: i32) -> JsString; |
| 5033 | |
| 5034 | /// The `replace()` method returns a new string with some or all matches of a pattern |
| 5035 | /// replaced by a replacement. The pattern can be a string or a RegExp, and |
| 5036 | /// the replacement can be a string or a function to be called for each match. |
| 5037 | /// |
| 5038 | /// Note: The original string will remain unchanged. |
| 5039 | /// |
| 5040 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace) |
| 5041 | #[wasm_bindgen (method, js_class = "String" )] |
| 5042 | pub unsafefn replace(this: &JsString, pattern: &str, replacement: &str) -> JsString; |
| 5043 | |
| 5044 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace) |
| 5045 | #[wasm_bindgen (method, js_class = "String" , js_name = replace)] |
| 5046 | pub unsafefn replace_with_function( |
| 5047 | this: &JsString, |
| 5048 | pattern: &str, |
| 5049 | replacement: &Function, |
| 5050 | ) -> JsString; |
| 5051 | |
| 5052 | #[wasm_bindgen (method, js_class = "String" , js_name = replace)] |
| 5053 | pub unsafefn replace_by_pattern(this: &JsString, pattern: &RegExp, replacement: &str) -> JsString; |
| 5054 | |
| 5055 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace) |
| 5056 | #[wasm_bindgen (method, js_class = "String" , js_name = replace)] |
| 5057 | pub unsafefn replace_by_pattern_with_function( |
| 5058 | this: &JsString, |
| 5059 | pattern: &RegExp, |
| 5060 | replacement: &Function, |
| 5061 | ) -> JsString; |
| 5062 | |
| 5063 | /// The `replace_all()` method returns a new string with all matches of a pattern |
| 5064 | /// replaced by a replacement. The pattern can be a string or a global RegExp, and |
| 5065 | /// the replacement can be a string or a function to be called for each match. |
| 5066 | /// |
| 5067 | /// Note: The original string will remain unchanged. |
| 5068 | /// |
| 5069 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll) |
| 5070 | #[wasm_bindgen (method, js_class = "String" , js_name = replaceAll)] |
| 5071 | pub unsafefn replace_all(this: &JsString, pattern: &str, replacement: &str) -> JsString; |
| 5072 | |
| 5073 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll) |
| 5074 | #[wasm_bindgen (method, js_class = "String" , js_name = replaceAll)] |
| 5075 | pub unsafefn replace_all_with_function( |
| 5076 | this: &JsString, |
| 5077 | pattern: &str, |
| 5078 | replacement: &Function, |
| 5079 | ) -> JsString; |
| 5080 | |
| 5081 | #[wasm_bindgen (method, js_class = "String" , js_name = replaceAll)] |
| 5082 | pub unsafefn replace_all_by_pattern(this: &JsString, pattern: &RegExp, replacement: &str) |
| 5083 | -> JsString; |
| 5084 | |
| 5085 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll) |
| 5086 | #[wasm_bindgen (method, js_class = "String" , js_name = replaceAll)] |
| 5087 | pub unsafefn replace_all_by_pattern_with_function( |
| 5088 | this: &JsString, |
| 5089 | pattern: &RegExp, |
| 5090 | replacement: &Function, |
| 5091 | ) -> JsString; |
| 5092 | |
| 5093 | /// The `search()` method executes a search for a match between |
| 5094 | /// a regular expression and this String object. |
| 5095 | /// |
| 5096 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/search) |
| 5097 | #[wasm_bindgen (method, js_class = "String" )] |
| 5098 | pub unsafefn search(this: &JsString, pattern: &RegExp) -> i32; |
| 5099 | |
| 5100 | /// The `slice()` method extracts a section of a string and returns it as a |
| 5101 | /// new string, without modifying the original string. |
| 5102 | /// |
| 5103 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice) |
| 5104 | #[wasm_bindgen (method, js_class = "String" )] |
| 5105 | pub unsafefn slice(this: &JsString, start: u32, end: u32) -> JsString; |
| 5106 | |
| 5107 | /// The `split()` method splits a String object into an array of strings by separating the string |
| 5108 | /// into substrings, using a specified separator string to determine where to make each split. |
| 5109 | /// |
| 5110 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split) |
| 5111 | #[wasm_bindgen (method, js_class = "String" )] |
| 5112 | pub unsafefn split(this: &JsString, separator: &str) -> Array; |
| 5113 | |
| 5114 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split) |
| 5115 | #[wasm_bindgen (method, js_class = "String" , js_name = split)] |
| 5116 | pub unsafefn split_limit(this: &JsString, separator: &str, limit: u32) -> Array; |
| 5117 | |
| 5118 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split) |
| 5119 | #[wasm_bindgen (method, js_class = "String" , js_name = split)] |
| 5120 | pub unsafefn split_by_pattern(this: &JsString, pattern: &RegExp) -> Array; |
| 5121 | |
| 5122 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split) |
| 5123 | #[wasm_bindgen (method, js_class = "String" , js_name = split)] |
| 5124 | pub unsafefn split_by_pattern_limit(this: &JsString, pattern: &RegExp, limit: u32) -> Array; |
| 5125 | |
| 5126 | /// The `startsWith()` method determines whether a string begins with the |
| 5127 | /// characters of a specified string, returning true or false as |
| 5128 | /// appropriate. |
| 5129 | /// |
| 5130 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith) |
| 5131 | #[wasm_bindgen (method, js_class = "String" , js_name = startsWith)] |
| 5132 | pub unsafefn starts_with(this: &JsString, search_string: &str, position: u32) -> bool; |
| 5133 | |
| 5134 | /// The `substring()` method returns the part of the string between the |
| 5135 | /// start and end indexes, or to the end of the string. |
| 5136 | /// |
| 5137 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring) |
| 5138 | #[wasm_bindgen (method, js_class = "String" )] |
| 5139 | pub unsafefn substring(this: &JsString, index_start: u32, index_end: u32) -> JsString; |
| 5140 | |
| 5141 | /// The `substr()` method returns the part of a string between |
| 5142 | /// the start index and a number of characters after it. |
| 5143 | /// |
| 5144 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr) |
| 5145 | #[wasm_bindgen (method, js_class = "String" )] |
| 5146 | pub unsafefn substr(this: &JsString, start: i32, length: i32) -> JsString; |
| 5147 | |
| 5148 | /// The `toLocaleLowerCase()` method returns the calling string value converted to lower case, |
| 5149 | /// according to any locale-specific case mappings. |
| 5150 | /// |
| 5151 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLocaleLowerCase) |
| 5152 | #[wasm_bindgen (method, js_class = "String" , js_name = toLocaleLowerCase)] |
| 5153 | pub unsafefn to_locale_lower_case(this: &JsString, locale: Option<&str>) -> JsString; |
| 5154 | |
| 5155 | /// The `toLocaleUpperCase()` method returns the calling string value converted to upper case, |
| 5156 | /// according to any locale-specific case mappings. |
| 5157 | /// |
| 5158 | /// [MDN documentation](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/String/toLocaleUpperCase) |
| 5159 | #[wasm_bindgen (method, js_class = "String" , js_name = toLocaleUpperCase)] |
| 5160 | pub unsafefn to_locale_upper_case(this: &JsString, locale: Option<&str>) -> JsString; |
| 5161 | |
| 5162 | /// The `toLowerCase()` method returns the calling string value |
| 5163 | /// converted to lower case. |
| 5164 | /// |
| 5165 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLowerCase) |
| 5166 | #[wasm_bindgen (method, js_class = "String" , js_name = toLowerCase)] |
| 5167 | pub unsafefn to_lower_case(this: &JsString) -> JsString; |
| 5168 | |
| 5169 | /// The `toString()` method returns a string representing the specified |
| 5170 | /// object. |
| 5171 | /// |
| 5172 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toString) |
| 5173 | #[wasm_bindgen (method, js_class = "String" , js_name = toString)] |
| 5174 | pub unsafefn to_string(this: &JsString) -> JsString; |
| 5175 | |
| 5176 | /// The `toUpperCase()` method returns the calling string value converted to |
| 5177 | /// uppercase (the value will be converted to a string if it isn't one). |
| 5178 | /// |
| 5179 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase) |
| 5180 | #[wasm_bindgen (method, js_class = "String" , js_name = toUpperCase)] |
| 5181 | pub unsafefn to_upper_case(this: &JsString) -> JsString; |
| 5182 | |
| 5183 | /// The `trim()` method removes whitespace from both ends of a string. |
| 5184 | /// Whitespace in this context is all the whitespace characters (space, tab, |
| 5185 | /// no-break space, etc.) and all the line terminator characters (LF, CR, |
| 5186 | /// etc.). |
| 5187 | /// |
| 5188 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trim) |
| 5189 | #[wasm_bindgen (method, js_class = "String" )] |
| 5190 | pub unsafefn trim(this: &JsString) -> JsString; |
| 5191 | |
| 5192 | /// The `trimEnd()` method removes whitespace from the end of a string. |
| 5193 | /// `trimRight()` is an alias of this method. |
| 5194 | /// |
| 5195 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimEnd) |
| 5196 | #[wasm_bindgen (method, js_class = "String" , js_name = trimEnd)] |
| 5197 | pub unsafefn trim_end(this: &JsString) -> JsString; |
| 5198 | |
| 5199 | /// The `trimEnd()` method removes whitespace from the end of a string. |
| 5200 | /// `trimRight()` is an alias of this method. |
| 5201 | /// |
| 5202 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimEnd) |
| 5203 | #[wasm_bindgen (method, js_class = "String" , js_name = trimRight)] |
| 5204 | pub unsafefn trim_right(this: &JsString) -> JsString; |
| 5205 | |
| 5206 | /// The `trimStart()` method removes whitespace from the beginning of a |
| 5207 | /// string. `trimLeft()` is an alias of this method. |
| 5208 | /// |
| 5209 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimStart) |
| 5210 | #[wasm_bindgen (method, js_class = "String" , js_name = trimStart)] |
| 5211 | pub unsafefn trim_start(this: &JsString) -> JsString; |
| 5212 | |
| 5213 | /// The `trimStart()` method removes whitespace from the beginning of a |
| 5214 | /// string. `trimLeft()` is an alias of this method. |
| 5215 | /// |
| 5216 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimStart) |
| 5217 | #[wasm_bindgen (method, js_class = "String" , js_name = trimLeft)] |
| 5218 | pub unsafefn trim_left(this: &JsString) -> JsString; |
| 5219 | |
| 5220 | /// The `valueOf()` method returns the primitive value of a `String` object. |
| 5221 | /// |
| 5222 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/valueOf) |
| 5223 | #[wasm_bindgen (method, js_class = "String" , js_name = valueOf)] |
| 5224 | pub unsafefn value_of(this: &JsString) -> JsString; |
| 5225 | |
| 5226 | /// The static `raw()` method is a tag function of template literals, |
| 5227 | /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals. |
| 5228 | /// |
| 5229 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw) |
| 5230 | #[wasm_bindgen (catch, variadic, static_method_of = JsString, js_class = "String" )] |
| 5231 | pub unsafefn raw(call_site: &Object, substitutions: &Array) -> Result<JsString, JsValue>; |
| 5232 | |
| 5233 | /// The static `raw()` method is a tag function of template literals, |
| 5234 | /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals. |
| 5235 | /// |
| 5236 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw) |
| 5237 | #[wasm_bindgen (catch, static_method_of = JsString, js_class = "String" , js_name = raw)] |
| 5238 | pub unsafefn raw_0(call_site: &Object) -> Result<JsString, JsValue>; |
| 5239 | |
| 5240 | /// The static `raw()` method is a tag function of template literals, |
| 5241 | /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals. |
| 5242 | /// |
| 5243 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw) |
| 5244 | #[wasm_bindgen (catch, static_method_of = JsString, js_class = "String" , js_name = raw)] |
| 5245 | pub unsafefn raw_1(call_site: &Object, substitutions_1: &str) -> Result<JsString, JsValue>; |
| 5246 | |
| 5247 | /// The static `raw()` method is a tag function of template literals, |
| 5248 | /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals. |
| 5249 | /// |
| 5250 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw) |
| 5251 | #[wasm_bindgen (catch, static_method_of = JsString, js_class = "String" , js_name = raw)] |
| 5252 | pub unsafefn raw_2( |
| 5253 | call_site: &Object, |
| 5254 | substitutions_1: &str, |
| 5255 | substitutions_2: &str, |
| 5256 | ) -> Result<JsString, JsValue>; |
| 5257 | |
| 5258 | /// The static `raw()` method is a tag function of template literals, |
| 5259 | /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals. |
| 5260 | /// |
| 5261 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw) |
| 5262 | #[wasm_bindgen (catch, static_method_of = JsString, js_class = "String" , js_name = raw)] |
| 5263 | pub unsafefn raw_3( |
| 5264 | call_site: &Object, |
| 5265 | substitutions_1: &str, |
| 5266 | substitutions_2: &str, |
| 5267 | substitutions_3: &str, |
| 5268 | ) -> Result<JsString, JsValue>; |
| 5269 | |
| 5270 | /// The static `raw()` method is a tag function of template literals, |
| 5271 | /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals. |
| 5272 | /// |
| 5273 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw) |
| 5274 | #[wasm_bindgen (catch, static_method_of = JsString, js_class = "String" , js_name = raw)] |
| 5275 | pub unsafefn raw_4( |
| 5276 | call_site: &Object, |
| 5277 | substitutions_1: &str, |
| 5278 | substitutions_2: &str, |
| 5279 | substitutions_3: &str, |
| 5280 | substitutions_4: &str, |
| 5281 | ) -> Result<JsString, JsValue>; |
| 5282 | |
| 5283 | /// The static `raw()` method is a tag function of template literals, |
| 5284 | /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals. |
| 5285 | /// |
| 5286 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw) |
| 5287 | #[wasm_bindgen (catch, static_method_of = JsString, js_class = "String" , js_name = raw)] |
| 5288 | pub unsafefn raw_5( |
| 5289 | call_site: &Object, |
| 5290 | substitutions_1: &str, |
| 5291 | substitutions_2: &str, |
| 5292 | substitutions_3: &str, |
| 5293 | substitutions_4: &str, |
| 5294 | substitutions_5: &str, |
| 5295 | ) -> Result<JsString, JsValue>; |
| 5296 | |
| 5297 | /// The static `raw()` method is a tag function of template literals, |
| 5298 | /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals. |
| 5299 | /// |
| 5300 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw) |
| 5301 | #[wasm_bindgen (catch, static_method_of = JsString, js_class = "String" , js_name = raw)] |
| 5302 | pub unsafefn raw_6( |
| 5303 | call_site: &Object, |
| 5304 | substitutions_1: &str, |
| 5305 | substitutions_2: &str, |
| 5306 | substitutions_3: &str, |
| 5307 | substitutions_4: &str, |
| 5308 | substitutions_5: &str, |
| 5309 | substitutions_6: &str, |
| 5310 | ) -> Result<JsString, JsValue>; |
| 5311 | |
| 5312 | /// The static `raw()` method is a tag function of template literals, |
| 5313 | /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals. |
| 5314 | /// |
| 5315 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw) |
| 5316 | #[wasm_bindgen (catch, static_method_of = JsString, js_class = "String" , js_name = raw)] |
| 5317 | pub unsafefn raw_7( |
| 5318 | call_site: &Object, |
| 5319 | substitutions_1: &str, |
| 5320 | substitutions_2: &str, |
| 5321 | substitutions_3: &str, |
| 5322 | substitutions_4: &str, |
| 5323 | substitutions_5: &str, |
| 5324 | substitutions_6: &str, |
| 5325 | substitutions_7: &str, |
| 5326 | ) -> Result<JsString, JsValue>; |
| 5327 | } |
| 5328 | |
| 5329 | impl JsString { |
| 5330 | /// Returns the `JsString` value of this JS value if it's an instance of a |
| 5331 | /// string. |
| 5332 | /// |
| 5333 | /// If this JS value is not an instance of a string then this returns |
| 5334 | /// `None`. |
| 5335 | #[deprecated (note = "recommended to use dyn_ref instead which is now equivalent" )] |
| 5336 | pub fn try_from(val: &JsValue) -> Option<&JsString> { |
| 5337 | val.dyn_ref() |
| 5338 | } |
| 5339 | |
| 5340 | /// Returns whether this string is a valid UTF-16 string. |
| 5341 | /// |
| 5342 | /// This is useful for learning whether `String::from(..)` will return a |
| 5343 | /// lossless representation of the JS string. If this string contains |
| 5344 | /// unpaired surrogates then `String::from` will succeed but it will be a |
| 5345 | /// lossy representation of the JS string because unpaired surrogates will |
| 5346 | /// become replacement characters. |
| 5347 | /// |
| 5348 | /// If this function returns `false` then to get a lossless representation |
| 5349 | /// of the string you'll need to manually use the `iter` method (or the |
| 5350 | /// `char_code_at` accessor) to view the raw character codes. |
| 5351 | /// |
| 5352 | /// For more information, see the documentation on [JS strings vs Rust |
| 5353 | /// strings][docs] |
| 5354 | /// |
| 5355 | /// [docs]: https://rustwasm.github.io/docs/wasm-bindgen/reference/types/str.html |
| 5356 | pub fn is_valid_utf16(&self) -> bool { |
| 5357 | core::char::decode_utf16(self.iter()).all(|i| i.is_ok()) |
| 5358 | } |
| 5359 | |
| 5360 | /// Returns an iterator over the `u16` character codes that make up this JS |
| 5361 | /// string. |
| 5362 | /// |
| 5363 | /// This method will call `char_code_at` for each code in this JS string, |
| 5364 | /// returning an iterator of the codes in sequence. |
| 5365 | pub fn iter( |
| 5366 | &self, |
| 5367 | ) -> impl ExactSizeIterator<Item = u16> + DoubleEndedIterator<Item = u16> + '_ { |
| 5368 | (0..self.length()).map(move |i| self.char_code_at(i) as u16) |
| 5369 | } |
| 5370 | |
| 5371 | /// If this string consists of a single Unicode code point, then this method |
| 5372 | /// converts it into a Rust `char` without doing any allocations. |
| 5373 | /// |
| 5374 | /// If this JS value is not a valid UTF-8 or consists of more than a single |
| 5375 | /// codepoint, then this returns `None`. |
| 5376 | /// |
| 5377 | /// Note that a single Unicode code point might be represented as more than |
| 5378 | /// one code unit on the JavaScript side. For example, a JavaScript string |
| 5379 | /// `"\uD801\uDC37"` is actually a single Unicode code point U+10437 which |
| 5380 | /// corresponds to a character '𐐷'. |
| 5381 | pub fn as_char(&self) -> Option<char> { |
| 5382 | let len = self.length(); |
| 5383 | |
| 5384 | if len == 0 || len > 2 { |
| 5385 | return None; |
| 5386 | } |
| 5387 | |
| 5388 | // This will be simplified when definitions are fixed: |
| 5389 | // https://github.com/rustwasm/wasm-bindgen/issues/1362 |
| 5390 | let cp = self.code_point_at(0).as_f64().unwrap_throw() as u32; |
| 5391 | |
| 5392 | let c = core::char::from_u32(cp)?; |
| 5393 | |
| 5394 | if c.len_utf16() as u32 == len { |
| 5395 | Some(c) |
| 5396 | } else { |
| 5397 | None |
| 5398 | } |
| 5399 | } |
| 5400 | } |
| 5401 | |
| 5402 | impl PartialEq<str> for JsString { |
| 5403 | #[allow (clippy::cmp_owned)] // prevent infinite recursion |
| 5404 | fn eq(&self, other: &str) -> bool { |
| 5405 | String::from(self) == other |
| 5406 | } |
| 5407 | } |
| 5408 | |
| 5409 | impl<'a> PartialEq<&'a str> for JsString { |
| 5410 | fn eq(&self, other: &&'a str) -> bool { |
| 5411 | <JsString as PartialEq<str>>::eq(self, other) |
| 5412 | } |
| 5413 | } |
| 5414 | |
| 5415 | impl PartialEq<String> for JsString { |
| 5416 | fn eq(&self, other: &String) -> bool { |
| 5417 | <JsString as PartialEq<str>>::eq(self, other) |
| 5418 | } |
| 5419 | } |
| 5420 | |
| 5421 | impl<'a> PartialEq<&'a String> for JsString { |
| 5422 | fn eq(&self, other: &&'a String) -> bool { |
| 5423 | <JsString as PartialEq<str>>::eq(self, other) |
| 5424 | } |
| 5425 | } |
| 5426 | |
| 5427 | impl<'a> From<&'a str> for JsString { |
| 5428 | fn from(s: &'a str) -> Self { |
| 5429 | JsString::unchecked_from_js(JsValue::from_str(s)) |
| 5430 | } |
| 5431 | } |
| 5432 | |
| 5433 | impl From<String> for JsString { |
| 5434 | fn from(s: String) -> Self { |
| 5435 | From::from(&*s) |
| 5436 | } |
| 5437 | } |
| 5438 | |
| 5439 | impl From<char> for JsString { |
| 5440 | #[inline ] |
| 5441 | fn from(c: char) -> Self { |
| 5442 | JsString::from_code_point1(c as u32).unwrap_throw() |
| 5443 | } |
| 5444 | } |
| 5445 | |
| 5446 | impl<'a> From<&'a JsString> for String { |
| 5447 | fn from(s: &'a JsString) -> Self { |
| 5448 | s.obj.as_string().unwrap_throw() |
| 5449 | } |
| 5450 | } |
| 5451 | |
| 5452 | impl From<JsString> for String { |
| 5453 | fn from(s: JsString) -> Self { |
| 5454 | From::from(&s) |
| 5455 | } |
| 5456 | } |
| 5457 | |
| 5458 | impl fmt::Debug for JsString { |
| 5459 | #[inline ] |
| 5460 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
| 5461 | fmt::Debug::fmt(&String::from(self), f) |
| 5462 | } |
| 5463 | } |
| 5464 | |
| 5465 | impl fmt::Display for JsString { |
| 5466 | #[inline ] |
| 5467 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
| 5468 | fmt::Display::fmt(&String::from(self), f) |
| 5469 | } |
| 5470 | } |
| 5471 | |
| 5472 | impl str::FromStr for JsString { |
| 5473 | type Err = convert::Infallible; |
| 5474 | fn from_str(s: &str) -> Result<Self, Self::Err> { |
| 5475 | Ok(JsString::from(s)) |
| 5476 | } |
| 5477 | } |
| 5478 | |
| 5479 | // Symbol |
| 5480 | #[wasm_bindgen ] |
| 5481 | unsafeextern "C" { |
| 5482 | #[wasm_bindgen (is_type_of = JsValue::is_symbol, typescript_type = "Symbol" )] |
| 5483 | #[derive (Clone, Debug)] |
| 5484 | pub type Symbol; |
| 5485 | |
| 5486 | /// The `Symbol.hasInstance` well-known symbol is used to determine |
| 5487 | /// if a constructor object recognizes an object as its instance. |
| 5488 | /// The `instanceof` operator's behavior can be customized by this symbol. |
| 5489 | /// |
| 5490 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/hasInstance) |
| 5491 | #[wasm_bindgen (static_method_of = Symbol, getter, structural, js_name = hasInstance)] |
| 5492 | pub unsafefn has_instance() -> Symbol; |
| 5493 | |
| 5494 | /// The `Symbol.isConcatSpreadable` well-known symbol is used to configure |
| 5495 | /// if an object should be flattened to its array elements when using the |
| 5496 | /// `Array.prototype.concat()` method. |
| 5497 | /// |
| 5498 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/isConcatSpreadable) |
| 5499 | #[wasm_bindgen (static_method_of = Symbol, getter, structural, js_name = isConcatSpreadable)] |
| 5500 | pub unsafefn is_concat_spreadable() -> Symbol; |
| 5501 | |
| 5502 | /// The `Symbol.asyncIterator` well-known symbol specifies the default AsyncIterator for an object. |
| 5503 | /// If this property is set on an object, it is an async iterable and can be used in a `for await...of` loop. |
| 5504 | /// |
| 5505 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/asyncIterator) |
| 5506 | #[wasm_bindgen (static_method_of = Symbol, getter, structural, js_name = asyncIterator)] |
| 5507 | pub unsafefn async_iterator() -> Symbol; |
| 5508 | |
| 5509 | /// The `Symbol.iterator` well-known symbol specifies the default iterator |
| 5510 | /// for an object. Used by `for...of`. |
| 5511 | /// |
| 5512 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/iterator) |
| 5513 | #[wasm_bindgen (static_method_of = Symbol, getter, structural)] |
| 5514 | pub unsafefn iterator() -> Symbol; |
| 5515 | |
| 5516 | /// The `Symbol.match` well-known symbol specifies the matching of a regular |
| 5517 | /// expression against a string. This function is called by the |
| 5518 | /// `String.prototype.match()` method. |
| 5519 | /// |
| 5520 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/match) |
| 5521 | #[wasm_bindgen (static_method_of = Symbol, getter, structural, js_name = match)] |
| 5522 | pub unsafefn match_() -> Symbol; |
| 5523 | |
| 5524 | /// The `Symbol.replace` well-known symbol specifies the method that |
| 5525 | /// replaces matched substrings of a string. This function is called by the |
| 5526 | /// `String.prototype.replace()` method. |
| 5527 | /// |
| 5528 | /// For more information, see `RegExp.prototype[@@replace]()` and |
| 5529 | /// `String.prototype.replace()`. |
| 5530 | /// |
| 5531 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/replace) |
| 5532 | #[wasm_bindgen (static_method_of = Symbol, getter, structural)] |
| 5533 | pub unsafefn replace() -> Symbol; |
| 5534 | |
| 5535 | /// The `Symbol.search` well-known symbol specifies the method that returns |
| 5536 | /// the index within a string that matches the regular expression. This |
| 5537 | /// function is called by the `String.prototype.search()` method. |
| 5538 | /// |
| 5539 | /// For more information, see `RegExp.prototype[@@search]()` and |
| 5540 | /// `String.prototype.search()`. |
| 5541 | /// |
| 5542 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/search) |
| 5543 | #[wasm_bindgen (static_method_of = Symbol, getter, structural)] |
| 5544 | pub unsafefn search() -> Symbol; |
| 5545 | |
| 5546 | /// The well-known symbol `Symbol.species` specifies a function-valued |
| 5547 | /// property that the constructor function uses to create derived objects. |
| 5548 | /// |
| 5549 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/species) |
| 5550 | #[wasm_bindgen (static_method_of = Symbol, getter, structural)] |
| 5551 | pub unsafefn species() -> Symbol; |
| 5552 | |
| 5553 | /// The `Symbol.split` well-known symbol specifies the method that splits a |
| 5554 | /// string at the indices that match a regular expression. This function is |
| 5555 | /// called by the `String.prototype.split()` method. |
| 5556 | /// |
| 5557 | /// For more information, see `RegExp.prototype[@@split]()` and |
| 5558 | /// `String.prototype.split()`. |
| 5559 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/split) |
| 5560 | #[wasm_bindgen (static_method_of = Symbol, getter, structural)] |
| 5561 | pub unsafefn split() -> Symbol; |
| 5562 | |
| 5563 | /// The `Symbol.toPrimitive` is a symbol that specifies a function valued |
| 5564 | /// property that is called to convert an object to a corresponding |
| 5565 | /// primitive value. |
| 5566 | /// |
| 5567 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toPrimitive) |
| 5568 | #[wasm_bindgen (static_method_of = Symbol, getter, structural, js_name = toPrimitive)] |
| 5569 | pub unsafefn to_primitive() -> Symbol; |
| 5570 | |
| 5571 | /// The `Symbol.toStringTag` well-known symbol is a string valued property |
| 5572 | /// that is used in the creation of the default string description of an |
| 5573 | /// object. It is accessed internally by the `Object.prototype.toString()` |
| 5574 | /// method. |
| 5575 | /// |
| 5576 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toString) |
| 5577 | #[wasm_bindgen (static_method_of = Symbol, getter, structural, js_name = toStringTag)] |
| 5578 | pub unsafefn to_string_tag() -> Symbol; |
| 5579 | |
| 5580 | /// The `Symbol.for(key)` method searches for existing symbols in a runtime-wide symbol registry with |
| 5581 | /// the given key and returns it if found. |
| 5582 | /// Otherwise a new symbol gets created in the global symbol registry with this key. |
| 5583 | /// |
| 5584 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/for) |
| 5585 | #[wasm_bindgen (static_method_of = Symbol, js_name = for)] |
| 5586 | pub unsafefn for_(key: &str) -> Symbol; |
| 5587 | |
| 5588 | /// The `Symbol.keyFor(sym)` method retrieves a shared symbol key from the global symbol registry for the given symbol. |
| 5589 | /// |
| 5590 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/keyFor) |
| 5591 | #[wasm_bindgen (static_method_of = Symbol, js_name = keyFor)] |
| 5592 | pub unsafefn key_for(sym: &Symbol) -> JsValue; |
| 5593 | |
| 5594 | /// The `toString()` method returns a string representing the specified Symbol object. |
| 5595 | /// |
| 5596 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toString) |
| 5597 | #[wasm_bindgen (method, js_name = toString)] |
| 5598 | pub unsafefn to_string(this: &Symbol) -> JsString; |
| 5599 | |
| 5600 | /// The `Symbol.unscopables` well-known symbol is used to specify an object |
| 5601 | /// value of whose own and inherited property names are excluded from the |
| 5602 | /// with environment bindings of the associated object. |
| 5603 | /// |
| 5604 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/unscopables) |
| 5605 | #[wasm_bindgen (static_method_of = Symbol, getter, structural)] |
| 5606 | pub unsafefn unscopables() -> Symbol; |
| 5607 | |
| 5608 | /// The `valueOf()` method returns the primitive value of a Symbol object. |
| 5609 | /// |
| 5610 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/valueOf) |
| 5611 | #[wasm_bindgen (method, js_name = valueOf)] |
| 5612 | pub unsafefn value_of(this: &Symbol) -> Symbol; |
| 5613 | } |
| 5614 | |
| 5615 | #[allow (non_snake_case)] |
| 5616 | pub mod Intl { |
| 5617 | use super::*; |
| 5618 | |
| 5619 | // Intl |
| 5620 | #[wasm_bindgen ] |
| 5621 | extern "C" { |
| 5622 | /// The `Intl.getCanonicalLocales()` method returns an array containing |
| 5623 | /// the canonical locale names. Duplicates will be omitted and elements |
| 5624 | /// will be validated as structurally valid language tags. |
| 5625 | /// |
| 5626 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/getCanonicalLocales) |
| 5627 | #[wasm_bindgen (js_name = getCanonicalLocales, js_namespace = Intl)] |
| 5628 | pub fn get_canonical_locales(s: &JsValue) -> Array; |
| 5629 | } |
| 5630 | |
| 5631 | // Intl.Collator |
| 5632 | #[wasm_bindgen ] |
| 5633 | extern "C" { |
| 5634 | /// The `Intl.Collator` object is a constructor for collators, objects |
| 5635 | /// that enable language sensitive string comparison. |
| 5636 | /// |
| 5637 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator) |
| 5638 | #[wasm_bindgen (extends = Object, js_namespace = Intl, typescript_type = "Intl.Collator" )] |
| 5639 | #[derive (Clone, Debug)] |
| 5640 | pub type Collator; |
| 5641 | |
| 5642 | /// The `Intl.Collator` object is a constructor for collators, objects |
| 5643 | /// that enable language sensitive string comparison. |
| 5644 | /// |
| 5645 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator) |
| 5646 | #[wasm_bindgen (constructor, js_namespace = Intl)] |
| 5647 | pub fn new(locales: &Array, options: &Object) -> Collator; |
| 5648 | |
| 5649 | /// The Intl.Collator.prototype.compare property returns a function that |
| 5650 | /// compares two strings according to the sort order of this Collator |
| 5651 | /// object. |
| 5652 | /// |
| 5653 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/compare) |
| 5654 | #[wasm_bindgen (method, getter, js_class = "Intl.Collator" )] |
| 5655 | pub fn compare(this: &Collator) -> Function; |
| 5656 | |
| 5657 | /// The `Intl.Collator.prototype.resolvedOptions()` method returns a new |
| 5658 | /// object with properties reflecting the locale and collation options |
| 5659 | /// computed during initialization of this Collator object. |
| 5660 | /// |
| 5661 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/resolvedOptions) |
| 5662 | #[wasm_bindgen (method, js_namespace = Intl, js_name = resolvedOptions)] |
| 5663 | pub fn resolved_options(this: &Collator) -> Object; |
| 5664 | |
| 5665 | /// The `Intl.Collator.supportedLocalesOf()` method returns an array |
| 5666 | /// containing those of the provided locales that are supported in |
| 5667 | /// collation without having to fall back to the runtime's default |
| 5668 | /// locale. |
| 5669 | /// |
| 5670 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/supportedLocalesOf) |
| 5671 | #[wasm_bindgen (static_method_of = Collator, js_namespace = Intl, js_name = supportedLocalesOf)] |
| 5672 | pub fn supported_locales_of(locales: &Array, options: &Object) -> Array; |
| 5673 | } |
| 5674 | |
| 5675 | impl Default for Collator { |
| 5676 | fn default() -> Self { |
| 5677 | Self::new( |
| 5678 | &JsValue::UNDEFINED.unchecked_into(), |
| 5679 | &JsValue::UNDEFINED.unchecked_into(), |
| 5680 | ) |
| 5681 | } |
| 5682 | } |
| 5683 | |
| 5684 | // Intl.DateTimeFormat |
| 5685 | #[wasm_bindgen ] |
| 5686 | extern "C" { |
| 5687 | /// The `Intl.DateTimeFormat` object is a constructor for objects |
| 5688 | /// that enable language-sensitive date and time formatting. |
| 5689 | /// |
| 5690 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat) |
| 5691 | #[wasm_bindgen (extends = Object, js_namespace = Intl, typescript_type = "Intl.DateTimeFormat" )] |
| 5692 | #[derive (Clone, Debug)] |
| 5693 | pub type DateTimeFormat; |
| 5694 | |
| 5695 | /// The `Intl.DateTimeFormat` object is a constructor for objects |
| 5696 | /// that enable language-sensitive date and time formatting. |
| 5697 | /// |
| 5698 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat) |
| 5699 | #[wasm_bindgen (constructor, js_namespace = Intl)] |
| 5700 | pub fn new(locales: &Array, options: &Object) -> DateTimeFormat; |
| 5701 | |
| 5702 | /// The Intl.DateTimeFormat.prototype.format property returns a getter function that |
| 5703 | /// formats a date according to the locale and formatting options of this |
| 5704 | /// Intl.DateTimeFormat object. |
| 5705 | /// |
| 5706 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/format) |
| 5707 | #[wasm_bindgen (method, getter, js_class = "Intl.DateTimeFormat" )] |
| 5708 | pub fn format(this: &DateTimeFormat) -> Function; |
| 5709 | |
| 5710 | /// The `Intl.DateTimeFormat.prototype.formatToParts()` method allows locale-aware |
| 5711 | /// formatting of strings produced by DateTimeFormat formatters. |
| 5712 | /// |
| 5713 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/formatToParts) |
| 5714 | #[wasm_bindgen (method, js_class = "Intl.DateTimeFormat" , js_name = formatToParts)] |
| 5715 | pub fn format_to_parts(this: &DateTimeFormat, date: &Date) -> Array; |
| 5716 | |
| 5717 | /// The `Intl.DateTimeFormat.prototype.resolvedOptions()` method returns a new |
| 5718 | /// object with properties reflecting the locale and date and time formatting |
| 5719 | /// options computed during initialization of this DateTimeFormat object. |
| 5720 | /// |
| 5721 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/resolvedOptions) |
| 5722 | #[wasm_bindgen (method, js_namespace = Intl, js_name = resolvedOptions)] |
| 5723 | pub fn resolved_options(this: &DateTimeFormat) -> Object; |
| 5724 | |
| 5725 | /// The `Intl.DateTimeFormat.supportedLocalesOf()` method returns an array |
| 5726 | /// containing those of the provided locales that are supported in date |
| 5727 | /// and time formatting without having to fall back to the runtime's default |
| 5728 | /// locale. |
| 5729 | /// |
| 5730 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/supportedLocalesOf) |
| 5731 | #[wasm_bindgen (static_method_of = DateTimeFormat, js_namespace = Intl, js_name = supportedLocalesOf)] |
| 5732 | pub fn supported_locales_of(locales: &Array, options: &Object) -> Array; |
| 5733 | } |
| 5734 | |
| 5735 | impl Default for DateTimeFormat { |
| 5736 | fn default() -> Self { |
| 5737 | Self::new( |
| 5738 | &JsValue::UNDEFINED.unchecked_into(), |
| 5739 | &JsValue::UNDEFINED.unchecked_into(), |
| 5740 | ) |
| 5741 | } |
| 5742 | } |
| 5743 | |
| 5744 | // Intl.NumberFormat |
| 5745 | #[wasm_bindgen ] |
| 5746 | extern "C" { |
| 5747 | /// The `Intl.NumberFormat` object is a constructor for objects |
| 5748 | /// that enable language sensitive number formatting. |
| 5749 | /// |
| 5750 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat) |
| 5751 | #[wasm_bindgen (extends = Object, js_namespace = Intl, typescript_type = "Intl.NumberFormat" )] |
| 5752 | #[derive (Clone, Debug)] |
| 5753 | pub type NumberFormat; |
| 5754 | |
| 5755 | /// The `Intl.NumberFormat` object is a constructor for objects |
| 5756 | /// that enable language sensitive number formatting. |
| 5757 | /// |
| 5758 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat) |
| 5759 | #[wasm_bindgen (constructor, js_namespace = Intl)] |
| 5760 | pub fn new(locales: &Array, options: &Object) -> NumberFormat; |
| 5761 | |
| 5762 | /// The Intl.NumberFormat.prototype.format property returns a getter function that |
| 5763 | /// formats a number according to the locale and formatting options of this |
| 5764 | /// NumberFormat object. |
| 5765 | /// |
| 5766 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/format) |
| 5767 | #[wasm_bindgen (method, getter, js_class = "Intl.NumberFormat" )] |
| 5768 | pub fn format(this: &NumberFormat) -> Function; |
| 5769 | |
| 5770 | /// The `Intl.Numberformat.prototype.formatToParts()` method allows locale-aware |
| 5771 | /// formatting of strings produced by NumberTimeFormat formatters. |
| 5772 | /// |
| 5773 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/formatToParts) |
| 5774 | #[wasm_bindgen (method, js_class = "Intl.NumberFormat" , js_name = formatToParts)] |
| 5775 | pub fn format_to_parts(this: &NumberFormat, number: f64) -> Array; |
| 5776 | |
| 5777 | /// The `Intl.NumberFormat.prototype.resolvedOptions()` method returns a new |
| 5778 | /// object with properties reflecting the locale and number formatting |
| 5779 | /// options computed during initialization of this NumberFormat object. |
| 5780 | /// |
| 5781 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/resolvedOptions) |
| 5782 | #[wasm_bindgen (method, js_namespace = Intl, js_name = resolvedOptions)] |
| 5783 | pub fn resolved_options(this: &NumberFormat) -> Object; |
| 5784 | |
| 5785 | /// The `Intl.NumberFormat.supportedLocalesOf()` method returns an array |
| 5786 | /// containing those of the provided locales that are supported in number |
| 5787 | /// formatting without having to fall back to the runtime's default locale. |
| 5788 | /// |
| 5789 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/supportedLocalesOf) |
| 5790 | #[wasm_bindgen (static_method_of = NumberFormat, js_namespace = Intl, js_name = supportedLocalesOf)] |
| 5791 | pub fn supported_locales_of(locales: &Array, options: &Object) -> Array; |
| 5792 | } |
| 5793 | |
| 5794 | impl Default for NumberFormat { |
| 5795 | fn default() -> Self { |
| 5796 | Self::new( |
| 5797 | &JsValue::UNDEFINED.unchecked_into(), |
| 5798 | &JsValue::UNDEFINED.unchecked_into(), |
| 5799 | ) |
| 5800 | } |
| 5801 | } |
| 5802 | |
| 5803 | // Intl.PluralRules |
| 5804 | #[wasm_bindgen ] |
| 5805 | extern "C" { |
| 5806 | /// The `Intl.PluralRules` object is a constructor for objects |
| 5807 | /// that enable plural sensitive formatting and plural language rules. |
| 5808 | /// |
| 5809 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules) |
| 5810 | #[wasm_bindgen (extends = Object, js_namespace = Intl, typescript_type = "Intl.PluralRules" )] |
| 5811 | #[derive (Clone, Debug)] |
| 5812 | pub type PluralRules; |
| 5813 | |
| 5814 | /// The `Intl.PluralRules` object is a constructor for objects |
| 5815 | /// that enable plural sensitive formatting and plural language rules. |
| 5816 | /// |
| 5817 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules) |
| 5818 | #[wasm_bindgen (constructor, js_namespace = Intl)] |
| 5819 | pub fn new(locales: &Array, options: &Object) -> PluralRules; |
| 5820 | |
| 5821 | /// The `Intl.PluralRules.prototype.resolvedOptions()` method returns a new |
| 5822 | /// object with properties reflecting the locale and plural formatting |
| 5823 | /// options computed during initialization of this PluralRules object. |
| 5824 | /// |
| 5825 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/resolvedOptions) |
| 5826 | #[wasm_bindgen (method, js_namespace = Intl, js_name = resolvedOptions)] |
| 5827 | pub fn resolved_options(this: &PluralRules) -> Object; |
| 5828 | |
| 5829 | /// The `Intl.PluralRules.prototype.select()` method returns a String indicating |
| 5830 | /// which plural rule to use for locale-aware formatting. |
| 5831 | /// |
| 5832 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/select) |
| 5833 | #[wasm_bindgen (method, js_namespace = Intl)] |
| 5834 | pub fn select(this: &PluralRules, number: f64) -> JsString; |
| 5835 | |
| 5836 | /// The `Intl.PluralRules.supportedLocalesOf()` method returns an array |
| 5837 | /// containing those of the provided locales that are supported in plural |
| 5838 | /// formatting without having to fall back to the runtime's default locale. |
| 5839 | /// |
| 5840 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/supportedLocalesOf) |
| 5841 | #[wasm_bindgen (static_method_of = PluralRules, js_namespace = Intl, js_name = supportedLocalesOf)] |
| 5842 | pub fn supported_locales_of(locales: &Array, options: &Object) -> Array; |
| 5843 | } |
| 5844 | |
| 5845 | impl Default for PluralRules { |
| 5846 | fn default() -> Self { |
| 5847 | Self::new( |
| 5848 | &JsValue::UNDEFINED.unchecked_into(), |
| 5849 | &JsValue::UNDEFINED.unchecked_into(), |
| 5850 | ) |
| 5851 | } |
| 5852 | } |
| 5853 | |
| 5854 | // Intl.RelativeTimeFormat |
| 5855 | #[wasm_bindgen ] |
| 5856 | extern "C" { |
| 5857 | /// The `Intl.RelativeTimeFormat` object is a constructor for objects |
| 5858 | /// that enable language-sensitive relative time formatting. |
| 5859 | /// |
| 5860 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat) |
| 5861 | #[wasm_bindgen (extends = Object, js_namespace = Intl, typescript_type = "Intl.RelativeTimeFormat" )] |
| 5862 | #[derive (Clone, Debug)] |
| 5863 | pub type RelativeTimeFormat; |
| 5864 | |
| 5865 | /// The `Intl.RelativeTimeFormat` object is a constructor for objects |
| 5866 | /// that enable language-sensitive relative time formatting. |
| 5867 | /// |
| 5868 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat) |
| 5869 | #[wasm_bindgen (constructor, js_namespace = Intl)] |
| 5870 | pub fn new(locales: &Array, options: &Object) -> RelativeTimeFormat; |
| 5871 | |
| 5872 | /// The `Intl.RelativeTimeFormat.prototype.format` method formats a `value` and `unit` |
| 5873 | /// according to the locale and formatting options of this Intl.RelativeTimeFormat object. |
| 5874 | /// |
| 5875 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/format) |
| 5876 | #[wasm_bindgen (method, js_class = "Intl.RelativeTimeFormat" )] |
| 5877 | pub fn format(this: &RelativeTimeFormat, value: f64, unit: &str) -> JsString; |
| 5878 | |
| 5879 | /// The `Intl.RelativeTimeFormat.prototype.formatToParts()` method returns an array of |
| 5880 | /// objects representing the relative time format in parts that can be used for custom locale-aware formatting. |
| 5881 | /// |
| 5882 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/formatToParts) |
| 5883 | #[wasm_bindgen (method, js_class = "Intl.RelativeTimeFormat" , js_name = formatToParts)] |
| 5884 | pub fn format_to_parts(this: &RelativeTimeFormat, value: f64, unit: &str) -> Array; |
| 5885 | |
| 5886 | /// The `Intl.RelativeTimeFormat.prototype.resolvedOptions()` method returns a new |
| 5887 | /// object with properties reflecting the locale and relative time formatting |
| 5888 | /// options computed during initialization of this RelativeTimeFormat object. |
| 5889 | /// |
| 5890 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/resolvedOptions) |
| 5891 | #[wasm_bindgen (method, js_namespace = Intl, js_name = resolvedOptions)] |
| 5892 | pub fn resolved_options(this: &RelativeTimeFormat) -> Object; |
| 5893 | |
| 5894 | /// The `Intl.RelativeTimeFormat.supportedLocalesOf()` method returns an array |
| 5895 | /// containing those of the provided locales that are supported in date and time |
| 5896 | /// formatting without having to fall back to the runtime's default locale. |
| 5897 | /// |
| 5898 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RelativeTimeFormat/supportedLocalesOf) |
| 5899 | #[wasm_bindgen (static_method_of = RelativeTimeFormat, js_namespace = Intl, js_name = supportedLocalesOf)] |
| 5900 | pub fn supported_locales_of(locales: &Array, options: &Object) -> Array; |
| 5901 | } |
| 5902 | |
| 5903 | impl Default for RelativeTimeFormat { |
| 5904 | fn default() -> Self { |
| 5905 | Self::new( |
| 5906 | &JsValue::UNDEFINED.unchecked_into(), |
| 5907 | &JsValue::UNDEFINED.unchecked_into(), |
| 5908 | ) |
| 5909 | } |
| 5910 | } |
| 5911 | } |
| 5912 | |
| 5913 | // Promise |
| 5914 | #[wasm_bindgen ] |
| 5915 | unsafeextern "C" { |
| 5916 | /// The `Promise` object represents the eventual completion (or failure) of |
| 5917 | /// an asynchronous operation, and its resulting value. |
| 5918 | /// |
| 5919 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) |
| 5920 | #[must_use ] |
| 5921 | #[wasm_bindgen (extends = Object, typescript_type = "Promise<any>" )] |
| 5922 | #[derive (Clone, Debug)] |
| 5923 | pub type Promise; |
| 5924 | |
| 5925 | /// Creates a new `Promise` with the provided executor `cb` |
| 5926 | /// |
| 5927 | /// The `cb` is a function that is passed with the arguments `resolve` and |
| 5928 | /// `reject`. The `cb` function is executed immediately by the `Promise` |
| 5929 | /// implementation, passing `resolve` and `reject` functions (the executor |
| 5930 | /// is called before the `Promise` constructor even returns the created |
| 5931 | /// object). The `resolve` and `reject` functions, when called, resolve or |
| 5932 | /// reject the promise, respectively. The executor normally initiates |
| 5933 | /// some asynchronous work, and then, once that completes, either calls |
| 5934 | /// the `resolve` function to resolve the promise or else rejects it if an |
| 5935 | /// error occurred. |
| 5936 | /// |
| 5937 | /// If an error is thrown in the executor function, the promise is rejected. |
| 5938 | /// The return value of the executor is ignored. |
| 5939 | /// |
| 5940 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) |
| 5941 | #[wasm_bindgen (constructor)] |
| 5942 | pub unsafefn new(cb: &mut dyn FnMut(Function, Function)) -> Promise; |
| 5943 | |
| 5944 | /// The `Promise.all(iterable)` method returns a single `Promise` that |
| 5945 | /// resolves when all of the promises in the iterable argument have resolved |
| 5946 | /// or when the iterable argument contains no promises. It rejects with the |
| 5947 | /// reason of the first promise that rejects. |
| 5948 | /// |
| 5949 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all) |
| 5950 | #[wasm_bindgen (static_method_of = Promise)] |
| 5951 | pub unsafefn all(obj: &JsValue) -> Promise; |
| 5952 | |
| 5953 | /// The `Promise.allSettled(iterable)` method returns a single `Promise` that |
| 5954 | /// resolves when all of the promises in the iterable argument have either |
| 5955 | /// fulfilled or rejected or when the iterable argument contains no promises. |
| 5956 | /// |
| 5957 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled) |
| 5958 | #[wasm_bindgen (static_method_of = Promise, js_name = allSettled)] |
| 5959 | pub unsafefn all_settled(obj: &JsValue) -> Promise; |
| 5960 | |
| 5961 | /// The `Promise.any(iterable)` method returns a single `Promise` that |
| 5962 | /// resolves when any of the promises in the iterable argument have resolved |
| 5963 | /// or when the iterable argument contains no promises. It rejects with an |
| 5964 | /// `AggregateError` if all promises in the iterable rejected. |
| 5965 | /// |
| 5966 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/any) |
| 5967 | #[wasm_bindgen (static_method_of = Promise)] |
| 5968 | pub unsafefn any(obj: &JsValue) -> Promise; |
| 5969 | |
| 5970 | /// The `Promise.race(iterable)` method returns a promise that resolves or |
| 5971 | /// rejects as soon as one of the promises in the iterable resolves or |
| 5972 | /// rejects, with the value or reason from that promise. |
| 5973 | /// |
| 5974 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/race) |
| 5975 | #[wasm_bindgen (static_method_of = Promise)] |
| 5976 | pub unsafefn race(obj: &JsValue) -> Promise; |
| 5977 | |
| 5978 | /// The `Promise.reject(reason)` method returns a `Promise` object that is |
| 5979 | /// rejected with the given reason. |
| 5980 | /// |
| 5981 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/reject) |
| 5982 | #[wasm_bindgen (static_method_of = Promise)] |
| 5983 | pub unsafefn reject(obj: &JsValue) -> Promise; |
| 5984 | |
| 5985 | /// The `Promise.resolve(value)` method returns a `Promise` object that is |
| 5986 | /// resolved with the given value. If the value is a promise, that promise |
| 5987 | /// is returned; if the value is a thenable (i.e. has a "then" method), the |
| 5988 | /// returned promise will "follow" that thenable, adopting its eventual |
| 5989 | /// state; otherwise the returned promise will be fulfilled with the value. |
| 5990 | /// |
| 5991 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/resolve) |
| 5992 | #[wasm_bindgen (static_method_of = Promise)] |
| 5993 | pub unsafefn resolve(obj: &JsValue) -> Promise; |
| 5994 | |
| 5995 | /// The `catch()` method returns a `Promise` and deals with rejected cases |
| 5996 | /// only. It behaves the same as calling `Promise.prototype.then(undefined, |
| 5997 | /// onRejected)` (in fact, calling `obj.catch(onRejected)` internally calls |
| 5998 | /// `obj.then(undefined, onRejected)`). |
| 5999 | /// |
| 6000 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch) |
| 6001 | #[wasm_bindgen (method)] |
| 6002 | pub unsafefn catch(this: &Promise, cb: &Closure<dyn FnMut(JsValue)>) -> Promise; |
| 6003 | |
| 6004 | /// The `then()` method returns a `Promise`. It takes up to two arguments: |
| 6005 | /// callback functions for the success and failure cases of the `Promise`. |
| 6006 | /// |
| 6007 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then) |
| 6008 | #[wasm_bindgen (method)] |
| 6009 | pub unsafefn then(this: &Promise, cb: &Closure<dyn FnMut(JsValue)>) -> Promise; |
| 6010 | |
| 6011 | /// Same as `then`, only with both arguments provided. |
| 6012 | #[wasm_bindgen (method, js_name = then)] |
| 6013 | pub unsafefn then2( |
| 6014 | this: &Promise, |
| 6015 | resolve: &Closure<dyn FnMut(JsValue)>, |
| 6016 | reject: &Closure<dyn FnMut(JsValue)>, |
| 6017 | ) -> Promise; |
| 6018 | |
| 6019 | /// The `finally()` method returns a `Promise`. When the promise is settled, |
| 6020 | /// whether fulfilled or rejected, the specified callback function is |
| 6021 | /// executed. This provides a way for code that must be executed once the |
| 6022 | /// `Promise` has been dealt with to be run whether the promise was |
| 6023 | /// fulfilled successfully or rejected. |
| 6024 | /// |
| 6025 | /// This lets you avoid duplicating code in both the promise's `then()` and |
| 6026 | /// `catch()` handlers. |
| 6027 | /// |
| 6028 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/finally) |
| 6029 | #[wasm_bindgen (method)] |
| 6030 | pub unsafefn finally(this: &Promise, cb: &Closure<dyn FnMut()>) -> Promise; |
| 6031 | } |
| 6032 | |
| 6033 | /// Returns a handle to the global scope object. |
| 6034 | /// |
| 6035 | /// This allows access to the global properties and global names by accessing |
| 6036 | /// the `Object` returned. |
| 6037 | pub fn global() -> Object { |
| 6038 | use once_cell::unsync::Lazy; |
| 6039 | |
| 6040 | struct Wrapper<T>(Lazy<T>); |
| 6041 | |
| 6042 | #[cfg (not(target_feature = "atomics" ))] |
| 6043 | unsafe impl<T> Sync for Wrapper<T> {} |
| 6044 | |
| 6045 | #[cfg (not(target_feature = "atomics" ))] |
| 6046 | unsafe impl<T> Send for Wrapper<T> {} |
| 6047 | |
| 6048 | #[cfg_attr (target_feature = "atomics" , thread_local)] |
| 6049 | static GLOBAL: Wrapper<Object> = Wrapper(Lazy::new(get_global_object)); |
| 6050 | |
| 6051 | return GLOBAL.0.clone(); |
| 6052 | |
| 6053 | fn get_global_object() -> Object { |
| 6054 | // Accessing the global object is not an easy thing to do, and what we |
| 6055 | // basically want is `globalThis` but we can't rely on that existing |
| 6056 | // everywhere. In the meantime we've got the fallbacks mentioned in: |
| 6057 | // |
| 6058 | // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis |
| 6059 | // |
| 6060 | // Note that this is pretty heavy code-size wise but it at least gets |
| 6061 | // the job largely done for now and avoids the `Function` constructor at |
| 6062 | // the end which triggers CSP errors. |
| 6063 | #[wasm_bindgen ] |
| 6064 | extern "C" { |
| 6065 | type Global; |
| 6066 | |
| 6067 | #[wasm_bindgen (thread_local_v2, js_name = globalThis)] |
| 6068 | static GLOBAL_THIS: Option<Object>; |
| 6069 | |
| 6070 | #[wasm_bindgen (thread_local_v2, js_name = self)] |
| 6071 | static SELF: Option<Object>; |
| 6072 | |
| 6073 | #[wasm_bindgen (thread_local_v2, js_name = window)] |
| 6074 | static WINDOW: Option<Object>; |
| 6075 | |
| 6076 | #[wasm_bindgen (thread_local_v2, js_name = global)] |
| 6077 | static GLOBAL: Option<Object>; |
| 6078 | } |
| 6079 | |
| 6080 | // The order is important: in Firefox Extension Content Scripts `globalThis` |
| 6081 | // is a Sandbox (not Window), so `globalThis` must be checked after `window`. |
| 6082 | let static_object = SELF |
| 6083 | .with(Option::clone) |
| 6084 | .or_else(|| WINDOW.with(Option::clone)) |
| 6085 | .or_else(|| GLOBAL_THIS.with(Option::clone)) |
| 6086 | .or_else(|| GLOBAL.with(Option::clone)); |
| 6087 | if let Some(obj) = static_object { |
| 6088 | if !obj.is_undefined() { |
| 6089 | return obj; |
| 6090 | } |
| 6091 | } |
| 6092 | |
| 6093 | // According to StackOverflow you can access the global object via: |
| 6094 | // |
| 6095 | // const global = Function('return this')(); |
| 6096 | // |
| 6097 | // I think that's because the manufactured function isn't in "strict" mode. |
| 6098 | // It also turns out that non-strict functions will ignore `undefined` |
| 6099 | // values for `this` when using the `apply` function. |
| 6100 | // |
| 6101 | // As a result we use the equivalent of this snippet to get a handle to the |
| 6102 | // global object in a sort of roundabout way that should hopefully work in |
| 6103 | // all contexts like ESM, node, browsers, etc. |
| 6104 | let this = Function::new_no_args("return this" ) |
| 6105 | .call0(&JsValue::undefined()) |
| 6106 | .ok(); |
| 6107 | |
| 6108 | // Note that we avoid `unwrap()` on `call0` to avoid code size bloat, we |
| 6109 | // just handle the `Err` case as returning a different object. |
| 6110 | debug_assert!(this.is_some()); |
| 6111 | match this { |
| 6112 | Some(this) => this.unchecked_into(), |
| 6113 | None => JsValue::undefined().unchecked_into(), |
| 6114 | } |
| 6115 | } |
| 6116 | } |
| 6117 | |
| 6118 | macro_rules! arrays { |
| 6119 | ($(#[doc = $ctor:literal] #[doc = $mdn:literal] $name:ident: $ty:ident,)*) => ($( |
| 6120 | #[wasm_bindgen] |
| 6121 | extern "C" { |
| 6122 | #[wasm_bindgen(extends = Object, typescript_type = $name)] |
| 6123 | #[derive(Clone, Debug)] |
| 6124 | pub type $name; |
| 6125 | |
| 6126 | /// The |
| 6127 | #[doc = $ctor] |
| 6128 | /// constructor creates a new array. |
| 6129 | /// |
| 6130 | /// [MDN documentation]( |
| 6131 | #[doc = $mdn] |
| 6132 | /// ) |
| 6133 | #[wasm_bindgen(constructor)] |
| 6134 | pub fn new(constructor_arg: &JsValue) -> $name; |
| 6135 | |
| 6136 | /// An |
| 6137 | #[doc = $ctor] |
| 6138 | /// which creates an array with an internal buffer large |
| 6139 | /// enough for `length` elements. |
| 6140 | /// |
| 6141 | /// [MDN documentation]( |
| 6142 | #[doc = $mdn] |
| 6143 | /// ) |
| 6144 | #[wasm_bindgen(constructor)] |
| 6145 | pub fn new_with_length(length: u32) -> $name; |
| 6146 | |
| 6147 | /// An |
| 6148 | #[doc = $ctor] |
| 6149 | /// which creates an array with the given buffer but is a |
| 6150 | /// view starting at `byte_offset`. |
| 6151 | /// |
| 6152 | /// [MDN documentation]( |
| 6153 | #[doc = $mdn] |
| 6154 | /// ) |
| 6155 | #[wasm_bindgen(constructor)] |
| 6156 | pub fn new_with_byte_offset(buffer: &JsValue, byte_offset: u32) -> $name; |
| 6157 | |
| 6158 | /// An |
| 6159 | #[doc = $ctor] |
| 6160 | /// which creates an array with the given buffer but is a |
| 6161 | /// view starting at `byte_offset` for `length` elements. |
| 6162 | /// |
| 6163 | /// [MDN documentation]( |
| 6164 | #[doc = $mdn] |
| 6165 | /// ) |
| 6166 | #[wasm_bindgen(constructor)] |
| 6167 | pub fn new_with_byte_offset_and_length( |
| 6168 | buffer: &JsValue, |
| 6169 | byte_offset: u32, |
| 6170 | length: u32, |
| 6171 | ) -> $name; |
| 6172 | |
| 6173 | /// The `fill()` method fills all the elements of an array from a start index |
| 6174 | /// to an end index with a static value. The end index is not included. |
| 6175 | /// |
| 6176 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/fill) |
| 6177 | #[wasm_bindgen(method)] |
| 6178 | pub fn fill(this: &$name, value: $ty, start: u32, end: u32) -> $name; |
| 6179 | |
| 6180 | /// The buffer accessor property represents the `ArrayBuffer` referenced |
| 6181 | /// by a `TypedArray` at construction time. |
| 6182 | #[wasm_bindgen(getter, method)] |
| 6183 | pub fn buffer(this: &$name) -> ArrayBuffer; |
| 6184 | |
| 6185 | /// The `subarray()` method returns a new `TypedArray` on the same |
| 6186 | /// `ArrayBuffer` store and with the same element types as for this |
| 6187 | /// `TypedArray` object. |
| 6188 | #[wasm_bindgen(method)] |
| 6189 | pub fn subarray(this: &$name, begin: u32, end: u32) -> $name; |
| 6190 | |
| 6191 | /// The `slice()` method returns a shallow copy of a portion of a typed |
| 6192 | /// array into a new typed array object. This method has the same algorithm |
| 6193 | /// as `Array.prototype.slice()`. |
| 6194 | #[wasm_bindgen(method)] |
| 6195 | pub fn slice(this: &$name, begin: u32, end: u32) -> $name; |
| 6196 | |
| 6197 | /// The `forEach()` method executes a provided function once per array |
| 6198 | /// element. This method has the same algorithm as |
| 6199 | /// `Array.prototype.forEach()`. `TypedArray` is one of the typed array |
| 6200 | /// types here. |
| 6201 | #[wasm_bindgen(method, js_name = forEach)] |
| 6202 | pub fn for_each(this: &$name, callback: &mut dyn FnMut($ty, u32, $name)); |
| 6203 | |
| 6204 | /// The length accessor property represents the length (in elements) of a |
| 6205 | /// typed array. |
| 6206 | #[wasm_bindgen(method, getter)] |
| 6207 | pub fn length(this: &$name) -> u32; |
| 6208 | |
| 6209 | /// The byteLength accessor property represents the length (in bytes) of a |
| 6210 | /// typed array. |
| 6211 | #[wasm_bindgen(method, getter, js_name = byteLength)] |
| 6212 | pub fn byte_length(this: &$name) -> u32; |
| 6213 | |
| 6214 | /// The byteOffset accessor property represents the offset (in bytes) of a |
| 6215 | /// typed array from the start of its `ArrayBuffer`. |
| 6216 | #[wasm_bindgen(method, getter, js_name = byteOffset)] |
| 6217 | pub fn byte_offset(this: &$name) -> u32; |
| 6218 | |
| 6219 | /// The `set()` method stores multiple values in the typed array, reading |
| 6220 | /// input values from a specified array. |
| 6221 | #[wasm_bindgen(method)] |
| 6222 | pub fn set(this: &$name, src: &JsValue, offset: u32); |
| 6223 | |
| 6224 | /// Gets the value at `idx`, counting from the end if negative. |
| 6225 | #[wasm_bindgen(method)] |
| 6226 | pub fn at(this: &$name, idx: i32) -> Option<$ty>; |
| 6227 | |
| 6228 | /// The `copyWithin()` method shallow copies part of a typed array to another |
| 6229 | /// location in the same typed array and returns it, without modifying its size. |
| 6230 | /// |
| 6231 | /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin) |
| 6232 | #[wasm_bindgen(method, js_name = copyWithin)] |
| 6233 | pub fn copy_within(this: &$name, target: i32, start: i32, end: i32) -> $name; |
| 6234 | |
| 6235 | /// Gets the value at `idx`, equivalent to the javascript `my_var = arr[idx]`. |
| 6236 | #[wasm_bindgen(method, structural, indexing_getter)] |
| 6237 | pub fn get_index(this: &$name, idx: u32) -> $ty; |
| 6238 | |
| 6239 | /// Sets the value at `idx`, equivalent to the javascript `arr[idx] = value`. |
| 6240 | #[wasm_bindgen(method, structural, indexing_setter)] |
| 6241 | pub fn set_index(this: &$name, idx: u32, value: $ty); |
| 6242 | } |
| 6243 | |
| 6244 | impl $name { |
| 6245 | /// Creates a JS typed array which is a view into wasm's linear |
| 6246 | /// memory at the slice specified. |
| 6247 | /// |
| 6248 | /// This function returns a new typed array which is a view into |
| 6249 | /// wasm's memory. This view does not copy the underlying data. |
| 6250 | /// |
| 6251 | /// # Safety |
| 6252 | /// |
| 6253 | /// Views into WebAssembly memory are only valid so long as the |
| 6254 | /// backing buffer isn't resized in JS. Once this function is called |
| 6255 | /// any future calls to `Box::new` (or malloc of any form) may cause |
| 6256 | /// the returned value here to be invalidated. Use with caution! |
| 6257 | /// |
| 6258 | /// Additionally the returned object can be safely mutated but the |
| 6259 | /// input slice isn't guaranteed to be mutable. |
| 6260 | /// |
| 6261 | /// Finally, the returned object is disconnected from the input |
| 6262 | /// slice's lifetime, so there's no guarantee that the data is read |
| 6263 | /// at the right time. |
| 6264 | pub unsafe fn view(rust: &[$ty]) -> $name { |
| 6265 | let buf = wasm_bindgen::memory(); |
| 6266 | let mem = buf.unchecked_ref::<WebAssembly::Memory>(); |
| 6267 | $name::new_with_byte_offset_and_length( |
| 6268 | &mem.buffer(), |
| 6269 | rust.as_ptr() as u32, |
| 6270 | rust.len() as u32, |
| 6271 | ) |
| 6272 | } |
| 6273 | |
| 6274 | /// Creates a JS typed array which is a view into wasm's linear |
| 6275 | /// memory at the specified pointer with specified length. |
| 6276 | /// |
| 6277 | /// This function returns a new typed array which is a view into |
| 6278 | /// wasm's memory. This view does not copy the underlying data. |
| 6279 | /// |
| 6280 | /// # Safety |
| 6281 | /// |
| 6282 | /// Views into WebAssembly memory are only valid so long as the |
| 6283 | /// backing buffer isn't resized in JS. Once this function is called |
| 6284 | /// any future calls to `Box::new` (or malloc of any form) may cause |
| 6285 | /// the returned value here to be invalidated. Use with caution! |
| 6286 | /// |
| 6287 | /// Additionally the returned object can be safely mutated, |
| 6288 | /// the changes are guaranteed to be reflected in the input array. |
| 6289 | pub unsafe fn view_mut_raw(ptr: *mut $ty, length: usize) -> $name { |
| 6290 | let buf = wasm_bindgen::memory(); |
| 6291 | let mem = buf.unchecked_ref::<WebAssembly::Memory>(); |
| 6292 | $name::new_with_byte_offset_and_length( |
| 6293 | &mem.buffer(), |
| 6294 | ptr as u32, |
| 6295 | length as u32 |
| 6296 | ) |
| 6297 | } |
| 6298 | |
| 6299 | |
| 6300 | /// Copy the contents of this JS typed array into the destination |
| 6301 | /// Rust pointer. |
| 6302 | /// |
| 6303 | /// This function will efficiently copy the memory from a typed |
| 6304 | /// array into this Wasm module's own linear memory, initializing |
| 6305 | /// the memory destination provided. |
| 6306 | /// |
| 6307 | /// # Safety |
| 6308 | /// |
| 6309 | /// This function requires `dst` to point to a buffer |
| 6310 | /// large enough to fit this array's contents. |
| 6311 | pub unsafe fn raw_copy_to_ptr(&self, dst: *mut $ty) { |
| 6312 | let buf = wasm_bindgen::memory(); |
| 6313 | let mem = buf.unchecked_ref::<WebAssembly::Memory>(); |
| 6314 | let all_wasm_memory = $name::new(&mem.buffer()); |
| 6315 | let offset = dst as usize / mem::size_of::<$ty>(); |
| 6316 | all_wasm_memory.set(self, offset as u32); |
| 6317 | } |
| 6318 | |
| 6319 | /// Copy the contents of this JS typed array into the destination |
| 6320 | /// Rust slice. |
| 6321 | /// |
| 6322 | /// This function will efficiently copy the memory from a typed |
| 6323 | /// array into this Wasm module's own linear memory, initializing |
| 6324 | /// the memory destination provided. |
| 6325 | /// |
| 6326 | /// # Panics |
| 6327 | /// |
| 6328 | /// This function will panic if this typed array's length is |
| 6329 | /// different than the length of the provided `dst` array. |
| 6330 | pub fn copy_to(&self, dst: &mut [$ty]) { |
| 6331 | core::assert_eq!(self.length() as usize, dst.len()); |
| 6332 | unsafe { self.raw_copy_to_ptr(dst.as_mut_ptr()); } |
| 6333 | } |
| 6334 | |
| 6335 | /// Copy the contents of this JS typed array into the destination |
| 6336 | /// Rust slice. |
| 6337 | /// |
| 6338 | /// This function will efficiently copy the memory from a typed |
| 6339 | /// array into this Wasm module's own linear memory, initializing |
| 6340 | /// the memory destination provided. |
| 6341 | /// |
| 6342 | /// # Panics |
| 6343 | /// |
| 6344 | /// This function will panic if this typed array's length is |
| 6345 | /// different than the length of the provided `dst` array. |
| 6346 | pub fn copy_to_uninit<'dst>(&self, dst: &'dst mut [MaybeUninit<$ty>]) -> &'dst mut [$ty] { |
| 6347 | core::assert_eq!(self.length() as usize, dst.len()); |
| 6348 | unsafe { self.raw_copy_to_ptr(dst.as_mut_ptr().cast()); } |
| 6349 | unsafe { &mut *(dst as *mut [MaybeUninit<$ty>] as *mut [$ty]) } |
| 6350 | } |
| 6351 | |
| 6352 | /// Copy the contents of the source Rust slice into this |
| 6353 | /// JS typed array. |
| 6354 | /// |
| 6355 | /// This function will efficiently copy the memory from within |
| 6356 | /// the Wasm module's own linear memory to this typed array. |
| 6357 | /// |
| 6358 | /// # Panics |
| 6359 | /// |
| 6360 | /// This function will panic if this typed array's length is |
| 6361 | /// different than the length of the provided `src` array. |
| 6362 | pub fn copy_from(&self, src: &[$ty]) { |
| 6363 | core::assert_eq!(self.length() as usize, src.len()); |
| 6364 | // This is safe because the `set` function copies from its TypedArray argument |
| 6365 | unsafe { self.set(&$name::view(src), 0) } |
| 6366 | } |
| 6367 | |
| 6368 | /// Efficiently copies the contents of this JS typed array into a new Vec. |
| 6369 | pub fn to_vec(&self) -> Vec<$ty> { |
| 6370 | let mut output = Vec::with_capacity(self.length() as usize); |
| 6371 | unsafe { |
| 6372 | self.raw_copy_to_ptr(output.as_mut_ptr()); |
| 6373 | output.set_len(self.length() as usize); |
| 6374 | } |
| 6375 | output |
| 6376 | } |
| 6377 | } |
| 6378 | |
| 6379 | impl<'a> From<&'a [$ty]> for $name { |
| 6380 | #[inline] |
| 6381 | fn from(slice: &'a [$ty]) -> $name { |
| 6382 | // This is safe because the `new` function makes a copy if its argument is a TypedArray |
| 6383 | unsafe { $name::new(&$name::view(slice)) } |
| 6384 | } |
| 6385 | } |
| 6386 | |
| 6387 | impl Default for $name { |
| 6388 | fn default() -> Self { |
| 6389 | Self::new(&JsValue::UNDEFINED.unchecked_into()) |
| 6390 | } |
| 6391 | } |
| 6392 | )*); |
| 6393 | } |
| 6394 | |
| 6395 | arrays! { |
| 6396 | /// `Int8Array()` |
| 6397 | /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int8Array |
| 6398 | Int8Array: i8, |
| 6399 | |
| 6400 | /// `Int16Array()` |
| 6401 | /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int16Array |
| 6402 | Int16Array: i16, |
| 6403 | |
| 6404 | /// `Int32Array()` |
| 6405 | /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int32Array |
| 6406 | Int32Array: i32, |
| 6407 | |
| 6408 | /// `Uint8Array()` |
| 6409 | /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array |
| 6410 | Uint8Array: u8, |
| 6411 | |
| 6412 | /// `Uint8ClampedArray()` |
| 6413 | /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8ClampedArray |
| 6414 | Uint8ClampedArray: u8, |
| 6415 | |
| 6416 | /// `Uint16Array()` |
| 6417 | /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint16Array |
| 6418 | Uint16Array: u16, |
| 6419 | |
| 6420 | /// `Uint32Array()` |
| 6421 | /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint32Array |
| 6422 | Uint32Array: u32, |
| 6423 | |
| 6424 | /// `Float32Array()` |
| 6425 | /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array |
| 6426 | Float32Array: f32, |
| 6427 | |
| 6428 | /// `Float64Array()` |
| 6429 | /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float64Array |
| 6430 | Float64Array: f64, |
| 6431 | |
| 6432 | /// `BigInt64Array()` |
| 6433 | /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt64Array |
| 6434 | BigInt64Array: i64, |
| 6435 | |
| 6436 | /// `BigUint64Array()` |
| 6437 | /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigUint64Array |
| 6438 | BigUint64Array: u64, |
| 6439 | } |
| 6440 | |