mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-03-16 10:10:52 +00:00
add binding for copyWithin
This commit is contained in:
parent
d155136f0e
commit
2f6f734216
@ -133,4 +133,10 @@ extern {
|
||||
/// 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;
|
||||
|
||||
/// The copyWithin() method shallow copies part of an array to another location in the same array and returns it, without modifying its size.
|
||||
///
|
||||
/// http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin
|
||||
#[wasm_bindgen(method, js_name = copyWithin)]
|
||||
pub fn copy_within(this: &Array, target: i32, start: i32, end: i32) -> Array;
|
||||
}
|
@ -168,4 +168,38 @@ fn fill() {
|
||||
}
|
||||
"#)
|
||||
.test()
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn copy_within() {
|
||||
project()
|
||||
.file("src/lib.rs", r#"
|
||||
#![feature(proc_macro, wasm_custom_section)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::js;
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn copy_values_within_array(this: &js::Array, target: i32, start: i32, end: i32) -> js::Array {
|
||||
this.copy_within(target, start, end)
|
||||
}
|
||||
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
export function test() {
|
||||
let characters = [8, 5, 4, 3, 1, 2]
|
||||
wasm.copy_values_within_array(characters, 1, 4, 5);
|
||||
|
||||
assert.equal(characters[1], 1);
|
||||
|
||||
// if negatives were used
|
||||
wasm.copy_values_within_array(characters, -1, -3, -2);
|
||||
assert.equal(characters[5], 3);
|
||||
}
|
||||
"#)
|
||||
.test()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user