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
21 use std::convert;
22 use std::f64;
23 use std::fmt;
24 use std::mem;
25 use std::str;
26
27 use wasm_bindgen::prelude::*;
28 use wasm_bindgen::JsCast;
29
30 // When adding new imports:
31 //
32 // * Keep imports in alphabetical order.
33 //
34 // * Rename imports with `js_name = ...` according to the note about `camelCase`
35 // and `snake_case` in the module's documentation above.
36 //
37 // * Include the one sentence summary of the import from the MDN link in the
38 // module's documentation above, and the MDN link itself.
39 //
40 // * If a function or method can throw an exception, make it catchable by adding
41 // `#[wasm_bindgen(catch)]`.
42 //
43 // * Add a new `#[test]` into the appropriate file in the
44 // `crates/js-sys/tests/wasm/` directory. If the imported function or method
45 // can throw an exception, make sure to also add test coverage for that case.
46 //
47 // * Arguments that are `JsValue`s or imported JavaScript types should be taken
48 // by reference.
49
50 #[wasm_bindgen]
51 extern "C" {
52 /// The `decodeURI()` function decodes a Uniform Resource Identifier (URI)
53 /// previously created by `encodeURI` or by a similar routine.
54 ///
55 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURI)
56 #[wasm_bindgen(catch, js_name = decodeURI)]
decode_uri(encoded: &str) -> Result<JsString, JsValue>57 pub fn decode_uri(encoded: &str) -> Result<JsString, JsValue>;
58
59 /// The `decodeURIComponent()` function decodes a Uniform Resource Identifier (URI) component
60 /// previously created by `encodeURIComponent` or by a similar routine.
61 ///
62 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURIComponent)
63 #[wasm_bindgen(catch, js_name = decodeURIComponent)]
decode_uri_component(encoded: &str) -> Result<JsString, JsValue>64 pub fn decode_uri_component(encoded: &str) -> Result<JsString, JsValue>;
65
66 /// The `encodeURI()` function encodes a Uniform Resource Identifier (URI)
67 /// by replacing each instance of certain characters by one, two, three, or
68 /// four escape sequences representing the UTF-8 encoding of the character
69 /// (will only be four escape sequences for characters composed of two
70 /// "surrogate" characters).
71 ///
72 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURI)
73 #[wasm_bindgen(js_name = encodeURI)]
encode_uri(decoded: &str) -> JsString74 pub fn encode_uri(decoded: &str) -> JsString;
75
76 /// The `encodeURIComponent()` function encodes a Uniform Resource Identifier (URI) component
77 /// by replacing each instance of certain characters by one, two, three, or four escape sequences
78 /// representing the UTF-8 encoding of the character
79 /// (will only be four escape sequences for characters composed of two "surrogate" characters).
80 ///
81 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent)
82 #[wasm_bindgen(js_name = encodeURIComponent)]
encode_uri_component(decoded: &str) -> JsString83 pub fn encode_uri_component(decoded: &str) -> JsString;
84
85 /// The `eval()` function evaluates JavaScript code represented as a string.
86 ///
87 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval)
88 #[wasm_bindgen(catch)]
eval(js_source_text: &str) -> Result<JsValue, JsValue>89 pub fn eval(js_source_text: &str) -> Result<JsValue, JsValue>;
90
91 /// The global `isFinite()` function determines whether the passed value is a finite number.
92 /// If needed, the parameter is first converted to a number.
93 ///
94 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isFinite)
95 #[wasm_bindgen(js_name = isFinite)]
is_finite(value: &JsValue) -> bool96 pub fn is_finite(value: &JsValue) -> bool;
97
98 /// The `parseInt()` function parses a string argument and returns an integer
99 /// of the specified radix (the base in mathematical numeral systems), or NaN on error.
100 ///
101 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt)
102 #[wasm_bindgen(js_name = parseInt)]
parse_int(text: &str, radix: u8) -> f64103 pub fn parse_int(text: &str, radix: u8) -> f64;
104
105 /// The `parseFloat()` function parses an argument and returns a floating point number,
106 /// or NaN on error.
107 ///
108 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseFloat)
109 #[wasm_bindgen(js_name = parseFloat)]
parse_float(text: &str) -> f64110 pub fn parse_float(text: &str) -> f64;
111
112 /// The `escape()` function computes a new string in which certain characters have been
113 /// replaced by a hexadecimal escape sequence.
114 ///
115 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/escape)
116 #[wasm_bindgen]
escape(string: &str) -> JsString117 pub fn escape(string: &str) -> JsString;
118
119 /// The `unescape()` function computes a new string in which hexadecimal escape
120 /// sequences are replaced with the character that it represents. The escape sequences might
121 /// be introduced by a function like `escape`. Usually, `decodeURI` or `decodeURIComponent`
122 /// are preferred over `unescape`.
123 ///
124 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/unescape)
125 #[wasm_bindgen]
unescape(string: &str) -> JsString126 pub fn unescape(string: &str) -> JsString;
127 }
128
129 // Array
130 #[wasm_bindgen]
131 extern "C" {
132 #[wasm_bindgen(extends = Object, is_type_of = Array::is_array, typescript_type = "Array<any>")]
133 #[derive(Clone, Debug, PartialEq, Eq)]
134 pub type Array;
135
136 /// Creates a new empty array.
137 #[wasm_bindgen(constructor)]
new() -> Array138 pub fn new() -> Array;
139
140 /// Creates a new array with the specified length (elements are initialized to `undefined`).
141 #[wasm_bindgen(constructor)]
new_with_length(len: u32) -> Array142 pub fn new_with_length(len: u32) -> Array;
143
144 /// Retrieves the element at the index (returns `undefined` if the index is out of range).
145 #[wasm_bindgen(method, structural, indexing_getter)]
get(this: &Array, index: u32) -> JsValue146 pub fn get(this: &Array, index: u32) -> JsValue;
147
148 /// Sets the element at the index (auto-enlarges the array if the index is out of range).
149 #[wasm_bindgen(method, structural, indexing_setter)]
set(this: &Array, index: u32, value: JsValue)150 pub fn set(this: &Array, index: u32, value: JsValue);
151
152 /// Deletes the element at the index (does nothing if the index is out of range).
153 ///
154 /// The element at the index is set to `undefined`.
155 ///
156 /// This does not resize the array, the array will still be the same length.
157 #[wasm_bindgen(method, structural, indexing_deleter)]
delete(this: &Array, index: u32)158 pub fn delete(this: &Array, index: u32);
159
160 /// The `Array.from()` method creates a new, shallow-copied `Array` instance
161 /// from an array-like or iterable object.
162 #[wasm_bindgen(static_method_of = Array)]
from(val: &JsValue) -> Array163 pub fn from(val: &JsValue) -> Array;
164
165 /// The `copyWithin()` method shallow copies part of an array to another
166 /// location in the same array and returns it, without modifying its size.
167 ///
168 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin)
169 #[wasm_bindgen(method, js_name = copyWithin)]
copy_within(this: &Array, target: i32, start: i32, end: i32) -> Array170 pub fn copy_within(this: &Array, target: i32, start: i32, end: i32) -> Array;
171
172 /// The `concat()` method is used to merge two or more arrays. This method
173 /// does not change the existing arrays, but instead returns a new array.
174 ///
175 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat)
176 #[wasm_bindgen(method)]
concat(this: &Array, array: &Array) -> Array177 pub fn concat(this: &Array, array: &Array) -> Array;
178
179 /// The `every()` method tests whether all elements in the array pass the test
180 /// implemented by the provided function.
181 ///
182 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every)
183 #[wasm_bindgen(method)]
every(this: &Array, predicate: &mut dyn FnMut(JsValue, u32, Array) -> bool) -> bool184 pub fn every(this: &Array, predicate: &mut dyn FnMut(JsValue, u32, Array) -> bool) -> bool;
185
186 /// The `fill()` method fills all the elements of an array from a start index
187 /// to an end index with a static value. The end index is not included.
188 ///
189 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill)
190 #[wasm_bindgen(method)]
fill(this: &Array, value: &JsValue, start: u32, end: u32) -> Array191 pub fn fill(this: &Array, value: &JsValue, start: u32, end: u32) -> Array;
192
193 /// The `filter()` method creates a new array with all elements that pass the
194 /// test implemented by the provided function.
195 ///
196 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter)
197 #[wasm_bindgen(method)]
filter(this: &Array, predicate: &mut dyn FnMut(JsValue, u32, Array) -> bool) -> Array198 pub fn filter(this: &Array, predicate: &mut dyn FnMut(JsValue, u32, Array) -> bool) -> Array;
199
200 /// The `find()` method returns the value of the first element in the array that satisfies
201 /// the provided testing function. Otherwise `undefined` is returned.
202 ///
203 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find)
204 #[wasm_bindgen(method)]
find(this: &Array, predicate: &mut dyn FnMut(JsValue, u32, Array) -> bool) -> JsValue205 pub fn find(this: &Array, predicate: &mut dyn FnMut(JsValue, u32, Array) -> bool) -> JsValue;
206
207 /// The `findIndex()` method returns the index of the first element in the array that
208 /// satisfies the provided testing function. Otherwise -1 is returned.
209 ///
210 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex)
211 #[wasm_bindgen(method, js_name = findIndex)]
find_index(this: &Array, predicate: &mut dyn FnMut(JsValue, u32, Array) -> bool) -> i32212 pub fn find_index(this: &Array, predicate: &mut dyn FnMut(JsValue, u32, Array) -> bool) -> i32;
213
214 /// The `flat()` method creates a new array with all sub-array elements concatenated into it
215 /// recursively up to the specified depth.
216 ///
217 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat)
218 #[wasm_bindgen(method)]
flat(this: &Array, depth: i32) -> Array219 pub fn flat(this: &Array, depth: i32) -> Array;
220
221 /// The `flatMap()` method first maps each element using a mapping function, then flattens
222 /// the result into a new array.
223 ///
224 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap)
225 #[wasm_bindgen(method, js_name = flatMap)]
flat_map( this: &Array, callback: &mut dyn FnMut(JsValue, u32, Array) -> Vec<JsValue>, ) -> Array226 pub fn flat_map(
227 this: &Array,
228 callback: &mut dyn FnMut(JsValue, u32, Array) -> Vec<JsValue>,
229 ) -> Array;
230
231 /// The `forEach()` method executes a provided function once for each array element.
232 ///
233 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach)
234 #[wasm_bindgen(method, js_name = forEach)]
for_each(this: &Array, callback: &mut dyn FnMut(JsValue, u32, Array))235 pub fn for_each(this: &Array, callback: &mut dyn FnMut(JsValue, u32, Array));
236
237 /// The `includes()` method determines whether an array includes a certain
238 /// element, returning true or false as appropriate.
239 ///
240 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes)
241 #[wasm_bindgen(method)]
includes(this: &Array, value: &JsValue, from_index: i32) -> bool242 pub fn includes(this: &Array, value: &JsValue, from_index: i32) -> bool;
243
244 /// The `indexOf()` method returns the first index at which a given element
245 /// can be found in the array, or -1 if it is not present.
246 ///
247 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf)
248 #[wasm_bindgen(method, js_name = indexOf)]
index_of(this: &Array, value: &JsValue, from_index: i32) -> i32249 pub fn index_of(this: &Array, value: &JsValue, from_index: i32) -> i32;
250
251 /// The `Array.isArray()` method determines whether the passed value is an Array.
252 ///
253 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray)
254 #[wasm_bindgen(static_method_of = Array, js_name = isArray)]
is_array(value: &JsValue) -> bool255 pub fn is_array(value: &JsValue) -> bool;
256
257 /// The `join()` method joins all elements of an array (or an array-like object)
258 /// into a string and returns this string.
259 ///
260 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join)
261 #[wasm_bindgen(method)]
join(this: &Array, delimiter: &str) -> JsString262 pub fn join(this: &Array, delimiter: &str) -> JsString;
263
264 /// The `lastIndexOf()` method returns the last index at which a given element
265 /// can be found in the array, or -1 if it is not present. The array is
266 /// searched backwards, starting at fromIndex.
267 ///
268 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/lastIndexOf)
269 #[wasm_bindgen(method, js_name = lastIndexOf)]
last_index_of(this: &Array, value: &JsValue, from_index: i32) -> i32270 pub fn last_index_of(this: &Array, value: &JsValue, from_index: i32) -> i32;
271
272 /// The length property of an object which is an instance of type Array
273 /// sets or returns the number of elements in that array. The value is an
274 /// unsigned, 32-bit integer that is always numerically greater than the
275 /// highest index in the array.
276 ///
277 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/length)
278 #[wasm_bindgen(method, getter, structural)]
length(this: &Array) -> u32279 pub fn length(this: &Array) -> u32;
280
281 /// `map()` calls a provided callback function once for each element in an array,
282 /// in order, and constructs a new array from the results. callback is invoked
283 /// only for indexes of the array which have assigned values, including undefined.
284 /// It is not called for missing elements of the array (that is, indexes that have
285 /// never been set, which have been deleted or which have never been assigned a value).
286 ///
287 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map)
288 #[wasm_bindgen(method)]
map(this: &Array, predicate: &mut dyn FnMut(JsValue, u32, Array) -> JsValue) -> Array289 pub fn map(this: &Array, predicate: &mut dyn FnMut(JsValue, u32, Array) -> JsValue) -> Array;
290
291 /// The `Array.of()` method creates a new Array instance with a variable
292 /// number of arguments, regardless of number or type of the arguments.
293 ///
294 /// The difference between `Array.of()` and the `Array` constructor is in the
295 /// handling of integer arguments: `Array.of(7)` creates an array with a single
296 /// element, `7`, whereas `Array(7)` creates an empty array with a `length`
297 /// property of `7` (Note: this implies an array of 7 empty slots, not slots
298 /// with actual undefined values).
299 ///
300 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of)
301 ///
302 /// # Notes
303 ///
304 /// There are a few bindings to `of` in `js-sys`: `of1`, `of2`, etc...
305 /// with different arities.
306 #[wasm_bindgen(static_method_of = Array, js_name = of)]
of1(a: &JsValue) -> Array307 pub fn of1(a: &JsValue) -> Array;
308
309 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of)
310 #[wasm_bindgen(static_method_of = Array, js_name = of)]
of2(a: &JsValue, b: &JsValue) -> Array311 pub fn of2(a: &JsValue, b: &JsValue) -> Array;
312
313 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of)
314 #[wasm_bindgen(static_method_of = Array, js_name = of)]
of3(a: &JsValue, b: &JsValue, c: &JsValue) -> Array315 pub fn of3(a: &JsValue, b: &JsValue, c: &JsValue) -> Array;
316
317 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of)
318 #[wasm_bindgen(static_method_of = Array, js_name = of)]
of4(a: &JsValue, b: &JsValue, c: &JsValue, d: &JsValue) -> Array319 pub fn of4(a: &JsValue, b: &JsValue, c: &JsValue, d: &JsValue) -> Array;
320
321 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of)
322 #[wasm_bindgen(static_method_of = Array, js_name = of)]
of5(a: &JsValue, b: &JsValue, c: &JsValue, d: &JsValue, e: &JsValue) -> Array323 pub fn of5(a: &JsValue, b: &JsValue, c: &JsValue, d: &JsValue, e: &JsValue) -> Array;
324
325 /// The `pop()` method removes the last element from an array and returns that
326 /// element. This method changes the length of the array.
327 ///
328 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pop)
329 #[wasm_bindgen(method)]
pop(this: &Array) -> JsValue330 pub fn pop(this: &Array) -> JsValue;
331
332 /// The `push()` method adds one or more elements to the end of an array and
333 /// returns the new length of the array.
334 ///
335 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push)
336 #[wasm_bindgen(method)]
push(this: &Array, value: &JsValue) -> u32337 pub fn push(this: &Array, value: &JsValue) -> u32;
338
339 /// The `reduce()` method applies a function against an accumulator and each element in
340 /// the array (from left to right) to reduce it to a single value.
341 ///
342 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce)
343 #[wasm_bindgen(method)]
reduce( this: &Array, predicate: &mut dyn FnMut(JsValue, JsValue, u32, Array) -> JsValue, initial_value: &JsValue, ) -> JsValue344 pub fn reduce(
345 this: &Array,
346 predicate: &mut dyn FnMut(JsValue, JsValue, u32, Array) -> JsValue,
347 initial_value: &JsValue,
348 ) -> JsValue;
349
350 /// The `reduceRight()` method applies a function against an accumulator and each value
351 /// of the array (from right-to-left) to reduce it to a single value.
352 ///
353 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/ReduceRight)
354 #[wasm_bindgen(method, js_name = reduceRight)]
reduce_right( this: &Array, predicate: &mut dyn FnMut(JsValue, JsValue, u32, Array) -> JsValue, initial_value: &JsValue, ) -> JsValue355 pub fn reduce_right(
356 this: &Array,
357 predicate: &mut dyn FnMut(JsValue, JsValue, u32, Array) -> JsValue,
358 initial_value: &JsValue,
359 ) -> JsValue;
360
361 /// The `reverse()` method reverses an array in place. The first array
362 /// element becomes the last, and the last array element becomes the first.
363 ///
364 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse)
365 #[wasm_bindgen(method)]
reverse(this: &Array) -> Array366 pub fn reverse(this: &Array) -> Array;
367
368 /// The `shift()` method removes the first element from an array and returns
369 /// that removed element. This method changes the length of the array.
370 ///
371 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift)
372 #[wasm_bindgen(method)]
shift(this: &Array) -> JsValue373 pub fn shift(this: &Array) -> JsValue;
374
375 /// The `slice()` method returns a shallow copy of a portion of an array into
376 /// a new array object selected from begin to end (end not included).
377 /// The original array will not be modified.
378 ///
379 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)
380 #[wasm_bindgen(method)]
slice(this: &Array, start: u32, end: u32) -> Array381 pub fn slice(this: &Array, start: u32, end: u32) -> Array;
382
383 /// The `some()` method tests whether at least one element in the array passes the test implemented
384 /// by the provided function.
385 /// Note: This method returns false for any condition put on an empty array.
386 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some)
387 #[wasm_bindgen(method)]
some(this: &Array, predicate: &mut dyn FnMut(JsValue) -> bool) -> bool388 pub fn some(this: &Array, predicate: &mut dyn FnMut(JsValue) -> bool) -> bool;
389
390 /// The `sort()` method sorts the elements of an array in place and returns
391 /// the array. The sort is not necessarily stable. The default sort
392 /// order is according to string Unicode code points.
393 ///
394 /// The time and space complexity of the sort cannot be guaranteed as it
395 /// is implementation dependent.
396 ///
397 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)
398 #[wasm_bindgen(method)]
sort(this: &Array) -> Array399 pub fn sort(this: &Array) -> Array;
400
401 /// The `splice()` method changes the contents of an array by removing existing elements and/or
402 /// adding new elements.
403 ///
404 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice)
405 #[wasm_bindgen(method)]
splice(this: &Array, start: u32, delete_count: u32, item: &JsValue) -> Array406 pub fn splice(this: &Array, start: u32, delete_count: u32, item: &JsValue) -> Array;
407
408 /// The `toLocaleString()` method returns a string representing the elements of the array.
409 /// The elements are converted to Strings using their toLocaleString methods and these
410 /// Strings are separated by a locale-specific String (such as a comma “,”).
411 ///
412 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toLocaleString)
413 #[wasm_bindgen(method, js_name = toLocaleString)]
to_locale_string(this: &Array, locales: &JsValue, options: &JsValue) -> JsString414 pub fn to_locale_string(this: &Array, locales: &JsValue, options: &JsValue) -> JsString;
415
416 /// The `toString()` method returns a string representing the specified array
417 /// and its elements.
418 ///
419 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toString)
420 #[wasm_bindgen(method, js_name = toString)]
to_string(this: &Array) -> JsString421 pub fn to_string(this: &Array) -> JsString;
422
423 /// The `unshift()` method adds one or more elements to the beginning of an
424 /// array and returns the new length of the array.
425 ///
426 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift)
427 #[wasm_bindgen(method)]
unshift(this: &Array, value: &JsValue) -> u32428 pub fn unshift(this: &Array, value: &JsValue) -> u32;
429 }
430
431 /// Iterator returned by `Array::iter`
432 #[derive(Debug, Clone)]
433 pub struct ArrayIter<'a> {
434 range: std::ops::Range<u32>,
435 array: &'a Array,
436 }
437
438 impl<'a> std::iter::Iterator for ArrayIter<'a> {
439 type Item = JsValue;
440
next(&mut self) -> Option<Self::Item>441 fn next(&mut self) -> Option<Self::Item> {
442 let index = self.range.next()?;
443 Some(self.array.get(index))
444 }
445
446 #[inline]
size_hint(&self) -> (usize, Option<usize>)447 fn size_hint(&self) -> (usize, Option<usize>) {
448 self.range.size_hint()
449 }
450 }
451
452 impl<'a> std::iter::DoubleEndedIterator for ArrayIter<'a> {
next_back(&mut self) -> Option<Self::Item>453 fn next_back(&mut self) -> Option<Self::Item> {
454 let index = self.range.next_back()?;
455 Some(self.array.get(index))
456 }
457 }
458
459 impl<'a> std::iter::FusedIterator for ArrayIter<'a> {}
460
461 impl<'a> std::iter::ExactSizeIterator for ArrayIter<'a> {}
462
463 impl Array {
464 /// Returns an iterator over the values of the JS array.
iter(&self) -> ArrayIter<'_>465 pub fn iter(&self) -> ArrayIter<'_> {
466 ArrayIter {
467 range: 0..self.length(),
468 array: self,
469 }
470 }
471
472 /// Converts the JS array into a new Vec.
to_vec(&self) -> Vec<JsValue>473 pub fn to_vec(&self) -> Vec<JsValue> {
474 let len = self.length();
475
476 let mut output = Vec::with_capacity(len as usize);
477
478 for i in 0..len {
479 output.push(self.get(i));
480 }
481
482 output
483 }
484 }
485
486 // TODO pre-initialize the Array with the correct length using TrustedLen
487 impl<A> std::iter::FromIterator<A> for Array
488 where
489 A: AsRef<JsValue>,
490 {
from_iter<T>(iter: T) -> Array where T: IntoIterator<Item = A>,491 fn from_iter<T>(iter: T) -> Array
492 where
493 T: IntoIterator<Item = A>,
494 {
495 let out = Array::new();
496
497 for value in iter {
498 out.push(value.as_ref());
499 }
500
501 out
502 }
503 }
504
505 impl Default for Array {
default() -> Self506 fn default() -> Self {
507 Self::new()
508 }
509 }
510
511 // ArrayBuffer
512 #[wasm_bindgen]
513 extern "C" {
514 #[wasm_bindgen(extends = Object, typescript_type = "ArrayBuffer")]
515 #[derive(Clone, Debug, PartialEq, Eq)]
516 pub type ArrayBuffer;
517
518 /// The `ArrayBuffer` object is used to represent a generic,
519 /// fixed-length raw binary data buffer. You cannot directly
520 /// manipulate the contents of an `ArrayBuffer`; instead, you
521 /// create one of the typed array objects or a `DataView` object
522 /// which represents the buffer in a specific format, and use that
523 /// to read and write the contents of the buffer.
524 ///
525 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer)
526 #[wasm_bindgen(constructor)]
new(length: u32) -> ArrayBuffer527 pub fn new(length: u32) -> ArrayBuffer;
528
529 /// The byteLength property of an object which is an instance of type ArrayBuffer
530 /// it's an accessor property whose set accessor function is undefined,
531 /// meaning that you can only read this property.
532 /// The value is established when the array is constructed and cannot be changed.
533 /// This property returns 0 if this ArrayBuffer has been detached.
534 ///
535 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/byteLength)
536 #[wasm_bindgen(method, getter, js_name = byteLength)]
byte_length(this: &ArrayBuffer) -> u32537 pub fn byte_length(this: &ArrayBuffer) -> u32;
538
539 /// The `isView()` method returns true if arg is one of the `ArrayBuffer`
540 /// views, such as typed array objects or a DataView; false otherwise.
541 ///
542 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/isView)
543 #[wasm_bindgen(static_method_of = ArrayBuffer, js_name = isView)]
is_view(value: &JsValue) -> bool544 pub fn is_view(value: &JsValue) -> bool;
545
546 /// The `slice()` method returns a new `ArrayBuffer` whose contents
547 /// are a copy of this `ArrayBuffer`'s bytes from begin, inclusive,
548 /// up to end, exclusive.
549 ///
550 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/slice)
551 #[wasm_bindgen(method)]
slice(this: &ArrayBuffer, begin: u32) -> ArrayBuffer552 pub fn slice(this: &ArrayBuffer, begin: u32) -> ArrayBuffer;
553
554 /// Like `slice()` but with the `end` argument.
555 ///
556 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/slice)
557 #[wasm_bindgen(method, js_name = slice)]
slice_with_end(this: &ArrayBuffer, begin: u32, end: u32) -> ArrayBuffer558 pub fn slice_with_end(this: &ArrayBuffer, begin: u32, end: u32) -> ArrayBuffer;
559 }
560
561 // SharedArrayBuffer
562 #[wasm_bindgen]
563 extern "C" {
564 #[wasm_bindgen(extends = Object, typescript_type = "SharedArrayBuffer")]
565 #[derive(Clone, Debug)]
566 pub type SharedArrayBuffer;
567
568 /// The `SharedArrayBuffer` object is used to represent a generic,
569 /// fixed-length raw binary data buffer, similar to the `ArrayBuffer`
570 /// object, but in a way that they can be used to create views
571 /// on shared memory. Unlike an `ArrayBuffer`, a `SharedArrayBuffer`
572 /// cannot become detached.
573 ///
574 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer)
575 #[wasm_bindgen(constructor)]
new(length: u32) -> SharedArrayBuffer576 pub fn new(length: u32) -> SharedArrayBuffer;
577
578 /// The byteLength accessor property represents the length of
579 /// an `SharedArrayBuffer` in bytes. This is established when
580 /// the `SharedArrayBuffer` is constructed and cannot be changed.
581 ///
582 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/byteLength)
583 #[wasm_bindgen(method, getter, js_name = byteLength)]
byte_length(this: &SharedArrayBuffer) -> u32584 pub fn byte_length(this: &SharedArrayBuffer) -> u32;
585
586 /// The `slice()` method returns a new `SharedArrayBuffer` whose contents
587 /// are a copy of this `SharedArrayBuffer`'s bytes from begin, inclusive,
588 /// up to end, exclusive.
589 ///
590 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/slice)
591 #[wasm_bindgen(method)]
slice(this: &SharedArrayBuffer, begin: u32) -> SharedArrayBuffer592 pub fn slice(this: &SharedArrayBuffer, begin: u32) -> SharedArrayBuffer;
593
594 /// Like `slice()` but with the `end` argument.
595 ///
596 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/slice)
597 #[wasm_bindgen(method, js_name = slice)]
slice_with_end(this: &SharedArrayBuffer, begin: u32, end: u32) -> SharedArrayBuffer598 pub fn slice_with_end(this: &SharedArrayBuffer, begin: u32, end: u32) -> SharedArrayBuffer;
599 }
600
601 // Array Iterator
602 #[wasm_bindgen]
603 extern "C" {
604 /// The `keys()` method returns a new Array Iterator object that contains the
605 /// keys for each index in the array.
606 ///
607 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/keys)
608 #[wasm_bindgen(method)]
keys(this: &Array) -> Iterator609 pub fn keys(this: &Array) -> Iterator;
610
611 /// The `entries()` method returns a new Array Iterator object that contains
612 /// the key/value pairs for each index in the array.
613 ///
614 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries)
615 #[wasm_bindgen(method)]
entries(this: &Array) -> Iterator616 pub fn entries(this: &Array) -> Iterator;
617
618 /// The `values()` method returns a new Array Iterator object that
619 /// contains the values for each index in the array.
620 ///
621 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/values)
622 #[wasm_bindgen(method)]
values(this: &Array) -> Iterator623 pub fn values(this: &Array) -> Iterator;
624 }
625
626 /// The `Atomics` object provides atomic operations as static methods.
627 /// They are used with `SharedArrayBuffer` objects.
628 ///
629 /// The Atomic operations are installed on an `Atomics` module. Unlike
630 /// the other global objects, `Atomics` is not a constructor. You cannot
631 /// use it with a new operator or invoke the `Atomics` object as a
632 /// function. All properties and methods of `Atomics` are static
633 /// (as is the case with the Math object, for example).
634 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics)
635 #[allow(non_snake_case)]
636 pub mod Atomics {
637 use super::*;
638
639 #[wasm_bindgen]
640 extern "C" {
641 /// The static `Atomics.add()` method adds a given value at a given
642 /// position in the array and returns the old value at that position.
643 /// This atomic operation guarantees that no other write happens
644 /// until the modified value is written back.
645 ///
646 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/add)
647 #[wasm_bindgen(js_namespace = Atomics, catch)]
add(typed_array: &JsValue, index: u32, value: i32) -> Result<i32, JsValue>648 pub fn add(typed_array: &JsValue, index: u32, value: i32) -> Result<i32, JsValue>;
649
650 /// The static `Atomics.and()` method computes a bitwise AND with a given
651 /// value at a given position in the array, and returns the old value
652 /// at that position.
653 /// This atomic operation guarantees that no other write happens
654 /// until the modified value is written back.
655 ///
656 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/and)
657 #[wasm_bindgen(js_namespace = Atomics, catch)]
and(typed_array: &JsValue, index: u32, value: i32) -> Result<i32, JsValue>658 pub fn and(typed_array: &JsValue, index: u32, value: i32) -> Result<i32, JsValue>;
659
660 /// The static `Atomics.compareExchange()` method exchanges a given
661 /// replacement value at a given position in the array, if a given expected
662 /// value equals the old value. It returns the old value at that position
663 /// whether it was equal to the expected value or not.
664 /// This atomic operation guarantees that no other write happens
665 /// until the modified value is written back.
666 ///
667 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/compareExchange)
668 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = compareExchange)]
compare_exchange( typed_array: &JsValue, index: u32, expected_value: i32, replacement_value: i32, ) -> Result<i32, JsValue>669 pub fn compare_exchange(
670 typed_array: &JsValue,
671 index: u32,
672 expected_value: i32,
673 replacement_value: i32,
674 ) -> Result<i32, JsValue>;
675
676 /// The static `Atomics.exchange()` method stores a given value at a given
677 /// position in the array and returns the old value at that position.
678 /// This atomic operation guarantees that no other write happens
679 /// until the modified value is written back.
680 ///
681 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/exchange)
682 #[wasm_bindgen(js_namespace = Atomics, catch)]
exchange(typed_array: &JsValue, index: u32, value: i32) -> Result<i32, JsValue>683 pub fn exchange(typed_array: &JsValue, index: u32, value: i32) -> Result<i32, JsValue>;
684
685 /// The static `Atomics.isLockFree()` method is used to determine
686 /// whether to use locks or atomic operations. It returns true,
687 /// if the given size is one of the `BYTES_PER_ELEMENT` property
688 /// of integer `TypedArray` types.
689 ///
690 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/isLockFree)
691 #[wasm_bindgen(js_namespace = Atomics, js_name = isLockFree)]
is_lock_free(size: u32) -> bool692 pub fn is_lock_free(size: u32) -> bool;
693
694 /// The static `Atomics.load()` method returns a value at a given
695 /// position in the array.
696 ///
697 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/load)
698 #[wasm_bindgen(js_namespace = Atomics, catch)]
load(typed_array: &JsValue, index: u32) -> Result<i32, JsValue>699 pub fn load(typed_array: &JsValue, index: u32) -> Result<i32, JsValue>;
700
701 /// The static `Atomics.notify()` method notifies up some agents that
702 /// are sleeping in the wait queue.
703 /// Note: This operation works with a shared `Int32Array` only.
704 /// If `count` is not provided, notifies all the agents in the queue.
705 ///
706 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/notify)
707 #[wasm_bindgen(js_namespace = Atomics, catch)]
notify(typed_array: &Int32Array, index: u32) -> Result<u32, JsValue>708 pub fn notify(typed_array: &Int32Array, index: u32) -> Result<u32, JsValue>;
709
710 /// Notifies up to `count` agents in the wait queue.
711 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = notify)]
notify_with_count( typed_array: &Int32Array, index: u32, count: u32, ) -> Result<u32, JsValue>712 pub fn notify_with_count(
713 typed_array: &Int32Array,
714 index: u32,
715 count: u32,
716 ) -> Result<u32, JsValue>;
717
718 /// The static `Atomics.or()` method computes a bitwise OR with a given value
719 /// at a given position in the array, and returns the old value at that position.
720 /// This atomic operation guarantees that no other write happens
721 /// until the modified value is written back.
722 ///
723 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/or)
724 #[wasm_bindgen(js_namespace = Atomics, catch)]
or(typed_array: &JsValue, index: u32, value: i32) -> Result<i32, JsValue>725 pub fn or(typed_array: &JsValue, index: u32, value: i32) -> Result<i32, JsValue>;
726
727 /// The static `Atomics.store()` method stores a given value at the given
728 /// position in the array and returns that value.
729 ///
730 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/store)
731 #[wasm_bindgen(js_namespace = Atomics, catch)]
store(typed_array: &JsValue, index: u32, value: i32) -> Result<i32, JsValue>732 pub fn store(typed_array: &JsValue, index: u32, value: i32) -> Result<i32, JsValue>;
733
734 /// The static `Atomics.sub()` method substracts a given value at a
735 /// given position in the array and returns the old value at that position.
736 /// This atomic operation guarantees that no other write happens
737 /// until the modified value is written back.
738 ///
739 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/sub)
740 #[wasm_bindgen(js_namespace = Atomics, catch)]
sub(typed_array: &JsValue, index: u32, value: i32) -> Result<i32, JsValue>741 pub fn sub(typed_array: &JsValue, index: u32, value: i32) -> Result<i32, JsValue>;
742
743 /// The static `Atomics.wait()` method verifies that a given
744 /// position in an `Int32Array` still contains a given value
745 /// and if so sleeps, awaiting a wakeup or a timeout.
746 /// It returns a string which is either "ok", "not-equal", or "timed-out".
747 /// Note: This operation only works with a shared `Int32Array`
748 /// and may not be allowed on the main thread.
749 ///
750 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait)
751 #[wasm_bindgen(js_namespace = Atomics, catch)]
wait(typed_array: &Int32Array, index: u32, value: i32) -> Result<JsString, JsValue>752 pub fn wait(typed_array: &Int32Array, index: u32, value: i32) -> Result<JsString, JsValue>;
753
754 /// Like `wait()`, but with timeout
755 ///
756 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait)
757 #[wasm_bindgen(js_namespace = Atomics, catch, js_name = wait)]
wait_with_timeout( typed_array: &Int32Array, index: u32, value: i32, timeout: f64, ) -> Result<JsString, JsValue>758 pub fn wait_with_timeout(
759 typed_array: &Int32Array,
760 index: u32,
761 value: i32,
762 timeout: f64,
763 ) -> Result<JsString, JsValue>;
764
765 /// The static `Atomics.xor()` method computes a bitwise XOR
766 /// with a given value at a given position in the array,
767 /// and returns the old value at that position.
768 /// This atomic operation guarantees that no other write happens
769 /// until the modified value is written back.
770 ///
771 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/xor)
772 #[wasm_bindgen(js_namespace = Atomics, catch)]
xor(typed_array: &JsValue, index: u32, value: i32) -> Result<i32, JsValue>773 pub fn xor(typed_array: &JsValue, index: u32, value: i32) -> Result<i32, JsValue>;
774 }
775 }
776
777 // Boolean
778 #[wasm_bindgen]
779 extern "C" {
780 #[wasm_bindgen(extends = Object, is_type_of = |v| v.as_bool().is_some(), typescript_type = "boolean")]
781 #[derive(Clone, PartialEq, Eq)]
782 pub type Boolean;
783
784 /// The `Boolean()` constructor creates an object wrapper for a boolean value.
785 ///
786 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)
787 #[wasm_bindgen(constructor)]
788 #[deprecated(note = "recommended to use `Boolean::from` instead")]
789 #[allow(deprecated)]
new(value: &JsValue) -> Boolean790 pub fn new(value: &JsValue) -> Boolean;
791
792 /// The `valueOf()` method returns the primitive value of a `Boolean` object.
793 ///
794 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean/valueOf)
795 #[wasm_bindgen(method, js_name = valueOf)]
value_of(this: &Boolean) -> bool796 pub fn value_of(this: &Boolean) -> bool;
797 }
798
799 impl From<bool> for Boolean {
800 #[inline]
from(b: bool) -> Boolean801 fn from(b: bool) -> Boolean {
802 Boolean::unchecked_from_js(JsValue::from(b))
803 }
804 }
805
806 impl From<Boolean> for bool {
807 #[inline]
from(b: Boolean) -> bool808 fn from(b: Boolean) -> bool {
809 b.value_of()
810 }
811 }
812
813 impl PartialEq<bool> for Boolean {
814 #[inline]
eq(&self, other: &bool) -> bool815 fn eq(&self, other: &bool) -> bool {
816 self.value_of() == *other
817 }
818 }
819
820 impl fmt::Debug for Boolean {
fmt(&self, f: &mut fmt::Formatter) -> fmt::Result821 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
822 self.value_of().fmt(f)
823 }
824 }
825
826 impl Default for Boolean {
default() -> Self827 fn default() -> Self {
828 Self::from(bool::default())
829 }
830 }
831
832 // DataView
833 #[wasm_bindgen]
834 extern "C" {
835 #[wasm_bindgen(extends = Object, typescript_type = "DataView")]
836 #[derive(Clone, Debug, PartialEq, Eq)]
837 pub type DataView;
838
839 /// The `DataView` view provides a low-level interface for reading and
840 /// writing multiple number types in an `ArrayBuffer` irrespective of the
841 /// platform's endianness.
842 ///
843 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView)
844 #[wasm_bindgen(constructor)]
new(buffer: &ArrayBuffer, byteOffset: usize, byteLength: usize) -> DataView845 pub fn new(buffer: &ArrayBuffer, byteOffset: usize, byteLength: usize) -> DataView;
846
847 /// The ArrayBuffer referenced by this view. Fixed at construction time and thus read only.
848 ///
849 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/buffer)
850 #[wasm_bindgen(method, getter, structural)]
buffer(this: &DataView) -> ArrayBuffer851 pub fn buffer(this: &DataView) -> ArrayBuffer;
852
853 /// The length (in bytes) of this view from the start of its ArrayBuffer.
854 /// Fixed at construction time and thus read only.
855 ///
856 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/byteLength)
857 #[wasm_bindgen(method, getter, structural, js_name = byteLength)]
byte_length(this: &DataView) -> usize858 pub fn byte_length(this: &DataView) -> usize;
859
860 /// The offset (in bytes) of this view from the start of its ArrayBuffer.
861 /// Fixed at construction time and thus read only.
862 ///
863 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/byteOffset)
864 #[wasm_bindgen(method, getter, structural, js_name = byteOffset)]
byte_offset(this: &DataView) -> usize865 pub fn byte_offset(this: &DataView) -> usize;
866
867 /// The `getInt8()` method gets a signed 8-bit integer (byte) at the
868 /// specified byte offset from the start of the DataView.
869 ///
870 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt8)
871 #[wasm_bindgen(method, js_name = getInt8)]
get_int8(this: &DataView, byte_offset: usize) -> i8872 pub fn get_int8(this: &DataView, byte_offset: usize) -> i8;
873
874 /// The `getUint8()` method gets a unsigned 8-bit integer (byte) at the specified
875 /// byte offset from the start of the DataView.
876 ///
877 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint8)
878 #[wasm_bindgen(method, js_name = getUint8)]
get_uint8(this: &DataView, byte_offset: usize) -> u8879 pub fn get_uint8(this: &DataView, byte_offset: usize) -> u8;
880
881 /// The `getInt16()` method gets a signed 16-bit integer (short) at the specified
882 /// byte offset from the start of the DataView.
883 ///
884 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt16)
885 #[wasm_bindgen(method, js_name = getInt16)]
get_int16(this: &DataView, byte_offset: usize) -> i16886 pub fn get_int16(this: &DataView, byte_offset: usize) -> i16;
887
888 /// The `getInt16()` method gets a signed 16-bit integer (short) at the specified
889 /// byte offset from the start of the DataView.
890 ///
891 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt16)
892 #[wasm_bindgen(method, js_name = getInt16)]
get_int16_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> i16893 pub fn get_int16_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> i16;
894
895 /// The `getUint16()` method gets an unsigned 16-bit integer (unsigned short) at the specified
896 /// byte offset from the start of the view.
897 ///
898 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint16)
899 #[wasm_bindgen(method, js_name = getUint16)]
get_uint16(this: &DataView, byte_offset: usize) -> u16900 pub fn get_uint16(this: &DataView, byte_offset: usize) -> u16;
901
902 /// The `getUint16()` method gets an unsigned 16-bit integer (unsigned short) at the specified
903 /// byte offset from the start of the view.
904 ///
905 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint16)
906 #[wasm_bindgen(method, js_name = getUint16)]
get_uint16_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> u16907 pub fn get_uint16_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> u16;
908
909 /// The `getInt32()` method gets a signed 32-bit integer (long) at the specified
910 /// byte offset from the start of the DataView.
911 ///
912 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt32)
913 #[wasm_bindgen(method, js_name = getInt32)]
get_int32(this: &DataView, byte_offset: usize) -> i32914 pub fn get_int32(this: &DataView, byte_offset: usize) -> i32;
915
916 /// The `getInt32()` method gets a signed 32-bit integer (long) at the specified
917 /// byte offset from the start of the DataView.
918 ///
919 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getInt32)
920 #[wasm_bindgen(method, js_name = getInt32)]
get_int32_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> i32921 pub fn get_int32_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> i32;
922
923 /// The `getUint32()` method gets an unsigned 32-bit integer (unsigned long) at the specified
924 /// byte offset from the start of the view.
925 ///
926 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint32)
927 #[wasm_bindgen(method, js_name = getUint32)]
get_uint32(this: &DataView, byte_offset: usize) -> u32928 pub fn get_uint32(this: &DataView, byte_offset: usize) -> u32;
929
930 /// The `getUint32()` method gets an unsigned 32-bit integer (unsigned long) at the specified
931 /// byte offset from the start of the view.
932 ///
933 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getUint32)
934 #[wasm_bindgen(method, js_name = getUint32)]
get_uint32_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> u32935 pub fn get_uint32_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> u32;
936
937 /// The `getFloat32()` method gets a signed 32-bit float (float) at the specified
938 /// byte offset from the start of the DataView.
939 ///
940 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat32)
941 #[wasm_bindgen(method, js_name = getFloat32)]
get_float32(this: &DataView, byte_offset: usize) -> f32942 pub fn get_float32(this: &DataView, byte_offset: usize) -> f32;
943
944 /// The `getFloat32()` method gets a signed 32-bit float (float) at the specified
945 /// byte offset from the start of the DataView.
946 ///
947 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat32)
948 #[wasm_bindgen(method, js_name = getFloat32)]
get_float32_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> f32949 pub fn get_float32_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> f32;
950
951 /// The `getFloat64()` method gets a signed 64-bit float (double) at the specified
952 /// byte offset from the start of the DataView.
953 ///
954 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat64)
955 #[wasm_bindgen(method, js_name = getFloat64)]
get_float64(this: &DataView, byte_offset: usize) -> f64956 pub fn get_float64(this: &DataView, byte_offset: usize) -> f64;
957
958 /// The `getFloat64()` method gets a signed 64-bit float (double) at the specified
959 /// byte offset from the start of the DataView.
960 ///
961 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/getFloat64)
962 #[wasm_bindgen(method, js_name = getFloat64)]
get_float64_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> f64963 pub fn get_float64_endian(this: &DataView, byte_offset: usize, little_endian: bool) -> f64;
964
965 /// The `setInt8()` method stores a signed 8-bit integer (byte) value at the
966 /// specified byte offset from the start of the DataView.
967 ///
968 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt8)
969 #[wasm_bindgen(method, js_name = setInt8)]
set_int8(this: &DataView, byte_offset: usize, value: i8)970 pub fn set_int8(this: &DataView, byte_offset: usize, value: i8);
971
972 /// The `setUint8()` method stores an unsigned 8-bit integer (byte) value at the
973 /// specified byte offset from the start of the DataView.
974 ///
975 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint8)
976 #[wasm_bindgen(method, js_name = setUint8)]
set_uint8(this: &DataView, byte_offset: usize, value: u8)977 pub fn set_uint8(this: &DataView, byte_offset: usize, value: u8);
978
979 /// The `setInt16()` method stores a signed 16-bit integer (short) value at the
980 /// specified byte offset from the start of the DataView.
981 ///
982 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt16)
983 #[wasm_bindgen(method, js_name = setInt16)]
set_int16(this: &DataView, byte_offset: usize, value: i16)984 pub fn set_int16(this: &DataView, byte_offset: usize, value: i16);
985
986 /// The `setInt16()` method stores a signed 16-bit integer (short) value at the
987 /// specified byte offset from the start of the DataView.
988 ///
989 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt16)
990 #[wasm_bindgen(method, js_name = setInt16)]
set_int16_endian(this: &DataView, byte_offset: usize, value: i16, little_endian: bool)991 pub fn set_int16_endian(this: &DataView, byte_offset: usize, value: i16, little_endian: bool);
992
993 /// The `setUint16()` method stores an unsigned 16-bit integer (unsigned short) value at the
994 /// specified byte offset from the start of the DataView.
995 ///
996 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint16)
997 #[wasm_bindgen(method, js_name = setUint16)]
set_uint16(this: &DataView, byte_offset: usize, value: u16)998 pub fn set_uint16(this: &DataView, byte_offset: usize, value: u16);
999
1000 /// The `setUint16()` method stores an unsigned 16-bit integer (unsigned short) value at the
1001 /// specified byte offset from the start of the DataView.
1002 ///
1003 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint16)
1004 #[wasm_bindgen(method, js_name = setUint16)]
set_uint16_endian(this: &DataView, byte_offset: usize, value: u16, little_endian: bool)1005 pub fn set_uint16_endian(this: &DataView, byte_offset: usize, value: u16, little_endian: bool);
1006
1007 /// The `setInt32()` method stores a signed 32-bit integer (long) value at the
1008 /// specified byte offset from the start of the DataView.
1009 ///
1010 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt32)
1011 #[wasm_bindgen(method, js_name = setInt32)]
set_int32(this: &DataView, byte_offset: usize, value: i32)1012 pub fn set_int32(this: &DataView, byte_offset: usize, value: i32);
1013
1014 /// The `setInt32()` method stores a signed 32-bit integer (long) value at the
1015 /// specified byte offset from the start of the DataView.
1016 ///
1017 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setInt32)
1018 #[wasm_bindgen(method, js_name = setInt32)]
set_int32_endian(this: &DataView, byte_offset: usize, value: i32, little_endian: bool)1019 pub fn set_int32_endian(this: &DataView, byte_offset: usize, value: i32, little_endian: bool);
1020
1021 /// The `setUint32()` method stores an unsigned 32-bit integer (unsigned long) value at the
1022 /// specified byte offset from the start of the DataView.
1023 ///
1024 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint32)
1025 #[wasm_bindgen(method, js_name = setUint32)]
set_uint32(this: &DataView, byte_offset: usize, value: u32)1026 pub fn set_uint32(this: &DataView, byte_offset: usize, value: u32);
1027
1028 /// The `setUint32()` method stores an unsigned 32-bit integer (unsigned long) value at the
1029 /// specified byte offset from the start of the DataView.
1030 ///
1031 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setUint32)
1032 #[wasm_bindgen(method, js_name = setUint32)]
set_uint32_endian(this: &DataView, byte_offset: usize, value: u32, little_endian: bool)1033 pub fn set_uint32_endian(this: &DataView, byte_offset: usize, value: u32, little_endian: bool);
1034
1035 /// The `setFloat32()` method stores a signed 32-bit float (float) value at the
1036 /// specified byte offset from the start of the DataView.
1037 ///
1038 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat32)
1039 #[wasm_bindgen(method, js_name = setFloat32)]
set_float32(this: &DataView, byte_offset: usize, value: f32)1040 pub fn set_float32(this: &DataView, byte_offset: usize, value: f32);
1041
1042 /// The `setFloat32()` method stores a signed 32-bit float (float) value at the
1043 /// specified byte offset from the start of the DataView.
1044 ///
1045 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat32)
1046 #[wasm_bindgen(method, js_name = setFloat32)]
set_float32_endian(this: &DataView, byte_offset: usize, value: f32, little_endian: bool)1047 pub fn set_float32_endian(this: &DataView, byte_offset: usize, value: f32, little_endian: bool);
1048
1049 /// The `setFloat64()` method stores a signed 64-bit float (double) value at the
1050 /// specified byte offset from the start of the DataView.
1051 ///
1052 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat64)
1053 #[wasm_bindgen(method, js_name = setFloat64)]
set_float64(this: &DataView, byte_offset: usize, value: f64)1054 pub fn set_float64(this: &DataView, byte_offset: usize, value: f64);
1055
1056 /// The `setFloat64()` method stores a signed 64-bit float (double) value at the
1057 /// specified byte offset from the start of the DataView.
1058 ///
1059 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/setFloat64)
1060 #[wasm_bindgen(method, js_name = setFloat64)]
set_float64_endian(this: &DataView, byte_offset: usize, value: f64, little_endian: bool)1061 pub fn set_float64_endian(this: &DataView, byte_offset: usize, value: f64, little_endian: bool);
1062 }
1063
1064 // Error
1065 #[wasm_bindgen]
1066 extern "C" {
1067 #[wasm_bindgen(extends = Object, typescript_type = "Error")]
1068 #[derive(Clone, Debug, PartialEq, Eq)]
1069 pub type Error;
1070
1071 /// The Error constructor creates an error object.
1072 /// Instances of Error objects are thrown when runtime errors occur.
1073 /// The Error object can also be used as a base object for user-defined exceptions.
1074 /// See below for standard built-in error types.
1075 ///
1076 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)
1077 #[wasm_bindgen(constructor)]
new(message: &str) -> Error1078 pub fn new(message: &str) -> Error;
1079
1080 /// The message property is a human-readable description of the error.
1081 ///
1082 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/message)
1083 #[wasm_bindgen(method, getter, structural)]
message(this: &Error) -> JsString1084 pub fn message(this: &Error) -> JsString;
1085 #[wasm_bindgen(method, setter, structural)]
set_message(this: &Error, message: &str)1086 pub fn set_message(this: &Error, message: &str);
1087
1088 /// The name property represents a name for the type of error. The initial value is "Error".
1089 ///
1090 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/name)
1091 #[wasm_bindgen(method, getter, structural)]
name(this: &Error) -> JsString1092 pub fn name(this: &Error) -> JsString;
1093 #[wasm_bindgen(method, setter, structural)]
set_name(this: &Error, name: &str)1094 pub fn set_name(this: &Error, name: &str);
1095
1096 /// The `toString()` method returns a string representing the specified Error object
1097 ///
1098 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/toString)
1099 #[wasm_bindgen(method, js_name = toString)]
to_string(this: &Error) -> JsString1100 pub fn to_string(this: &Error) -> JsString;
1101 }
1102
1103 // EvalError
1104 #[wasm_bindgen]
1105 extern "C" {
1106 #[wasm_bindgen(extends = Object, extends = Error, typescript_type = "EvalError")]
1107 #[derive(Clone, Debug, PartialEq, Eq)]
1108 pub type EvalError;
1109
1110 /// The EvalError object indicates an error regarding the global eval() function. This
1111 /// exception is not thrown by JavaScript anymore, however the EvalError object remains for
1112 /// compatibility.
1113 ///
1114 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/EvalError)
1115 #[wasm_bindgen(constructor)]
new(message: &str) -> EvalError1116 pub fn new(message: &str) -> EvalError;
1117 }
1118
1119 // Function
1120 #[wasm_bindgen]
1121 extern "C" {
1122 #[wasm_bindgen(extends = Object, is_type_of = JsValue::is_function, typescript_type = "Function")]
1123 #[derive(Clone, Debug, PartialEq, Eq)]
1124 pub type Function;
1125
1126 /// The `Function` constructor creates a new `Function` object. Calling the
1127 /// constructor directly can create functions dynamically, but suffers from
1128 /// security and similar (but far less significant) performance issues
1129 /// similar to `eval`. However, unlike `eval`, the `Function` constructor
1130 /// allows executing code in the global scope, prompting better programming
1131 /// habits and allowing for more efficient code minification.
1132 ///
1133 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
1134 #[wasm_bindgen(constructor)]
new_with_args(args: &str, body: &str) -> Function1135 pub fn new_with_args(args: &str, body: &str) -> Function;
1136
1137 /// The `Function` constructor creates a new `Function` object. Calling the
1138 /// constructor directly can create functions dynamically, but suffers from
1139 /// security and similar (but far less significant) performance issues
1140 /// similar to `eval`. However, unlike `eval`, the `Function` constructor
1141 /// allows executing code in the global scope, prompting better programming
1142 /// habits and allowing for more efficient code minification.
1143 ///
1144 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
1145 #[wasm_bindgen(constructor)]
new_no_args(body: &str) -> Function1146 pub fn new_no_args(body: &str) -> Function;
1147
1148 /// The `apply()` method calls a function with a given this value, and arguments provided as an array
1149 /// (or an array-like object).
1150 ///
1151 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply)
1152 #[wasm_bindgen(method, catch)]
apply(this: &Function, context: &JsValue, args: &Array) -> Result<JsValue, JsValue>1153 pub fn apply(this: &Function, context: &JsValue, args: &Array) -> Result<JsValue, JsValue>;
1154
1155 /// The `call()` method calls a function with a given this value and
1156 /// arguments provided individually.
1157 ///
1158 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
1159 #[wasm_bindgen(method, catch, js_name = call)]
call0(this: &Function, context: &JsValue) -> Result<JsValue, JsValue>1160 pub fn call0(this: &Function, context: &JsValue) -> Result<JsValue, JsValue>;
1161
1162 /// The `call()` method calls a function with a given this value and
1163 /// arguments provided individually.
1164 ///
1165 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
1166 #[wasm_bindgen(method, catch, js_name = call)]
call1(this: &Function, context: &JsValue, arg1: &JsValue) -> Result<JsValue, JsValue>1167 pub fn call1(this: &Function, context: &JsValue, arg1: &JsValue) -> Result<JsValue, JsValue>;
1168
1169 /// The `call()` method calls a function with a given this value and
1170 /// arguments provided individually.
1171 ///
1172 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
1173 #[wasm_bindgen(method, catch, js_name = call)]
call2( this: &Function, context: &JsValue, arg1: &JsValue, arg2: &JsValue, ) -> Result<JsValue, JsValue>1174 pub fn call2(
1175 this: &Function,
1176 context: &JsValue,
1177 arg1: &JsValue,
1178 arg2: &JsValue,
1179 ) -> Result<JsValue, JsValue>;
1180
1181 /// The `call()` method calls a function with a given this value and
1182 /// arguments provided individually.
1183 ///
1184 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
1185 #[wasm_bindgen(method, catch, js_name = call)]
call3( this: &Function, context: &JsValue, arg1: &JsValue, arg2: &JsValue, arg3: &JsValue, ) -> Result<JsValue, JsValue>1186 pub fn call3(
1187 this: &Function,
1188 context: &JsValue,
1189 arg1: &JsValue,
1190 arg2: &JsValue,
1191 arg3: &JsValue,
1192 ) -> Result<JsValue, JsValue>;
1193
1194 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
1195 /// with a given sequence of arguments preceding any provided when the new function is called.
1196 ///
1197 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
1198 #[wasm_bindgen(method, js_name = bind)]
bind(this: &Function, context: &JsValue) -> Function1199 pub fn bind(this: &Function, context: &JsValue) -> Function;
1200
1201 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
1202 /// with a given sequence of arguments preceding any provided when the new function is called.
1203 ///
1204 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
1205 #[wasm_bindgen(method, js_name = bind)]
bind0(this: &Function, context: &JsValue) -> Function1206 pub fn bind0(this: &Function, context: &JsValue) -> Function;
1207
1208 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
1209 /// with a given sequence of arguments preceding any provided when the new function is called.
1210 ///
1211 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
1212 #[wasm_bindgen(method, js_name = bind)]
bind1(this: &Function, context: &JsValue, arg1: &JsValue) -> Function1213 pub fn bind1(this: &Function, context: &JsValue, arg1: &JsValue) -> Function;
1214
1215 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
1216 /// with a given sequence of arguments preceding any provided when the new function is called.
1217 ///
1218 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
1219 #[wasm_bindgen(method, js_name = bind)]
bind2(this: &Function, context: &JsValue, arg1: &JsValue, arg2: &JsValue) -> Function1220 pub fn bind2(this: &Function, context: &JsValue, arg1: &JsValue, arg2: &JsValue) -> Function;
1221
1222 /// The `bind()` method creates a new function that, when called, has its this keyword set to the provided value,
1223 /// with a given sequence of arguments preceding any provided when the new function is called.
1224 ///
1225 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind)
1226 #[wasm_bindgen(method, js_name = bind)]
bind3( this: &Function, context: &JsValue, arg1: &JsValue, arg2: &JsValue, arg3: &JsValue, ) -> Function1227 pub fn bind3(
1228 this: &Function,
1229 context: &JsValue,
1230 arg1: &JsValue,
1231 arg2: &JsValue,
1232 arg3: &JsValue,
1233 ) -> Function;
1234
1235 /// The length property indicates the number of arguments expected by the function.
1236 ///
1237 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/length)
1238 #[wasm_bindgen(method, getter, structural)]
length(this: &Function) -> u321239 pub fn length(this: &Function) -> u32;
1240
1241 /// A Function object's read-only name property indicates the function's
1242 /// name as specified when it was created or "anonymous" for functions
1243 /// created anonymously.
1244 ///
1245 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name)
1246 #[wasm_bindgen(method, getter, structural)]
name(this: &Function) -> JsString1247 pub fn name(this: &Function) -> JsString;
1248
1249 /// The `toString()` method returns a string representing the source code of the function.
1250 ///
1251 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/toString)
1252 #[wasm_bindgen(method, js_name = toString)]
to_string(this: &Function) -> JsString1253 pub fn to_string(this: &Function) -> JsString;
1254 }
1255
1256 impl Function {
1257 /// Returns the `Function` value of this JS value if it's an instance of a
1258 /// function.
1259 ///
1260 /// If this JS value is not an instance of a function then this returns
1261 /// `None`.
1262 #[deprecated(note = "recommended to use dyn_ref instead which is now equivalent")]
try_from(val: &JsValue) -> Option<&Function>1263 pub fn try_from(val: &JsValue) -> Option<&Function> {
1264 val.dyn_ref()
1265 }
1266 }
1267
1268 impl Default for Function {
default() -> Self1269 fn default() -> Self {
1270 Self::new_no_args("")
1271 }
1272 }
1273
1274 // Generator
1275 #[wasm_bindgen]
1276 extern "C" {
1277 #[wasm_bindgen(extends = Object, typescript_type = "Generator<any, any, any>")]
1278 #[derive(Clone, Debug, PartialEq, Eq)]
1279 pub type Generator;
1280
1281 /// The `next()` method returns an object with two properties done and value.
1282 /// You can also provide a parameter to the next method to send a value to the generator.
1283 ///
1284 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/next)
1285 #[wasm_bindgen(method, structural, catch)]
next(this: &Generator, value: &JsValue) -> Result<JsValue, JsValue>1286 pub fn next(this: &Generator, value: &JsValue) -> Result<JsValue, JsValue>;
1287
1288 /// The `return()` method returns the given value and finishes the generator.
1289 ///
1290 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/return)
1291 #[wasm_bindgen(method, structural, js_name = return)]
return_(this: &Generator, value: &JsValue) -> JsValue1292 pub fn return_(this: &Generator, value: &JsValue) -> JsValue;
1293
1294 /// The `throw()` method resumes the execution of a generator by throwing an error into it
1295 /// and returns an object with two properties done and value.
1296 ///
1297 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator/throw)
1298 #[wasm_bindgen(method, structural, catch)]
throw(this: &Generator, error: &Error) -> Result<JsValue, JsValue>1299 pub fn throw(this: &Generator, error: &Error) -> Result<JsValue, JsValue>;
1300 }
1301
1302 // Map
1303 #[wasm_bindgen]
1304 extern "C" {
1305 #[wasm_bindgen(extends = Object, typescript_type = "Map<any, any>")]
1306 #[derive(Clone, Debug, PartialEq, Eq)]
1307 pub type Map;
1308
1309 /// The `clear()` method removes all elements from a Map object.
1310 ///
1311 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/clear)
1312 #[wasm_bindgen(method)]
clear(this: &Map)1313 pub fn clear(this: &Map);
1314
1315 /// The `delete()` method removes the specified element from a Map object.
1316 ///
1317 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/delete)
1318 #[wasm_bindgen(method)]
delete(this: &Map, key: &JsValue) -> bool1319 pub fn delete(this: &Map, key: &JsValue) -> bool;
1320
1321 /// The `forEach()` method executes a provided function once per each
1322 /// key/value pair in the Map object, in insertion order.
1323 /// Note that in Javascript land the `Key` and `Value` are reversed compared to normal expectations:
1324 /// # Examples
1325 /// ```
1326 /// let js_map = Map::new();
1327 /// js_map.for_each(&mut |value, key| {
1328 /// // Do something here...
1329 /// })
1330 /// ```
1331 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/forEach)
1332 #[wasm_bindgen(method, js_name = forEach)]
for_each(this: &Map, callback: &mut dyn FnMut(JsValue, JsValue))1333 pub fn for_each(this: &Map, callback: &mut dyn FnMut(JsValue, JsValue));
1334
1335 /// The `get()` method returns a specified element from a Map object.
1336 ///
1337 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/get)
1338 #[wasm_bindgen(method)]
get(this: &Map, key: &JsValue) -> JsValue1339 pub fn get(this: &Map, key: &JsValue) -> JsValue;
1340
1341 /// The `has()` method returns a boolean indicating whether an element with
1342 /// the specified key exists or not.
1343 ///
1344 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/has)
1345 #[wasm_bindgen(method)]
has(this: &Map, key: &JsValue) -> bool1346 pub fn has(this: &Map, key: &JsValue) -> bool;
1347
1348 /// The Map object holds key-value pairs. Any value (both objects and
1349 /// primitive values) maybe used as either a key or a value.
1350 ///
1351 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)
1352 #[wasm_bindgen(constructor)]
new() -> Map1353 pub fn new() -> Map;
1354
1355 /// The `set()` method adds or updates an element with a specified key
1356 /// and value to a Map object.
1357 ///
1358 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/set)
1359 #[wasm_bindgen(method)]
set(this: &Map, key: &JsValue, value: &JsValue) -> Map1360 pub fn set(this: &Map, key: &JsValue, value: &JsValue) -> Map;
1361
1362 /// The value of size is an integer representing how many entries
1363 /// the Map object has. A set accessor function for size is undefined;
1364 /// you can not change this property.
1365 ///
1366 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/size)
1367 #[wasm_bindgen(method, getter, structural)]
size(this: &Map) -> u321368 pub fn size(this: &Map) -> u32;
1369 }
1370
1371 impl Default for Map {
default() -> Self1372 fn default() -> Self {
1373 Self::new()
1374 }
1375 }
1376
1377 // Map Iterator
1378 #[wasm_bindgen]
1379 extern "C" {
1380 /// The `entries()` method returns a new Iterator object that contains
1381 /// the [key, value] pairs for each element in the Map object in
1382 /// insertion order.
1383 ///
1384 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries)
1385 #[wasm_bindgen(method)]
entries(this: &Map) -> Iterator1386 pub fn entries(this: &Map) -> Iterator;
1387
1388 /// The `keys()` method returns a new Iterator object that contains the
1389 /// keys for each element in the Map object in insertion order.
1390 ///
1391 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/keys)
1392 #[wasm_bindgen(method)]
keys(this: &Map) -> Iterator1393 pub fn keys(this: &Map) -> Iterator;
1394
1395 /// The `values()` method returns a new Iterator object that contains the
1396 /// values for each element in the Map object in insertion order.
1397 ///
1398 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/values)
1399 #[wasm_bindgen(method)]
values(this: &Map) -> Iterator1400 pub fn values(this: &Map) -> Iterator;
1401 }
1402
1403 // Iterator
1404 #[wasm_bindgen]
1405 extern "C" {
1406 /// Any object that conforms to the JS iterator protocol. For example,
1407 /// something returned by `myArray[Symbol.iterator]()`.
1408 ///
1409 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols)
1410 #[derive(Clone, Debug)]
1411 #[wasm_bindgen(is_type_of = Iterator::looks_like_iterator, typescript_type = "Iterator<any>")]
1412 pub type Iterator;
1413
1414 /// The `next()` method always has to return an object with appropriate
1415 /// properties including done and value. If a non-object value gets returned
1416 /// (such as false or undefined), a TypeError ("iterator.next() returned a
1417 /// non-object value") will be thrown.
1418 #[wasm_bindgen(catch, method, structural)]
next(this: &Iterator) -> Result<IteratorNext, JsValue>1419 pub fn next(this: &Iterator) -> Result<IteratorNext, JsValue>;
1420 }
1421
1422 impl Iterator {
looks_like_iterator(it: &JsValue) -> bool1423 fn looks_like_iterator(it: &JsValue) -> bool {
1424 #[wasm_bindgen]
1425 extern "C" {
1426 type MaybeIterator;
1427
1428 #[wasm_bindgen(method, getter)]
1429 fn next(this: &MaybeIterator) -> JsValue;
1430 }
1431
1432 if !it.is_object() {
1433 return false;
1434 }
1435
1436 let it = it.unchecked_ref::<MaybeIterator>();
1437
1438 it.next().is_function()
1439 }
1440 }
1441
1442 // Async Iterator
1443 #[wasm_bindgen]
1444 extern "C" {
1445 /// Any object that conforms to the JS async iterator protocol. For example,
1446 /// something returned by `myObject[Symbol.asyncIterator]()`.
1447 ///
1448 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of)
1449 #[derive(Clone, Debug)]
1450 #[wasm_bindgen(is_type_of = Iterator::looks_like_iterator, typescript_type = "Iterator<Promise<any>>")]
1451 pub type AsyncIterator;
1452
1453 /// The `next()` method always has to return a Promise which resolves to an object
1454 /// with appropriate properties including done and value. If a non-object value
1455 /// gets returned (such as false or undefined), a TypeError ("iterator.next()
1456 /// returned a non-object value") will be thrown.
1457 #[wasm_bindgen(catch, method, structural)]
next(this: &AsyncIterator) -> Result<Promise, JsValue>1458 pub fn next(this: &AsyncIterator) -> Result<Promise, JsValue>;
1459 }
1460
1461 /// An iterator over the JS `Symbol.iterator` iteration protocol.
1462 ///
1463 /// Use the `IntoIterator for &js_sys::Iterator` implementation to create this.
1464 pub struct Iter<'a> {
1465 js: &'a Iterator,
1466 state: IterState,
1467 }
1468
1469 /// An iterator over the JS `Symbol.iterator` iteration protocol.
1470 ///
1471 /// Use the `IntoIterator for js_sys::Iterator` implementation to create this.
1472 pub struct IntoIter {
1473 js: Iterator,
1474 state: IterState,
1475 }
1476
1477 struct IterState {
1478 done: bool,
1479 }
1480
1481 impl<'a> IntoIterator for &'a Iterator {
1482 type Item = Result<JsValue, JsValue>;
1483 type IntoIter = Iter<'a>;
1484
into_iter(self) -> Iter<'a>1485 fn into_iter(self) -> Iter<'a> {
1486 Iter {
1487 js: self,
1488 state: IterState::new(),
1489 }
1490 }
1491 }
1492
1493 impl<'a> std::iter::Iterator for Iter<'a> {
1494 type Item = Result<JsValue, JsValue>;
1495
next(&mut self) -> Option<Self::Item>1496 fn next(&mut self) -> Option<Self::Item> {
1497 self.state.next(self.js)
1498 }
1499 }
1500
1501 impl IntoIterator for Iterator {
1502 type Item = Result<JsValue, JsValue>;
1503 type IntoIter = IntoIter;
1504
into_iter(self) -> IntoIter1505 fn into_iter(self) -> IntoIter {
1506 IntoIter {
1507 js: self,
1508 state: IterState::new(),
1509 }
1510 }
1511 }
1512
1513 impl std::iter::Iterator for IntoIter {
1514 type Item = Result<JsValue, JsValue>;
1515
next(&mut self) -> Option<Self::Item>1516 fn next(&mut self) -> Option<Self::Item> {
1517 self.state.next(&self.js)
1518 }
1519 }
1520
1521 impl IterState {
new() -> IterState1522 fn new() -> IterState {
1523 IterState { done: false }
1524 }
1525
next(&mut self, js: &Iterator) -> Option<Result<JsValue, JsValue>>1526 fn next(&mut self, js: &Iterator) -> Option<Result<JsValue, JsValue>> {
1527 if self.done {
1528 return None;
1529 }
1530 let next = match js.next() {
1531 Ok(val) => val,
1532 Err(e) => {
1533 self.done = true;
1534 return Some(Err(e));
1535 }
1536 };
1537 if next.done() {
1538 self.done = true;
1539 None
1540 } else {
1541 Some(Ok(next.value()))
1542 }
1543 }
1544 }
1545
1546 /// Create an iterator over `val` using the JS iteration protocol and
1547 /// `Symbol.iterator`.
try_iter(val: &JsValue) -> Result<Option<IntoIter>, JsValue>1548 pub fn try_iter(val: &JsValue) -> Result<Option<IntoIter>, JsValue> {
1549 let iter_sym = Symbol::iterator();
1550 let iter_fn = Reflect::get(val, iter_sym.as_ref())?;
1551
1552 let iter_fn: Function = match iter_fn.dyn_into() {
1553 Ok(iter_fn) => iter_fn,
1554 Err(_) => return Ok(None),
1555 };
1556
1557 let it: Iterator = match iter_fn.call0(val)?.dyn_into() {
1558 Ok(it) => it,
1559 Err(_) => return Ok(None),
1560 };
1561
1562 Ok(Some(it.into_iter()))
1563 }
1564
1565 // IteratorNext
1566 #[wasm_bindgen]
1567 extern "C" {
1568 /// The result of calling `next()` on a JS iterator.
1569 ///
1570 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols)
1571 #[wasm_bindgen(extends = Object, typescript_type = "IteratorResult<any>")]
1572 #[derive(Clone, Debug, PartialEq, Eq)]
1573 pub type IteratorNext;
1574
1575 /// Has the value `true` if the iterator is past the end of the iterated
1576 /// sequence. In this case value optionally specifies the return value of
1577 /// the iterator.
1578 ///
1579 /// Has the value `false` if the iterator was able to produce the next value
1580 /// in the sequence. This is equivalent of not specifying the done property
1581 /// altogether.
1582 #[wasm_bindgen(method, getter, structural)]
done(this: &IteratorNext) -> bool1583 pub fn done(this: &IteratorNext) -> bool;
1584
1585 /// Any JavaScript value returned by the iterator. Can be omitted when done
1586 /// is true.
1587 #[wasm_bindgen(method, getter, structural)]
value(this: &IteratorNext) -> JsValue1588 pub fn value(this: &IteratorNext) -> JsValue;
1589 }
1590
1591 #[allow(non_snake_case)]
1592 pub mod Math {
1593 use super::*;
1594
1595 // Math
1596 #[wasm_bindgen]
1597 extern "C" {
1598 /// The `Math.abs()` function returns the absolute value of a number, that is
1599 /// Math.abs(x) = |x|
1600 ///
1601 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/abs)
1602 #[wasm_bindgen(js_namespace = Math)]
abs(x: f64) -> f641603 pub fn abs(x: f64) -> f64;
1604
1605 /// The `Math.acos()` function returns the arccosine (in radians) of a
1606 /// number, that is ∀x∊[-1;1]
1607 /// Math.acos(x) = arccos(x) = the unique y∊[0;π] such that cos(y)=x
1608 ///
1609 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/acos)
1610 #[wasm_bindgen(js_namespace = Math)]
acos(x: f64) -> f641611 pub fn acos(x: f64) -> f64;
1612
1613 /// The `Math.acosh()` function returns the hyperbolic arc-cosine of a
1614 /// number, that is ∀x ≥ 1
1615 /// Math.acosh(x) = arcosh(x) = the unique y ≥ 0 such that cosh(y) = x
1616 ///
1617 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/acosh)
1618 #[wasm_bindgen(js_namespace = Math)]
acosh(x: f64) -> f641619 pub fn acosh(x: f64) -> f64;
1620
1621 /// The `Math.asin()` function returns the arcsine (in radians) of a
1622 /// number, that is ∀x ∊ [-1;1]
1623 /// Math.asin(x) = arcsin(x) = the unique y∊[-π2;π2] such that sin(y) = x
1624 ///
1625 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/asin)
1626 #[wasm_bindgen(js_namespace = Math)]
asin(x: f64) -> f641627 pub fn asin(x: f64) -> f64;
1628
1629 /// The `Math.asinh()` function returns the hyperbolic arcsine of a
1630 /// number, that is Math.asinh(x) = arsinh(x) = the unique y such that sinh(y) = x
1631 ///
1632 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/asinh)
1633 #[wasm_bindgen(js_namespace = Math)]
asinh(x: f64) -> f641634 pub fn asinh(x: f64) -> f64;
1635
1636 /// The `Math.atan()` function returns the arctangent (in radians) of a
1637 /// number, that is Math.atan(x) = arctan(x) = the unique y ∊ [-π2;π2]such that
1638 /// tan(y) = x
1639 #[wasm_bindgen(js_namespace = Math)]
atan(x: f64) -> f641640 pub fn atan(x: f64) -> f64;
1641
1642 /// The `Math.atan2()` function returns the arctangent of the quotient of
1643 /// its arguments.
1644 ///
1645 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/atan2)
1646 #[wasm_bindgen(js_namespace = Math)]
atan2(y: f64, x: f64) -> f641647 pub fn atan2(y: f64, x: f64) -> f64;
1648
1649 /// The `Math.atanh()` function returns the hyperbolic arctangent of a number,
1650 /// that is ∀x ∊ (-1,1), Math.atanh(x) = arctanh(x) = the unique y such that
1651 /// tanh(y) = x
1652 ///
1653 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/atanh)
1654 #[wasm_bindgen(js_namespace = Math)]
atanh(x: f64) -> f641655 pub fn atanh(x: f64) -> f64;
1656
1657 /// The `Math.cbrt() `function returns the cube root of a number, that is
1658 /// Math.cbrt(x) = ∛x = the unique y such that y^3 = x
1659 ///
1660 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/cbrt)
1661 #[wasm_bindgen(js_namespace = Math)]
cbrt(x: f64) -> f641662 pub fn cbrt(x: f64) -> f64;
1663
1664 /// The `Math.ceil()` function returns the smallest integer greater than
1665 /// or equal to a given number.
1666 ///
1667 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/ceil)
1668 #[wasm_bindgen(js_namespace = Math)]
ceil(x: f64) -> f641669 pub fn ceil(x: f64) -> f64;
1670
1671 /// The `Math.clz32()` function returns the number of leading zero bits in
1672 /// the 32-bit binary representation of a number.
1673 ///
1674 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/clz32)
1675 #[wasm_bindgen(js_namespace = Math)]
clz32(x: i32) -> u321676 pub fn clz32(x: i32) -> u32;
1677
1678 /// The `Math.cos()` static function returns the cosine of the specified angle,
1679 /// which must be specified in radians. This value is length(adjacent)/length(hypotenuse).
1680 ///
1681 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/cos)
1682 #[wasm_bindgen(js_namespace = Math)]
cos(x: f64) -> f641683 pub fn cos(x: f64) -> f64;
1684
1685 /// The `Math.cosh()` function returns the hyperbolic cosine of a number,
1686 /// that can be expressed using the constant e.
1687 ///
1688 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/cosh)
1689 #[wasm_bindgen(js_namespace = Math)]
cosh(x: f64) -> f641690 pub fn cosh(x: f64) -> f64;
1691
1692 /// The `Math.exp()` function returns e^x, where x is the argument, and e is Euler's number
1693 /// (also known as Napier's constant), the base of the natural logarithms.
1694 ///
1695 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/exp)
1696 #[wasm_bindgen(js_namespace = Math)]
exp(x: f64) -> f641697 pub fn exp(x: f64) -> f64;
1698
1699 /// The `Math.expm1()` function returns e^x - 1, where x is the argument, and e the base of the
1700 /// natural logarithms.
1701 ///
1702 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/expm1)
1703 #[wasm_bindgen(js_namespace = Math)]
expm1(x: f64) -> f641704 pub fn expm1(x: f64) -> f64;
1705
1706 /// The `Math.floor()` function returns the largest integer less than or
1707 /// equal to a given number.
1708 ///
1709 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/floor)
1710 #[wasm_bindgen(js_namespace = Math)]
floor(x: f64) -> f641711 pub fn floor(x: f64) -> f64;
1712
1713 /// The `Math.fround()` function returns the nearest 32-bit single precision float representation
1714 /// of a Number.
1715 ///
1716 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/fround)
1717 #[wasm_bindgen(js_namespace = Math)]
fround(x: f64) -> f321718 pub fn fround(x: f64) -> f32;
1719
1720 /// The `Math.hypot()` function returns the square root of the sum of squares of its arguments.
1721 ///
1722 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/hypot)
1723 #[wasm_bindgen(js_namespace = Math)]
hypot(x: f64, y: f64) -> f641724 pub fn hypot(x: f64, y: f64) -> f64;
1725
1726 /// The `Math.imul()` function returns the result of the C-like 32-bit multiplication of the
1727 /// two parameters.
1728 ///
1729 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/imul)
1730 #[wasm_bindgen(js_namespace = Math)]
imul(x: i32, y: i32) -> i321731 pub fn imul(x: i32, y: i32) -> i32;
1732
1733 /// The `Math.log()` function returns the natural logarithm (base e) of a number.
1734 /// The JavaScript `Math.log()` function is equivalent to ln(x) in mathematics.
1735 ///
1736 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log)
1737 #[wasm_bindgen(js_namespace = Math)]
log(x: f64) -> f641738 pub fn log(x: f64) -> f64;
1739
1740 /// The `Math.log10()` function returns the base 10 logarithm of a number.
1741 ///
1742 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log10)
1743 #[wasm_bindgen(js_namespace = Math)]
log10(x: f64) -> f641744 pub fn log10(x: f64) -> f64;
1745
1746 /// The `Math.log1p()` function returns the natural logarithm (base e) of 1 + a number.
1747 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log1p)
1748 #[wasm_bindgen(js_namespace = Math)]
log1p(x: f64) -> f641749 pub fn log1p(x: f64) -> f64;
1750
1751 /// The `Math.log2()` function returns the base 2 logarithm of a number.
1752 ///
1753 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log2)
1754 #[wasm_bindgen(js_namespace = Math)]
log2(x: f64) -> f641755 pub fn log2(x: f64) -> f64;
1756
1757 /// The `Math.max()` function returns the largest of two numbers.
1758 ///
1759 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/max)
1760 #[wasm_bindgen(js_namespace = Math)]
max(x: f64, y: f64) -> f641761 pub fn max(x: f64, y: f64) -> f64;
1762
1763 /// The static function `Math.min()` returns the lowest-valued number passed into it.
1764 ///
1765 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/min)
1766 #[wasm_bindgen(js_namespace = Math)]
min(x: f64, y: f64) -> f641767 pub fn min(x: f64, y: f64) -> f64;
1768
1769 /// The `Math.pow()` function returns the base to the exponent power, that is, base^exponent.
1770 ///
1771 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/pow)
1772 #[wasm_bindgen(js_namespace = Math)]
pow(base: f64, exponent: f64) -> f641773 pub fn pow(base: f64, exponent: f64) -> f64;
1774
1775 /// The `Math.random()` function returns a floating-point, pseudo-random number
1776 /// in the range 0–1 (inclusive of 0, but not 1) with approximately uniform distribution
1777 /// over that range — which you can then scale to your desired range.
1778 /// The implementation selects the initial seed to the random number generation algorithm;
1779 /// it cannot be chosen or reset by the user.
1780 ///
1781 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random)
1782 #[wasm_bindgen(js_namespace = Math)]
random() -> f641783 pub fn random() -> f64;
1784
1785 /// The `Math.round()` function returns the value of a number rounded to the nearest integer.
1786 ///
1787 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round)
1788 #[wasm_bindgen(js_namespace = Math)]
round(x: f64) -> f641789 pub fn round(x: f64) -> f64;
1790
1791 /// The `Math.sign()` function returns the sign of a number, indicating whether the number is
1792 /// positive, negative or zero.
1793 ///
1794 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign)
1795 #[wasm_bindgen(js_namespace = Math)]
sign(x: f64) -> f641796 pub fn sign(x: f64) -> f64;
1797
1798 /// The `Math.sin()` function returns the sine of a number.
1799 ///
1800 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sin)
1801 #[wasm_bindgen(js_namespace = Math)]
sin(x: f64) -> f641802 pub fn sin(x: f64) -> f64;
1803
1804 /// The `Math.sinh()` function returns the hyperbolic sine of a number, that can be expressed
1805 /// using the constant e: Math.sinh(x) = (e^x - e^-x)/2
1806 ///
1807 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sinh)
1808 #[wasm_bindgen(js_namespace = Math)]
sinh(x: f64) -> f641809 pub fn sinh(x: f64) -> f64;
1810
1811 /// The `Math.sqrt()` function returns the square root of a number, that is
1812 /// ∀x ≥ 0, Math.sqrt(x) = √x = the unique y ≥ 0 such that y^2 = x
1813 ///
1814 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sqrt)
1815 #[wasm_bindgen(js_namespace = Math)]
sqrt(x: f64) -> f641816 pub fn sqrt(x: f64) -> f64;
1817
1818 /// The `Math.tan()` function returns the tangent of a number.
1819 ///
1820 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/tan)
1821 #[wasm_bindgen(js_namespace = Math)]
tan(x: f64) -> f641822 pub fn tan(x: f64) -> f64;
1823
1824 /// The `Math.tanh()` function returns the hyperbolic tangent of a number, that is
1825 /// tanh x = sinh x / cosh x = (e^x - e^-x)/(e^x + e^-x) = (e^2x - 1)/(e^2x + 1)
1826 ///
1827 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/tanh)
1828 #[wasm_bindgen(js_namespace = Math)]
tanh(x: f64) -> f641829 pub fn tanh(x: f64) -> f64;
1830
1831 /// The `Math.trunc()` function returns the integer part of a number by removing any fractional
1832 /// digits.
1833 ///
1834 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/trunc)
1835 #[wasm_bindgen(js_namespace = Math)]
trunc(x: f64) -> f641836 pub fn trunc(x: f64) -> f64;
1837 }
1838 }
1839
1840 // Number.
1841 #[wasm_bindgen]
1842 extern "C" {
1843 #[wasm_bindgen(extends = Object, is_type_of = |v| v.as_f64().is_some(), typescript_type = "number")]
1844 #[derive(Clone)]
1845 pub type Number;
1846
1847 /// The `Number.isFinite()` method determines whether the passed value is a finite number.
1848 ///
1849 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isFinite)
1850 #[wasm_bindgen(static_method_of = Number, js_name = isFinite)]
is_finite(value: &JsValue) -> bool1851 pub fn is_finite(value: &JsValue) -> bool;
1852
1853 /// The `Number.isInteger()` method determines whether the passed value is an integer.
1854 ///
1855 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isInteger)
1856 #[wasm_bindgen(static_method_of = Number, js_name = isInteger)]
is_integer(value: &JsValue) -> bool1857 pub fn is_integer(value: &JsValue) -> bool;
1858
1859 /// The `Number.isNaN()` method determines whether the passed value is `NaN` and its type is Number.
1860 /// It is a more robust version of the original, global isNaN().
1861 ///
1862 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isNaN)
1863 #[wasm_bindgen(static_method_of = Number, js_name = isNaN)]
is_nan(value: &JsValue) -> bool1864 pub fn is_nan(value: &JsValue) -> bool;
1865
1866 /// The `Number.isSafeInteger()` method determines whether the provided value is a number
1867 /// that is a safe integer.
1868 ///
1869 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isSafeInteger)
1870 #[wasm_bindgen(static_method_of = Number, js_name = isSafeInteger)]
is_safe_integer(value: &JsValue) -> bool1871 pub fn is_safe_integer(value: &JsValue) -> bool;
1872
1873 /// The `Number` JavaScript object is a wrapper object allowing
1874 /// you to work with numerical values. A `Number` object is
1875 /// created using the `Number()` constructor.
1876 ///
1877 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
1878 #[wasm_bindgen(constructor)]
1879 #[deprecated(note = "recommended to use `Number::from` instead")]
1880 #[allow(deprecated)]
new(value: &JsValue) -> Number1881 pub fn new(value: &JsValue) -> Number;
1882
1883 /// The `Number.parseInt()` method parses a string argument and returns an
1884 /// integer of the specified radix or base.
1885 ///
1886 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/parseInt)
1887 #[wasm_bindgen(static_method_of = Number, js_name = parseInt)]
parse_int(text: &str, radix: u8) -> f641888 pub fn parse_int(text: &str, radix: u8) -> f64;
1889
1890 /// The `Number.parseFloat()` method parses a string argument and returns a
1891 /// floating point number.
1892 ///
1893 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/parseFloat)
1894 #[wasm_bindgen(static_method_of = Number, js_name = parseFloat)]
parse_float(text: &str) -> f641895 pub fn parse_float(text: &str) -> f64;
1896
1897 /// The `toLocaleString()` method returns a string with a language sensitive
1898 /// representation of this number.
1899 ///
1900 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString)
1901 #[wasm_bindgen(method, js_name = toLocaleString)]
to_locale_string(this: &Number, locale: &str) -> JsString1902 pub fn to_locale_string(this: &Number, locale: &str) -> JsString;
1903
1904 /// The `toPrecision()` method returns a string representing the Number
1905 /// object to the specified precision.
1906 ///
1907 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision)
1908 #[wasm_bindgen(catch, method, js_name = toPrecision)]
to_precision(this: &Number, precision: u8) -> Result<JsString, JsValue>1909 pub fn to_precision(this: &Number, precision: u8) -> Result<JsString, JsValue>;
1910
1911 /// The `toFixed()` method returns a string representing the Number
1912 /// object using fixed-point notation.
1913 ///
1914 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed)
1915 #[wasm_bindgen(catch, method, js_name = toFixed)]
to_fixed(this: &Number, digits: u8) -> Result<JsString, JsValue>1916 pub fn to_fixed(this: &Number, digits: u8) -> Result<JsString, JsValue>;
1917
1918 /// The `toExponential()` method returns a string representing the Number
1919 /// object in exponential notation.
1920 ///
1921 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toExponential)
1922 #[wasm_bindgen(catch, method, js_name = toExponential)]
to_exponential(this: &Number, fraction_digits: u8) -> Result<JsString, JsValue>1923 pub fn to_exponential(this: &Number, fraction_digits: u8) -> Result<JsString, JsValue>;
1924
1925 /// The `toString()` method returns a string representing the
1926 /// specified Number object.
1927 ///
1928 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString)
1929 #[wasm_bindgen(catch, method, js_name = toString)]
to_string(this: &Number, radix: u8) -> Result<JsString, JsValue>1930 pub fn to_string(this: &Number, radix: u8) -> Result<JsString, JsValue>;
1931
1932 /// The `valueOf()` method returns the wrapped primitive value of
1933 /// a Number object.
1934 ///
1935 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/valueOf)
1936 #[wasm_bindgen(method, js_name = valueOf)]
value_of(this: &Number) -> f641937 pub fn value_of(this: &Number) -> f64;
1938 }
1939
1940 impl Number {
1941 /// The smallest interval between two representable numbers.
1942 ///
1943 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/EPSILON)
1944 pub const EPSILON: f64 = f64::EPSILON;
1945 /// The maximum safe integer in JavaScript (2^53 - 1).
1946 ///
1947 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER)
1948 pub const MAX_SAFE_INTEGER: f64 = 9007199254740991.0;
1949 /// The largest positive representable number.
1950 ///
1951 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_VALUE)
1952 pub const MAX_VALUE: f64 = f64::MAX;
1953 /// The minimum safe integer in JavaScript (-(2^53 - 1)).
1954 ///
1955 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MIN_SAFE_INTEGER)
1956 pub const MIN_SAFE_INTEGER: f64 = -9007199254740991.0;
1957 /// The smallest positive representable number—that is, the positive number closest to zero
1958 /// (without actually being zero).
1959 ///
1960 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MIN_VALUE)
1961 // Cannot use f64::MIN_POSITIVE since that is the smallest **normal** postitive number.
1962 pub const MIN_VALUE: f64 = 5E-324;
1963 /// Special "Not a Number" value.
1964 ///
1965 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/NaN)
1966 pub const NAN: f64 = f64::NAN;
1967 /// Special value representing negative infinity. Returned on overflow.
1968 ///
1969 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/NEGATIVE_INFINITY)
1970 pub const NEGATIVE_INFINITY: f64 = f64::NEG_INFINITY;
1971 /// Special value representing infinity. Returned on overflow.
1972 ///
1973 /// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/POSITIVE_INFINITY)
1974 pub const POSITIVE_INFINITY: f64 = f64::INFINITY;
1975 }
1976
1977 macro_rules! number_from {
1978 ($($x:ident)*) => ($(
1979 impl From<$x> for Number {
1980 #[inline]
1981 fn from(x: $x) -> Number {
1982 Number::unchecked_from_js(JsValue::from(x))
1983 }
1984 }
1985
1986 impl PartialEq<$x> for Number {
1987 #[inline]
1988 fn eq(&self, other: &$x) -> bool {
1989 self.value_of() == f64::from(*other)
1990 }
1991 }
1992 )*)
1993 }
1994 number_from!(i8 u8 i16 u16 i32 u32 f32 f64);
1995
1996 impl From<Number> for f64 {
1997 #[inline]
from(n: Number) -> f641998 fn from(n: Number) -> f64 {
1999 n.value_of()
2000 }
2001 }
2002
2003 impl fmt::Debug for Number {
fmt(&self, f: &mut fmt::Formatter) -> fmt::Result2004 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2005 self.value_of().fmt(f)
2006 }
2007 }
2008
2009 impl Default for Number {
default() -> Self2010 fn default() -> Self {
2011 Self::from(f64::default())
2012 }
2013 }
2014
2015 // Date.
2016 #[wasm_bindgen]
2017 extern "C" {
2018 #[wasm_bindgen(extends = Object, typescript_type = "Date")]
2019 #[derive(Clone, Debug, PartialEq, Eq)]
2020 pub type Date;
2021
2022 /// The `getDate()` method returns the day of the month for the
2023 /// specified date according to local time.
2024 ///
2025 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getDate)
2026 #[wasm_bindgen(method, js_name = getDate)]
get_date(this: &Date) -> u322027 pub fn get_date(this: &Date) -> u32;
2028
2029 /// The `getDay()` method returns the day of the week for the specified date according to local time,
2030 /// where 0 represents Sunday. For the day of the month see getDate().
2031 ///
2032 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getDay)
2033 #[wasm_bindgen(method, js_name = getDay)]
get_day(this: &Date) -> u322034 pub fn get_day(this: &Date) -> u32;
2035
2036 /// The `getFullYear()` method returns the year of the specified date according to local time.
2037 ///
2038 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getFullYear)
2039 #[wasm_bindgen(method, js_name = getFullYear)]
get_full_year(this: &Date) -> u322040 pub fn get_full_year(this: &Date) -> u32;
2041
2042 /// The `getHours()` method returns the hour for the specified date, according to local time.
2043 ///
2044 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getHours)
2045 #[wasm_bindgen(method, js_name = getHours)]
get_hours(this: &Date) -> u322046 pub fn get_hours(this: &Date) -> u32;
2047
2048 /// The `getMilliseconds()` method returns the milliseconds in the specified date according to local time.
2049 ///
2050 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMilliseconds)
2051 #[wasm_bindgen(method, js_name = getMilliseconds)]
get_milliseconds(this: &Date) -> u322052 pub fn get_milliseconds(this: &Date) -> u32;
2053
2054 /// The `getMinutes()` method returns the minutes in the specified date according to local time.
2055 ///
2056 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMinutes)
2057 #[wasm_bindgen(method, js_name = getMinutes)]
get_minutes(this: &Date) -> u322058 pub fn get_minutes(this: &Date) -> u32;
2059
2060 /// The `getMonth()` method returns the month in the specified date according to local time,
2061 /// as a zero-based value (where zero indicates the first month of the year).
2062 ///
2063 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMonth)
2064 #[wasm_bindgen(method, js_name = getMonth)]
get_month(this: &Date) -> u322065 pub fn get_month(this: &Date) -> u32;
2066
2067 /// The `getSeconds()` method returns the seconds in the specified date according to local time.
2068 ///
2069 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getSeconds)
2070 #[wasm_bindgen(method, js_name = getSeconds)]
get_seconds(this: &Date) -> u322071 pub fn get_seconds(this: &Date) -> u32;
2072
2073 /// The `getTime()` method returns the numeric value corresponding to the time for the specified date
2074 /// according to universal time.
2075 ///
2076 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTime)
2077 #[wasm_bindgen(method, js_name = getTime)]
get_time(this: &Date) -> f642078 pub fn get_time(this: &Date) -> f64;
2079
2080 /// The `getTimezoneOffset()` method returns the time zone difference, in minutes,
2081 /// from current locale (host system settings) to UTC.
2082 ///
2083 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTimezoneOffset)
2084 #[wasm_bindgen(method, js_name = getTimezoneOffset)]
get_timezone_offset(this: &Date) -> f642085 pub fn get_timezone_offset(this: &Date) -> f64;
2086
2087 /// The `getUTCDate()` method returns the day (date) of the month in the specified date
2088 /// according to universal time.
2089 ///
2090 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCDate)
2091 #[wasm_bindgen(method, js_name = getUTCDate)]
get_utc_date(this: &Date) -> u322092 pub fn get_utc_date(this: &Date) -> u32;
2093
2094 /// The `getUTCDay()` method returns the day of the week in the specified date according to universal time,
2095 /// where 0 represents Sunday.
2096 ///
2097 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCDay)
2098 #[wasm_bindgen(method, js_name = getUTCDay)]
get_utc_day(this: &Date) -> u322099 pub fn get_utc_day(this: &Date) -> u32;
2100
2101 /// The `getUTCFullYear()` method returns the year in the specified date according to universal time.
2102 ///
2103 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCFullYear)
2104 #[wasm_bindgen(method, js_name = getUTCFullYear)]
get_utc_full_year(this: &Date) -> u322105 pub fn get_utc_full_year(this: &Date) -> u32;
2106
2107 /// The `getUTCHours()` method returns the hours in the specified date according to universal time.
2108 ///
2109 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCHours)
2110 #[wasm_bindgen(method, js_name = getUTCHours)]
get_utc_hours(this: &Date) -> u322111 pub fn get_utc_hours(this: &Date) -> u32;
2112
2113 /// The `getUTCMilliseconds()` method returns the milliseconds in the specified date
2114 /// according to universal time.
2115 ///
2116 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCMilliseconds)
2117 #[wasm_bindgen(method, js_name = getUTCMilliseconds)]
get_utc_milliseconds(this: &Date) -> u322118 pub fn get_utc_milliseconds(this: &Date) -> u32;
2119
2120 /// The `getUTCMinutes()` method returns the minutes in the specified date according to universal time.
2121 ///
2122 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCMinutes)
2123 #[wasm_bindgen(method, js_name = getUTCMinutes)]
get_utc_minutes(this: &Date) -> u322124 pub fn get_utc_minutes(this: &Date) -> u32;
2125
2126 /// The `getUTCMonth()` returns the month of the specified date according to universal time,
2127 /// as a zero-based value (where zero indicates the first month of the year).
2128 ///
2129 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCMonth)
2130 #[wasm_bindgen(method, js_name = getUTCMonth)]
get_utc_month(this: &Date) -> u322131 pub fn get_utc_month(this: &Date) -> u32;
2132
2133 /// The `getUTCSeconds()` method returns the seconds in the specified date according to universal time.
2134 ///
2135 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCSeconds)
2136 #[wasm_bindgen(method, js_name = getUTCSeconds)]
get_utc_seconds(this: &Date) -> u322137 pub fn get_utc_seconds(this: &Date) -> u32;
2138
2139 /// Creates a JavaScript `Date` instance that represents
2140 /// a single moment in time. `Date` objects are based on a time value that is
2141 /// the number of milliseconds since 1 January 1970 UTC.
2142 ///
2143 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
2144 #[wasm_bindgen(constructor)]
new(init: &JsValue) -> Date2145 pub fn new(init: &JsValue) -> Date;
2146
2147 /// Creates a JavaScript `Date` instance that represents the current moment in
2148 /// time.
2149 ///
2150 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
2151 #[wasm_bindgen(constructor)]
new_0() -> Date2152 pub fn new_0() -> Date;
2153
2154 /// Creates a JavaScript `Date` instance that represents
2155 /// a single moment in time. `Date` objects are based on a time value that is
2156 /// the number of milliseconds since 1 January 1970 UTC.
2157 ///
2158 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
2159 #[wasm_bindgen(constructor)]
new_with_year_month(year: u32, month: i32) -> Date2160 pub fn new_with_year_month(year: u32, month: i32) -> Date;
2161
2162 /// Creates a JavaScript `Date` instance that represents
2163 /// a single moment in time. `Date` objects are based on a time value that is
2164 /// the number of milliseconds since 1 January 1970 UTC.
2165 ///
2166 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
2167 #[wasm_bindgen(constructor)]
new_with_year_month_day(year: u32, month: i32, day: i32) -> Date2168 pub fn new_with_year_month_day(year: u32, month: i32, day: i32) -> Date;
2169
2170 /// Creates a JavaScript `Date` instance that represents
2171 /// a single moment in time. `Date` objects are based on a time value that is
2172 /// the number of milliseconds since 1 January 1970 UTC.
2173 ///
2174 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
2175 #[wasm_bindgen(constructor)]
new_with_year_month_day_hr(year: u32, month: i32, day: i32, hr: i32) -> Date2176 pub fn new_with_year_month_day_hr(year: u32, month: i32, day: i32, hr: i32) -> Date;
2177
2178 /// Creates a JavaScript `Date` instance that represents
2179 /// a single moment in time. `Date` objects are based on a time value that is
2180 /// the number of milliseconds since 1 January 1970 UTC.
2181 ///
2182 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
2183 #[wasm_bindgen(constructor)]
new_with_year_month_day_hr_min( year: u32, month: i32, day: i32, hr: i32, min: i32, ) -> Date2184 pub fn new_with_year_month_day_hr_min(
2185 year: u32,
2186 month: i32,
2187 day: i32,
2188 hr: i32,
2189 min: i32,
2190 ) -> Date;
2191
2192 /// Creates a JavaScript `Date` instance that represents
2193 /// a single moment in time. `Date` objects are based on a time value that is
2194 /// the number of milliseconds since 1 January 1970 UTC.
2195 ///
2196 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
2197 #[wasm_bindgen(constructor)]
new_with_year_month_day_hr_min_sec( year: u32, month: i32, day: i32, hr: i32, min: i32, sec: i32, ) -> Date2198 pub fn new_with_year_month_day_hr_min_sec(
2199 year: u32,
2200 month: i32,
2201 day: i32,
2202 hr: i32,
2203 min: i32,
2204 sec: i32,
2205 ) -> Date;
2206
2207 /// Creates a JavaScript `Date` instance that represents
2208 /// a single moment in time. `Date` objects are based on a time value that is
2209 /// the number of milliseconds since 1 January 1970 UTC.
2210 ///
2211 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
2212 #[wasm_bindgen(constructor)]
new_with_year_month_day_hr_min_sec_milli( year: u32, month: i32, day: i32, hr: i32, min: i32, sec: i32, milli: i32, ) -> Date2213 pub fn new_with_year_month_day_hr_min_sec_milli(
2214 year: u32,
2215 month: i32,
2216 day: i32,
2217 hr: i32,
2218 min: i32,
2219 sec: i32,
2220 milli: i32,
2221 ) -> Date;
2222
2223 /// The `Date.now()` method returns the number of milliseconds
2224 /// elapsed since January 1, 1970 00:00:00 UTC.
2225 ///
2226 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/now)
2227 #[wasm_bindgen(static_method_of = Date)]
now() -> f642228 pub fn now() -> f64;
2229
2230 /// The `Date.parse()` method parses a string representation of a date, and returns the number of milliseconds
2231 /// since January 1, 1970, 00:00:00 UTC or `NaN` if the string is unrecognized or, in some cases,
2232 /// contains illegal date values (e.g. 2015-02-31).
2233 ///
2234 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse)
2235 #[wasm_bindgen(static_method_of = Date)]
parse(date: &str) -> f642236 pub fn parse(date: &str) -> f64;
2237
2238 /// The `setDate()` method sets the day of the Date object relative to the beginning of the currently set month.
2239 ///
2240 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setDate)
2241 #[wasm_bindgen(method, js_name = setDate)]
set_date(this: &Date, day: u32) -> f642242 pub fn set_date(this: &Date, day: u32) -> f64;
2243
2244 /// The `setFullYear()` method sets the full year for a specified date according to local time.
2245 /// Returns new timestamp.
2246 ///
2247 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setFullYear)
2248 #[wasm_bindgen(method, js_name = setFullYear)]
set_full_year(this: &Date, year: u32) -> f642249 pub fn set_full_year(this: &Date, year: u32) -> f64;
2250
2251 /// The `setFullYear()` method sets the full year for a specified date according to local time.
2252 /// Returns new timestamp.
2253 ///
2254 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setFullYear)
2255 #[wasm_bindgen(method, js_name = setFullYear)]
set_full_year_with_month(this: &Date, year: u32, month: i32) -> f642256 pub fn set_full_year_with_month(this: &Date, year: u32, month: i32) -> f64;
2257
2258 /// The `setFullYear()` method sets the full year for a specified date according to local time.
2259 /// Returns new timestamp.
2260 ///
2261 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setFullYear)
2262 #[wasm_bindgen(method, js_name = setFullYear)]
set_full_year_with_month_date(this: &Date, year: u32, month: i32, date: i32) -> f642263 pub fn set_full_year_with_month_date(this: &Date, year: u32, month: i32, date: i32) -> f64;
2264
2265 /// The `setHours()` method sets the hours for a specified date according to local time,
2266 /// and returns the number of milliseconds since January 1, 1970 00:00:00 UTC until the time represented
2267 /// by the updated Date instance.
2268 ///
2269 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setHours)
2270 #[wasm_bindgen(method, js_name = setHours)]
set_hours(this: &Date, hours: u32) -> f642271 pub fn set_hours(this: &Date, hours: u32) -> f64;
2272
2273 /// The `setMilliseconds()` method sets the milliseconds for a specified date according to local time.
2274 ///
2275 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setMilliseconds)
2276 #[wasm_bindgen(method, js_name = setMilliseconds)]
set_milliseconds(this: &Date, milliseconds: u32) -> f642277 pub fn set_milliseconds(this: &Date, milliseconds: u32) -> f64;
2278
2279 /// The `setMinutes()` method sets the minutes for a specified date according to local time.
2280 ///
2281 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setMinutes)
2282 #[wasm_bindgen(method, js_name = setMinutes)]
set_minutes(this: &Date, minutes: u32) -> f642283 pub fn set_minutes(this: &Date, minutes: u32) -> f64;
2284
2285 /// The `setMonth()` method sets the month for a specified date according to the currently set year.
2286 ///
2287 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setMonth)
2288 #[wasm_bindgen(method, js_name = setMonth)]
set_month(this: &Date, month: u32) -> f642289 pub fn set_month(this: &Date, month: u32) -> f64;
2290
2291 /// The `setSeconds()` method sets the seconds for a specified date according to local time.
2292 ///
2293 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setSeconds)
2294 #[wasm_bindgen(method, js_name = setSeconds)]
set_seconds(this: &Date, seconds: u32) -> f642295 pub fn set_seconds(this: &Date, seconds: u32) -> f64;
2296
2297 /// The `setTime()` method sets the Date object to the time represented by a number of milliseconds
2298 /// since January 1, 1970, 00:00:00 UTC.
2299 ///
2300 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setTime)
2301 #[wasm_bindgen(method, js_name = setTime)]
set_time(this: &Date, time: f64) -> f642302 pub fn set_time(this: &Date, time: f64) -> f64;
2303
2304 /// The `setUTCDate()` method sets the day of the month for a specified date
2305 /// according to universal time.
2306 ///
2307 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCDate)
2308 #[wasm_bindgen(method, js_name = setUTCDate)]
set_utc_date(this: &Date, day: u32) -> f642309 pub fn set_utc_date(this: &Date, day: u32) -> f64;
2310
2311 /// The `setUTCFullYear()` method sets the full year for a specified date according to universal time.
2312 ///
2313 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCFullYear)
2314 #[wasm_bindgen(method, js_name = setUTCFullYear)]
set_utc_full_year(this: &Date, year: u32) -> f642315 pub fn set_utc_full_year(this: &Date, year: u32) -> f64;
2316
2317 /// The `setUTCFullYear()` method sets the full year for a specified date according to universal time.
2318 ///
2319 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCFullYear)
2320 #[wasm_bindgen(method, js_name = setUTCFullYear)]
set_utc_full_year_with_month(this: &Date, year: u32, month: i32) -> f642321 pub fn set_utc_full_year_with_month(this: &Date, year: u32, month: i32) -> f64;
2322
2323 /// The `setUTCFullYear()` method sets the full year for a specified date according to universal time.
2324 ///
2325 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCFullYear)
2326 #[wasm_bindgen(method, js_name = setUTCFullYear)]
set_utc_full_year_with_month_date(this: &Date, year: u32, month: i32, date: i32) -> f642327 pub fn set_utc_full_year_with_month_date(this: &Date, year: u32, month: i32, date: i32) -> f64;
2328
2329 /// The `setUTCHours()` method sets the hour for a specified date according to universal time,
2330 /// and returns the number of milliseconds since January 1, 1970 00:00:00 UTC until the time
2331 /// represented by the updated Date instance.
2332 ///
2333 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCHours)
2334 #[wasm_bindgen(method, js_name = setUTCHours)]
set_utc_hours(this: &Date, hours: u32) -> f642335 pub fn set_utc_hours(this: &Date, hours: u32) -> f64;
2336
2337 /// The `setUTCMilliseconds()` method sets the milliseconds for a specified date
2338 /// according to universal time.
2339 ///
2340 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCMilliseconds)
2341 #[wasm_bindgen(method, js_name = setUTCMilliseconds)]
set_utc_milliseconds(this: &Date, milliseconds: u32) -> f642342 pub fn set_utc_milliseconds(this: &Date, milliseconds: u32) -> f64;
2343
2344 /// The `setUTCMinutes()` method sets the minutes for a specified date according to universal time.
2345 ///
2346 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCMinutes)
2347 #[wasm_bindgen(method, js_name = setUTCMinutes)]
set_utc_minutes(this: &Date, minutes: u32) -> f642348 pub fn set_utc_minutes(this: &Date, minutes: u32) -> f64;
2349
2350 /// The `setUTCMonth()` method sets the month for a specified date according to universal time.
2351 ///
2352 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCMonth)
2353 #[wasm_bindgen(method, js_name = setUTCMonth)]
set_utc_month(this: &Date, month: u32) -> f642354 pub fn set_utc_month(this: &Date, month: u32) -> f64;
2355
2356 /// The `setUTCSeconds()` method sets the seconds for a specified date according to universal time.
2357 ///
2358 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setUTCSeconds)
2359 #[wasm_bindgen(method, js_name = setUTCSeconds)]
set_utc_seconds(this: &Date, seconds: u32) -> f642360 pub fn set_utc_seconds(this: &Date, seconds: u32) -> f64;
2361
2362 /// The `toDateString()` method returns the date portion of a Date object
2363 /// in human readable form in American English.
2364 ///
2365 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toDateString)
2366 #[wasm_bindgen(method, js_name = toDateString)]
to_date_string(this: &Date) -> JsString2367 pub fn to_date_string(this: &Date) -> JsString;
2368
2369 /// The `toISOString()` method returns a string in simplified extended ISO format (ISO
2370 /// 8601), which is always 24 or 27 characters long (YYYY-MM-DDTHH:mm:ss.sssZ or
2371 /// ±YYYYYY-MM-DDTHH:mm:ss.sssZ, respectively). The timezone is always zero UTC offset,
2372 /// as denoted by the suffix "Z"
2373 ///
2374 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString)
2375 #[wasm_bindgen(method, js_name = toISOString)]
to_iso_string(this: &Date) -> JsString2376 pub fn to_iso_string(this: &Date) -> JsString;
2377
2378 /// The `toJSON()` method returns a string representation of the Date object.
2379 ///
2380 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toJSON)
2381 #[wasm_bindgen(method, js_name = toJSON)]
to_json(this: &Date) -> JsString2382 pub fn to_json(this: &Date) -> JsString;
2383
2384 /// The `toLocaleDateString()` method returns a string with a language sensitive
2385 /// representation of the date portion of this date. The new locales and options
2386 /// arguments let applications specify the language whose formatting conventions
2387 /// should be used and allow to customize the behavior of the function.
2388 /// In older implementations, which ignore the locales and options arguments,
2389 /// the locale used and the form of the string
2390 /// returned are entirely implementation dependent.
2391 ///
2392 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString)
2393 #[wasm_bindgen(method, js_name = toLocaleDateString)]
to_locale_date_string(this: &Date, locale: &str, options: &JsValue) -> JsString2394 pub fn to_locale_date_string(this: &Date, locale: &str, options: &JsValue) -> JsString;
2395
2396 /// The `toLocaleString()` method returns a string with a language sensitive
2397 /// representation of this date. The new locales and options arguments
2398 /// let applications specify the language whose formatting conventions
2399 /// should be used and customize the behavior of the function.
2400 /// In older implementations, which ignore the locales
2401 /// and options arguments, the locale used and the form of the string
2402 /// returned are entirely implementation dependent.
2403 ///
2404 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString)
2405 #[wasm_bindgen(method, js_name = toLocaleString)]
to_locale_string(this: &Date, locale: &str, options: &JsValue) -> JsString2406 pub fn to_locale_string(this: &Date, locale: &str, options: &JsValue) -> JsString;
2407
2408 /// The `toLocaleTimeString()` method returns a string with a language sensitive
2409 /// representation of the time portion of this date. The new locales and options
2410 /// arguments let applications specify the language whose formatting conventions should be
2411 /// used and customize the behavior of the function. In older implementations, which ignore
2412 /// the locales and options arguments, the locale used and the form of the string
2413 /// returned are entirely implementation dependent.
2414 ///
2415 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleTimeString)
2416 #[wasm_bindgen(method, js_name = toLocaleTimeString)]
to_locale_time_string(this: &Date, locale: &str) -> JsString2417 pub fn to_locale_time_string(this: &Date, locale: &str) -> JsString;
2418
2419 /// The `toString()` method returns a string representing
2420 /// the specified Date object.
2421 ///
2422 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toString)
2423 #[wasm_bindgen(method, js_name = toString)]
to_string(this: &Date) -> JsString2424 pub fn to_string(this: &Date) -> JsString;
2425
2426 /// The `toTimeString()` method returns the time portion of a Date object in human
2427 /// readable form in American English.
2428 ///
2429 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toTimeString)
2430 #[wasm_bindgen(method, js_name = toTimeString)]
to_time_string(this: &Date) -> JsString2431 pub fn to_time_string(this: &Date) -> JsString;
2432
2433 /// The `toUTCString()` method converts a date to a string,
2434 /// using the UTC time zone.
2435 ///
2436 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toUTCString)
2437 #[wasm_bindgen(method, js_name = toUTCString)]
to_utc_string(this: &Date) -> JsString2438 pub fn to_utc_string(this: &Date) -> JsString;
2439
2440 /// The `Date.UTC()` method accepts the same parameters as the
2441 /// longest form of the constructor, and returns the number of
2442 /// milliseconds in a `Date` object since January 1, 1970,
2443 /// 00:00:00, universal time.
2444 ///
2445 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/UTC)
2446 #[wasm_bindgen(static_method_of = Date, js_name = UTC)]
utc(year: f64, month: f64) -> f642447 pub fn utc(year: f64, month: f64) -> f64;
2448
2449 /// The `valueOf()` method returns the primitive value of
2450 /// a Date object.
2451 ///
2452 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/valueOf)
2453 #[wasm_bindgen(method, js_name = valueOf)]
value_of(this: &Date) -> f642454 pub fn value_of(this: &Date) -> f64;
2455 }
2456
2457 // Object.
2458 #[wasm_bindgen]
2459 extern "C" {
2460 #[wasm_bindgen(typescript_type = "object")]
2461 #[derive(Clone, Debug)]
2462 pub type Object;
2463
2464 /// The `Object.assign()` method is used to copy the values of all enumerable
2465 /// own properties from one or more source objects to a target object. It
2466 /// will return the target object.
2467 ///
2468 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
2469 #[wasm_bindgen(static_method_of = Object)]
assign(target: &Object, source: &Object) -> Object2470 pub fn assign(target: &Object, source: &Object) -> Object;
2471
2472 /// The `Object.assign()` method is used to copy the values of all enumerable
2473 /// own properties from one or more source objects to a target object. It
2474 /// will return the target object.
2475 ///
2476 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
2477 #[wasm_bindgen(static_method_of = Object, js_name = assign)]
assign2(target: &Object, source1: &Object, source2: &Object) -> Object2478 pub fn assign2(target: &Object, source1: &Object, source2: &Object) -> Object;
2479
2480 /// The `Object.assign()` method is used to copy the values of all enumerable
2481 /// own properties from one or more source objects to a target object. It
2482 /// will return the target object.
2483 ///
2484 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
2485 #[wasm_bindgen(static_method_of = Object, js_name = assign)]
assign3(target: &Object, source1: &Object, source2: &Object, source3: &Object) -> Object2486 pub fn assign3(target: &Object, source1: &Object, source2: &Object, source3: &Object)
2487 -> Object;
2488
2489 /// The constructor property returns a reference to the `Object` constructor
2490 /// function that created the instance object.
2491 ///
2492 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/constructor)
2493 #[wasm_bindgen(method, getter)]
constructor(this: &Object) -> Function2494 pub fn constructor(this: &Object) -> Function;
2495
2496 /// The `Object.create()` method creates a new object, using an existing
2497 /// object to provide the newly created object's prototype.
2498 ///
2499 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/create)
2500 #[wasm_bindgen(static_method_of = Object)]
create(prototype: &Object) -> Object2501 pub fn create(prototype: &Object) -> Object;
2502
2503 /// The static method `Object.defineProperty()` defines a new
2504 /// property directly on an object, or modifies an existing
2505 /// property on an object, and returns the object.
2506 ///
2507 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty)
2508 #[wasm_bindgen(static_method_of = Object, js_name = defineProperty)]
define_property(obj: &Object, prop: &JsValue, descriptor: &Object) -> Object2509 pub fn define_property(obj: &Object, prop: &JsValue, descriptor: &Object) -> Object;
2510
2511 /// The `Object.defineProperties()` method defines new or modifies
2512 /// existing properties directly on an object, returning the
2513 /// object.
2514 ///
2515 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperties)
2516 #[wasm_bindgen(static_method_of = Object, js_name = defineProperties)]
define_properties(obj: &Object, props: &Object) -> Object2517 pub fn define_properties(obj: &Object, props: &Object) -> Object;
2518
2519 /// The `Object.entries()` method returns an array of a given
2520 /// object's own enumerable property [key, value] pairs, in the
2521 /// same order as that provided by a for...in loop (the difference
2522 /// being that a for-in loop enumerates properties in the
2523 /// prototype chain as well).
2524 ///
2525 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries)
2526 #[wasm_bindgen(static_method_of = Object)]
entries(object: &Object) -> Array2527 pub fn entries(object: &Object) -> Array;
2528
2529 /// The `Object.freeze()` method freezes an object: that is, prevents new
2530 /// properties from being added to it; prevents existing properties from
2531 /// being removed; and prevents existing properties, or their enumerability,
2532 /// configurability, or writability, from being changed, it also prevents
2533 /// the prototype from being changed. The method returns the passed object.
2534 ///
2535 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze)
2536 #[wasm_bindgen(static_method_of = Object)]
freeze(value: &Object) -> Object2537 pub fn freeze(value: &Object) -> Object;
2538
2539 /// The `Object.fromEntries()` method transforms a list of key-value pairs
2540 /// into an object.
2541 ///
2542 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/fromEntries)
2543 #[wasm_bindgen(static_method_of = Object, catch, js_name = fromEntries)]
from_entries(iterable: &JsValue) -> Result<Object, JsValue>2544 pub fn from_entries(iterable: &JsValue) -> Result<Object, JsValue>;
2545
2546 /// The `Object.getOwnPropertyDescriptor()` method returns a
2547 /// property descriptor for an own property (that is, one directly
2548 /// present on an object and not in the object's prototype chain)
2549 /// of a given object.
2550 ///
2551 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor)
2552 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptor)]
get_own_property_descriptor(obj: &Object, prop: &JsValue) -> JsValue2553 pub fn get_own_property_descriptor(obj: &Object, prop: &JsValue) -> JsValue;
2554
2555 /// The `Object.getOwnPropertyDescriptors()` method returns all own
2556 /// property descriptors of a given object.
2557 ///
2558 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptors)
2559 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyDescriptors)]
get_own_property_descriptors(obj: &Object) -> JsValue2560 pub fn get_own_property_descriptors(obj: &Object) -> JsValue;
2561
2562 /// The `Object.getOwnPropertyNames()` method returns an array of
2563 /// all properties (including non-enumerable properties except for
2564 /// those which use Symbol) found directly upon a given object.
2565 ///
2566 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyNames)
2567 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertyNames)]
get_own_property_names(obj: &Object) -> Array2568 pub fn get_own_property_names(obj: &Object) -> Array;
2569
2570 /// The `Object.getOwnPropertySymbols()` method returns an array of
2571 /// all symbol properties found directly upon a given object.
2572 ///
2573 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertySymbols)
2574 #[wasm_bindgen(static_method_of = Object, js_name = getOwnPropertySymbols)]
get_own_property_symbols(obj: &Object) -> Array2575 pub fn get_own_property_symbols(obj: &Object) -> Array;
2576
2577 /// The `Object.getPrototypeOf()` method returns the prototype
2578 /// (i.e. the value of the internal [[Prototype]] property) of the
2579 /// specified object.
2580 ///
2581 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getPrototypeOf)
2582 #[wasm_bindgen(static_method_of = Object, js_name = getPrototypeOf)]
get_prototype_of(obj: &JsValue) -> Object2583 pub fn get_prototype_of(obj: &JsValue) -> Object;
2584
2585 /// The `hasOwnProperty()` method returns a boolean indicating whether the
2586 /// object has the specified property as its own property (as opposed to
2587 /// inheriting it).
2588 ///
2589 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty)
2590 #[wasm_bindgen(method, js_name = hasOwnProperty)]
has_own_property(this: &Object, property: &JsValue) -> bool2591 pub fn has_own_property(this: &Object, property: &JsValue) -> bool;
2592
2593 /// The `Object.is()` method determines whether two values are the same value.
2594 ///
2595 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is)
2596 #[wasm_bindgen(static_method_of = Object)]
is(value_1: &JsValue, value_2: &JsValue) -> bool2597 pub fn is(value_1: &JsValue, value_2: &JsValue) -> bool;
2598
2599 /// The `Object.isExtensible()` method determines if an object is extensible
2600 /// (whether it can have new properties added to it).
2601 ///
2602 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isExtensible)
2603 #[wasm_bindgen(static_method_of = Object, js_name = isExtensible)]
is_extensible(object: &Object) -> bool2604 pub fn is_extensible(object: &Object) -> bool;
2605
2606 /// The `Object.isFrozen()` determines if an object is frozen.
2607 ///
2608 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isFrozen)
2609 #[wasm_bindgen(static_method_of = Object, js_name = isFrozen)]
is_frozen(object: &Object) -> bool2610 pub fn is_frozen(object: &Object) -> bool;
2611
2612 /// The `Object.isSealed()` method determines if an object is sealed.
2613 ///
2614 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isSealed)
2615 #[wasm_bindgen(static_method_of = Object, js_name = isSealed)]
is_sealed(object: &Object) -> bool2616 pub fn is_sealed(object: &Object) -> bool;
2617
2618 /// The `isPrototypeOf()` method checks if an object exists in another
2619 /// object's prototype chain.
2620 ///
2621 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isPrototypeOf)
2622 #[wasm_bindgen(method, js_name = isPrototypeOf)]
is_prototype_of(this: &Object, value: &JsValue) -> bool2623 pub fn is_prototype_of(this: &Object, value: &JsValue) -> bool;
2624
2625 /// The `Object.keys()` method returns an array of a given object's property
2626 /// names, in the same order as we get with a normal loop.
2627 ///
2628 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys)
2629 #[wasm_bindgen(static_method_of = Object)]
keys(object: &Object) -> Array2630 pub fn keys(object: &Object) -> Array;
2631
2632 /// The [`Object`] constructor creates an object wrapper.
2633 ///
2634 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)
2635 #[wasm_bindgen(constructor)]
new() -> Object2636 pub fn new() -> Object;
2637
2638 /// The `Object.preventExtensions()` method prevents new properties from
2639 /// ever being added to an object (i.e. prevents future extensions to the
2640 /// object).
2641 ///
2642 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/preventExtensions)
2643 #[wasm_bindgen(static_method_of = Object, js_name = preventExtensions)]
prevent_extensions(object: &Object)2644 pub fn prevent_extensions(object: &Object);
2645
2646 /// The `propertyIsEnumerable()` method returns a Boolean indicating
2647 /// whether the specified property is enumerable.
2648 ///
2649 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/propertyIsEnumerable)
2650 #[wasm_bindgen(method, js_name = propertyIsEnumerable)]
property_is_enumerable(this: &Object, property: &JsValue) -> bool2651 pub fn property_is_enumerable(this: &Object, property: &JsValue) -> bool;
2652
2653 /// The `Object.seal()` method seals an object, preventing new properties
2654 /// from being added to it and marking all existing properties as
2655 /// non-configurable. Values of present properties can still be changed as
2656 /// long as they are writable.
2657 ///
2658 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/seal)
2659 #[wasm_bindgen(static_method_of = Object)]
seal(value: &Object) -> Object2660 pub fn seal(value: &Object) -> Object;
2661
2662 /// The `Object.setPrototypeOf()` method sets the prototype (i.e., the
2663 /// internal `[[Prototype]]` property) of a specified object to another
2664 /// object or `null`.
2665 ///
2666 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/setPrototypeOf)
2667 #[wasm_bindgen(static_method_of = Object, js_name = setPrototypeOf)]
set_prototype_of(object: &Object, prototype: &Object) -> Object2668 pub fn set_prototype_of(object: &Object, prototype: &Object) -> Object;
2669
2670 /// The `toLocaleString()` method returns a string representing the object.
2671 /// This method is meant to be overridden by derived objects for
2672 /// locale-specific purposes.
2673 ///
2674 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toLocaleString)
2675 #[wasm_bindgen(method, js_name = toLocaleString)]
to_locale_string(this: &Object) -> JsString2676 pub fn to_locale_string(this: &Object) -> JsString;
2677
2678 /// The `toString()` method returns a string representing the object.
2679 ///
2680 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString)
2681 #[wasm_bindgen(method, js_name = toString)]
to_string(this: &Object) -> JsString2682 pub fn to_string(this: &Object) -> JsString;
2683
2684 /// The `valueOf()` method returns the primitive value of the
2685 /// specified object.
2686 ///
2687 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf)
2688 #[wasm_bindgen(method, js_name = valueOf)]
value_of(this: &Object) -> Object2689 pub fn value_of(this: &Object) -> Object;
2690
2691 /// The `Object.values()` method returns an array of a given object's own
2692 /// enumerable property values, in the same order as that provided by a
2693 /// `for...in` loop (the difference being that a for-in loop enumerates
2694 /// properties in the prototype chain as well).
2695 ///
2696 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values)
2697 #[wasm_bindgen(static_method_of = Object)]
values(object: &Object) -> Array2698 pub fn values(object: &Object) -> Array;
2699 }
2700
2701 impl Object {
2702 /// Returns the `Object` value of this JS value if it's an instance of an
2703 /// object.
2704 ///
2705 /// If this JS value is not an instance of an object then this returns
2706 /// `None`.
try_from(val: &JsValue) -> Option<&Object>2707 pub fn try_from(val: &JsValue) -> Option<&Object> {
2708 if val.is_object() {
2709 Some(val.unchecked_ref())
2710 } else {
2711 None
2712 }
2713 }
2714 }
2715
2716 impl PartialEq for Object {
2717 #[inline]
eq(&self, other: &Object) -> bool2718 fn eq(&self, other: &Object) -> bool {
2719 Object::is(self.as_ref(), other.as_ref())
2720 }
2721 }
2722
2723 impl Eq for Object {}
2724
2725 impl Default for Object {
default() -> Self2726 fn default() -> Self {
2727 Self::new()
2728 }
2729 }
2730
2731 // Proxy
2732 #[wasm_bindgen]
2733 extern "C" {
2734 #[wasm_bindgen(typescript_type = "ProxyConstructor")]
2735 #[derive(Clone, Debug)]
2736 pub type Proxy;
2737
2738 /// The [`Proxy`] object is used to define custom behavior for fundamental
2739 /// operations (e.g. property lookup, assignment, enumeration, function
2740 /// invocation, etc).
2741 ///
2742 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy)
2743 #[wasm_bindgen(constructor)]
new(target: &JsValue, handler: &Object) -> Proxy2744 pub fn new(target: &JsValue, handler: &Object) -> Proxy;
2745
2746 /// The `Proxy.revocable()` method is used to create a revocable [`Proxy`]
2747 /// object.
2748 ///
2749 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy/revocable)
2750 #[wasm_bindgen(static_method_of = Proxy)]
revocable(target: &JsValue, handler: &Object) -> Object2751 pub fn revocable(target: &JsValue, handler: &Object) -> Object;
2752 }
2753
2754 // RangeError
2755 #[wasm_bindgen]
2756 extern "C" {
2757 /// The `RangeError` object indicates an error when a value is not in the set
2758 /// or range of allowed values.
2759 ///
2760 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError)
2761 #[wasm_bindgen(extends = Error, extends = Object, typescript_type = "RangeError")]
2762 #[derive(Clone, Debug, PartialEq, Eq)]
2763 pub type RangeError;
2764
2765 /// The `RangeError` object indicates an error when a value is not in the set
2766 /// or range of allowed values.
2767 ///
2768 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError)
2769 #[wasm_bindgen(constructor)]
new(message: &str) -> RangeError2770 pub fn new(message: &str) -> RangeError;
2771 }
2772
2773 // ReferenceError
2774 #[wasm_bindgen]
2775 extern "C" {
2776 /// The `ReferenceError` object represents an error when a non-existent
2777 /// variable is referenced.
2778 ///
2779 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError)
2780 #[wasm_bindgen(extends = Error, extends = Object, typescript_type = "ReferenceError")]
2781 #[derive(Clone, Debug, PartialEq, Eq)]
2782 pub type ReferenceError;
2783
2784 /// The `ReferenceError` object represents an error when a non-existent
2785 /// variable is referenced.
2786 ///
2787 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError)
2788 #[wasm_bindgen(constructor)]
new(message: &str) -> ReferenceError2789 pub fn new(message: &str) -> ReferenceError;
2790 }
2791
2792 #[allow(non_snake_case)]
2793 pub mod Reflect {
2794 use super::*;
2795
2796 // Reflect
2797 #[wasm_bindgen]
2798 extern "C" {
2799 /// The static `Reflect.apply()` method calls a target function with
2800 /// arguments as specified.
2801 ///
2802 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/apply)
2803 #[wasm_bindgen(js_namespace = Reflect, catch)]
apply( target: &Function, this_argument: &JsValue, arguments_list: &Array, ) -> Result<JsValue, JsValue>2804 pub fn apply(
2805 target: &Function,
2806 this_argument: &JsValue,
2807 arguments_list: &Array,
2808 ) -> Result<JsValue, JsValue>;
2809
2810 /// The static `Reflect.construct()` method acts like the new operator, but
2811 /// as a function. It is equivalent to calling `new target(...args)`. It
2812 /// gives also the added option to specify a different prototype.
2813 ///
2814 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/construct)
2815 #[wasm_bindgen(js_namespace = Reflect, catch)]
construct(target: &Function, arguments_list: &Array) -> Result<JsValue, JsValue>2816 pub fn construct(target: &Function, arguments_list: &Array) -> Result<JsValue, JsValue>;
2817
2818 /// The static `Reflect.construct()` method acts like the new operator, but
2819 /// as a function. It is equivalent to calling `new target(...args)`. It
2820 /// gives also the added option to specify a different prototype.
2821 ///
2822 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/construct)
2823 #[wasm_bindgen(js_namespace = Reflect, js_name = construct, catch)]
construct_with_new_target( target: &Function, arguments_list: &Array, new_target: &Function, ) -> Result<JsValue, JsValue>2824 pub fn construct_with_new_target(
2825 target: &Function,
2826 arguments_list: &Array,
2827 new_target: &Function,
2828 ) -> Result<JsValue, JsValue>;
2829
2830 /// The static `Reflect.defineProperty()` method is like
2831 /// `Object.defineProperty()` but returns a `Boolean`.
2832 ///
2833 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/defineProperty)
2834 #[wasm_bindgen(js_namespace = Reflect, js_name = defineProperty, catch)]
define_property( target: &Object, property_key: &JsValue, attributes: &Object, ) -> Result<bool, JsValue>2835 pub fn define_property(
2836 target: &Object,
2837 property_key: &JsValue,
2838 attributes: &Object,
2839 ) -> Result<bool, JsValue>;
2840
2841 /// The static `Reflect.deleteProperty()` method allows to delete
2842 /// properties. It is like the `delete` operator as a function.
2843 ///
2844 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/deleteProperty)
2845 #[wasm_bindgen(js_namespace = Reflect, js_name = deleteProperty, catch)]
delete_property(target: &Object, key: &JsValue) -> Result<bool, JsValue>2846 pub fn delete_property(target: &Object, key: &JsValue) -> Result<bool, JsValue>;
2847
2848 /// The static `Reflect.get()` method works like getting a property from
2849 /// an object (`target[propertyKey]`) as a function.
2850 ///
2851 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/get)
2852 #[wasm_bindgen(js_namespace = Reflect, catch)]
get(target: &JsValue, key: &JsValue) -> Result<JsValue, JsValue>2853 pub fn get(target: &JsValue, key: &JsValue) -> Result<JsValue, JsValue>;
2854
2855 /// The same as [`get`](fn.get.html)
2856 /// except the key is an `f64`, which is slightly faster.
2857 #[wasm_bindgen(js_namespace = Reflect, js_name = "get", catch)]
get_f64(target: &JsValue, key: f64) -> Result<JsValue, JsValue>2858 pub fn get_f64(target: &JsValue, key: f64) -> Result<JsValue, JsValue>;
2859
2860 /// The same as [`get`](fn.get.html)
2861 /// except the key is a `u32`, which is slightly faster.
2862 #[wasm_bindgen(js_namespace = Reflect, js_name = "get", catch)]
get_u32(target: &JsValue, key: u32) -> Result<JsValue, JsValue>2863 pub fn get_u32(target: &JsValue, key: u32) -> Result<JsValue, JsValue>;
2864
2865 /// The static `Reflect.getOwnPropertyDescriptor()` method is similar to
2866 /// `Object.getOwnPropertyDescriptor()`. It returns a property descriptor
2867 /// of the given property if it exists on the object, `undefined` otherwise.
2868 ///
2869 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getOwnPropertyDescriptor)
2870 #[wasm_bindgen(js_namespace = Reflect, js_name = getOwnPropertyDescriptor, catch)]
get_own_property_descriptor( target: &Object, property_key: &JsValue, ) -> Result<JsValue, JsValue>2871 pub fn get_own_property_descriptor(
2872 target: &Object,
2873 property_key: &JsValue,
2874 ) -> Result<JsValue, JsValue>;
2875
2876 /// The static `Reflect.getPrototypeOf()` method is almost the same
2877 /// method as `Object.getPrototypeOf()`. It returns the prototype
2878 /// (i.e. the value of the internal `[[Prototype]]` property) of
2879 /// the specified object.
2880 ///
2881 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getPrototypeOf)
2882 #[wasm_bindgen(js_namespace = Reflect, js_name = getPrototypeOf, catch)]
get_prototype_of(target: &JsValue) -> Result<Object, JsValue>2883 pub fn get_prototype_of(target: &JsValue) -> Result<Object, JsValue>;
2884
2885 /// The static `Reflect.has()` method works like the in operator as a
2886 /// function.
2887 ///
2888 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/has)
2889 #[wasm_bindgen(js_namespace = Reflect, catch)]
has(target: &JsValue, property_key: &JsValue) -> Result<bool, JsValue>2890 pub fn has(target: &JsValue, property_key: &JsValue) -> Result<bool, JsValue>;
2891
2892 /// The static `Reflect.isExtensible()` method determines if an object is
2893 /// extensible (whether it can have new properties added to it). It is
2894 /// similar to `Object.isExtensible()`, but with some differences.
2895 ///
2896 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/isExtensible)
2897 #[wasm_bindgen(js_namespace = Reflect, js_name = isExtensible, catch)]
is_extensible(target: &Object) -> Result<bool, JsValue>2898 pub fn is_extensible(target: &Object) -> Result<bool, JsValue>;
2899
2900 /// The static `Reflect.ownKeys()` method returns an array of the
2901 /// target object's own property keys.
2902 ///
2903 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/ownKeys)
2904 #[wasm_bindgen(js_namespace = Reflect, js_name = ownKeys, catch)]
own_keys(target: &JsValue) -> Result<Array, JsValue>2905 pub fn own_keys(target: &JsValue) -> Result<Array, JsValue>;
2906
2907 /// The static `Reflect.preventExtensions()` method prevents new
2908 /// properties from ever being added to an object (i.e. prevents
2909 /// future extensions to the object). It is similar to
2910 /// `Object.preventExtensions()`, but with some differences.
2911 ///
2912 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/preventExtensions)
2913 #[wasm_bindgen(js_namespace = Reflect, js_name = preventExtensions, catch)]
prevent_extensions(target: &Object) -> Result<bool, JsValue>2914 pub fn prevent_extensions(target: &Object) -> Result<bool, JsValue>;
2915
2916 /// The static `Reflect.set()` method works like setting a
2917 /// property on an object.
2918 ///
2919 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
2920 #[wasm_bindgen(js_namespace = Reflect, catch)]
set( target: &JsValue, property_key: &JsValue, value: &JsValue, ) -> Result<bool, JsValue>2921 pub fn set(
2922 target: &JsValue,
2923 property_key: &JsValue,
2924 value: &JsValue,
2925 ) -> Result<bool, JsValue>;
2926
2927 /// The same as [`set`](fn.set.html)
2928 /// except the key is an `f64`, which is slightly faster.
2929 #[wasm_bindgen(js_namespace = Reflect, js_name = "set", catch)]
set_f64( target: &JsValue, property_key: f64, value: &JsValue, ) -> Result<bool, JsValue>2930 pub fn set_f64(
2931 target: &JsValue,
2932 property_key: f64,
2933 value: &JsValue,
2934 ) -> Result<bool, JsValue>;
2935
2936 /// The same as [`set`](fn.set.html)
2937 /// except the key is a `u32`, which is slightly faster.
2938 #[wasm_bindgen(js_namespace = Reflect, js_name = "set", catch)]
set_u32( target: &JsValue, property_key: u32, value: &JsValue, ) -> Result<bool, JsValue>2939 pub fn set_u32(
2940 target: &JsValue,
2941 property_key: u32,
2942 value: &JsValue,
2943 ) -> Result<bool, JsValue>;
2944
2945 /// The static `Reflect.set()` method works like setting a
2946 /// property on an object.
2947 ///
2948 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set)
2949 #[wasm_bindgen(js_namespace = Reflect, js_name = set, catch)]
set_with_receiver( target: &JsValue, property_key: &JsValue, value: &JsValue, receiver: &JsValue, ) -> Result<bool, JsValue>2950 pub fn set_with_receiver(
2951 target: &JsValue,
2952 property_key: &JsValue,
2953 value: &JsValue,
2954 receiver: &JsValue,
2955 ) -> Result<bool, JsValue>;
2956
2957 /// The static `Reflect.setPrototypeOf()` method is the same
2958 /// method as `Object.setPrototypeOf()`. It sets the prototype
2959 /// (i.e., the internal `[[Prototype]]` property) of a specified
2960 /// object to another object or to null.
2961 ///
2962 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/setPrototypeOf)
2963 #[wasm_bindgen(js_namespace = Reflect, js_name = setPrototypeOf, catch)]
set_prototype_of(target: &Object, prototype: &JsValue) -> Result<bool, JsValue>2964 pub fn set_prototype_of(target: &Object, prototype: &JsValue) -> Result<bool, JsValue>;
2965 }
2966 }
2967
2968 // RegExp
2969 #[wasm_bindgen]
2970 extern "C" {
2971 #[wasm_bindgen(extends = Object, typescript_type = "RegExp")]
2972 #[derive(Clone, Debug, PartialEq, Eq)]
2973 pub type RegExp;
2974
2975 /// The `exec()` method executes a search for a match in a specified
2976 /// string. Returns a result array, or null.
2977 ///
2978 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec)
2979 #[wasm_bindgen(method)]
exec(this: &RegExp, text: &str) -> Option<Array>2980 pub fn exec(this: &RegExp, text: &str) -> Option<Array>;
2981
2982 /// The flags property returns a string consisting of the flags of
2983 /// the current regular expression object.
2984 ///
2985 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/flags)
2986 #[wasm_bindgen(method, getter)]
flags(this: &RegExp) -> JsString2987 pub fn flags(this: &RegExp) -> JsString;
2988
2989 /// The global property indicates whether or not the "g" flag is
2990 /// used with the regular expression. global is a read-only
2991 /// property of an individual regular expression instance.
2992 ///
2993 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/global)
2994 #[wasm_bindgen(method, getter)]
global(this: &RegExp) -> bool2995 pub fn global(this: &RegExp) -> bool;
2996
2997 /// The ignoreCase property indicates whether or not the "i" flag
2998 /// is used with the regular expression. ignoreCase is a read-only
2999 /// property of an individual regular expression instance.
3000 ///
3001 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/ignoreCase)
3002 #[wasm_bindgen(method, getter, js_name = ignoreCase)]
ignore_case(this: &RegExp) -> bool3003 pub fn ignore_case(this: &RegExp) -> bool;
3004
3005 /// The non-standard input property is a static property of
3006 /// regular expressions that contains the string against which a
3007 /// regular expression is matched. RegExp.$_ is an alias for this
3008 /// property.
3009 ///
3010 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/input)
3011 #[wasm_bindgen(static_method_of = RegExp, getter)]
input() -> JsString3012 pub fn input() -> JsString;
3013
3014 /// The lastIndex is a read/write integer property of regular expression
3015 /// instances that specifies the index at which to start the next match.
3016 ///
3017 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex)
3018 #[wasm_bindgen(structural, getter = lastIndex, method)]
last_index(this: &RegExp) -> u323019 pub fn last_index(this: &RegExp) -> u32;
3020
3021 /// The lastIndex is a read/write integer property of regular expression
3022 /// instances that specifies the index at which to start the next match.
3023 ///
3024 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex)
3025 #[wasm_bindgen(structural, setter = lastIndex, method)]
set_last_index(this: &RegExp, index: u32)3026 pub fn set_last_index(this: &RegExp, index: u32);
3027
3028 /// The non-standard lastMatch property is a static and read-only
3029 /// property of regular expressions that contains the last matched
3030 /// characters. `RegExp.$&` is an alias for this property.
3031 ///
3032 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastMatch)
3033 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = lastMatch)]
last_match() -> JsString3034 pub fn last_match() -> JsString;
3035
3036 /// The non-standard lastParen property is a static and read-only
3037 /// property of regular expressions that contains the last
3038 /// parenthesized substring match, if any. `RegExp.$+` is an alias
3039 /// for this property.
3040 ///
3041 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastParen)
3042 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = lastParen)]
last_paren() -> JsString3043 pub fn last_paren() -> JsString;
3044
3045 /// The non-standard leftContext property is a static and
3046 /// read-only property of regular expressions that contains the
3047 /// substring preceding the most recent match. `RegExp.$`` is an
3048 /// alias for this property.
3049 ///
3050 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/leftContext)
3051 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = leftContext)]
left_context() -> JsString3052 pub fn left_context() -> JsString;
3053
3054 /// The multiline property indicates whether or not the "m" flag
3055 /// is used with the regular expression. multiline is a read-only
3056 /// property of an individual regular expression instance.
3057 ///
3058 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/multiline)
3059 #[wasm_bindgen(method, getter)]
multiline(this: &RegExp) -> bool3060 pub fn multiline(this: &RegExp) -> bool;
3061
3062 /// The non-standard $1, $2, $3, $4, $5, $6, $7, $8, $9 properties
3063 /// are static and read-only properties of regular expressions
3064 /// that contain parenthesized substring matches.
3065 ///
3066 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/n)
3067 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$1")]
n1() -> JsString3068 pub fn n1() -> JsString;
3069 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$2")]
n2() -> JsString3070 pub fn n2() -> JsString;
3071 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$3")]
n3() -> JsString3072 pub fn n3() -> JsString;
3073 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$4")]
n4() -> JsString3074 pub fn n4() -> JsString;
3075 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$5")]
n5() -> JsString3076 pub fn n5() -> JsString;
3077 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$6")]
n6() -> JsString3078 pub fn n6() -> JsString;
3079 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$7")]
n7() -> JsString3080 pub fn n7() -> JsString;
3081 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$8")]
n8() -> JsString3082 pub fn n8() -> JsString;
3083 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = "$9")]
n9() -> JsString3084 pub fn n9() -> JsString;
3085
3086 /// The `RegExp` constructor creates a regular expression object for matching text with a pattern.
3087 ///
3088 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp)
3089 #[wasm_bindgen(constructor)]
new(pattern: &str, flags: &str) -> RegExp3090 pub fn new(pattern: &str, flags: &str) -> RegExp;
3091 #[wasm_bindgen(constructor)]
new_regexp(pattern: &RegExp, flags: &str) -> RegExp3092 pub fn new_regexp(pattern: &RegExp, flags: &str) -> RegExp;
3093
3094 /// The non-standard rightContext property is a static and
3095 /// read-only property of regular expressions that contains the
3096 /// substring following the most recent match. `RegExp.$'` is an
3097 /// alias for this property.
3098 ///
3099 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/rightContext)
3100 #[wasm_bindgen(static_method_of = RegExp, getter, js_name = rightContext)]
right_context() -> JsString3101 pub fn right_context() -> JsString;
3102
3103 /// The source property returns a String containing the source
3104 /// text of the regexp object, and it doesn't contain the two
3105 /// forward slashes on both sides and any flags.
3106 ///
3107 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/source)
3108 #[wasm_bindgen(method, getter)]
source(this: &RegExp) -> JsString3109 pub fn source(this: &RegExp) -> JsString;
3110
3111 /// The sticky property reflects whether or not the search is
3112 /// sticky (searches in strings only from the index indicated by
3113 /// the lastIndex property of this regular expression). sticky is
3114 /// a read-only property of an individual regular expression
3115 /// object.
3116 ///
3117 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/sticky)
3118 #[wasm_bindgen(method, getter)]
sticky(this: &RegExp) -> bool3119 pub fn sticky(this: &RegExp) -> bool;
3120
3121 /// The `test()` method executes a search for a match between a
3122 /// regular expression and a specified string. Returns true or
3123 /// false.
3124 ///
3125 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/test)
3126 #[wasm_bindgen(method)]
test(this: &RegExp, text: &str) -> bool3127 pub fn test(this: &RegExp, text: &str) -> bool;
3128
3129 /// The `toString()` method returns a string representing the
3130 /// regular expression.
3131 ///
3132 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/toString)
3133 #[wasm_bindgen(method, js_name = toString)]
to_string(this: &RegExp) -> JsString3134 pub fn to_string(this: &RegExp) -> JsString;
3135
3136 /// The unicode property indicates whether or not the "u" flag is
3137 /// used with a regular expression. unicode is a read-only
3138 /// property of an individual regular expression instance.
3139 ///
3140 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/unicode)
3141 #[wasm_bindgen(method, getter)]
unicode(this: &RegExp) -> bool3142 pub fn unicode(this: &RegExp) -> bool;
3143 }
3144
3145 // Set
3146 #[wasm_bindgen]
3147 extern "C" {
3148 #[wasm_bindgen(extends = Object, typescript_type = "Set<any>")]
3149 #[derive(Clone, Debug, PartialEq, Eq)]
3150 pub type Set;
3151
3152 /// The `add()` method appends a new element with a specified value to the
3153 /// end of a [`Set`] object.
3154 ///
3155 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/add)
3156 #[wasm_bindgen(method)]
add(this: &Set, value: &JsValue) -> Set3157 pub fn add(this: &Set, value: &JsValue) -> Set;
3158
3159 /// The `clear()` method removes all elements from a [`Set`] object.
3160 ///
3161 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/clear)
3162 #[wasm_bindgen(method)]
clear(this: &Set)3163 pub fn clear(this: &Set);
3164
3165 /// The `delete()` method removes the specified element from a [`Set`]
3166 /// object.
3167 ///
3168 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/delete)
3169 #[wasm_bindgen(method)]
delete(this: &Set, value: &JsValue) -> bool3170 pub fn delete(this: &Set, value: &JsValue) -> bool;
3171
3172 /// The `forEach()` method executes a provided function once for each value
3173 /// in the Set object, in insertion order.
3174 ///
3175 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/forEach)
3176 #[wasm_bindgen(method, js_name = forEach)]
for_each(this: &Set, callback: &mut dyn FnMut(JsValue, JsValue, Set))3177 pub fn for_each(this: &Set, callback: &mut dyn FnMut(JsValue, JsValue, Set));
3178
3179 /// The `has()` method returns a boolean indicating whether an element with
3180 /// the specified value exists in a [`Set`] object or not.
3181 ///
3182 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/has)
3183 #[wasm_bindgen(method)]
has(this: &Set, value: &JsValue) -> bool3184 pub fn has(this: &Set, value: &JsValue) -> bool;
3185
3186 /// The [`Set`] object lets you store unique values of any type, whether
3187 /// primitive values or object references.
3188 ///
3189 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
3190 #[wasm_bindgen(constructor)]
new(init: &JsValue) -> Set3191 pub fn new(init: &JsValue) -> Set;
3192
3193 /// The size accessor property returns the number of elements in a [`Set`]
3194 /// object.
3195 ///
3196 /// [MDN documentation](https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Set/size)
3197 #[wasm_bindgen(method, getter, structural)]
size(this: &Set) -> u323198 pub fn size(this: &Set) -> u32;
3199 }
3200
3201 impl Default for Set {
default() -> Self3202 fn default() -> Self {
3203 Self::new(&JsValue::UNDEFINED)
3204 }
3205 }
3206
3207 // SetIterator
3208 #[wasm_bindgen]
3209 extern "C" {
3210 /// The `entries()` method returns a new Iterator object that contains an
3211 /// array of [value, value] for each element in the Set object, in insertion
3212 /// order. For Set objects there is no key like in Map objects. However, to
3213 /// keep the API similar to the Map object, each entry has the same value
3214 /// for its key and value here, so that an array [value, value] is returned.
3215 ///
3216 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/entries)
3217 #[wasm_bindgen(method)]
entries(set: &Set) -> Iterator3218 pub fn entries(set: &Set) -> Iterator;
3219
3220 /// The `keys()` method is an alias for this method (for similarity with
3221 /// Map objects); it behaves exactly the same and returns values
3222 /// of Set elements.
3223 ///
3224 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/values)
3225 #[wasm_bindgen(method)]
keys(set: &Set) -> Iterator3226 pub fn keys(set: &Set) -> Iterator;
3227
3228 /// The `values()` method returns a new Iterator object that contains the
3229 /// values for each element in the Set object in insertion order.
3230 ///
3231 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/values)
3232 #[wasm_bindgen(method)]
values(set: &Set) -> Iterator3233 pub fn values(set: &Set) -> Iterator;
3234 }
3235
3236 // SyntaxError
3237 #[wasm_bindgen]
3238 extern "C" {
3239 /// A `SyntaxError` is thrown when the JavaScript engine encounters tokens or
3240 /// token order that does not conform to the syntax of the language when
3241 /// parsing code.
3242 ///
3243 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError)
3244 #[wasm_bindgen(extends = Error, extends = Object, typescript_type = "SyntaxError")]
3245 #[derive(Clone, Debug, PartialEq, Eq)]
3246 pub type SyntaxError;
3247
3248 /// A `SyntaxError` is thrown when the JavaScript engine encounters tokens or
3249 /// token order that does not conform to the syntax of the language when
3250 /// parsing code.
3251 ///
3252 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError)
3253 #[wasm_bindgen(constructor)]
new(message: &str) -> SyntaxError3254 pub fn new(message: &str) -> SyntaxError;
3255 }
3256
3257 // TypeError
3258 #[wasm_bindgen]
3259 extern "C" {
3260 /// The `TypeError` object represents an error when a value is not of the
3261 /// expected type.
3262 ///
3263 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError)
3264 #[wasm_bindgen(extends = Error, extends = Object, typescript_type = "TypeError")]
3265 #[derive(Clone, Debug, PartialEq, Eq)]
3266 pub type TypeError;
3267
3268 /// The `TypeError` object represents an error when a value is not of the
3269 /// expected type.
3270 ///
3271 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError)
3272 #[wasm_bindgen(constructor)]
new(message: &str) -> TypeError3273 pub fn new(message: &str) -> TypeError;
3274 }
3275
3276 // URIError
3277 #[wasm_bindgen]
3278 extern "C" {
3279 /// The `URIError` object represents an error when a global URI handling
3280 /// function was used in a wrong way.
3281 ///
3282 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError)
3283 #[wasm_bindgen(extends = Error, extends = Object, js_name = URIError, typescript_type = "URIError")]
3284 #[derive(Clone, Debug, PartialEq, Eq)]
3285 pub type UriError;
3286
3287 /// The `URIError` object represents an error when a global URI handling
3288 /// function was used in a wrong way.
3289 ///
3290 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError)
3291 #[wasm_bindgen(constructor, js_class = "URIError")]
new(message: &str) -> UriError3292 pub fn new(message: &str) -> UriError;
3293 }
3294
3295 // WeakMap
3296 #[wasm_bindgen]
3297 extern "C" {
3298 #[wasm_bindgen(extends = Object, typescript_type = "WeakMap<object, any>")]
3299 #[derive(Clone, Debug, PartialEq, Eq)]
3300 pub type WeakMap;
3301
3302 /// The [`WeakMap`] object is a collection of key/value pairs in which the
3303 /// keys are weakly referenced. The keys must be objects and the values can
3304 /// be arbitrary values.
3305 ///
3306 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap)
3307 #[wasm_bindgen(constructor)]
new() -> WeakMap3308 pub fn new() -> WeakMap;
3309
3310 /// The `set()` method sets the value for the key in the [`WeakMap`] object.
3311 /// Returns the [`WeakMap`] object.
3312 ///
3313 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/set)
3314 #[wasm_bindgen(method, js_class = "WeakMap")]
set(this: &WeakMap, key: &Object, value: &JsValue) -> WeakMap3315 pub fn set(this: &WeakMap, key: &Object, value: &JsValue) -> WeakMap;
3316
3317 /// The `get()` method returns a specified by key element
3318 /// from a [`WeakMap`] object.
3319 ///
3320 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/get)
3321 #[wasm_bindgen(method)]
get(this: &WeakMap, key: &Object) -> JsValue3322 pub fn get(this: &WeakMap, key: &Object) -> JsValue;
3323
3324 /// The `has()` method returns a boolean indicating whether an element with
3325 /// the specified key exists in the [`WeakMap`] object or not.
3326 ///
3327 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/has)
3328 #[wasm_bindgen(method)]
has(this: &WeakMap, key: &Object) -> bool3329 pub fn has(this: &WeakMap, key: &Object) -> bool;
3330
3331 /// The `delete()` method removes the specified element from a [`WeakMap`]
3332 /// object.
3333 ///
3334 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/delete)
3335 #[wasm_bindgen(method)]
delete(this: &WeakMap, key: &Object) -> bool3336 pub fn delete(this: &WeakMap, key: &Object) -> bool;
3337 }
3338
3339 impl Default for WeakMap {
default() -> Self3340 fn default() -> Self {
3341 Self::new()
3342 }
3343 }
3344
3345 // WeakSet
3346 #[wasm_bindgen]
3347 extern "C" {
3348 #[wasm_bindgen(extends = Object, typescript_type = "WeakSet<object>")]
3349 #[derive(Clone, Debug, PartialEq, Eq)]
3350 pub type WeakSet;
3351
3352 /// The `WeakSet` object lets you store weakly held objects in a collection.
3353 ///
3354 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet)
3355 #[wasm_bindgen(constructor)]
new() -> WeakSet3356 pub fn new() -> WeakSet;
3357
3358 /// The `has()` method returns a boolean indicating whether an object exists
3359 /// in a WeakSet or not.
3360 ///
3361 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet/has)
3362 #[wasm_bindgen(method)]
has(this: &WeakSet, value: &Object) -> bool3363 pub fn has(this: &WeakSet, value: &Object) -> bool;
3364
3365 /// The `add()` method appends a new object to the end of a WeakSet object.
3366 ///
3367 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet/add)
3368 #[wasm_bindgen(method)]
add(this: &WeakSet, value: &Object) -> WeakSet3369 pub fn add(this: &WeakSet, value: &Object) -> WeakSet;
3370
3371 /// The `delete()` method removes the specified element from a WeakSet
3372 /// object.
3373 ///
3374 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet/delete)
3375 #[wasm_bindgen(method)]
delete(this: &WeakSet, value: &Object) -> bool3376 pub fn delete(this: &WeakSet, value: &Object) -> bool;
3377 }
3378
3379 impl Default for WeakSet {
default() -> Self3380 fn default() -> Self {
3381 Self::new()
3382 }
3383 }
3384
3385 #[allow(non_snake_case)]
3386 pub mod WebAssembly {
3387 use super::*;
3388
3389 // WebAssembly
3390 #[wasm_bindgen]
3391 extern "C" {
3392 /// The `WebAssembly.compile()` function compiles a `WebAssembly.Module`
3393 /// from WebAssembly binary code. This function is useful if it is
3394 /// necessary to a compile a module before it can be instantiated
3395 /// (otherwise, the `WebAssembly.instantiate()` function should be used).
3396 ///
3397 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compile)
3398 #[wasm_bindgen(js_namespace = WebAssembly)]
compile(buffer_source: &JsValue) -> Promise3399 pub fn compile(buffer_source: &JsValue) -> Promise;
3400
3401 /// The `WebAssembly.instantiate()` function allows you to compile and
3402 /// instantiate WebAssembly code.
3403 ///
3404 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate)
3405 #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiate)]
instantiate_buffer(buffer: &[u8], imports: &Object) -> Promise3406 pub fn instantiate_buffer(buffer: &[u8], imports: &Object) -> Promise;
3407
3408 /// The `WebAssembly.instantiate()` function allows you to compile and
3409 /// instantiate WebAssembly code.
3410 ///
3411 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate)
3412 #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiate)]
instantiate_module(module: &Module, imports: &Object) -> Promise3413 pub fn instantiate_module(module: &Module, imports: &Object) -> Promise;
3414
3415 /// The `WebAssembly.instantiateStreaming()` function compiles and
3416 /// instantiates a WebAssembly module directly from a streamed
3417 /// underlying source. This is the most efficient, optimized way to load
3418 /// wasm code.
3419 ///
3420 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiateStreaming)
3421 #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiateStreaming)]
instantiate_streaming(response: &Promise, imports: &Object) -> Promise3422 pub fn instantiate_streaming(response: &Promise, imports: &Object) -> Promise;
3423
3424 /// The `WebAssembly.validate()` function validates a given typed
3425 /// array of WebAssembly binary code, returning whether the bytes
3426 /// form a valid wasm module (`true`) or not (`false`).
3427 ///
3428 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/validate)
3429 #[wasm_bindgen(js_namespace = WebAssembly, catch)]
validate(buffer_source: &JsValue) -> Result<bool, JsValue>3430 pub fn validate(buffer_source: &JsValue) -> Result<bool, JsValue>;
3431 }
3432
3433 // WebAssembly.CompileError
3434 #[wasm_bindgen]
3435 extern "C" {
3436 /// The `WebAssembly.CompileError()` constructor creates a new
3437 /// WebAssembly `CompileError` object, which indicates an error during
3438 /// WebAssembly decoding or validation.
3439 ///
3440 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/CompileError)
3441 #[wasm_bindgen(extends = Error, js_namespace = WebAssembly, typescript_type = "WebAssembly.CompileError")]
3442 #[derive(Clone, Debug, PartialEq, Eq)]
3443 pub type CompileError;
3444
3445 /// The `WebAssembly.CompileError()` constructor creates a new
3446 /// WebAssembly `CompileError` object, which indicates an error during
3447 /// WebAssembly decoding or validation.
3448 ///
3449 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/CompileError)
3450 #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
new(message: &str) -> CompileError3451 pub fn new(message: &str) -> CompileError;
3452 }
3453
3454 // WebAssembly.Instance
3455 #[wasm_bindgen]
3456 extern "C" {
3457 /// A `WebAssembly.Instance` object is a stateful, executable instance
3458 /// of a `WebAssembly.Module`. Instance objects contain all the exported
3459 /// WebAssembly functions that allow calling into WebAssembly code from
3460 /// JavaScript.
3461 ///
3462 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance)
3463 #[wasm_bindgen(extends = Object, js_namespace = WebAssembly, typescript_type = "WebAssembly.Instance")]
3464 #[derive(Clone, Debug, PartialEq, Eq)]
3465 pub type Instance;
3466
3467 /// The `WebAssembly.Instance()` constructor function can be called to
3468 /// synchronously instantiate a given `WebAssembly.Module`
3469 /// object. However, the primary way to get an `Instance` is through the
3470 /// asynchronous `WebAssembly.instantiateStreaming()` function.
3471 ///
3472 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance)
3473 #[wasm_bindgen(catch, constructor, js_namespace = WebAssembly)]
new(module: &Module, imports: &Object) -> Result<Instance, JsValue>3474 pub fn new(module: &Module, imports: &Object) -> Result<Instance, JsValue>;
3475
3476 /// The `exports` readonly property of the `WebAssembly.Instance` object
3477 /// prototype returns an object containing as its members all the
3478 /// functions exported from the WebAssembly module instance, to allow
3479 /// them to be accessed and used by JavaScript.
3480 ///
3481 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance/exports)
3482 #[wasm_bindgen(getter, method, js_namespace = WebAssembly)]
exports(this: &Instance) -> Object3483 pub fn exports(this: &Instance) -> Object;
3484 }
3485
3486 // WebAssembly.LinkError
3487 #[wasm_bindgen]
3488 extern "C" {
3489 /// The `WebAssembly.LinkError()` constructor creates a new WebAssembly
3490 /// LinkError object, which indicates an error during module
3491 /// instantiation (besides traps from the start function).
3492 ///
3493 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/LinkError)
3494 #[wasm_bindgen(extends = Error, js_namespace = WebAssembly, typescript_type = "WebAssembly.LinkError")]
3495 #[derive(Clone, Debug, PartialEq, Eq)]
3496 pub type LinkError;
3497
3498 /// The `WebAssembly.LinkError()` constructor creates a new WebAssembly
3499 /// LinkError object, which indicates an error during module
3500 /// instantiation (besides traps from the start function).
3501 ///
3502 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/LinkError)
3503 #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
new(message: &str) -> LinkError3504 pub fn new(message: &str) -> LinkError;
3505 }
3506
3507 // WebAssembly.RuntimeError
3508 #[wasm_bindgen]
3509 extern "C" {
3510 /// The `WebAssembly.RuntimeError()` constructor creates a new WebAssembly
3511 /// `RuntimeError` object — the type that is thrown whenever WebAssembly
3512 /// specifies a trap.
3513 ///
3514 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/RuntimeError)
3515 #[wasm_bindgen(extends = Error, js_namespace = WebAssembly, typescript_type = "WebAssembly.RuntimeError")]
3516 #[derive(Clone, Debug, PartialEq, Eq)]
3517 pub type RuntimeError;
3518
3519 /// The `WebAssembly.RuntimeError()` constructor creates a new WebAssembly
3520 /// `RuntimeError` object — the type that is thrown whenever WebAssembly
3521 /// specifies a trap.
3522 ///
3523 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/RuntimeError)
3524 #[wasm_bindgen(constructor, js_namespace = WebAssembly)]
new(message: &str) -> RuntimeError3525 pub fn new(message: &str) -> RuntimeError;
3526 }
3527
3528 // WebAssembly.Module
3529 #[wasm_bindgen]
3530 extern "C" {
3531 /// A `WebAssembly.Module` object contains stateless WebAssembly code
3532 /// that has already been compiled by the browser and can be
3533 /// efficiently shared with Workers, and instantiated multiple times.
3534 ///
3535 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module)
3536 #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Module")]
3537 #[derive(Clone, Debug, PartialEq, Eq)]
3538 pub type Module;
3539
3540 /// A `WebAssembly.Module` object contains stateless WebAssembly code
3541 /// that has already been compiled by the browser and can be
3542 /// efficiently shared with Workers, and instantiated multiple times.
3543 ///
3544 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module)
3545 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
new(buffer_source: &JsValue) -> Result<Module, JsValue>3546 pub fn new(buffer_source: &JsValue) -> Result<Module, JsValue>;
3547
3548 /// The `WebAssembly.customSections()` function returns a copy of the
3549 /// contents of all custom sections in the given module with the given
3550 /// string name.
3551 ///
3552 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/customSections)
3553 #[wasm_bindgen(static_method_of = Module, js_namespace = WebAssembly, js_name = customSections)]
custom_sections(module: &Module, sectionName: &str) -> Array3554 pub fn custom_sections(module: &Module, sectionName: &str) -> Array;
3555
3556 /// The `WebAssembly.exports()` function returns an array containing
3557 /// descriptions of all the declared exports of the given `Module`.
3558 ///
3559 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/exports)
3560 #[wasm_bindgen(static_method_of = Module, js_namespace = WebAssembly)]
exports(module: &Module) -> Array3561 pub fn exports(module: &Module) -> Array;
3562
3563 /// The `WebAssembly.imports()` function returns an array containing
3564 /// descriptions of all the declared imports of the given `Module`.
3565 ///
3566 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/imports)
3567 #[wasm_bindgen(static_method_of = Module, js_namespace = WebAssembly)]
imports(module: &Module) -> Array3568 pub fn imports(module: &Module) -> Array;
3569 }
3570
3571 // WebAssembly.Table
3572 #[wasm_bindgen]
3573 extern "C" {
3574 /// The `WebAssembly.Table()` constructor creates a new `Table` object
3575 /// of the given size and element type.
3576 ///
3577 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table)
3578 #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Table")]
3579 #[derive(Clone, Debug, PartialEq, Eq)]
3580 pub type Table;
3581
3582 /// The `WebAssembly.Table()` constructor creates a new `Table` object
3583 /// of the given size and element type.
3584 ///
3585 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table)
3586 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
new(table_descriptor: &Object) -> Result<Table, JsValue>3587 pub fn new(table_descriptor: &Object) -> Result<Table, JsValue>;
3588
3589 /// The length prototype property of the `WebAssembly.Table` object
3590 /// returns the length of the table, i.e. the number of elements in the
3591 /// table.
3592 ///
3593 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/length)
3594 #[wasm_bindgen(method, getter, js_namespace = WebAssembly)]
length(this: &Table) -> u323595 pub fn length(this: &Table) -> u32;
3596
3597 /// The `get()` prototype method of the `WebAssembly.Table()` object
3598 /// retrieves a function reference stored at a given index.
3599 ///
3600 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/get)
3601 #[wasm_bindgen(method, catch, js_namespace = WebAssembly)]
get(this: &Table, index: u32) -> Result<Function, JsValue>3602 pub fn get(this: &Table, index: u32) -> Result<Function, JsValue>;
3603
3604 /// The `grow()` prototype method of the `WebAssembly.Table` object
3605 /// increases the size of the `Table` instance by a specified number of
3606 /// elements.
3607 ///
3608 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/grow)
3609 #[wasm_bindgen(method, catch, js_namespace = WebAssembly)]
grow(this: &Table, additional_capacity: u32) -> Result<u32, JsValue>3610 pub fn grow(this: &Table, additional_capacity: u32) -> Result<u32, JsValue>;
3611
3612 /// The `set()` prototype method of the `WebAssembly.Table` object mutates a
3613 /// reference stored at a given index to a different value.
3614 ///
3615 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/set)
3616 #[wasm_bindgen(method, catch, js_namespace = WebAssembly)]
set(this: &Table, index: u32, function: &Function) -> Result<(), JsValue>3617 pub fn set(this: &Table, index: u32, function: &Function) -> Result<(), JsValue>;
3618 }
3619
3620 // WebAssembly.Global
3621 #[wasm_bindgen]
3622 extern "C" {
3623 /// The `WebAssembly.Global()` constructor creates a new `Global` object
3624 /// of the given type and value.
3625 ///
3626 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global)
3627 #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Global")]
3628 #[derive(Clone, Debug, PartialEq, Eq)]
3629 pub type Global;
3630
3631 /// The `WebAssembly.Global()` constructor creates a new `Global` object
3632 /// of the given type and value.
3633 ///
3634 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global)
3635 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
new(global_descriptor: &Object, value: &JsValue) -> Result<Global, JsValue>3636 pub fn new(global_descriptor: &Object, value: &JsValue) -> Result<Global, JsValue>;
3637
3638 /// The value prototype property of the `WebAssembly.Global` object
3639 /// returns the value of the global.
3640 ///
3641 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global)
3642 #[wasm_bindgen(method, getter, structural, js_namespace = WebAssembly)]
value(this: &Global) -> JsValue3643 pub fn value(this: &Global) -> JsValue;
3644 #[wasm_bindgen(method, setter = value, structural, js_namespace = WebAssembly)]
set_value(this: &Global, value: &JsValue)3645 pub fn set_value(this: &Global, value: &JsValue);
3646 }
3647
3648 // WebAssembly.Memory
3649 #[wasm_bindgen]
3650 extern "C" {
3651 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory)
3652 #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Memory")]
3653 #[derive(Clone, Debug, PartialEq, Eq)]
3654 pub type Memory;
3655
3656 /// The `WebAssembly.Memory()` constructor creates a new `Memory` object
3657 /// which is a resizable `ArrayBuffer` that holds the raw bytes of
3658 /// memory accessed by a WebAssembly `Instance`.
3659 ///
3660 /// A memory created by JavaScript or in WebAssembly code will be
3661 /// accessible and mutable from both JavaScript and WebAssembly.
3662 ///
3663 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory)
3664 #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)]
new(descriptor: &Object) -> Result<Memory, JsValue>3665 pub fn new(descriptor: &Object) -> Result<Memory, JsValue>;
3666
3667 /// An accessor property that returns the buffer contained in the
3668 /// memory.
3669 ///
3670 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory/buffer)
3671 #[wasm_bindgen(method, getter, js_namespace = WebAssembly)]
buffer(this: &Memory) -> JsValue3672 pub fn buffer(this: &Memory) -> JsValue;
3673
3674 /// The `grow()` protoype method of the `Memory` object increases the
3675 /// size of the memory instance by a specified number of WebAssembly
3676 /// pages.
3677 ///
3678 /// Takes the number of pages to grow (64KiB in size) and returns the
3679 /// previous size of memory, in pages.
3680 ///
3681 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory/grow)
3682 #[wasm_bindgen(method, js_namespace = WebAssembly)]
grow(this: &Memory, pages: u32) -> u323683 pub fn grow(this: &Memory, pages: u32) -> u32;
3684 }
3685 }
3686
3687 /// The `JSON` object contains methods for parsing [JavaScript Object
3688 /// Notation (JSON)](https://json.org/) and converting values to JSON. It
3689 /// can't be called or constructed, and aside from its two method
3690 /// properties, it has no interesting functionality of its own.
3691 #[allow(non_snake_case)]
3692 pub mod JSON {
3693 use super::*;
3694
3695 // JSON
3696 #[wasm_bindgen]
3697 extern "C" {
3698 /// The `JSON.parse()` method parses a JSON string, constructing the
3699 /// JavaScript value or object described by the string.
3700 ///
3701 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse)
3702 #[wasm_bindgen(catch, js_namespace = JSON)]
parse(text: &str) -> Result<JsValue, JsValue>3703 pub fn parse(text: &str) -> Result<JsValue, JsValue>;
3704
3705 /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
3706 ///
3707 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
3708 #[wasm_bindgen(catch, js_namespace = JSON)]
stringify(obj: &JsValue) -> Result<JsString, JsValue>3709 pub fn stringify(obj: &JsValue) -> Result<JsString, JsValue>;
3710
3711 /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
3712 ///
3713 /// The `replacer` argument is a function that alters the behavior of the stringification
3714 /// process, or an array of String and Number objects that serve as a whitelist
3715 /// for selecting/filtering the properties of the value object to be included
3716 /// in the JSON string. If this value is null or not provided, all properties
3717 /// of the object are included in the resulting JSON string.
3718 ///
3719 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
3720 #[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
stringify_with_replacer( obj: &JsValue, replacer: &JsValue, ) -> Result<JsString, JsValue>3721 pub fn stringify_with_replacer(
3722 obj: &JsValue,
3723 replacer: &JsValue,
3724 ) -> Result<JsString, JsValue>;
3725
3726 /// The `JSON.stringify()` method converts a JavaScript value to a JSON string.
3727 ///
3728 /// The `replacer` argument is a function that alters the behavior of the stringification
3729 /// process, or an array of String and Number objects that serve as a whitelist
3730 /// for selecting/filtering the properties of the value object to be included
3731 /// in the JSON string. If this value is null or not provided, all properties
3732 /// of the object are included in the resulting JSON string.
3733 ///
3734 /// The `space` argument is a String or Number object that's used to insert white space into
3735 /// the output JSON string for readability purposes. If this is a Number, it
3736 /// indicates the number of space characters to use as white space; this number
3737 /// is capped at 10 (if it is greater, the value is just 10). Values less than
3738 /// 1 indicate that no space should be used. If this is a String, the string
3739 /// (or the first 10 characters of the string, if it's longer than that) is
3740 /// used as white space. If this parameter is not provided (or is null), no
3741 /// white space is used.
3742 ///
3743 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
3744 #[wasm_bindgen(catch, js_namespace = JSON, js_name = stringify)]
stringify_with_replacer_and_space( obj: &JsValue, replacer: &JsValue, space: &JsValue, ) -> Result<JsString, JsValue>3745 pub fn stringify_with_replacer_and_space(
3746 obj: &JsValue,
3747 replacer: &JsValue,
3748 space: &JsValue,
3749 ) -> Result<JsString, JsValue>;
3750
3751 }
3752 }
3753
3754 // JsString
3755 #[wasm_bindgen]
3756 extern "C" {
3757 #[wasm_bindgen(js_name = String, extends = Object, is_type_of = JsValue::is_string, typescript_type = "string")]
3758 #[derive(Clone, PartialEq, Eq)]
3759 pub type JsString;
3760
3761 /// The length property of a String object indicates the length of a string,
3762 /// in UTF-16 code units.
3763 ///
3764 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/length)
3765 #[wasm_bindgen(method, getter, structural)]
length(this: &JsString) -> u323766 pub fn length(this: &JsString) -> u32;
3767
3768 /// The String object's `charAt()` method returns a new string consisting of
3769 /// the single UTF-16 code unit located at the specified offset into the
3770 /// string.
3771 ///
3772 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charAt)
3773 #[wasm_bindgen(method, js_class = "String", js_name = charAt)]
char_at(this: &JsString, index: u32) -> JsString3774 pub fn char_at(this: &JsString, index: u32) -> JsString;
3775
3776 /// The `charCodeAt()` method returns an integer between 0 and 65535
3777 /// representing the UTF-16 code unit at the given index (the UTF-16 code
3778 /// unit matches the Unicode code point for code points representable in a
3779 /// single UTF-16 code unit, but might also be the first code unit of a
3780 /// surrogate pair for code points not representable in a single UTF-16 code
3781 /// unit, e.g. Unicode code points > 0x10000). If you want the entire code
3782 /// point value, use `codePointAt()`.
3783 ///
3784 /// Returns `NaN` if index is out of range.
3785 ///
3786 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charCodeAt)
3787 #[wasm_bindgen(method, js_class = "String", js_name = charCodeAt)]
char_code_at(this: &JsString, index: u32) -> f643788 pub fn char_code_at(this: &JsString, index: u32) -> f64;
3789
3790 /// The `codePointAt()` method returns a non-negative integer that is the
3791 /// Unicode code point value.
3792 ///
3793 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/codePointAt)
3794 #[wasm_bindgen(method, js_class = "String", js_name = codePointAt)]
code_point_at(this: &JsString, pos: u32) -> JsValue3795 pub fn code_point_at(this: &JsString, pos: u32) -> JsValue;
3796
3797 /// The `concat()` method concatenates the string arguments to the calling
3798 /// string and returns a new string.
3799 ///
3800 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/concat)
3801 #[wasm_bindgen(method, js_class = "String")]
concat(this: &JsString, string_2: &JsValue) -> JsString3802 pub fn concat(this: &JsString, string_2: &JsValue) -> JsString;
3803
3804 /// The `endsWith()` method determines whether a string ends with the characters of a
3805 /// specified string, returning true or false as appropriate.
3806 ///
3807 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith)
3808 #[wasm_bindgen(method, js_class = "String", js_name = endsWith)]
ends_with(this: &JsString, search_string: &str, length: i32) -> bool3809 pub fn ends_with(this: &JsString, search_string: &str, length: i32) -> bool;
3810
3811 /// The static `String.fromCharCode()` method returns a string created from
3812 /// the specified sequence of UTF-16 code units.
3813 ///
3814 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
3815 ///
3816 /// # Notes
3817 ///
3818 /// There are a few bindings to `from_char_code` in `js-sys`: `from_char_code1`, `from_char_code2`, etc...
3819 /// with different arities.
3820 ///
3821 /// Additionally, this function accepts `u16` for character codes, but
3822 /// fixing others requires a breaking change release
3823 /// (see https://github.com/rustwasm/wasm-bindgen/issues/1460 for details).
3824 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode, variadic)]
from_char_code(char_codes: &[u16]) -> JsString3825 pub fn from_char_code(char_codes: &[u16]) -> JsString;
3826
3827 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
3828 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
from_char_code1(a: u32) -> JsString3829 pub fn from_char_code1(a: u32) -> JsString;
3830
3831 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
3832 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
from_char_code2(a: u32, b: u32) -> JsString3833 pub fn from_char_code2(a: u32, b: u32) -> JsString;
3834
3835 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
3836 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
from_char_code3(a: u32, b: u32, c: u32) -> JsString3837 pub fn from_char_code3(a: u32, b: u32, c: u32) -> JsString;
3838
3839 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
3840 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
from_char_code4(a: u32, b: u32, c: u32, d: u32) -> JsString3841 pub fn from_char_code4(a: u32, b: u32, c: u32, d: u32) -> JsString;
3842
3843 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode)
3844 #[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
from_char_code5(a: u32, b: u32, c: u32, d: u32, e: u32) -> JsString3845 pub fn from_char_code5(a: u32, b: u32, c: u32, d: u32, e: u32) -> JsString;
3846
3847 /// The static `String.fromCodePoint()` method returns a string created by
3848 /// using the specified sequence of code points.
3849 ///
3850 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
3851 ///
3852 /// # Exceptions
3853 ///
3854 /// A RangeError is thrown if an invalid Unicode code point is given
3855 ///
3856 /// # Notes
3857 ///
3858 /// There are a few bindings to `from_code_point` in `js-sys`: `from_code_point1`, `from_code_point2`, etc...
3859 /// with different arities.
3860 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint, variadic)]
from_code_point(code_points: &[u32]) -> Result<JsString, JsValue>3861 pub fn from_code_point(code_points: &[u32]) -> Result<JsString, JsValue>;
3862
3863 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
3864 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
from_code_point1(a: u32) -> Result<JsString, JsValue>3865 pub fn from_code_point1(a: u32) -> Result<JsString, JsValue>;
3866
3867 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
3868 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
from_code_point2(a: u32, b: u32) -> Result<JsString, JsValue>3869 pub fn from_code_point2(a: u32, b: u32) -> Result<JsString, JsValue>;
3870
3871 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
3872 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
from_code_point3(a: u32, b: u32, c: u32) -> Result<JsString, JsValue>3873 pub fn from_code_point3(a: u32, b: u32, c: u32) -> Result<JsString, JsValue>;
3874
3875 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
3876 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
from_code_point4(a: u32, b: u32, c: u32, d: u32) -> Result<JsString, JsValue>3877 pub fn from_code_point4(a: u32, b: u32, c: u32, d: u32) -> Result<JsString, JsValue>;
3878
3879 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint)
3880 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
from_code_point5(a: u32, b: u32, c: u32, d: u32, e: u32) -> Result<JsString, JsValue>3881 pub fn from_code_point5(a: u32, b: u32, c: u32, d: u32, e: u32) -> Result<JsString, JsValue>;
3882
3883 /// The `includes()` method determines whether one string may be found
3884 /// within another string, returning true or false as appropriate.
3885 ///
3886 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes)
3887 #[wasm_bindgen(method, js_class = "String")]
includes(this: &JsString, search_string: &str, position: i32) -> bool3888 pub fn includes(this: &JsString, search_string: &str, position: i32) -> bool;
3889
3890 /// The `indexOf()` method returns the index within the calling String
3891 /// object of the first occurrence of the specified value, starting the
3892 /// search at fromIndex. Returns -1 if the value is not found.
3893 ///
3894 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf)
3895 #[wasm_bindgen(method, js_class = "String", js_name = indexOf)]
index_of(this: &JsString, search_value: &str, from_index: i32) -> i323896 pub fn index_of(this: &JsString, search_value: &str, from_index: i32) -> i32;
3897
3898 /// The `lastIndexOf()` method returns the index within the calling String
3899 /// object of the last occurrence of the specified value, searching
3900 /// backwards from fromIndex. Returns -1 if the value is not found.
3901 ///
3902 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/lastIndexOf)
3903 #[wasm_bindgen(method, js_class = "String", js_name = lastIndexOf)]
last_index_of(this: &JsString, search_value: &str, from_index: i32) -> i323904 pub fn last_index_of(this: &JsString, search_value: &str, from_index: i32) -> i32;
3905
3906 /// The `localeCompare()` method returns a number indicating whether
3907 /// a reference string comes before or after or is the same as
3908 /// the given string in sort order.
3909 ///
3910 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare)
3911 #[wasm_bindgen(method, js_class = "String", js_name = localeCompare)]
locale_compare( this: &JsString, compare_string: &str, locales: &Array, options: &Object, ) -> i323912 pub fn locale_compare(
3913 this: &JsString,
3914 compare_string: &str,
3915 locales: &Array,
3916 options: &Object,
3917 ) -> i32;
3918
3919 /// The `match()` method retrieves the matches when matching a string against a regular expression.
3920 ///
3921 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match)
3922 #[wasm_bindgen(method, js_class = "String", js_name = match)]
match_(this: &JsString, pattern: &RegExp) -> Option<Object>3923 pub fn match_(this: &JsString, pattern: &RegExp) -> Option<Object>;
3924
3925 /// The `normalize()` method returns the Unicode Normalization Form
3926 /// of a given string (if the value isn't a string, it will be converted to one first).
3927 ///
3928 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize)
3929 #[wasm_bindgen(method, js_class = "String")]
normalize(this: &JsString, form: &str) -> JsString3930 pub fn normalize(this: &JsString, form: &str) -> JsString;
3931
3932 /// The `padEnd()` method pads the current string with a given string
3933 /// (repeated, if needed) so that the resulting string reaches a given
3934 /// length. The padding is applied from the end (right) of the current
3935 /// string.
3936 ///
3937 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padEnd)
3938 #[wasm_bindgen(method, js_class = "String", js_name = padEnd)]
pad_end(this: &JsString, target_length: u32, pad_string: &str) -> JsString3939 pub fn pad_end(this: &JsString, target_length: u32, pad_string: &str) -> JsString;
3940
3941 /// The `padStart()` method pads the current string with another string
3942 /// (repeated, if needed) so that the resulting string reaches the given
3943 /// length. The padding is applied from the start (left) of the current
3944 /// string.
3945 ///
3946 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padStart)
3947 #[wasm_bindgen(method, js_class = "String", js_name = padStart)]
pad_start(this: &JsString, target_length: u32, pad_string: &str) -> JsString3948 pub fn pad_start(this: &JsString, target_length: u32, pad_string: &str) -> JsString;
3949
3950 /// The `repeat()` method constructs and returns a new string which contains the specified
3951 /// number of copies of the string on which it was called, concatenated together.
3952 ///
3953 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat)
3954 #[wasm_bindgen(method, js_class = "String")]
repeat(this: &JsString, count: i32) -> JsString3955 pub fn repeat(this: &JsString, count: i32) -> JsString;
3956
3957 /// The `replace()` method returns a new string with some or all matches of a pattern
3958 /// replaced by a replacement. The pattern can be a string or a RegExp, and
3959 /// the replacement can be a string or a function to be called for each match.
3960 ///
3961 /// Note: The original string will remain unchanged.
3962 ///
3963 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
3964 #[wasm_bindgen(method, js_class = "String")]
replace(this: &JsString, pattern: &str, replacement: &str) -> JsString3965 pub fn replace(this: &JsString, pattern: &str, replacement: &str) -> JsString;
3966
3967 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
3968 #[wasm_bindgen(method, js_class = "String", js_name = replace)]
replace_with_function( this: &JsString, pattern: &str, replacement: &Function, ) -> JsString3969 pub fn replace_with_function(
3970 this: &JsString,
3971 pattern: &str,
3972 replacement: &Function,
3973 ) -> JsString;
3974
3975 #[wasm_bindgen(method, js_class = "String", js_name = replace)]
replace_by_pattern(this: &JsString, pattern: &RegExp, replacement: &str) -> JsString3976 pub fn replace_by_pattern(this: &JsString, pattern: &RegExp, replacement: &str) -> JsString;
3977
3978 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
3979 #[wasm_bindgen(method, js_class = "String", js_name = replace)]
replace_by_pattern_with_function( this: &JsString, pattern: &RegExp, replacement: &Function, ) -> JsString3980 pub fn replace_by_pattern_with_function(
3981 this: &JsString,
3982 pattern: &RegExp,
3983 replacement: &Function,
3984 ) -> JsString;
3985
3986 /// The `search()` method executes a search for a match between
3987 /// a regular expression and this String object.
3988 ///
3989 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/search)
3990 #[wasm_bindgen(method, js_class = "String")]
search(this: &JsString, pattern: &RegExp) -> i323991 pub fn search(this: &JsString, pattern: &RegExp) -> i32;
3992
3993 /// The `slice()` method extracts a section of a string and returns it as a
3994 /// new string, without modifying the original string.
3995 ///
3996 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice)
3997 #[wasm_bindgen(method, js_class = "String")]
slice(this: &JsString, start: u32, end: u32) -> JsString3998 pub fn slice(this: &JsString, start: u32, end: u32) -> JsString;
3999
4000 /// The `split()` method splits a String object into an array of strings by separating the string
4001 /// into substrings, using a specified separator string to determine where to make each split.
4002 ///
4003 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)
4004 #[wasm_bindgen(method, js_class = "String")]
split(this: &JsString, separator: &str) -> Array4005 pub fn split(this: &JsString, separator: &str) -> Array;
4006
4007 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)
4008 #[wasm_bindgen(method, js_class = "String", js_name = split)]
split_limit(this: &JsString, separator: &str, limit: u32) -> Array4009 pub fn split_limit(this: &JsString, separator: &str, limit: u32) -> Array;
4010
4011 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)
4012 #[wasm_bindgen(method, js_class = "String", js_name = split)]
split_by_pattern(this: &JsString, pattern: &RegExp) -> Array4013 pub fn split_by_pattern(this: &JsString, pattern: &RegExp) -> Array;
4014
4015 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)
4016 #[wasm_bindgen(method, js_class = "String", js_name = split)]
split_by_pattern_limit(this: &JsString, pattern: &RegExp, limit: u32) -> Array4017 pub fn split_by_pattern_limit(this: &JsString, pattern: &RegExp, limit: u32) -> Array;
4018
4019 /// The `startsWith()` method determines whether a string begins with the
4020 /// characters of a specified string, returning true or false as
4021 /// appropriate.
4022 ///
4023 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith)
4024 #[wasm_bindgen(method, js_class = "String", js_name = startsWith)]
starts_with(this: &JsString, search_string: &str, position: u32) -> bool4025 pub fn starts_with(this: &JsString, search_string: &str, position: u32) -> bool;
4026
4027 /// The `substring()` method returns the part of the string between the
4028 /// start and end indexes, or to the end of the string.
4029 ///
4030 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring)
4031 #[wasm_bindgen(method, js_class = "String")]
substring(this: &JsString, index_start: u32, index_end: u32) -> JsString4032 pub fn substring(this: &JsString, index_start: u32, index_end: u32) -> JsString;
4033
4034 /// The `substr()` method returns the part of a string between
4035 /// the start index and a number of characters after it.
4036 ///
4037 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr)
4038 #[wasm_bindgen(method, js_class = "String")]
substr(this: &JsString, start: i32, length: i32) -> JsString4039 pub fn substr(this: &JsString, start: i32, length: i32) -> JsString;
4040
4041 /// The `toLocaleLowerCase()` method returns the calling string value converted to lower case,
4042 /// according to any locale-specific case mappings.
4043 ///
4044 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLocaleLowerCase)
4045 #[wasm_bindgen(method, js_class = "String", js_name = toLocaleLowerCase)]
to_locale_lower_case(this: &JsString, locale: Option<&str>) -> JsString4046 pub fn to_locale_lower_case(this: &JsString, locale: Option<&str>) -> JsString;
4047
4048 /// The `toLocaleUpperCase()` method returns the calling string value converted to upper case,
4049 /// according to any locale-specific case mappings.
4050 ///
4051 /// [MDN documentation](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/String/toLocaleUpperCase)
4052 #[wasm_bindgen(method, js_class = "String", js_name = toLocaleUpperCase)]
to_locale_upper_case(this: &JsString, locale: Option<&str>) -> JsString4053 pub fn to_locale_upper_case(this: &JsString, locale: Option<&str>) -> JsString;
4054
4055 /// The `toLowerCase()` method returns the calling string value
4056 /// converted to lower case.
4057 ///
4058 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLowerCase)
4059 #[wasm_bindgen(method, js_class = "String", js_name = toLowerCase)]
to_lower_case(this: &JsString) -> JsString4060 pub fn to_lower_case(this: &JsString) -> JsString;
4061
4062 /// The `toString()` method returns a string representing the specified
4063 /// object.
4064 ///
4065 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toString)
4066 #[wasm_bindgen(method, js_class = "String", js_name = toString)]
to_string(this: &JsString) -> JsString4067 pub fn to_string(this: &JsString) -> JsString;
4068
4069 /// The `toUpperCase()` method returns the calling string value converted to
4070 /// uppercase (the value will be converted to a string if it isn't one).
4071 ///
4072 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase)
4073 #[wasm_bindgen(method, js_class = "String", js_name = toUpperCase)]
to_upper_case(this: &JsString) -> JsString4074 pub fn to_upper_case(this: &JsString) -> JsString;
4075
4076 /// The `trim()` method removes whitespace from both ends of a string.
4077 /// Whitespace in this context is all the whitespace characters (space, tab,
4078 /// no-break space, etc.) and all the line terminator characters (LF, CR,
4079 /// etc.).
4080 ///
4081 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trim)
4082 #[wasm_bindgen(method, js_class = "String")]
trim(this: &JsString) -> JsString4083 pub fn trim(this: &JsString) -> JsString;
4084
4085 /// The `trimEnd()` method removes whitespace from the end of a string.
4086 /// `trimRight()` is an alias of this method.
4087 ///
4088 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimEnd)
4089 #[wasm_bindgen(method, js_class = "String", js_name = trimEnd)]
trim_end(this: &JsString) -> JsString4090 pub fn trim_end(this: &JsString) -> JsString;
4091
4092 /// The `trimEnd()` method removes whitespace from the end of a string.
4093 /// `trimRight()` is an alias of this method.
4094 ///
4095 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimEnd)
4096 #[wasm_bindgen(method, js_class = "String", js_name = trimRight)]
trim_right(this: &JsString) -> JsString4097 pub fn trim_right(this: &JsString) -> JsString;
4098
4099 /// The `trimStart()` method removes whitespace from the beginning of a
4100 /// string. `trimLeft()` is an alias of this method.
4101 ///
4102 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimStart)
4103 #[wasm_bindgen(method, js_class = "String", js_name = trimStart)]
trim_start(this: &JsString) -> JsString4104 pub fn trim_start(this: &JsString) -> JsString;
4105
4106 /// The `trimStart()` method removes whitespace from the beginning of a
4107 /// string. `trimLeft()` is an alias of this method.
4108 ///
4109 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimStart)
4110 #[wasm_bindgen(method, js_class = "String", js_name = trimLeft)]
trim_left(this: &JsString) -> JsString4111 pub fn trim_left(this: &JsString) -> JsString;
4112
4113 /// The `valueOf()` method returns the primitive value of a `String` object.
4114 ///
4115 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/valueOf)
4116 #[wasm_bindgen(method, js_class = "String", js_name = valueOf)]
value_of(this: &JsString) -> JsString4117 pub fn value_of(this: &JsString) -> JsString;
4118
4119 /// The static `raw()` method is a tag function of template literals,
4120 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
4121 ///
4122 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
4123 #[wasm_bindgen(catch, variadic, static_method_of = JsString, js_class = "String")]
raw(call_site: &Object, substitutions: &Array) -> Result<JsString, JsValue>4124 pub fn raw(call_site: &Object, substitutions: &Array) -> Result<JsString, JsValue>;
4125
4126 /// The static `raw()` method is a tag function of template literals,
4127 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
4128 ///
4129 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
4130 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
raw_0(call_site: &Object) -> Result<JsString, JsValue>4131 pub fn raw_0(call_site: &Object) -> Result<JsString, JsValue>;
4132
4133 /// The static `raw()` method is a tag function of template literals,
4134 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
4135 ///
4136 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
4137 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
raw_1(call_site: &Object, substitutions_1: &str) -> Result<JsString, JsValue>4138 pub fn raw_1(call_site: &Object, substitutions_1: &str) -> Result<JsString, JsValue>;
4139
4140 /// The static `raw()` method is a tag function of template literals,
4141 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
4142 ///
4143 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
4144 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
raw_2( call_site: &Object, substitutions_1: &str, substitutions_2: &str, ) -> Result<JsString, JsValue>4145 pub fn raw_2(
4146 call_site: &Object,
4147 substitutions_1: &str,
4148 substitutions_2: &str,
4149 ) -> Result<JsString, JsValue>;
4150
4151 /// The static `raw()` method is a tag function of template literals,
4152 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
4153 ///
4154 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
4155 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
raw_3( call_site: &Object, substitutions_1: &str, substitutions_2: &str, substitutions_3: &str, ) -> Result<JsString, JsValue>4156 pub fn raw_3(
4157 call_site: &Object,
4158 substitutions_1: &str,
4159 substitutions_2: &str,
4160 substitutions_3: &str,
4161 ) -> Result<JsString, JsValue>;
4162
4163 /// The static `raw()` method is a tag function of template literals,
4164 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
4165 ///
4166 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
4167 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
raw_4( call_site: &Object, substitutions_1: &str, substitutions_2: &str, substitutions_3: &str, substitutions_4: &str, ) -> Result<JsString, JsValue>4168 pub fn raw_4(
4169 call_site: &Object,
4170 substitutions_1: &str,
4171 substitutions_2: &str,
4172 substitutions_3: &str,
4173 substitutions_4: &str,
4174 ) -> Result<JsString, JsValue>;
4175
4176 /// The static `raw()` method is a tag function of template literals,
4177 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
4178 ///
4179 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
4180 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
raw_5( call_site: &Object, substitutions_1: &str, substitutions_2: &str, substitutions_3: &str, substitutions_4: &str, substitutions_5: &str, ) -> Result<JsString, JsValue>4181 pub fn raw_5(
4182 call_site: &Object,
4183 substitutions_1: &str,
4184 substitutions_2: &str,
4185 substitutions_3: &str,
4186 substitutions_4: &str,
4187 substitutions_5: &str,
4188 ) -> Result<JsString, JsValue>;
4189
4190 /// The static `raw()` method is a tag function of template literals,
4191 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
4192 ///
4193 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
4194 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
raw_6( call_site: &Object, substitutions_1: &str, substitutions_2: &str, substitutions_3: &str, substitutions_4: &str, substitutions_5: &str, substitutions_6: &str, ) -> Result<JsString, JsValue>4195 pub fn raw_6(
4196 call_site: &Object,
4197 substitutions_1: &str,
4198 substitutions_2: &str,
4199 substitutions_3: &str,
4200 substitutions_4: &str,
4201 substitutions_5: &str,
4202 substitutions_6: &str,
4203 ) -> Result<JsString, JsValue>;
4204
4205 /// The static `raw()` method is a tag function of template literals,
4206 /// similar to the `r` prefix in Python or the `@` prefix in C# for string literals.
4207 ///
4208 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw)
4209 #[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = raw)]
raw_7( call_site: &Object, substitutions_1: &str, substitutions_2: &str, substitutions_3: &str, substitutions_4: &str, substitutions_5: &str, substitutions_6: &str, substitutions_7: &str, ) -> Result<JsString, JsValue>4210 pub fn raw_7(
4211 call_site: &Object,
4212 substitutions_1: &str,
4213 substitutions_2: &str,
4214 substitutions_3: &str,
4215 substitutions_4: &str,
4216 substitutions_5: &str,
4217 substitutions_6: &str,
4218 substitutions_7: &str,
4219 ) -> Result<JsString, JsValue>;
4220 }
4221
4222 impl JsString {
4223 /// Returns the `JsString` value of this JS value if it's an instance of a
4224 /// string.
4225 ///
4226 /// If this JS value is not an instance of a string then this returns
4227 /// `None`.
4228 #[deprecated(note = "recommended to use dyn_ref instead which is now equivalent")]
try_from(val: &JsValue) -> Option<&JsString>4229 pub fn try_from(val: &JsValue) -> Option<&JsString> {
4230 val.dyn_ref()
4231 }
4232
4233 /// Returns whether this string is a valid UTF-16 string.
4234 ///
4235 /// This is useful for learning whether `String::from(..)` will return a
4236 /// lossless representation of the JS string. If this string contains
4237 /// unpaired surrogates then `String::from` will succeed but it will be a
4238 /// lossy representation of the JS string because unpaired surrogates will
4239 /// become replacement characters.
4240 ///
4241 /// If this function returns `false` then to get a lossless representation
4242 /// of the string you'll need to manually use the `iter` method (or the
4243 /// `char_code_at` accessor) to view the raw character codes.
4244 ///
4245 /// For more information, see the documentation on [JS strings vs Rust
4246 /// strings][docs]
4247 ///
4248 /// [docs]: https://rustwasm.github.io/docs/wasm-bindgen/reference/types/str.html
is_valid_utf16(&self) -> bool4249 pub fn is_valid_utf16(&self) -> bool {
4250 std::char::decode_utf16(self.iter()).all(|i| i.is_ok())
4251 }
4252
4253 /// Returns an iterator over the `u16` character codes that make up this JS
4254 /// string.
4255 ///
4256 /// This method will call `char_code_at` for each code in this JS string,
4257 /// returning an iterator of the codes in sequence.
iter<'a>( &'a self, ) -> impl ExactSizeIterator<Item = u16> + DoubleEndedIterator<Item = u16> + 'a4258 pub fn iter<'a>(
4259 &'a self,
4260 ) -> impl ExactSizeIterator<Item = u16> + DoubleEndedIterator<Item = u16> + 'a {
4261 (0..self.length()).map(move |i| self.char_code_at(i) as u16)
4262 }
4263
4264 /// If this string consists of a single Unicode code point, then this method
4265 /// converts it into a Rust `char` without doing any allocations.
4266 ///
4267 /// If this JS value is not a valid UTF-8 or consists of more than a single
4268 /// codepoint, then this returns `None`.
4269 ///
4270 /// Note that a single Unicode code point might be represented as more than
4271 /// one code unit on the JavaScript side. For example, a JavaScript string
4272 /// `"\uD801\uDC37"` is actually a single Unicode code point U+10437 which
4273 /// corresponds to a character ''.
as_char(&self) -> Option<char>4274 pub fn as_char(&self) -> Option<char> {
4275 let len = self.length();
4276
4277 if len == 0 || len > 2 {
4278 return None;
4279 }
4280
4281 // This will be simplified when definitions are fixed:
4282 // https://github.com/rustwasm/wasm-bindgen/issues/1362
4283 let cp = self.code_point_at(0).as_f64().unwrap_throw() as u32;
4284
4285 let c = std::char::from_u32(cp)?;
4286
4287 if c.len_utf16() as u32 == len {
4288 Some(c)
4289 } else {
4290 None
4291 }
4292 }
4293 }
4294
4295 impl PartialEq<str> for JsString {
eq(&self, other: &str) -> bool4296 fn eq(&self, other: &str) -> bool {
4297 String::from(self) == other
4298 }
4299 }
4300
4301 impl<'a> PartialEq<&'a str> for JsString {
eq(&self, other: &&'a str) -> bool4302 fn eq(&self, other: &&'a str) -> bool {
4303 <JsString as PartialEq<str>>::eq(self, other)
4304 }
4305 }
4306
4307 impl PartialEq<String> for JsString {
eq(&self, other: &String) -> bool4308 fn eq(&self, other: &String) -> bool {
4309 <JsString as PartialEq<str>>::eq(self, other)
4310 }
4311 }
4312
4313 impl<'a> PartialEq<&'a String> for JsString {
eq(&self, other: &&'a String) -> bool4314 fn eq(&self, other: &&'a String) -> bool {
4315 <JsString as PartialEq<str>>::eq(self, other)
4316 }
4317 }
4318
4319 impl<'a> From<&'a str> for JsString {
from(s: &'a str) -> Self4320 fn from(s: &'a str) -> Self {
4321 JsString::unchecked_from_js(JsValue::from_str(s))
4322 }
4323 }
4324
4325 impl From<String> for JsString {
from(s: String) -> Self4326 fn from(s: String) -> Self {
4327 From::from(&*s)
4328 }
4329 }
4330
4331 impl From<char> for JsString {
4332 #[inline]
from(c: char) -> Self4333 fn from(c: char) -> Self {
4334 JsString::from_code_point1(c as u32).unwrap_throw()
4335 }
4336 }
4337
4338 impl<'a> From<&'a JsString> for String {
from(s: &'a JsString) -> Self4339 fn from(s: &'a JsString) -> Self {
4340 s.obj.as_string().unwrap_throw()
4341 }
4342 }
4343
4344 impl From<JsString> for String {
from(s: JsString) -> Self4345 fn from(s: JsString) -> Self {
4346 From::from(&s)
4347 }
4348 }
4349
4350 impl fmt::Debug for JsString {
fmt(&self, f: &mut fmt::Formatter) -> fmt::Result4351 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4352 String::from(self).fmt(f)
4353 }
4354 }
4355
4356 impl str::FromStr for JsString {
4357 type Err = convert::Infallible;
from_str(s: &str) -> Result<Self, Self::Err>4358 fn from_str(s: &str) -> Result<Self, Self::Err> {
4359 Ok(JsString::from(s))
4360 }
4361 }
4362
4363 // Symbol
4364 #[wasm_bindgen]
4365 extern "C" {
4366 #[wasm_bindgen(is_type_of = JsValue::is_symbol, typescript_type = "Symbol")]
4367 #[derive(Clone, Debug)]
4368 pub type Symbol;
4369
4370 /// The `Symbol.hasInstance` well-known symbol is used to determine
4371 /// if a constructor object recognizes an object as its instance.
4372 /// The `instanceof` operator's behavior can be customized by this symbol.
4373 ///
4374 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/hasInstance)
4375 #[wasm_bindgen(static_method_of = Symbol, getter, structural, js_name = hasInstance)]
has_instance() -> Symbol4376 pub fn has_instance() -> Symbol;
4377
4378 /// The `Symbol.isConcatSpreadable` well-known symbol is used to configure
4379 /// if an object should be flattened to its array elements when using the
4380 /// `Array.prototype.concat()` method.
4381 ///
4382 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/isConcatSpreadable)
4383 #[wasm_bindgen(static_method_of = Symbol, getter, structural, js_name = isConcatSpreadable)]
is_concat_spreadable() -> Symbol4384 pub fn is_concat_spreadable() -> Symbol;
4385
4386 /// The `Symbol.asyncIterator` well-known symbol specifies the default AsyncIterator for an object.
4387 /// If this property is set on an object, it is an async iterable and can be used in a `for await...of` loop.
4388 ///
4389 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/asyncIterator)
4390 #[wasm_bindgen(static_method_of = Symbol, getter, structural, js_name = asyncIterator)]
async_iterator() -> Symbol4391 pub fn async_iterator() -> Symbol;
4392
4393 /// The `Symbol.iterator` well-known symbol specifies the default iterator
4394 /// for an object. Used by `for...of`.
4395 ///
4396 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/iterator)
4397 #[wasm_bindgen(static_method_of = Symbol, getter, structural)]
iterator() -> Symbol4398 pub fn iterator() -> Symbol;
4399
4400 /// The `Symbol.match` well-known symbol specifies the matching of a regular
4401 /// expression against a string. This function is called by the
4402 /// `String.prototype.match()` method.
4403 ///
4404 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/match)
4405 #[wasm_bindgen(static_method_of = Symbol, getter, structural, js_name = match)]
match_() -> Symbol4406 pub fn match_() -> Symbol;
4407
4408 /// The `Symbol.replace` well-known symbol specifies the method that
4409 /// replaces matched substrings of a string. This function is called by the
4410 /// `String.prototype.replace()` method.
4411 ///
4412 /// For more information, see `RegExp.prototype[@@replace]()` and
4413 /// `String.prototype.replace()`.
4414 ///
4415 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/replace)
4416 #[wasm_bindgen(static_method_of = Symbol, getter, structural)]
replace() -> Symbol4417 pub fn replace() -> Symbol;
4418
4419 /// The `Symbol.search` well-known symbol specifies the method that returns
4420 /// the index within a string that matches the regular expression. This
4421 /// function is called by the `String.prototype.search()` method.
4422 ///
4423 /// For more information, see `RegExp.prototype[@@search]()` and
4424 /// `String.prototype.search()`.
4425 ///
4426 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/search)
4427 #[wasm_bindgen(static_method_of = Symbol, getter, structural)]
search() -> Symbol4428 pub fn search() -> Symbol;
4429
4430 /// The well-known symbol `Symbol.species` specifies a function-valued
4431 /// property that the constructor function uses to create derived objects.
4432 ///
4433 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/species)
4434 #[wasm_bindgen(static_method_of = Symbol, getter, structural)]
species() -> Symbol4435 pub fn species() -> Symbol;
4436
4437 /// The `Symbol.split` well-known symbol specifies the method that splits a
4438 /// string at the indices that match a regular expression. This function is
4439 /// called by the `String.prototype.split()` method.
4440 ///
4441 /// For more information, see `RegExp.prototype[@@split]()` and
4442 /// `String.prototype.split()`.
4443 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/split)
4444 #[wasm_bindgen(static_method_of = Symbol, getter, structural)]
split() -> Symbol4445 pub fn split() -> Symbol;
4446
4447 /// The `Symbol.toPrimitive` is a symbol that specifies a function valued
4448 /// property that is called to convert an object to a corresponding
4449 /// primitive value.
4450 ///
4451 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toPrimitive)
4452 #[wasm_bindgen(static_method_of = Symbol, getter, structural, js_name = toPrimitive)]
to_primitive() -> Symbol4453 pub fn to_primitive() -> Symbol;
4454
4455 /// The `Symbol.toStringTag` well-known symbol is a string valued property
4456 /// that is used in the creation of the default string description of an
4457 /// object. It is accessed internally by the `Object.prototype.toString()`
4458 /// method.
4459 ///
4460 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toString)
4461 #[wasm_bindgen(static_method_of = Symbol, getter, structural, js_name = toStringTag)]
to_string_tag() -> Symbol4462 pub fn to_string_tag() -> Symbol;
4463
4464 /// The `Symbol.for(key)` method searches for existing symbols in a runtime-wide symbol registry with
4465 /// the given key and returns it if found.
4466 /// Otherwise a new symbol gets created in the global symbol registry with this key.
4467 ///
4468 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/for)
4469 #[wasm_bindgen(static_method_of = Symbol, js_name = for)]
for_(key: &str) -> Symbol4470 pub fn for_(key: &str) -> Symbol;
4471
4472 /// The `Symbol.keyFor(sym)` method retrieves a shared symbol key from the global symbol registry for the given symbol.
4473 ///
4474 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/keyFor)
4475 #[wasm_bindgen(static_method_of = Symbol, js_name = keyFor)]
key_for(sym: &Symbol) -> JsValue4476 pub fn key_for(sym: &Symbol) -> JsValue;
4477
4478 /// The `toString()` method returns a string representing the specified Symbol object.
4479 ///
4480 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toString)
4481 #[wasm_bindgen(method, js_name = toString)]
to_string(this: &Symbol) -> JsString4482 pub fn to_string(this: &Symbol) -> JsString;
4483
4484 /// The `Symbol.unscopables` well-known symbol is used to specify an object
4485 /// value of whose own and inherited property names are excluded from the
4486 /// with environment bindings of the associated object.
4487 ///
4488 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/unscopables)
4489 #[wasm_bindgen(static_method_of = Symbol, getter, structural)]
unscopables() -> Symbol4490 pub fn unscopables() -> Symbol;
4491
4492 /// The `valueOf()` method returns the primitive value of a Symbol object.
4493 ///
4494 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/valueOf)
4495 #[wasm_bindgen(method, js_name = valueOf)]
value_of(this: &Symbol) -> Symbol4496 pub fn value_of(this: &Symbol) -> Symbol;
4497 }
4498
4499 #[allow(non_snake_case)]
4500 pub mod Intl {
4501 use super::*;
4502
4503 // Intl
4504 #[wasm_bindgen]
4505 extern "C" {
4506 /// The `Intl.getCanonicalLocales()` method returns an array containing
4507 /// the canonical locale names. Duplicates will be omitted and elements
4508 /// will be validated as structurally valid language tags.
4509 ///
4510 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/getCanonicalLocales)
4511 #[wasm_bindgen(js_name = getCanonicalLocales, js_namespace = Intl)]
get_canonical_locales(s: &JsValue) -> Array4512 pub fn get_canonical_locales(s: &JsValue) -> Array;
4513 }
4514
4515 // Intl.Collator
4516 #[wasm_bindgen]
4517 extern "C" {
4518 /// The `Intl.Collator` object is a constructor for collators, objects
4519 /// that enable language sensitive string comparison.
4520 ///
4521 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator)
4522 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.Collator")]
4523 #[derive(Clone, Debug)]
4524 pub type Collator;
4525
4526 /// The `Intl.Collator` object is a constructor for collators, objects
4527 /// that enable language sensitive string comparison.
4528 ///
4529 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator)
4530 #[wasm_bindgen(constructor, js_namespace = Intl)]
new(locales: &Array, options: &Object) -> Collator4531 pub fn new(locales: &Array, options: &Object) -> Collator;
4532
4533 /// The Intl.Collator.prototype.compare property returns a function that
4534 /// compares two strings according to the sort order of this Collator
4535 /// object.
4536 ///
4537 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/compare)
4538 #[wasm_bindgen(method, getter, js_class = "Intl.Collator")]
compare(this: &Collator) -> Function4539 pub fn compare(this: &Collator) -> Function;
4540
4541 /// The `Intl.Collator.prototype.resolvedOptions()` method returns a new
4542 /// object with properties reflecting the locale and collation options
4543 /// computed during initialization of this Collator object.
4544 ///
4545 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/resolvedOptions)
4546 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
resolved_options(this: &Collator) -> Object4547 pub fn resolved_options(this: &Collator) -> Object;
4548
4549 /// The `Intl.Collator.supportedLocalesOf()` method returns an array
4550 /// containing those of the provided locales that are supported in
4551 /// collation without having to fall back to the runtime's default
4552 /// locale.
4553 ///
4554 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator/supportedLocalesOf)
4555 #[wasm_bindgen(static_method_of = Collator, js_namespace = Intl, js_name = supportedLocalesOf)]
supported_locales_of(locales: &Array, options: &Object) -> Array4556 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
4557 }
4558
4559 impl Default for Collator {
default() -> Self4560 fn default() -> Self {
4561 Self::new(
4562 &JsValue::UNDEFINED.unchecked_into(),
4563 &JsValue::UNDEFINED.unchecked_into(),
4564 )
4565 }
4566 }
4567
4568 // Intl.DateTimeFormat
4569 #[wasm_bindgen]
4570 extern "C" {
4571 /// The `Intl.DateTimeFormat` object is a constructor for objects
4572 /// that enable language-sensitive date and time formatting.
4573 ///
4574 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat)
4575 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.DateTimeFormat")]
4576 #[derive(Clone, Debug)]
4577 pub type DateTimeFormat;
4578
4579 /// The `Intl.DateTimeFormat` object is a constructor for objects
4580 /// that enable language-sensitive date and time formatting.
4581 ///
4582 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat)
4583 #[wasm_bindgen(constructor, js_namespace = Intl)]
new(locales: &Array, options: &Object) -> DateTimeFormat4584 pub fn new(locales: &Array, options: &Object) -> DateTimeFormat;
4585
4586 /// The Intl.DateTimeFormat.prototype.format property returns a getter function that
4587 /// formats a date according to the locale and formatting options of this
4588 /// Intl.DateTimeFormat object.
4589 ///
4590 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/format)
4591 #[wasm_bindgen(method, getter, js_class = "Intl.DateTimeFormat")]
format(this: &DateTimeFormat) -> Function4592 pub fn format(this: &DateTimeFormat) -> Function;
4593
4594 /// The `Intl.DateTimeFormat.prototype.formatToParts()` method allows locale-aware
4595 /// formatting of strings produced by DateTimeFormat formatters.
4596 ///
4597 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/formatToParts)
4598 #[wasm_bindgen(method, js_class = "Intl.DateTimeFormat", js_name = formatToParts)]
format_to_parts(this: &DateTimeFormat, date: &Date) -> Array4599 pub fn format_to_parts(this: &DateTimeFormat, date: &Date) -> Array;
4600
4601 /// The `Intl.DateTimeFormat.prototype.resolvedOptions()` method returns a new
4602 /// object with properties reflecting the locale and date and time formatting
4603 /// options computed during initialization of this DateTimeFormat object.
4604 ///
4605 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/resolvedOptions)
4606 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
resolved_options(this: &DateTimeFormat) -> Object4607 pub fn resolved_options(this: &DateTimeFormat) -> Object;
4608
4609 /// The `Intl.DateTimeFormat.supportedLocalesOf()` method returns an array
4610 /// containing those of the provided locales that are supported in date
4611 /// and time formatting without having to fall back to the runtime's default
4612 /// locale.
4613 ///
4614 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/supportedLocalesOf)
4615 #[wasm_bindgen(static_method_of = DateTimeFormat, js_namespace = Intl, js_name = supportedLocalesOf)]
supported_locales_of(locales: &Array, options: &Object) -> Array4616 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
4617 }
4618
4619 impl Default for DateTimeFormat {
default() -> Self4620 fn default() -> Self {
4621 Self::new(
4622 &JsValue::UNDEFINED.unchecked_into(),
4623 &JsValue::UNDEFINED.unchecked_into(),
4624 )
4625 }
4626 }
4627
4628 // Intl.NumberFormat
4629 #[wasm_bindgen]
4630 extern "C" {
4631 /// The `Intl.NumberFormat` object is a constructor for objects
4632 /// that enable language sensitive number formatting.
4633 ///
4634 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat)
4635 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.NumberFormat")]
4636 #[derive(Clone, Debug)]
4637 pub type NumberFormat;
4638
4639 /// The `Intl.NumberFormat` object is a constructor for objects
4640 /// that enable language sensitive number formatting.
4641 ///
4642 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat)
4643 #[wasm_bindgen(constructor, js_namespace = Intl)]
new(locales: &Array, options: &Object) -> NumberFormat4644 pub fn new(locales: &Array, options: &Object) -> NumberFormat;
4645
4646 /// The Intl.NumberFormat.prototype.format property returns a getter function that
4647 /// formats a number according to the locale and formatting options of this
4648 /// NumberFormat object.
4649 ///
4650 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/format)
4651 #[wasm_bindgen(method, getter, js_class = "Intl.NumberFormat")]
format(this: &NumberFormat) -> Function4652 pub fn format(this: &NumberFormat) -> Function;
4653
4654 /// The `Intl.Numberformat.prototype.formatToParts()` method allows locale-aware
4655 /// formatting of strings produced by NumberTimeFormat formatters.
4656 ///
4657 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/formatToParts)
4658 #[wasm_bindgen(method, js_class = "Intl.NumberFormat", js_name = formatToParts)]
format_to_parts(this: &NumberFormat, number: f64) -> Array4659 pub fn format_to_parts(this: &NumberFormat, number: f64) -> Array;
4660
4661 /// The `Intl.NumberFormat.prototype.resolvedOptions()` method returns a new
4662 /// object with properties reflecting the locale and number formatting
4663 /// options computed during initialization of this NumberFormat object.
4664 ///
4665 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/resolvedOptions)
4666 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
resolved_options(this: &NumberFormat) -> Object4667 pub fn resolved_options(this: &NumberFormat) -> Object;
4668
4669 /// The `Intl.NumberFormat.supportedLocalesOf()` method returns an array
4670 /// containing those of the provided locales that are supported in number
4671 /// formatting without having to fall back to the runtime's default locale.
4672 ///
4673 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat/supportedLocalesOf)
4674 #[wasm_bindgen(static_method_of = NumberFormat, js_namespace = Intl, js_name = supportedLocalesOf)]
supported_locales_of(locales: &Array, options: &Object) -> Array4675 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
4676 }
4677
4678 impl Default for NumberFormat {
default() -> Self4679 fn default() -> Self {
4680 Self::new(
4681 &JsValue::UNDEFINED.unchecked_into(),
4682 &JsValue::UNDEFINED.unchecked_into(),
4683 )
4684 }
4685 }
4686
4687 // Intl.PluralRules
4688 #[wasm_bindgen]
4689 extern "C" {
4690 /// The `Intl.PluralRules` object is a constructor for objects
4691 /// that enable plural sensitive formatting and plural language rules.
4692 ///
4693 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules)
4694 #[wasm_bindgen(extends = Object, js_namespace = Intl, typescript_type = "Intl.PluralRules")]
4695 #[derive(Clone, Debug)]
4696 pub type PluralRules;
4697
4698 /// The `Intl.PluralRules` object is a constructor for objects
4699 /// that enable plural sensitive formatting and plural language rules.
4700 ///
4701 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules)
4702 #[wasm_bindgen(constructor, js_namespace = Intl)]
new(locales: &Array, options: &Object) -> PluralRules4703 pub fn new(locales: &Array, options: &Object) -> PluralRules;
4704
4705 /// The `Intl.PluralRules.prototype.resolvedOptions()` method returns a new
4706 /// object with properties reflecting the locale and plural formatting
4707 /// options computed during initialization of this PluralRules object.
4708 ///
4709 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/resolvedOptions)
4710 #[wasm_bindgen(method, js_namespace = Intl, js_name = resolvedOptions)]
resolved_options(this: &PluralRules) -> Object4711 pub fn resolved_options(this: &PluralRules) -> Object;
4712
4713 /// The `Intl.PluralRules.prototype.select()` method returns a String indicating
4714 /// which plural rule to use for locale-aware formatting.
4715 ///
4716 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/select)
4717 #[wasm_bindgen(method, js_namespace = Intl)]
select(this: &PluralRules, number: f64) -> JsString4718 pub fn select(this: &PluralRules, number: f64) -> JsString;
4719
4720 /// The `Intl.PluralRules.supportedLocalesOf()` method returns an array
4721 /// containing those of the provided locales that are supported in plural
4722 /// formatting without having to fall back to the runtime's default locale.
4723 ///
4724 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules/supportedLocalesOf)
4725 #[wasm_bindgen(static_method_of = PluralRules, js_namespace = Intl, js_name = supportedLocalesOf)]
supported_locales_of(locales: &Array, options: &Object) -> Array4726 pub fn supported_locales_of(locales: &Array, options: &Object) -> Array;
4727 }
4728
4729 impl Default for PluralRules {
default() -> Self4730 fn default() -> Self {
4731 Self::new(
4732 &JsValue::UNDEFINED.unchecked_into(),
4733 &JsValue::UNDEFINED.unchecked_into(),
4734 )
4735 }
4736 }
4737 }
4738
4739 // Promise
4740 #[wasm_bindgen]
4741 extern "C" {
4742 /// The `Promise` object represents the eventual completion (or failure) of
4743 /// an asynchronous operation, and its resulting value.
4744 ///
4745 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
4746 #[must_use]
4747 #[wasm_bindgen(extends = Object, typescript_type = "Promise<any>")]
4748 #[derive(Clone, Debug)]
4749 pub type Promise;
4750
4751 /// Creates a new `Promise` with the provided executor `cb`
4752 ///
4753 /// The `cb` is a function that is passed with the arguments `resolve` and
4754 /// `reject`. The `cb` function is executed immediately by the `Promise`
4755 /// implementation, passing `resolve` and `reject` functions (the executor
4756 /// is called before the `Promise` constructor even returns the created
4757 /// object). The `resolve` and `reject` functions, when called, resolve or
4758 /// reject the promise, respectively. The executor normally initiates
4759 /// some asynchronous work, and then, once that completes, either calls
4760 /// the `resolve` function to resolve the promise or else rejects it if an
4761 /// error occurred.
4762 ///
4763 /// If an error is thrown in the executor function, the promise is rejected.
4764 /// The return value of the executor is ignored.
4765 ///
4766 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
4767 #[wasm_bindgen(constructor)]
new(cb: &mut dyn FnMut(Function, Function)) -> Promise4768 pub fn new(cb: &mut dyn FnMut(Function, Function)) -> Promise;
4769
4770 /// The `Promise.all(iterable)` method returns a single `Promise` that
4771 /// resolves when all of the promises in the iterable argument have resolved
4772 /// or when the iterable argument contains no promises. It rejects with the
4773 /// reason of the first promise that rejects.
4774 ///
4775 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all)
4776 #[wasm_bindgen(static_method_of = Promise)]
all(obj: &JsValue) -> Promise4777 pub fn all(obj: &JsValue) -> Promise;
4778
4779 /// The `Promise.race(iterable)` method returns a promise that resolves or
4780 /// rejects as soon as one of the promises in the iterable resolves or
4781 /// rejects, with the value or reason from that promise.
4782 ///
4783 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/race)
4784 #[wasm_bindgen(static_method_of = Promise)]
race(obj: &JsValue) -> Promise4785 pub fn race(obj: &JsValue) -> Promise;
4786
4787 /// The `Promise.reject(reason)` method returns a `Promise` object that is
4788 /// rejected with the given reason.
4789 ///
4790 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/reject)
4791 #[wasm_bindgen(static_method_of = Promise)]
reject(obj: &JsValue) -> Promise4792 pub fn reject(obj: &JsValue) -> Promise;
4793
4794 /// The `Promise.resolve(value)` method returns a `Promise` object that is
4795 /// resolved with the given value. If the value is a promise, that promise
4796 /// is returned; if the value is a thenable (i.e. has a "then" method), the
4797 /// returned promise will "follow" that thenable, adopting its eventual
4798 /// state; otherwise the returned promise will be fulfilled with the value.
4799 ///
4800 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/resolve)
4801 #[wasm_bindgen(static_method_of = Promise)]
resolve(obj: &JsValue) -> Promise4802 pub fn resolve(obj: &JsValue) -> Promise;
4803
4804 /// The `catch()` method returns a `Promise` and deals with rejected cases
4805 /// only. It behaves the same as calling `Promise.prototype.then(undefined,
4806 /// onRejected)` (in fact, calling `obj.catch(onRejected)` internally calls
4807 /// `obj.then(undefined, onRejected)`).
4808 ///
4809 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch)
4810 #[wasm_bindgen(method)]
catch(this: &Promise, cb: &Closure<dyn FnMut(JsValue)>) -> Promise4811 pub fn catch(this: &Promise, cb: &Closure<dyn FnMut(JsValue)>) -> Promise;
4812
4813 /// The `then()` method returns a `Promise`. It takes up to two arguments:
4814 /// callback functions for the success and failure cases of the `Promise`.
4815 ///
4816 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then)
4817 #[wasm_bindgen(method)]
then(this: &Promise, cb: &Closure<dyn FnMut(JsValue)>) -> Promise4818 pub fn then(this: &Promise, cb: &Closure<dyn FnMut(JsValue)>) -> Promise;
4819
4820 /// Same as `then`, only with both arguments provided.
4821 #[wasm_bindgen(method, js_name = then)]
then2( this: &Promise, resolve: &Closure<dyn FnMut(JsValue)>, reject: &Closure<dyn FnMut(JsValue)>, ) -> Promise4822 pub fn then2(
4823 this: &Promise,
4824 resolve: &Closure<dyn FnMut(JsValue)>,
4825 reject: &Closure<dyn FnMut(JsValue)>,
4826 ) -> Promise;
4827
4828 /// The `finally()` method returns a `Promise`. When the promise is settled,
4829 /// whether fulfilled or rejected, the specified callback function is
4830 /// executed. This provides a way for code that must be executed once the
4831 /// `Promise` has been dealt with to be run whether the promise was
4832 /// fulfilled successfully or rejected.
4833 ///
4834 /// This lets you avoid duplicating code in both the promise's `then()` and
4835 /// `catch()` handlers.
4836 ///
4837 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/finally)
4838 #[wasm_bindgen(method)]
finally(this: &Promise, cb: &Closure<dyn FnMut()>) -> Promise4839 pub fn finally(this: &Promise, cb: &Closure<dyn FnMut()>) -> Promise;
4840 }
4841
4842 /// Returns a handle to the global scope object.
4843 ///
4844 /// This allows access to the global properties and global names by accessing
4845 /// the `Object` returned.
global() -> Object4846 pub fn global() -> Object {
4847 thread_local!(static GLOBAL: Object = get_global_object());
4848
4849 return GLOBAL.with(|g| g.clone());
4850
4851 fn get_global_object() -> Object {
4852 // This is a bit wonky, but we're basically using `#[wasm_bindgen]`
4853 // attributes to synthesize imports so we can access properties of the
4854 // form:
4855 //
4856 // * `globalThis.globalThis`
4857 // * `self.self`
4858 // * ... (etc)
4859 //
4860 // Accessing the global object is not an easy thing to do, and what we
4861 // basically want is `globalThis` but we can't rely on that existing
4862 // everywhere. In the meantime we've got the fallbacks mentioned in:
4863 //
4864 // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis
4865 //
4866 // Note that this is pretty heavy code-size wise but it at least gets
4867 // the job largely done for now and avoids the `Function` constructor at
4868 // the end which triggers CSP errors.
4869 #[wasm_bindgen]
4870 extern "C" {
4871 type Global;
4872
4873 #[wasm_bindgen(getter, catch, static_method_of = Global, js_class = globalThis, js_name = globalThis)]
4874 fn get_global_this() -> Result<Object, JsValue>;
4875
4876 #[wasm_bindgen(getter, catch, static_method_of = Global, js_class = self, js_name = self)]
4877 fn get_self() -> Result<Object, JsValue>;
4878
4879 #[wasm_bindgen(getter, catch, static_method_of = Global, js_class = window, js_name = window)]
4880 fn get_window() -> Result<Object, JsValue>;
4881
4882 #[wasm_bindgen(getter, catch, static_method_of = Global, js_class = global, js_name = global)]
4883 fn get_global() -> Result<Object, JsValue>;
4884 }
4885
4886 // The order is important: in Firefox Extension Content Scripts `globalThis`
4887 // is a Sandbox (not Window), so `globalThis` must be checked after `window`.
4888 let static_object = Global::get_self()
4889 .or_else(|_| Global::get_window())
4890 .or_else(|_| Global::get_global_this())
4891 .or_else(|_| Global::get_global());
4892 if let Ok(obj) = static_object {
4893 if !obj.is_undefined() {
4894 return obj;
4895 }
4896 }
4897
4898 // According to StackOverflow you can access the global object via:
4899 //
4900 // const global = Function('return this')();
4901 //
4902 // I think that's because the manufactured function isn't in "strict" mode.
4903 // It also turns out that non-strict functions will ignore `undefined`
4904 // values for `this` when using the `apply` function.
4905 //
4906 // As a result we use the equivalent of this snippet to get a handle to the
4907 // global object in a sort of roundabout way that should hopefully work in
4908 // all contexts like ESM, node, browsers, etc.
4909 let this = Function::new_no_args("return this")
4910 .call0(&JsValue::undefined())
4911 .ok();
4912
4913 // Note that we avoid `unwrap()` on `call0` to avoid code size bloat, we
4914 // just handle the `Err` case as returning a different object.
4915 debug_assert!(this.is_some());
4916 match this {
4917 Some(this) => this.unchecked_into(),
4918 None => JsValue::undefined().unchecked_into(),
4919 }
4920 }
4921 }
4922
4923 macro_rules! arrays {
4924 ($(#[doc = $ctor:literal] #[doc = $mdn:literal] $name:ident: $ty:ident,)*) => ($(
4925 #[wasm_bindgen]
4926 extern "C" {
4927 #[wasm_bindgen(extends = Object, typescript_type = $name)]
4928 #[derive(Clone, Debug)]
4929 pub type $name;
4930
4931 /// The
4932 #[doc = $ctor]
4933 /// constructor creates a new array.
4934 ///
4935 /// [MDN documentation](
4936 #[doc = $mdn]
4937 /// )
4938 #[wasm_bindgen(constructor)]
4939 pub fn new(constructor_arg: &JsValue) -> $name;
4940
4941 /// An
4942 #[doc = $ctor]
4943 /// which creates an array with an internal buffer large
4944 /// enough for `length` elements.
4945 ///
4946 /// [MDN documentation](
4947 #[doc = $mdn]
4948 /// )
4949 #[wasm_bindgen(constructor)]
4950 pub fn new_with_length(length: u32) -> $name;
4951
4952 /// An
4953 #[doc = $ctor]
4954 /// which creates an array with the given buffer but is a
4955 /// view starting at `byte_offset`.
4956 ///
4957 /// [MDN documentation](
4958 #[doc = $mdn]
4959 /// )
4960 #[wasm_bindgen(constructor)]
4961 pub fn new_with_byte_offset(buffer: &JsValue, byte_offset: u32) -> $name;
4962
4963 /// An
4964 #[doc = $ctor]
4965 /// which creates an array with the given buffer but is a
4966 /// view starting at `byte_offset` for `length` elements.
4967 ///
4968 /// [MDN documentation](
4969 #[doc = $mdn]
4970 /// )
4971 #[wasm_bindgen(constructor)]
4972 pub fn new_with_byte_offset_and_length(
4973 buffer: &JsValue,
4974 byte_offset: u32,
4975 length: u32,
4976 ) -> $name;
4977
4978 /// The `fill()` method fills all the elements of an array from a start index
4979 /// to an end index with a static value. The end index is not included.
4980 ///
4981 /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/fill)
4982 #[wasm_bindgen(method)]
4983 pub fn fill(this: &$name, value: $ty, start: u32, end: u32) -> $name;
4984
4985 /// The buffer accessor property represents the `ArrayBuffer` referenced
4986 /// by a `TypedArray` at construction time.
4987 #[wasm_bindgen(getter, method)]
4988 pub fn buffer(this: &$name) -> ArrayBuffer;
4989
4990 /// The `subarray()` method returns a new `TypedArray` on the same
4991 /// `ArrayBuffer` store and with the same element types as for this
4992 /// `TypedArray` object.
4993 #[wasm_bindgen(method)]
4994 pub fn subarray(this: &$name, begin: u32, end: u32) -> $name;
4995
4996 /// The `slice()` method returns a shallow copy of a portion of a typed
4997 /// array into a new typed array object. This method has the same algorithm
4998 /// as `Array.prototype.slice()`.
4999 #[wasm_bindgen(method)]
5000 pub fn slice(this: &$name, begin: u32, end: u32) -> $name;
5001
5002 /// The `forEach()` method executes a provided function once per array
5003 /// element. This method has the same algorithm as
5004 /// `Array.prototype.forEach()`. `TypedArray` is one of the typed array
5005 /// types here.
5006 #[wasm_bindgen(method, js_name = forEach)]
5007 pub fn for_each(this: &$name, callback: &mut dyn FnMut($ty, u32, $name));
5008
5009 /// The length accessor property represents the length (in elements) of a
5010 /// typed array.
5011 #[wasm_bindgen(method, getter)]
5012 pub fn length(this: &$name) -> u32;
5013
5014 /// The byteLength accessor property represents the length (in bytes) of a
5015 /// typed array.
5016 #[wasm_bindgen(method, getter, js_name = byteLength)]
5017 pub fn byte_length(this: &$name) -> u32;
5018
5019 /// The byteOffset accessor property represents the offset (in bytes) of a
5020 /// typed array from the start of its `ArrayBuffer`.
5021 #[wasm_bindgen(method, getter, js_name = byteOffset)]
5022 pub fn byte_offset(this: &$name) -> u32;
5023
5024 /// The `set()` method stores multiple values in the typed array, reading
5025 /// input values from a specified array.
5026 #[wasm_bindgen(method)]
5027 pub fn set(this: &$name, src: &JsValue, offset: u32);
5028
5029 /// Gets the value at `idx`, equivalent to the javascript `my_var = arr[idx]`.
5030 #[wasm_bindgen(method, structural, indexing_getter)]
5031 pub fn get_index(this: &$name, idx: u32) -> $ty;
5032
5033 /// Sets the value at `idx`, equivalent to the javascript `arr[idx] = value`.
5034 #[wasm_bindgen(method, structural, indexing_setter)]
5035 pub fn set_index(this: &$name, idx: u32, value: $ty);
5036 }
5037
5038 impl $name {
5039 /// Creates a JS typed array which is a view into wasm's linear
5040 /// memory at the slice specified.
5041 ///
5042 /// This function returns a new typed array which is a view into
5043 /// wasm's memory. This view does not copy the underlying data.
5044 ///
5045 /// # Unsafety
5046 ///
5047 /// Views into WebAssembly memory are only valid so long as the
5048 /// backing buffer isn't resized in JS. Once this function is called
5049 /// any future calls to `Box::new` (or malloc of any form) may cause
5050 /// the returned value here to be invalidated. Use with caution!
5051 ///
5052 /// Additionally the returned object can be safely mutated but the
5053 /// input slice isn't guaranteed to be mutable.
5054 ///
5055 /// Finally, the returned object is disconnected from the input
5056 /// slice's lifetime, so there's no guarantee that the data is read
5057 /// at the right time.
5058 pub unsafe fn view(rust: &[$ty]) -> $name {
5059 let buf = wasm_bindgen::memory();
5060 let mem = buf.unchecked_ref::<WebAssembly::Memory>();
5061 $name::new_with_byte_offset_and_length(
5062 &mem.buffer(),
5063 rust.as_ptr() as u32,
5064 rust.len() as u32,
5065 )
5066 }
5067
5068 /// Creates a JS typed array which is a view into wasm's linear
5069 /// memory at the specified pointer with specified length.
5070 ///
5071 /// This function returns a new typed array which is a view into
5072 /// wasm's memory. This view does not copy the underlying data.
5073 ///
5074 /// # Unsafety
5075 ///
5076 /// Views into WebAssembly memory are only valid so long as the
5077 /// backing buffer isn't resized in JS. Once this function is called
5078 /// any future calls to `Box::new` (or malloc of any form) may cause
5079 /// the returned value here to be invalidated. Use with caution!
5080 ///
5081 /// Additionally the returned object can be safely mutated,
5082 /// the changes are guranteed to be reflected in the input array.
5083 pub unsafe fn view_mut_raw(ptr: *mut $ty, length: usize) -> $name {
5084 let buf = wasm_bindgen::memory();
5085 let mem = buf.unchecked_ref::<WebAssembly::Memory>();
5086 $name::new_with_byte_offset_and_length(
5087 &mem.buffer(),
5088 ptr as u32,
5089 length as u32
5090 )
5091 }
5092
5093
5094 /// Copy the contents of this JS typed array into the destination
5095 /// Rust pointer.
5096 ///
5097 /// This function will efficiently copy the memory from a typed
5098 /// array into this wasm module's own linear memory, initializing
5099 /// the memory destination provided.
5100 ///
5101 /// # Unsafety
5102 ///
5103 /// This function requires `dst` to point to a buffer
5104 /// large enough to fit this array's contents.
5105 pub unsafe fn raw_copy_to_ptr(&self, dst: *mut $ty) {
5106 let buf = wasm_bindgen::memory();
5107 let mem = buf.unchecked_ref::<WebAssembly::Memory>();
5108 let all_wasm_memory = $name::new(&mem.buffer());
5109 let offset = dst as usize / mem::size_of::<$ty>();
5110 all_wasm_memory.set(self, offset as u32);
5111 }
5112
5113 /// Copy the contents of this JS typed array into the destination
5114 /// Rust slice.
5115 ///
5116 /// This function will efficiently copy the memory from a typed
5117 /// array into this wasm module's own linear memory, initializing
5118 /// the memory destination provided.
5119 ///
5120 /// # Panics
5121 ///
5122 /// This function will panic if this typed array's length is
5123 /// different than the length of the provided `dst` array.
5124 pub fn copy_to(&self, dst: &mut [$ty]) {
5125 assert_eq!(self.length() as usize, dst.len());
5126 unsafe { self.raw_copy_to_ptr(dst.as_mut_ptr()); }
5127 }
5128
5129 /// Copy the contents of the source Rust slice into this
5130 /// JS typed array.
5131 ///
5132 /// This function will efficiently copy the memory from within
5133 /// the wasm module's own linear memory to this typed array.
5134 ///
5135 /// # Panics
5136 ///
5137 /// This function will panic if this typed array's length is
5138 /// different than the length of the provided `src` array.
5139 pub fn copy_from(&self, src: &[$ty]) {
5140 assert_eq!(self.length() as usize, src.len());
5141 // This is safe because the `set` function copies from its TypedArray argument
5142 unsafe { self.set(&$name::view(src), 0) }
5143 }
5144
5145 /// Efficiently copies the contents of this JS typed array into a new Vec.
5146 pub fn to_vec(&self) -> Vec<$ty> {
5147 let mut output = Vec::with_capacity(self.length() as usize);
5148 unsafe {
5149 self.raw_copy_to_ptr(output.as_mut_ptr());
5150 output.set_len(self.length() as usize);
5151 }
5152 output
5153 }
5154 }
5155
5156 impl<'a> From<&'a [$ty]> for $name {
5157 #[inline]
5158 fn from(slice: &'a [$ty]) -> $name {
5159 // This is safe because the `new` function makes a copy if its argument is a TypedArray
5160 unsafe { $name::new(&$name::view(slice)) }
5161 }
5162 }
5163
5164 impl Default for $name {
5165 fn default() -> Self {
5166 Self::new(&JsValue::UNDEFINED.unchecked_into())
5167 }
5168 }
5169 )*);
5170 }
5171
5172 arrays! {
5173 /// `Int8Array()`
5174 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int8Array
5175 Int8Array: i8,
5176
5177 /// `Int16Array()`
5178 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int16Array
5179 Int16Array: i16,
5180
5181 /// `Int32Array()`
5182 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int32Array
5183 Int32Array: i32,
5184
5185 /// `Uint8Array()`
5186 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array
5187 Uint8Array: u8,
5188
5189 /// `Uint8ClampedArray()`
5190 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8ClampedArray
5191 Uint8ClampedArray: u8,
5192
5193 /// `Uint16Array()`
5194 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint16Array
5195 Uint16Array: u16,
5196
5197 /// `Uint32Array()`
5198 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint32Array
5199 Uint32Array: u32,
5200
5201 /// `Float32Array()`
5202 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array
5203 Float32Array: f32,
5204
5205 /// `Float64Array()`
5206 /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float64Array
5207 Float64Array: f64,
5208 }
5209