js-sys: add bindings for regexp.lastIndex

This commit is contained in:
Nick Fitzgerald 2018-08-10 13:14:54 -07:00
parent dc028d38c8
commit 178a5e89df
2 changed files with 23 additions and 0 deletions

View File

@ -2280,6 +2280,20 @@ extern {
#[wasm_bindgen(static_method_of = RegExp, getter)]
pub fn input() -> JsString;
/// The lastIndex is a read/write integer property of regular expression
/// instances that specifies the index at which to start the next match.
///
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex
#[wasm_bindgen(structural, getter = lastIndex, method)]
pub fn last_index(this: &RegExp) -> u32;
/// The lastIndex is a read/write integer property of regular expression
/// instances that specifies the index at which to start the next match.
///
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex
#[wasm_bindgen(structural, setter = lastIndex, method)]
pub fn set_last_index(this: &RegExp, index: u32);
/// The non-standard lastMatch property is a static and read-only
/// property of regular expressions that contains the last matched
/// characters. RegExp.$& is an alias for this property.

View File

@ -56,6 +56,15 @@ fn input() {
assert_eq!(RegExp::input(), "hi there!");
}
#[wasm_bindgen_test]
fn last_index() {
let re = RegExp::new("hi", "g");
assert_eq!(re.last_index(), 0);
re.set_last_index(42);
assert_eq!(re.last_index(), 42);
}
#[wasm_bindgen_test]
fn last_match() {
let re = RegExp::new("hi", "g");