From 178a5e89df2529cd6907b69bc599ef74f1f92eb5 Mon Sep 17 00:00:00 2001 From: Nick Fitzgerald Date: Fri, 10 Aug 2018 13:14:54 -0700 Subject: [PATCH] js-sys: add bindings for `regexp.lastIndex` --- crates/js-sys/src/lib.rs | 14 ++++++++++++++ crates/js-sys/tests/wasm/RegExp.rs | 9 +++++++++ 2 files changed, 23 insertions(+) diff --git a/crates/js-sys/src/lib.rs b/crates/js-sys/src/lib.rs index 01a75c1a..c21f7fdc 100644 --- a/crates/js-sys/src/lib.rs +++ b/crates/js-sys/src/lib.rs @@ -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. diff --git a/crates/js-sys/tests/wasm/RegExp.rs b/crates/js-sys/tests/wasm/RegExp.rs index edaf5c92..a77d4892 100644 --- a/crates/js-sys/tests/wasm/RegExp.rs +++ b/crates/js-sys/tests/wasm/RegExp.rs @@ -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");