mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-15 05:51:23 +00:00
Adds Array.prototype.splice()
to js-sys (#571)
This commit is contained in:
committed by
Alex Crichton
parent
66649018ae
commit
01194558bf
@ -314,6 +314,13 @@ extern "C" {
|
|||||||
#[wasm_bindgen(method)]
|
#[wasm_bindgen(method)]
|
||||||
pub fn sort(this: &Array) -> Array;
|
pub fn sort(this: &Array) -> Array;
|
||||||
|
|
||||||
|
/// The splice() method changes the contents of an array by removing existing elements and/or
|
||||||
|
/// adding new elements.
|
||||||
|
///
|
||||||
|
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice
|
||||||
|
#[wasm_bindgen(method)]
|
||||||
|
pub fn splice(this: &Array, start: u32, delete_count: u32, item: &JsValue) -> Array;
|
||||||
|
|
||||||
/// The toLocaleString() method returns a string representing the elements of the array.
|
/// The toLocaleString() method returns a string representing the elements of the array.
|
||||||
/// The elements are converted to Strings using their toLocaleString methods and these
|
/// The elements are converted to Strings using their toLocaleString methods and these
|
||||||
/// Strings are separated by a locale-specific String (such as a comma “,”).
|
/// Strings are separated by a locale-specific String (such as a comma “,”).
|
||||||
|
@ -96,6 +96,15 @@ fn slice() {
|
|||||||
assert_eq!(to_rust(&subset), array!["c", "x"]);
|
assert_eq!(to_rust(&subset), array!["c", "x"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[wasm_bindgen_test]
|
||||||
|
fn splice() {
|
||||||
|
let characters = js_array!["a", "c", "x", "n", 1, "8"];
|
||||||
|
let removed = characters.splice(1, 3, &"b".into());
|
||||||
|
|
||||||
|
assert_eq!(to_rust(&removed), array!["c", "x", "n"]);
|
||||||
|
assert_eq!(to_rust(&characters), array!["a", "b", 1, "8"]);
|
||||||
|
}
|
||||||
|
|
||||||
#[wasm_bindgen_test]
|
#[wasm_bindgen_test]
|
||||||
fn fill() {
|
fn fill() {
|
||||||
let characters = js_array!["a", "c", "x", "n", 1, "8"];
|
let characters = js_array!["a", "c", "x", "n", 1, "8"];
|
||||||
|
Reference in New Issue
Block a user