mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-05-04 18:12:16 +00:00
Js sys once over (#550)
* js-sys: Return `f64` instead of `Number` * js-sys: remove trailing whitespace * js-sys: Ensure that all imported types derive Clone and Debug * js-sys: Imported functions should always take JS object arguments by-ref
This commit is contained in:
parent
93933f033f
commit
61fc8d2567
@ -125,6 +125,7 @@ extern "C" {
|
||||
// Array
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
#[derive(Clone, Debug)]
|
||||
pub type Array;
|
||||
|
||||
/// Creates a new empty array
|
||||
@ -134,7 +135,7 @@ extern "C" {
|
||||
/// The `Array.from()` method creates a new, shallow-copied `Array` instance
|
||||
/// from an array-like or iterable object.
|
||||
#[wasm_bindgen(static_method_of = Array)]
|
||||
pub fn from(val: JsValue) -> Array;
|
||||
pub fn from(val: &JsValue) -> Array;
|
||||
|
||||
/// The copyWithin() method shallow copies part of an array to another
|
||||
/// location in the same array and returns it, without modifying its size.
|
||||
@ -162,7 +163,7 @@ extern "C" {
|
||||
///
|
||||
/// http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn fill(this: &Array, value: JsValue, start: u32, end: u32) -> Array;
|
||||
pub fn fill(this: &Array, value: &JsValue, start: u32, end: u32) -> Array;
|
||||
|
||||
/// The `filter()` method creates a new array with all elements that pass the
|
||||
/// test implemented by the provided function.
|
||||
@ -196,14 +197,14 @@ extern "C" {
|
||||
///
|
||||
/// http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn includes(this: &Array, value: JsValue, from_index: i32) -> bool;
|
||||
pub fn includes(this: &Array, value: &JsValue, from_index: i32) -> bool;
|
||||
|
||||
/// The indexOf() method returns the first index at which a given element
|
||||
/// can be found in the array, or -1 if it is not present.
|
||||
///
|
||||
/// http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf
|
||||
#[wasm_bindgen(method, js_name = indexOf)]
|
||||
pub fn index_of(this: &Array, value: JsValue, from_index: i32) -> i32;
|
||||
pub fn index_of(this: &Array, value: &JsValue, from_index: i32) -> i32;
|
||||
|
||||
/// The Array.isArray() method determines whether the passed value is an Array.
|
||||
///
|
||||
@ -224,7 +225,7 @@ extern "C" {
|
||||
///
|
||||
/// http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/lastIndexOf
|
||||
#[wasm_bindgen(method, js_name = lastIndexOf)]
|
||||
pub fn last_index_of(this: &Array, value: JsValue, from_index: i32) -> i32;
|
||||
pub fn last_index_of(this: &Array, value: &JsValue, from_index: i32) -> i32;
|
||||
|
||||
/// The length property of an object which is an instance of type Array
|
||||
/// sets or returns the number of elements in that array. The value is an
|
||||
@ -257,21 +258,21 @@ extern "C" {
|
||||
///
|
||||
/// http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn push(this: &Array, value: JsValue) -> u32;
|
||||
pub fn push(this: &Array, value: &JsValue) -> u32;
|
||||
|
||||
/// The reduce() method applies a function against an accumulator and each element in
|
||||
/// the array (from left to right) to reduce it to a single value.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn reduce(this: &Array, predicate: &mut FnMut(JsValue, JsValue, u32, Array) -> JsValue, initial_value: JsValue) -> JsValue;
|
||||
pub fn reduce(this: &Array, predicate: &mut FnMut(JsValue, JsValue, u32, Array) -> JsValue, initial_value: &JsValue) -> JsValue;
|
||||
|
||||
/// The reduceRight() method applies a function against an accumulator and each value
|
||||
/// of the array (from right-to-left) to reduce it to a single value.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/ReduceRight
|
||||
#[wasm_bindgen(method, js_name = reduceRight)]
|
||||
pub fn reduce_right(this: &Array, predicate: &mut FnMut(JsValue, JsValue, u32, Array) -> JsValue, initial_value: JsValue) -> JsValue;
|
||||
pub fn reduce_right(this: &Array, predicate: &mut FnMut(JsValue, JsValue, u32, Array) -> JsValue, initial_value: &JsValue) -> JsValue;
|
||||
|
||||
/// The reverse() method reverses an array in place. The first array
|
||||
/// element becomes the last, and the last array element becomes the first.
|
||||
@ -333,12 +334,13 @@ extern "C" {
|
||||
///
|
||||
/// http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn unshift(this: &Array, value: JsValue) -> u32;
|
||||
pub fn unshift(this: &Array, value: &JsValue) -> u32;
|
||||
}
|
||||
|
||||
// ArrayBuffer
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
#[derive(Clone, Debug)]
|
||||
pub type ArrayBuffer;
|
||||
|
||||
/// The `ArrayBuffer` object is used to represent a generic,
|
||||
@ -357,7 +359,7 @@ extern "C" {
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/isView
|
||||
#[wasm_bindgen(static_method_of = ArrayBuffer, js_name = isView)]
|
||||
pub fn is_view(value: JsValue) -> bool;
|
||||
pub fn is_view(value: &JsValue) -> bool;
|
||||
|
||||
/// The `slice()` method returns a new `ArrayBuffer` whose contents
|
||||
/// are a copy of this `ArrayBuffer`'s bytes from begin, inclusive,
|
||||
@ -377,6 +379,7 @@ extern "C" {
|
||||
// Array Iterator
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
#[derive(Clone, Debug)]
|
||||
pub type ArrayIterator;
|
||||
|
||||
/// The keys() method returns a new Array Iterator object that contains the
|
||||
@ -404,13 +407,14 @@ extern "C" {
|
||||
// Boolean
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
#[derive(Clone, Debug)]
|
||||
pub type Boolean;
|
||||
|
||||
/// The `Boolean()` constructor creates an object wrapper for a boolean value.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
||||
#[wasm_bindgen(constructor)]
|
||||
pub fn new(value: JsValue) -> Boolean;
|
||||
pub fn new(value: &JsValue) -> Boolean;
|
||||
|
||||
/// The `valueOf()` method returns the primitive value of a `Boolean` object.
|
||||
///
|
||||
@ -422,6 +426,7 @@ extern "C" {
|
||||
// DataView
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
#[derive(Clone, Debug)]
|
||||
pub type DataView;
|
||||
|
||||
/// The `DataView` view provides a low-level interface for reading and
|
||||
@ -568,6 +573,7 @@ extern "C" {
|
||||
// Error
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
#[derive(Clone, Debug)]
|
||||
pub type Error;
|
||||
|
||||
/// The Error constructor creates an error object.
|
||||
@ -605,13 +611,14 @@ extern "C" {
|
||||
// Float32Array
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
#[derive(Clone, Debug)]
|
||||
pub type Float32Array;
|
||||
|
||||
/// The `Float32Array()` constructor creates an array of 32-bit floats.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array
|
||||
#[wasm_bindgen(constructor)]
|
||||
pub fn new(constructor_arg: JsValue) -> Float32Array;
|
||||
pub fn new(constructor_arg: &JsValue) -> Float32Array;
|
||||
|
||||
/// The fill() method fills all the elements of an array from a start index
|
||||
/// to an end index with a static value. The end index is not included.
|
||||
@ -656,13 +663,14 @@ extern "C" {
|
||||
// Float64Array
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
#[derive(Clone, Debug)]
|
||||
pub type Float64Array;
|
||||
|
||||
/// The `Float64Array()` constructor creates an array of 64-bit floats.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float64Array
|
||||
#[wasm_bindgen(constructor)]
|
||||
pub fn new(constructor_arg: JsValue) -> Float64Array;
|
||||
pub fn new(constructor_arg: &JsValue) -> Float64Array;
|
||||
|
||||
/// The fill() method fills all the elements of an array from a start index
|
||||
/// to an end index with a static value. The end index is not included.
|
||||
@ -707,6 +715,7 @@ extern "C" {
|
||||
// Function
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
#[derive(Clone, Debug)]
|
||||
pub type Function;
|
||||
|
||||
/// The apply() method calls a function with a given this value, and arguments provided as an array
|
||||
@ -762,6 +771,7 @@ impl Function {
|
||||
// Generator
|
||||
#[wasm_bindgen]
|
||||
extern {
|
||||
#[derive(Clone, Debug)]
|
||||
pub type Generator;
|
||||
|
||||
/// The next() method returns an object with two properties done and value.
|
||||
@ -788,13 +798,14 @@ extern {
|
||||
// Int8Array
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
#[derive(Clone, Debug)]
|
||||
pub type Int8Array;
|
||||
|
||||
/// The `Int8Array()` constructor creates an array of signed 8-bit integers.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int8Array
|
||||
#[wasm_bindgen(constructor)]
|
||||
pub fn new(constructor_arg: JsValue) -> Int8Array;
|
||||
pub fn new(constructor_arg: &JsValue) -> Int8Array;
|
||||
|
||||
/// The fill() method fills all the elements of an array from a start index
|
||||
/// to an end index with a static value. The end index is not included.
|
||||
@ -839,13 +850,14 @@ extern "C" {
|
||||
// Int16Array
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
#[derive(Clone, Debug)]
|
||||
pub type Int16Array;
|
||||
|
||||
/// The `Int16Array()` constructor creates an array of signed 16-bit integers.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int16Array
|
||||
#[wasm_bindgen(constructor)]
|
||||
pub fn new(constructor_arg: JsValue) -> Int16Array;
|
||||
pub fn new(constructor_arg: &JsValue) -> Int16Array;
|
||||
|
||||
/// The fill() method fills all the elements of an array from a start index
|
||||
/// to an end index with a static value. The end index is not included.
|
||||
@ -890,13 +902,14 @@ extern "C" {
|
||||
// Int32Array
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
#[derive(Clone, Debug)]
|
||||
pub type Int32Array;
|
||||
|
||||
/// The `Int32Array()` constructor creates an array of signed 32-bit integers.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int32Array
|
||||
#[wasm_bindgen(constructor)]
|
||||
pub fn new(constructor_arg: JsValue) -> Int32Array;
|
||||
pub fn new(constructor_arg: &JsValue) -> Int32Array;
|
||||
|
||||
/// The fill() method fills all the elements of an array from a start index
|
||||
/// to an end index with a static value. The end index is not included.
|
||||
@ -941,6 +954,7 @@ extern "C" {
|
||||
// Map
|
||||
#[wasm_bindgen]
|
||||
extern {
|
||||
#[derive(Clone, Debug)]
|
||||
pub type Map;
|
||||
|
||||
/// The clear() method removes all elements from a Map object.
|
||||
@ -1001,6 +1015,7 @@ extern {
|
||||
// Map Iterator
|
||||
#[wasm_bindgen]
|
||||
extern {
|
||||
#[derive(Clone, Debug)]
|
||||
pub type MapIterator;
|
||||
|
||||
/// The entries() method returns a new Iterator object that contains
|
||||
@ -1029,6 +1044,7 @@ extern {
|
||||
// Math
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
#[derive(Clone, Debug)]
|
||||
pub type Math;
|
||||
|
||||
/// The Math.abs() function returns the absolute value of a number, that is
|
||||
@ -1276,6 +1292,7 @@ extern "C" {
|
||||
// Number.
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
#[derive(Clone, Debug)]
|
||||
pub type Number;
|
||||
|
||||
/// The Number.isFinite() method determines whether the passed value is a finite number.
|
||||
@ -1310,21 +1327,21 @@ extern "C" {
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number
|
||||
#[wasm_bindgen(constructor)]
|
||||
pub fn new(value: JsValue) -> Number;
|
||||
pub fn new(value: &JsValue) -> Number;
|
||||
|
||||
/// The Number.parseInt() method parses a string argument and returns an
|
||||
/// integer of the specified radix or base.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/parseInt
|
||||
#[wasm_bindgen(static_method_of = Number, js_name = parseInt)]
|
||||
pub fn parse_int(text: &str, radix: u8) -> Number;
|
||||
pub fn parse_int(text: &str, radix: u8) -> f64;
|
||||
|
||||
/// The Number.parseFloat() method parses a string argument and returns a
|
||||
/// floating point number.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/parseFloat
|
||||
#[wasm_bindgen(static_method_of = Number, js_name = parseFloat)]
|
||||
pub fn parse_float(text: &str) -> Number;
|
||||
pub fn parse_float(text: &str) -> f64;
|
||||
|
||||
/// The toLocaleString() method returns a string with a language sensitive
|
||||
/// representation of this number.
|
||||
@ -1372,6 +1389,7 @@ extern "C" {
|
||||
// Date.
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
#[derive(Clone, Debug)]
|
||||
pub type Date;
|
||||
|
||||
/// The getDate() method returns the day of the month for the
|
||||
@ -1497,7 +1515,7 @@ extern "C" {
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date
|
||||
#[wasm_bindgen(constructor)]
|
||||
pub fn new(init: JsValue) -> Date;
|
||||
pub fn new(init: &JsValue) -> Date;
|
||||
|
||||
/// The `Date.now()` method returns the number of milliseconds
|
||||
/// elapsed since January 1, 1970 00:00:00 UTC.
|
||||
@ -1512,7 +1530,7 @@ extern "C" {
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse
|
||||
#[wasm_bindgen(static_method_of = Date)]
|
||||
pub fn parse(date: JsString) -> f64;
|
||||
pub fn parse(date: &JsString) -> f64;
|
||||
|
||||
/// The setDate() method sets the day of the Date object relative to the beginning of the currently set month.
|
||||
///
|
||||
@ -1644,7 +1662,7 @@ extern "C" {
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString
|
||||
#[wasm_bindgen(method, js_name = toLocaleDateString)]
|
||||
pub fn to_locale_date_string(this: &Date, locale: JsString, options: JsValue) -> JsString;
|
||||
pub fn to_locale_date_string(this: &Date, locale: &JsString, options: &JsValue) -> JsString;
|
||||
|
||||
/// The toLocaleString() method returns a string with a language sensitive
|
||||
/// representation of this date. The new locales and options arguments
|
||||
@ -1656,7 +1674,7 @@ extern "C" {
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString
|
||||
#[wasm_bindgen(method, js_name = toLocaleString)]
|
||||
pub fn to_locale_string(this: &Date, locale: JsString, options: JsValue) -> JsString;
|
||||
pub fn to_locale_string(this: &Date, locale: &JsString, options: &JsValue) -> JsString;
|
||||
|
||||
/// The toLocaleTimeString() method returns a string with a language sensitive
|
||||
/// representation of the time portion of this date. The new locales and options
|
||||
@ -1667,7 +1685,7 @@ extern "C" {
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleTimeString
|
||||
#[wasm_bindgen(method, js_name = toLocaleTimeString)]
|
||||
pub fn to_locale_time_string(this: &Date, locale: JsString) -> JsString;
|
||||
pub fn to_locale_time_string(this: &Date, locale: &JsString) -> JsString;
|
||||
|
||||
/// The toString() method returns a string representing
|
||||
/// the specified Date object.
|
||||
@ -1710,6 +1728,7 @@ extern "C" {
|
||||
// Object.
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
#[derive(Clone, Debug)]
|
||||
pub type Object;
|
||||
|
||||
/// The `Object.freeze()` method freezes an object: that is, prevents new
|
||||
@ -1856,6 +1875,7 @@ impl Object {
|
||||
// Proxy
|
||||
#[wasm_bindgen]
|
||||
extern {
|
||||
#[derive(Clone, Debug)]
|
||||
pub type Proxy;
|
||||
|
||||
/// The [`Proxy`] object is used to define custom behavior for fundamental
|
||||
@ -1877,6 +1897,7 @@ extern {
|
||||
// Reflect
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
#[derive(Clone, Debug)]
|
||||
pub type Reflect;
|
||||
|
||||
/// The static `Reflect.apply()` method calls a target function with
|
||||
@ -1988,6 +2009,7 @@ extern "C" {
|
||||
// Set
|
||||
#[wasm_bindgen]
|
||||
extern {
|
||||
#[derive(Clone, Debug)]
|
||||
pub type Set;
|
||||
|
||||
/// The `add()` method appends a new element with a specified value to the
|
||||
@ -2042,6 +2064,7 @@ extern {
|
||||
// SetIterator
|
||||
#[wasm_bindgen]
|
||||
extern {
|
||||
#[derive(Clone, Debug)]
|
||||
pub type SetIterator;
|
||||
|
||||
/// The `entries()` method returns a new Iterator object that contains an
|
||||
@ -2073,13 +2096,14 @@ extern {
|
||||
// Uint8Array
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
#[derive(Clone, Debug)]
|
||||
pub type Uint8Array;
|
||||
|
||||
/// The `Uint8Array()` constructor creates an array of unsigned 8-bit integers.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array
|
||||
#[wasm_bindgen(constructor)]
|
||||
pub fn new(constructor_arg: JsValue) -> Uint8Array;
|
||||
pub fn new(constructor_arg: &JsValue) -> Uint8Array;
|
||||
|
||||
/// The fill() method fills all the elements of an array from a start index
|
||||
/// to an end index with a static value. The end index is not included.
|
||||
@ -2124,6 +2148,7 @@ extern "C" {
|
||||
// Uint8ClampedArray
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
#[derive(Clone, Debug)]
|
||||
pub type Uint8ClampedArray;
|
||||
|
||||
/// The `Uint8ClampedArray()` constructor creates an array of unsigned 8-bit integers clamped
|
||||
@ -2132,7 +2157,7 @@ extern "C" {
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8ClampedArray
|
||||
#[wasm_bindgen(constructor)]
|
||||
pub fn new(constructor_arg: JsValue) -> Uint8ClampedArray;
|
||||
pub fn new(constructor_arg: &JsValue) -> Uint8ClampedArray;
|
||||
|
||||
/// The fill() method fills all the elements of an array from a start index
|
||||
/// to an end index with a static value. The end index is not included.
|
||||
@ -2177,13 +2202,14 @@ extern "C" {
|
||||
// Uint16Array
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
#[derive(Clone, Debug)]
|
||||
pub type Uint16Array;
|
||||
|
||||
/// The `Uint16Array()` constructor creates an array of unsigned 16-bit integers.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint16Array
|
||||
#[wasm_bindgen(constructor)]
|
||||
pub fn new(constructor_arg: JsValue) -> Uint16Array;
|
||||
pub fn new(constructor_arg: &JsValue) -> Uint16Array;
|
||||
|
||||
/// The fill() method fills all the elements of an array from a start index
|
||||
/// to an end index with a static value. The end index is not included.
|
||||
@ -2228,13 +2254,14 @@ extern "C" {
|
||||
// Uint32Array
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
#[derive(Clone, Debug)]
|
||||
pub type Uint32Array;
|
||||
|
||||
/// The `Uint32Array()` constructor creates an array of unsigned 32-bit integers.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint32Array
|
||||
#[wasm_bindgen(constructor)]
|
||||
pub fn new(constructor_arg: JsValue) -> Uint32Array;
|
||||
pub fn new(constructor_arg: &JsValue) -> Uint32Array;
|
||||
|
||||
/// The fill() method fills all the elements of an array from a start index
|
||||
/// to an end index with a static value. The end index is not included.
|
||||
@ -2279,6 +2306,7 @@ extern "C" {
|
||||
// WeakMap
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
#[derive(Clone, Debug)]
|
||||
pub type WeakMap;
|
||||
|
||||
/// The [`WeakMap`] object is a collection of key/value pairs in which the
|
||||
@ -2294,7 +2322,7 @@ extern "C" {
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap/set
|
||||
#[wasm_bindgen(method, js_class = "WeakMap")]
|
||||
pub fn set(this: &WeakMap, key: &Object, value: JsValue) -> WeakMap;
|
||||
pub fn set(this: &WeakMap, key: &Object, value: &JsValue) -> WeakMap;
|
||||
|
||||
/// The get() method returns a specified by key element
|
||||
/// from a [`WeakMap`] object.
|
||||
@ -2321,6 +2349,7 @@ extern "C" {
|
||||
// WeakSet
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
#[derive(Clone, Debug)]
|
||||
pub type WeakSet;
|
||||
|
||||
/// The `WeakSet` object lets you store weakly held objects in a collection.
|
||||
@ -2353,6 +2382,7 @@ extern "C" {
|
||||
// WebAssembly
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
#[derive(Clone, Debug)]
|
||||
pub type WebAssembly;
|
||||
|
||||
/// The `WebAssembly.validate()` function validates a given typed
|
||||
@ -2361,13 +2391,14 @@ extern "C" {
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/validate
|
||||
#[wasm_bindgen(static_method_of = WebAssembly, catch)]
|
||||
pub fn validate(bufferSource: JsValue) -> Result<bool, JsValue>;
|
||||
pub fn validate(bufferSource: &JsValue) -> Result<bool, JsValue>;
|
||||
}
|
||||
|
||||
// JsString
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
#[wasm_bindgen(js_name = JsString)]
|
||||
#[wasm_bindgen(js_name = String)]
|
||||
#[derive(Clone)]
|
||||
pub type JsString;
|
||||
|
||||
/// The length property of a String object indicates the length of a string,
|
||||
@ -2657,6 +2688,7 @@ impl fmt::Debug for JsString {
|
||||
// Symbol
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
#[derive(Clone, Debug)]
|
||||
pub type Symbol;
|
||||
|
||||
/// The `Symbol.hasInstance` well-known symbol is used to determine
|
||||
@ -2776,6 +2808,7 @@ extern "C" {
|
||||
// Intl
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
#[derive(Clone, Debug)]
|
||||
pub type Intl;
|
||||
|
||||
/// The `Intl.getCanonicalLocales()` method returns an array containing
|
||||
|
@ -5,7 +5,7 @@ use js_sys::*;
|
||||
macro_rules! js_array {
|
||||
($($e:expr),*) => ({
|
||||
let __x = Array::new();
|
||||
$(__x.push(JsValue::from($e));)*
|
||||
$(__x.push(&JsValue::from($e));)*
|
||||
__x
|
||||
})
|
||||
}
|
||||
@ -39,10 +39,10 @@ fn filter() {
|
||||
#[wasm_bindgen_test]
|
||||
fn index_of() {
|
||||
let chars = js_array!["a", "c", "x", "n"];
|
||||
assert_eq!(chars.index_of("x".into(), 0), 2);
|
||||
assert_eq!(chars.index_of("z".into(), 0), -1);
|
||||
assert_eq!(chars.index_of("x".into(), -3), 2);
|
||||
assert_eq!(chars.index_of("z".into(), -2), -1);
|
||||
assert_eq!(chars.index_of(&"x".into(), 0), 2);
|
||||
assert_eq!(chars.index_of(&"z".into(), 0), -1);
|
||||
assert_eq!(chars.index_of(&"x".into(), -3), 2);
|
||||
assert_eq!(chars.index_of(&"z".into(), -2), -1);
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
@ -75,10 +75,10 @@ fn some() {
|
||||
#[wasm_bindgen_test]
|
||||
fn last_index_of() {
|
||||
let characters = js_array!["a", "x", "c", "x", "n"];
|
||||
assert_eq!(characters.last_index_of("x".into(), 5), 3);
|
||||
assert_eq!(characters.last_index_of("z".into(), 5), -1);
|
||||
assert_eq!(characters.last_index_of("x".into(), 2), 1);
|
||||
assert_eq!(characters.last_index_of("x".into(), 0), -1);
|
||||
assert_eq!(characters.last_index_of(&"x".into(), 5), 3);
|
||||
assert_eq!(characters.last_index_of(&"z".into(), 5), -1);
|
||||
assert_eq!(characters.last_index_of(&"x".into(), 2), 1);
|
||||
assert_eq!(characters.last_index_of(&"x".into(), 0), -1);
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
@ -99,7 +99,7 @@ fn slice() {
|
||||
#[wasm_bindgen_test]
|
||||
fn fill() {
|
||||
let characters = js_array!["a", "c", "x", "n", 1, "8"];
|
||||
let subset = characters.fill(0.into(), 0, 3);
|
||||
let subset = characters.fill(&0.into(), 0, 3);
|
||||
|
||||
assert_eq!(to_rust(&subset), array![0, 0, 0, "n", 1, "8"]);
|
||||
}
|
||||
@ -127,7 +127,7 @@ fn pop() {
|
||||
#[wasm_bindgen_test]
|
||||
fn push() {
|
||||
let characters = js_array![8, 5, 4, 3, 1, 2];
|
||||
let length = characters.push("a".into());
|
||||
let length = characters.push(&"a".into());
|
||||
assert_eq!(length, 7);
|
||||
assert_eq!(to_rust(&characters)[6], "a");
|
||||
}
|
||||
@ -151,7 +151,7 @@ fn shift() {
|
||||
#[wasm_bindgen_test]
|
||||
fn unshift() {
|
||||
let characters = js_array![8, 5, 4, 3, 1, 2];
|
||||
let length = characters.unshift("abba".into());
|
||||
let length = characters.unshift(&"abba".into());
|
||||
|
||||
assert_eq!(length, 7);
|
||||
assert_eq!(to_rust(&characters)[0], "abba");
|
||||
@ -166,9 +166,9 @@ fn to_string() {
|
||||
#[wasm_bindgen_test]
|
||||
fn includes() {
|
||||
let characters = js_array![8, 5, 4, 3, 1, 2];
|
||||
assert!(characters.includes(2.into(), 0));
|
||||
assert!(!characters.includes(9.into(), 0));
|
||||
assert!(!characters.includes(3.into(), 4));
|
||||
assert!(characters.includes(&2.into(), 0));
|
||||
assert!(!characters.includes(&9.into(), 0));
|
||||
assert!(!characters.includes(&3.into(), 4));
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
@ -225,7 +225,7 @@ fn reduce() {
|
||||
format!("{}{}", &ac.as_string().unwrap(), &cr.as_string().unwrap())
|
||||
.into()
|
||||
},
|
||||
"".into(),
|
||||
&"".into(),
|
||||
);
|
||||
assert_eq!(arr, "01234");
|
||||
}
|
||||
@ -238,7 +238,7 @@ fn reduce_right() {
|
||||
format!("{}{}", &ac.as_string().unwrap(), &cr.as_string().unwrap())
|
||||
.into()
|
||||
},
|
||||
"".into(),
|
||||
&"".into(),
|
||||
);
|
||||
assert_eq!(arr, "43210");
|
||||
}
|
||||
@ -255,7 +255,7 @@ fn find_index() {
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn to_locale_string() {
|
||||
let output = js_array![1, "a", Date::new("21 Dec 1997 14:12:00 UTC".into())]
|
||||
let output = js_array![1, "a", Date::new(&"21 Dec 1997 14:12:00 UTC".into())]
|
||||
.to_locale_string(&"en".into(), &JsValue::undefined());
|
||||
assert!(String::from(output).len() > 0);
|
||||
}
|
||||
|
@ -11,8 +11,8 @@ fn new() {
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn is_view() {
|
||||
let x = Uint8Array::new(JsValue::from(42));
|
||||
assert!(ArrayBuffer::is_view(JsValue::from(x)));
|
||||
let x = Uint8Array::new(&JsValue::from(42));
|
||||
assert!(ArrayBuffer::is_view(&JsValue::from(x)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -5,13 +5,13 @@ use js_sys::*;
|
||||
#[wasm_bindgen_test]
|
||||
fn keys() {
|
||||
let array = Array::new();
|
||||
array.push(JsValue::from(1));
|
||||
array.push(JsValue::from(2));
|
||||
array.push(JsValue::from(3));
|
||||
array.push(JsValue::from(4));
|
||||
array.push(JsValue::from(5));
|
||||
array.push(&JsValue::from(1));
|
||||
array.push(&JsValue::from(2));
|
||||
array.push(&JsValue::from(3));
|
||||
array.push(&JsValue::from(4));
|
||||
array.push(&JsValue::from(5));
|
||||
|
||||
let new_array = Array::from(array.keys().into());
|
||||
let new_array = Array::from(&array.keys().into());
|
||||
|
||||
let mut result = Vec::new();
|
||||
new_array.for_each(&mut |i, _, _| result.push(i.as_f64().unwrap()));
|
||||
@ -21,13 +21,13 @@ fn keys() {
|
||||
#[wasm_bindgen_test]
|
||||
fn entries() {
|
||||
let array = Array::new();
|
||||
array.push(JsValue::from(1));
|
||||
array.push(JsValue::from(2));
|
||||
array.push(JsValue::from(3));
|
||||
array.push(JsValue::from(4));
|
||||
array.push(JsValue::from(5));
|
||||
array.push(&JsValue::from(1));
|
||||
array.push(&JsValue::from(2));
|
||||
array.push(&JsValue::from(3));
|
||||
array.push(&JsValue::from(4));
|
||||
array.push(&JsValue::from(5));
|
||||
|
||||
let new_array = Array::from(array.entries().into());
|
||||
let new_array = Array::from(&array.entries().into());
|
||||
|
||||
new_array.for_each(&mut |a, i, _| {
|
||||
assert!(a.is_object());
|
||||
|
@ -4,10 +4,10 @@ use js_sys::*;
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn new_undefined() {
|
||||
assert_eq!(Boolean::new(JsValue::undefined()).value_of(), false);
|
||||
assert_eq!(Boolean::new(&JsValue::undefined()).value_of(), false);
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn new_truely() {
|
||||
assert_eq!(Boolean::new(JsValue::from("foo")).value_of(), true);
|
||||
assert_eq!(Boolean::new(&JsValue::from("foo")).value_of(), true);
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ use js_sys::*;
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn test() {
|
||||
let bytes = Int8Array::new(JsValue::from(10));
|
||||
let bytes = Int8Array::new(&JsValue::from(10));
|
||||
|
||||
// TODO: figure out how to do `bytes[2] = 2`
|
||||
bytes.subarray(2, 3).fill(2, 0, 1);
|
||||
|
@ -4,20 +4,20 @@ use js_sys::*;
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn get_date() {
|
||||
let date = Date::new("August 19, 1975 23:15:30".into());
|
||||
let date = Date::new(&"August 19, 1975 23:15:30".into());
|
||||
assert_eq!(date.get_date(), 19);
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn get_day() {
|
||||
let date = Date::new("August 19, 1975 23:15:30".into());
|
||||
let date = Date::new(&"August 19, 1975 23:15:30".into());
|
||||
assert_eq!(date.get_day(), 2);
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn get_full_year() {
|
||||
let date = Date::new("July 20, 1969 00:20:18".into());
|
||||
let abbr = Date::new("Thu, 06 Sep 12 00:00:00".into());
|
||||
let date = Date::new(&"July 20, 1969 00:20:18".into());
|
||||
let abbr = Date::new(&"Thu, 06 Sep 12 00:00:00".into());
|
||||
|
||||
assert_eq!(date.get_full_year(), 1969);
|
||||
assert_eq!(abbr.get_full_year(), 2012);
|
||||
@ -25,14 +25,14 @@ fn get_full_year() {
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn get_hours() {
|
||||
let date = Date::new("March 13, 08 04:20".into());
|
||||
let date = Date::new(&"March 13, 08 04:20".into());
|
||||
assert_eq!(date.get_hours(), 4);
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn get_milliseconds() {
|
||||
let date = Date::new("July 20, 69 00:20:18".into());
|
||||
let ms = Date::new("July 20, 69 00:20:18:123".into());
|
||||
let date = Date::new(&"July 20, 69 00:20:18".into());
|
||||
let ms = Date::new(&"July 20, 69 00:20:18:123".into());
|
||||
|
||||
assert_eq!(date.get_milliseconds(), 0);
|
||||
assert_eq!(ms.get_milliseconds(), 123);
|
||||
@ -40,51 +40,51 @@ fn get_milliseconds() {
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn get_minutes() {
|
||||
let date = Date::new("March 13, 08 04:20".into());
|
||||
let date = Date::new(&"March 13, 08 04:20".into());
|
||||
|
||||
assert_eq!(date.get_minutes(), 20);
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn get_month() {
|
||||
let date = Date::new("July 20, 69 00:20:18".into());
|
||||
let date = Date::new(&"July 20, 69 00:20:18".into());
|
||||
|
||||
assert_eq!(date.get_month(), 6);
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn get_seconds() {
|
||||
let date = Date::new("July 20, 69 00:20:18".into());
|
||||
let date = Date::new(&"July 20, 69 00:20:18".into());
|
||||
|
||||
assert_eq!(date.get_seconds(), 18);
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn get_time() {
|
||||
let date = Date::new("July 20, 69 00:20:18 GMT+00:00".into());
|
||||
let date = Date::new(&"July 20, 69 00:20:18 GMT+00:00".into());
|
||||
|
||||
assert_eq!(date.get_time(), -14254782000.0);
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn get_timezone_offset() {
|
||||
let date1 = Date::new("August 19, 1975 23:15:30 GMT+07:00".into());
|
||||
let date2 = Date::new("August 19, 1975 23:15:30 GMT-02:00".into());
|
||||
let date1 = Date::new(&"August 19, 1975 23:15:30 GMT+07:00".into());
|
||||
let date2 = Date::new(&"August 19, 1975 23:15:30 GMT-02:00".into());
|
||||
assert_eq!(date1.get_timezone_offset(), date2.get_timezone_offset());
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn get_utc_date() {
|
||||
let date1 = Date::new("August 19, 1975 23:15:30 GMT+11:00".into());
|
||||
let date2 = Date::new("August 19, 1975 23:15:30 GMT-11:00".into());
|
||||
let date1 = Date::new(&"August 19, 1975 23:15:30 GMT+11:00".into());
|
||||
let date2 = Date::new(&"August 19, 1975 23:15:30 GMT-11:00".into());
|
||||
assert_eq!(date1.get_utc_date(), 19);
|
||||
assert_eq!(date2.get_utc_date(), 20);
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn get_utc_day() {
|
||||
let date1 = Date::new("August 19, 1975 23:15:30 GMT+11:00".into());
|
||||
let date2 = Date::new("August 19, 1975 23:15:30 GMT-11:00".into());
|
||||
let date1 = Date::new(&"August 19, 1975 23:15:30 GMT+11:00".into());
|
||||
let date2 = Date::new(&"August 19, 1975 23:15:30 GMT-11:00".into());
|
||||
|
||||
assert_eq!(date1.get_utc_day(), 2);
|
||||
assert_eq!(date2.get_utc_day(), 3);
|
||||
@ -92,16 +92,16 @@ fn get_utc_day() {
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn get_utc_full_year() {
|
||||
let date1 = Date::new("December 31, 1975, 23:15:30 GMT+11:00".into());
|
||||
let date2 = Date::new("December 31, 1975, 23:15:30 GMT-11:00".into());
|
||||
let date1 = Date::new(&"December 31, 1975, 23:15:30 GMT+11:00".into());
|
||||
let date2 = Date::new(&"December 31, 1975, 23:15:30 GMT-11:00".into());
|
||||
assert_eq!(date1.get_utc_full_year(), 1975);
|
||||
assert_eq!(date2.get_utc_full_year(), 1976);
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn get_utc_hours() {
|
||||
let date1 = Date::new("December 31, 1975, 23:15:30 GMT+11:00".into());
|
||||
let date2 = Date::new("December 31, 1975, 23:15:30 GMT-11:00".into());
|
||||
let date1 = Date::new(&"December 31, 1975, 23:15:30 GMT+11:00".into());
|
||||
let date2 = Date::new(&"December 31, 1975, 23:15:30 GMT-11:00".into());
|
||||
|
||||
assert_eq!(date1.get_utc_hours(), 12);
|
||||
assert_eq!(date2.get_utc_hours(), 10);
|
||||
@ -109,22 +109,22 @@ fn get_utc_hours() {
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn get_utc_milliseconds() {
|
||||
let date = Date::new("2018-01-02T03:04:05.678Z".into());
|
||||
let date = Date::new(&"2018-01-02T03:04:05.678Z".into());
|
||||
assert_eq!(date.get_utc_milliseconds(), 678);
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn get_utc_minutes() {
|
||||
let date1 = Date::new("1 January 2000 03:15:30 GMT+07:00".into());
|
||||
let date2 = Date::new("1 January 2000 03:15:30 GMT+03:30".into());
|
||||
let date1 = Date::new(&"1 January 2000 03:15:30 GMT+07:00".into());
|
||||
let date2 = Date::new(&"1 January 2000 03:15:30 GMT+03:30".into());
|
||||
assert_eq!(date1.get_utc_minutes(), 15);
|
||||
assert_eq!(date2.get_utc_minutes(), 45);
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn get_utc_month() {
|
||||
let date1 = Date::new("December 31, 1975, 23:15:30 GMT+11:00".into());
|
||||
let date2 = Date::new("December 31, 1975, 23:15:30 GMT-11:00".into());
|
||||
let date1 = Date::new(&"December 31, 1975, 23:15:30 GMT+11:00".into());
|
||||
let date2 = Date::new(&"December 31, 1975, 23:15:30 GMT-11:00".into());
|
||||
|
||||
assert_eq!(date1.get_utc_month(), 11);
|
||||
assert_eq!(date2.get_utc_month(), 0);
|
||||
@ -132,14 +132,14 @@ fn get_utc_month() {
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn get_utc_seconds() {
|
||||
let date = Date::new("July 20, 1969, 20:18:04 UTC".into());
|
||||
let date = Date::new(&"July 20, 1969, 20:18:04 UTC".into());
|
||||
|
||||
assert_eq!(date.get_utc_seconds(), 4);
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn new() {
|
||||
assert!(JsValue::from(Date::new(JsValue::undefined())).is_object());
|
||||
assert!(JsValue::from(Date::new(&JsValue::undefined())).is_object());
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
@ -149,8 +149,8 @@ fn now() {
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn parse() {
|
||||
let date = Date::parse("04 Dec 1995 00:12:00 GMT".into());
|
||||
let zero = Date::parse("01 Jan 1970 00:00:00 GMT".into());
|
||||
let date = Date::parse(&"04 Dec 1995 00:12:00 GMT".into());
|
||||
let zero = Date::parse(&"01 Jan 1970 00:00:00 GMT".into());
|
||||
|
||||
assert_eq!(date, 818035920000.0);
|
||||
assert_eq!(zero, 0.0);
|
||||
@ -158,8 +158,8 @@ fn parse() {
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn set_date() {
|
||||
let event1 = Date::new("August 19, 1975 23:15:30".into());
|
||||
let event2 = Date::new("August 24, 1975 23:15:30".into());
|
||||
let event1 = Date::new(&"August 19, 1975 23:15:30".into());
|
||||
let event2 = Date::new(&"August 24, 1975 23:15:30".into());
|
||||
|
||||
let ms = event1.set_date(24);
|
||||
|
||||
@ -170,8 +170,8 @@ fn set_date() {
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn set_full_year() {
|
||||
let event1 = Date::new("August 19, 1975 23:15:30".into());
|
||||
let event2 = Date::new("August 19, 1976 23:15:30".into());
|
||||
let event1 = Date::new(&"August 19, 1975 23:15:30".into());
|
||||
let event2 = Date::new(&"August 19, 1976 23:15:30".into());
|
||||
|
||||
let ms = event1.set_full_year(1976);
|
||||
|
||||
@ -182,8 +182,8 @@ fn set_full_year() {
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn set_hours() {
|
||||
let event1 = Date::new("August 19, 1975 23:15:30".into());
|
||||
let event2 = Date::new("August 19, 1975 20:15:30".into());
|
||||
let event1 = Date::new(&"August 19, 1975 23:15:30".into());
|
||||
let event2 = Date::new(&"August 19, 1975 20:15:30".into());
|
||||
|
||||
let ms = event1.set_hours(20);
|
||||
|
||||
@ -194,7 +194,7 @@ fn set_hours() {
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn set_milliseconds() {
|
||||
let event = Date::new("August 19, 1975 23:15:30".into());
|
||||
let event = Date::new(&"August 19, 1975 23:15:30".into());
|
||||
|
||||
let ms = event.set_milliseconds(456);
|
||||
|
||||
@ -204,8 +204,8 @@ fn set_milliseconds() {
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn set_minutes() {
|
||||
let event1 = Date::new("August 19, 1975 23:15:30".into());
|
||||
let event2 = Date::new("August 19, 1975 23:45:30".into());
|
||||
let event1 = Date::new(&"August 19, 1975 23:15:30".into());
|
||||
let event2 = Date::new(&"August 19, 1975 23:45:30".into());
|
||||
|
||||
let ms = event1.set_minutes(45);
|
||||
|
||||
@ -216,8 +216,8 @@ fn set_minutes() {
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn set_month() {
|
||||
let event1 = Date::new("August 19, 1975 23:15:30".into());
|
||||
let event2 = Date::new("April 19, 1975 23:15:30".into());
|
||||
let event1 = Date::new(&"August 19, 1975 23:15:30".into());
|
||||
let event2 = Date::new(&"April 19, 1975 23:15:30".into());
|
||||
|
||||
let ms = event1.set_month(3);
|
||||
|
||||
@ -228,8 +228,8 @@ fn set_month() {
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn set_seconds() {
|
||||
let event1 = Date::new("August 19, 1975 23:15:30".into());
|
||||
let event2 = Date::new("August 19, 1975 23:15:42".into());
|
||||
let event1 = Date::new(&"August 19, 1975 23:15:30".into());
|
||||
let event2 = Date::new(&"August 19, 1975 23:15:42".into());
|
||||
|
||||
let ms = event1.set_seconds(42);
|
||||
|
||||
@ -240,8 +240,8 @@ fn set_seconds() {
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn set_time() {
|
||||
let event1 = Date::new("July 1, 1999".into());
|
||||
let event2 = Date::new(JsValue::undefined());
|
||||
let event1 = Date::new(&"July 1, 1999".into());
|
||||
let event2 = Date::new(&JsValue::undefined());
|
||||
|
||||
let ms = event2.set_time(event1.get_time());
|
||||
|
||||
@ -251,8 +251,8 @@ fn set_time() {
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn set_utc_date() {
|
||||
let event1 = Date::new("August 19, 1975 23:15:30 GMT-3:00".into());
|
||||
let event2 = Date::new("August 19, 1975 02:15:30 GMT".into());
|
||||
let event1 = Date::new(&"August 19, 1975 23:15:30 GMT-3:00".into());
|
||||
let event2 = Date::new(&"August 19, 1975 02:15:30 GMT".into());
|
||||
|
||||
let ms = event1.set_utc_date(19);
|
||||
|
||||
@ -263,8 +263,8 @@ fn set_utc_date() {
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn set_utc_full_year() {
|
||||
let event1 = Date::new("December 31, 1975 23:15:30 GMT-3:00".into());
|
||||
let event2 = Date::new("January 01, 1975 02:15:30 GMT".into());
|
||||
let event1 = Date::new(&"December 31, 1975 23:15:30 GMT-3:00".into());
|
||||
let event2 = Date::new(&"January 01, 1975 02:15:30 GMT".into());
|
||||
|
||||
let ms = event1.set_utc_full_year(1975);
|
||||
|
||||
@ -275,8 +275,8 @@ fn set_utc_full_year() {
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn set_utc_hours() {
|
||||
let event1 = Date::new("August 19, 1975 23:15:30 GMT-3:00".into());
|
||||
let event2 = Date::new("August 20, 1975 23:15:30 GMT".into());
|
||||
let event1 = Date::new(&"August 19, 1975 23:15:30 GMT-3:00".into());
|
||||
let event2 = Date::new(&"August 20, 1975 23:15:30 GMT".into());
|
||||
|
||||
let ms = event1.set_utc_hours(23);
|
||||
|
||||
@ -287,8 +287,8 @@ fn set_utc_hours() {
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn set_utc_milliseconds() {
|
||||
let event1 = Date::new("August 19, 1975 23:15:30 GMT-3:00".into());
|
||||
let event2 = Date::new("August 20, 1975 02:15:30.420Z GMT".into());
|
||||
let event1 = Date::new(&"August 19, 1975 23:15:30 GMT-3:00".into());
|
||||
let event2 = Date::new(&"August 20, 1975 02:15:30.420Z GMT".into());
|
||||
|
||||
let ms = event1.set_utc_milliseconds(420);
|
||||
|
||||
@ -299,8 +299,8 @@ fn set_utc_milliseconds() {
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn set_utc_minutes() {
|
||||
let event1 = Date::new("December 31, 1975, 23:15:30 GMT-3:00".into());
|
||||
let event2 = Date::new("January 01, 1976 02:25:30 GMT".into());
|
||||
let event1 = Date::new(&"December 31, 1975, 23:15:30 GMT-3:00".into());
|
||||
let event2 = Date::new(&"January 01, 1976 02:25:30 GMT".into());
|
||||
|
||||
let ms = event1.set_utc_minutes(25);
|
||||
|
||||
@ -311,8 +311,8 @@ fn set_utc_minutes() {
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn set_utc_month() {
|
||||
let event1 = Date::new("December 31, 1975 23:15:30 GMT-3:00".into());
|
||||
let event2 = Date::new("December 01, 1976 02:15:30 GMT".into());
|
||||
let event1 = Date::new(&"December 31, 1975 23:15:30 GMT-3:00".into());
|
||||
let event2 = Date::new(&"December 01, 1976 02:15:30 GMT".into());
|
||||
|
||||
let ms = event1.set_utc_month(11);
|
||||
|
||||
@ -323,8 +323,8 @@ fn set_utc_month() {
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn set_utc_seconds() {
|
||||
let event1 = Date::new("December 31, 1975 23:15:30 GMT-3:00".into());
|
||||
let event2 = Date::new("January 01, 1976 02:15:39 GMT".into());
|
||||
let event1 = Date::new(&"December 31, 1975 23:15:30 GMT-3:00".into());
|
||||
let event2 = Date::new(&"January 01, 1976 02:15:39 GMT".into());
|
||||
|
||||
let ms = event1.set_utc_seconds(39);
|
||||
|
||||
@ -335,63 +335,63 @@ fn set_utc_seconds() {
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn to_date_string() {
|
||||
let date = Date::new("05 October 2011 14:48 UTC".into());
|
||||
let date = Date::new(&"05 October 2011 14:48 UTC".into());
|
||||
assert_eq!(JsValue::from(date.to_date_string()), "Wed Oct 05 2011");
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn to_iso_string() {
|
||||
let date = Date::new("05 October 2011 14:48 UTC".into());
|
||||
let date = Date::new(&"05 October 2011 14:48 UTC".into());
|
||||
assert_eq!(JsValue::from(date.to_iso_string()), "2011-10-05T14:48:00.000Z");
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn to_json() {
|
||||
let date = Date::new("August 19, 1975 23:15:30 UTC".into());
|
||||
let date = Date::new(&"August 19, 1975 23:15:30 UTC".into());
|
||||
|
||||
assert_eq!(JsValue::from(date.to_json()), "1975-08-19T23:15:30.000Z");
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn to_locale_date_string() {
|
||||
let date = Date::new("August 19, 1975 23:15:30 UTC".into());
|
||||
let s = date.to_locale_date_string("de-DE".into(), JsValue::undefined());
|
||||
let date = Date::new(&"August 19, 1975 23:15:30 UTC".into());
|
||||
let s = date.to_locale_date_string(&"de-DE".into(), &JsValue::undefined());
|
||||
assert!(s.length() > 0);
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn to_locale_string() {
|
||||
let date = Date::new("August 19, 1975 23:15:30 UTC".into());
|
||||
let s = date.to_locale_string("de-DE".into(), JsValue::undefined());
|
||||
let date = Date::new(&"August 19, 1975 23:15:30 UTC".into());
|
||||
let s = date.to_locale_string(&"de-DE".into(), &JsValue::undefined());
|
||||
assert!(s.length() > 0);
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn to_locale_time_string() {
|
||||
let date = Date::new("August 19, 1975 23:15:30".into());
|
||||
let date = Date::new(&"August 19, 1975 23:15:30".into());
|
||||
assert_eq!(
|
||||
JsValue::from(date.to_locale_time_string("en-US".into())),
|
||||
JsValue::from(date.to_locale_time_string(&"en-US".into())),
|
||||
"11:15:30 PM",
|
||||
);
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn to_string() {
|
||||
let date = Date::new("August 19, 1975 23:15:30".into());
|
||||
let date = Date::new(&"August 19, 1975 23:15:30".into());
|
||||
let s = JsValue::from(date.to_string()).as_string().unwrap();
|
||||
assert_eq!(&s[0..15], "Tue Aug 19 1975");
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn to_time_string() {
|
||||
let date = Date::new("August 19, 1975 23:15:30".into());
|
||||
let date = Date::new(&"August 19, 1975 23:15:30".into());
|
||||
let s = JsValue::from(date.to_time_string()).as_string().unwrap();
|
||||
assert_eq!(&s[0..8], "23:15:30");
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn to_utc_string() {
|
||||
let date = Date::new("14 Jun 2017 00:00:00 PDT".into());
|
||||
let date = Date::new(&"14 Jun 2017 00:00:00 PDT".into());
|
||||
let s = JsValue::from(date.to_utc_string()).as_string().unwrap();
|
||||
assert_eq!(s, "Wed, 14 Jun 2017 07:00:00 GMT");
|
||||
}
|
||||
@ -403,6 +403,6 @@ fn utc() {
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn value_of() {
|
||||
let date = Date::new(Date::utc(2018f64, 6f64).into());
|
||||
let date = Date::new(&Date::utc(2018f64, 6f64).into());
|
||||
assert_eq!(date.value_of(), 1530403200000.0);
|
||||
}
|
||||
|
@ -17,16 +17,16 @@ extern {
|
||||
#[wasm_bindgen_test]
|
||||
fn apply() {
|
||||
let args = Array::new();
|
||||
args.push(1.into());
|
||||
args.push(2.into());
|
||||
args.push(3.into());
|
||||
args.push(&1.into());
|
||||
args.push(&2.into());
|
||||
args.push(&3.into());
|
||||
assert_eq!(MAX.apply(&JsValue::undefined(), &args).unwrap(), 3);
|
||||
|
||||
let arr = JsValue::from(Array::new());
|
||||
let args = Array::new();
|
||||
args.push(1.into());
|
||||
args.push(&1.into());
|
||||
ARRAY_PROTOTYPE.push().apply(&arr, &args).unwrap();
|
||||
assert_eq!(Array::from(arr).length(), 1);
|
||||
assert_eq!(Array::from(&arr).length(), 1);
|
||||
}
|
||||
|
||||
#[wasm_bindgen(module = "tests/wasm/Function.js", version = "*")]
|
||||
|
@ -5,8 +5,8 @@ use js_sys::*;
|
||||
#[wasm_bindgen_test]
|
||||
fn get_canonical_locales() {
|
||||
let locales = Array::new();
|
||||
locales.push("EN-US".into());
|
||||
locales.push("Fr".into());
|
||||
locales.push(&"EN-US".into());
|
||||
locales.push(&"Fr".into());
|
||||
let locales = JsValue::from(locales);
|
||||
let canonical_locales = Intl::get_canonical_locales(&locales);
|
||||
assert_eq!(canonical_locales.length(), 2);
|
||||
|
@ -50,7 +50,7 @@ fn is_safe_integer() {
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn new() {
|
||||
let n = Number::new(JsValue::from(42));
|
||||
let n = Number::new(&JsValue::from(42));
|
||||
let v = JsValue::from(n);
|
||||
assert!(v.is_object());
|
||||
assert_eq!(Number::from(v).value_of(), 42.);
|
||||
@ -58,17 +58,17 @@ fn new() {
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn parse_int_float() {
|
||||
assert_eq!(Number::parse_int("42", 10).value_of(), 42.);
|
||||
assert_eq!(Number::parse_int("42", 16).value_of(), 66.); // 0x42 == 66
|
||||
assert!(Number::parse_int("invalid int", 10).value_of().is_nan());
|
||||
assert_eq!(Number::parse_int("42", 10), 42.);
|
||||
assert_eq!(Number::parse_int("42", 16), 66.); // 0x42 == 66
|
||||
assert!(Number::parse_int("invalid int", 10).is_nan());
|
||||
|
||||
assert_eq!(Number::parse_float("123456.789").value_of(), 123456.789);
|
||||
assert!(Number::parse_float("invalid float").value_of().is_nan());
|
||||
assert_eq!(Number::parse_float("123456.789"), 123456.789);
|
||||
assert!(Number::parse_float("invalid float").is_nan());
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn to_locale_string() {
|
||||
let number = Number::new(1234.45.into());
|
||||
let number = Number::new(&1234.45.into());
|
||||
assert_eq!(number.to_locale_string("en-US"), "1,234.45");
|
||||
// TODO: these tests seems to be system dependent, disable for now
|
||||
// assert_eq!(wasm.to_locale_string(number, "de-DE"), "1,234.45");
|
||||
@ -77,30 +77,30 @@ fn to_locale_string() {
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn to_precision() {
|
||||
assert_eq!(Number::new(0.1.into()).to_precision(3).unwrap(), "0.100");
|
||||
assert!(Number::new(10.into()).to_precision(101).is_err());
|
||||
assert_eq!(Number::new(&0.1.into()).to_precision(3).unwrap(), "0.100");
|
||||
assert!(Number::new(&10.into()).to_precision(101).is_err());
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn to_string() {
|
||||
assert_eq!(Number::new(42.into()).to_string(10).unwrap(), "42");
|
||||
assert_eq!(Number::new(233.into()).to_string(16).unwrap(), "e9");
|
||||
assert!(Number::new(100.into()).to_string(100).is_err());
|
||||
assert_eq!(Number::new(&42.into()).to_string(10).unwrap(), "42");
|
||||
assert_eq!(Number::new(&233.into()).to_string(16).unwrap(), "e9");
|
||||
assert!(Number::new(&100.into()).to_string(100).is_err());
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn value_of() {
|
||||
assert_eq!(Number::new(42.into()).value_of(), 42.);
|
||||
assert_eq!(Number::new(&42.into()).value_of(), 42.);
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn to_fixed() {
|
||||
assert_eq!(Number::new(123.456.into()).to_fixed(2).unwrap(), "123.46");
|
||||
assert!(Number::new(10.into()).to_fixed(101).is_err());
|
||||
assert_eq!(Number::new(&123.456.into()).to_fixed(2).unwrap(), "123.46");
|
||||
assert!(Number::new(&10.into()).to_fixed(101).is_err());
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn to_exponential() {
|
||||
assert_eq!(Number::new(123456.into()).to_exponential(2).unwrap(), "1.23e+5");
|
||||
assert!(Number::new(10.into()).to_exponential(101).is_err());
|
||||
assert_eq!(Number::new(&123456.into()).to_exponential(2).unwrap(), "1.23e+5");
|
||||
assert!(Number::new(&10.into()).to_exponential(101).is_err());
|
||||
}
|
||||
|
@ -42,15 +42,15 @@ extern {
|
||||
#[wasm_bindgen_test]
|
||||
fn apply() {
|
||||
let args = Array::new();
|
||||
args.push(3.into());
|
||||
args.push(&3.into());
|
||||
assert_eq!(Reflect::apply(&get_char_at(), &"ponies".into(), &args).unwrap(), "i");
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn construct() {
|
||||
let args = Array::new();
|
||||
args.push(10.into());
|
||||
args.push(10.into());
|
||||
args.push(&10.into());
|
||||
args.push(&10.into());
|
||||
let instance = Reflect::construct(&RECTANGLE_CLASS, &args);
|
||||
assert_eq!(Rectangle::from(instance).x(), 10);
|
||||
}
|
||||
@ -58,8 +58,8 @@ fn construct() {
|
||||
#[wasm_bindgen_test]
|
||||
fn construct_with_new_target() {
|
||||
let args = Array::new();
|
||||
args.push(10.into());
|
||||
args.push(10.into());
|
||||
args.push(&10.into());
|
||||
args.push(&10.into());
|
||||
let instance = Reflect::construct_with_new_target(
|
||||
&RECTANGLE_CLASS,
|
||||
&args,
|
||||
@ -86,10 +86,10 @@ fn delete_property() {
|
||||
assert!(r.x_jsval().is_undefined());
|
||||
|
||||
let array = Array::new();
|
||||
array.push(1.into());
|
||||
array.push(&1.into());
|
||||
let obj = Object::from(JsValue::from(array));
|
||||
Reflect::delete_property(&obj, &0.into());
|
||||
let array = Array::from(JsValue::from(obj));
|
||||
let array = Array::from(&JsValue::from(obj));
|
||||
assert!(array.length() == 1);
|
||||
array.for_each(&mut |x, _, _| assert!(x.is_undefined()));
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ fn entries() {
|
||||
let iter = GenericIterator::from(JsValue::from(s.entries()));
|
||||
let obj = iter.next();
|
||||
assert!(!obj.done());
|
||||
let array = Array::from(obj.value());
|
||||
let array = Array::from(&obj.value());
|
||||
assert_eq!(array.length(), 2);
|
||||
array.for_each(&mut |a, _, _| {
|
||||
assert_eq!(a, 1);
|
||||
|
@ -18,7 +18,7 @@ macro_rules! each {
|
||||
|
||||
macro_rules! test_undefined {
|
||||
($arr:ident) => ({
|
||||
let arr = $arr::new(JsValue::undefined());
|
||||
let arr = $arr::new(&JsValue::undefined());
|
||||
assert_eq!(arr.length(), 0);
|
||||
assert_eq!(arr.byte_length(), 0);
|
||||
assert_eq!(arr.byte_offset(), 0);
|
||||
@ -32,7 +32,7 @@ fn new_undefined() {
|
||||
|
||||
macro_rules! test_length {
|
||||
($arr:ident) => ({
|
||||
let arr = $arr::new(4.into());
|
||||
let arr = $arr::new(&4.into());
|
||||
assert_eq!(arr.length(), 4);
|
||||
assert!(arr.byte_length() != 0);
|
||||
assert_eq!(arr.byte_offset(), 0);
|
||||
@ -46,7 +46,7 @@ fn new_length() {
|
||||
|
||||
macro_rules! test_subarray {
|
||||
($arr:ident) => ({
|
||||
assert_eq!($arr::new(4.into()).subarray(0, 1).length(), 1);
|
||||
assert_eq!($arr::new(&4.into()).subarray(0, 1).length(), 1);
|
||||
})
|
||||
}
|
||||
#[wasm_bindgen_test]
|
||||
@ -56,7 +56,7 @@ fn new_subarray() {
|
||||
|
||||
macro_rules! test_fill {
|
||||
($arr:ident) => ({
|
||||
let arr = $arr::new(4.into());
|
||||
let arr = $arr::new(&4.into());
|
||||
arr.for_each(&mut |x, _, _| {
|
||||
assert_eq!(x as f64, 0.0);
|
||||
});
|
||||
|
@ -24,7 +24,7 @@ fn new() {
|
||||
fn get_and_set() {
|
||||
let map = WeakMap::new();
|
||||
let key = some_key();
|
||||
map.set(&key, "value".into());
|
||||
map.set(&key, &"value".into());
|
||||
assert_eq!(map.get(&key), "value");
|
||||
assert_eq!(map.get(&Object::new()), JsValue::undefined());
|
||||
assert_eq!(map.get(&some_key()), JsValue::undefined());
|
||||
@ -34,7 +34,7 @@ fn get_and_set() {
|
||||
fn has() {
|
||||
let map = WeakMap::new();
|
||||
let key = some_key();
|
||||
map.set(&key, "value".into());
|
||||
map.set(&key, &"value".into());
|
||||
assert!(map.has(&key));
|
||||
assert!(!map.has(&Object::new()));
|
||||
assert!(!map.has(&some_key()));
|
||||
@ -45,7 +45,7 @@ fn delete() {
|
||||
let map = WeakMap::new();
|
||||
let key = some_key();
|
||||
assert!(!map.has(&key));
|
||||
map.set(&key, "value".into());
|
||||
map.set(&key, &"value".into());
|
||||
assert!(map.has(&key));
|
||||
map.delete(&key);
|
||||
assert!(!map.has(&key));
|
||||
|
@ -3,7 +3,7 @@ use js_sys::*;
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn validate() {
|
||||
assert!(!WebAssembly::validate(ArrayBuffer::new(42).into()).unwrap());
|
||||
assert!(!WebAssembly::validate(&ArrayBuffer::new(42).into()).unwrap());
|
||||
|
||||
assert!(WebAssembly::validate(2.into()).is_err());
|
||||
assert!(WebAssembly::validate(&2.into()).is_err());
|
||||
}
|
||||
|
0
crates/js-sys/tests/wasm/main.rs
Normal file → Executable file
0
crates/js-sys/tests/wasm/main.rs
Normal file → Executable file
@ -92,7 +92,7 @@ impl Context {
|
||||
pub fn run(&self, tests: Vec<JsValue>) -> bool {
|
||||
let this = JsValue::null();
|
||||
let args = Array::new();
|
||||
args.push(JsValue::from(self as *const Context as u32));
|
||||
args.push(&JsValue::from(self as *const Context as u32));
|
||||
|
||||
let noun = if tests.len() == 1 { "test" } else { "tests" };
|
||||
console_log!("running {} {}", tests.len(), noun);
|
||||
|
5
examples/closures/src/lib.rs
Normal file → Executable file
5
examples/closures/src/lib.rs
Normal file → Executable file
@ -4,7 +4,6 @@ extern crate wasm_bindgen;
|
||||
extern crate js_sys;
|
||||
|
||||
use js_sys::Date;
|
||||
use js_sys::JsString;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen]
|
||||
@ -55,8 +54,8 @@ pub fn run() {
|
||||
document
|
||||
.get_element_by_id("current-time")
|
||||
.set_inner_html(&String::from(
|
||||
Date::new(JsValue::undefined())
|
||||
.to_locale_string("en-GB".into(), JsValue::undefined()),
|
||||
Date::new(&JsValue::undefined())
|
||||
.to_locale_string(&"en-GB".into(), &JsValue::undefined()),
|
||||
));
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user