Skip to content

Commit c8857b5

Browse files
committed
avm2: Implement missing AS3 RegExp features
1 parent e3fdfe1 commit c8857b5

File tree

4 files changed

+23
-18
lines changed

4 files changed

+23
-18
lines changed

Cargo.lock

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ rand = { version = "0.8.5", features = ["std", "small_rng"], default-features =
4141
serde = { workspace = true }
4242
serde_json = { version = "1.0", features = ["preserve_order"] }
4343
nellymoser-rs = { git = "https://github.com/ruffle-rs/nellymoser", rev = "073eb48d907201f46dea0c8feb4e8d9a1d92208c", optional = true }
44-
regress = "0.10"
44+
regress = { git = "https://github.com/evilpie/regress", branch = "as3" }
4545
flash-lso = { git = "https://github.com/ruffle-rs/rust-flash-lso", rev = "a5e938d9bb1909095f2340c2435867f6aae930b0" }
4646
lzma-rs = {version = "0.3.0", optional = true }
4747
dasp = { version = "0.11.0", features = ["interpolate", "interpolate-linear", "signal"], optional = true }

core/src/avm2/globals/reg_exp.rs

+20-15
Original file line numberDiff line numberDiff line change
@@ -219,27 +219,32 @@ pub fn exec<'gc>(
219219
.unwrap_or(&Value::Undefined)
220220
.coerce_to_string(activation)?;
221221

222-
let (storage, index) = match re.exec(text) {
223-
Some(matched) => {
224-
let substrings = matched
225-
.groups()
226-
.map(|range| range.map(|r| WString::from(&text[r])));
227-
228-
let storage = ArrayStorage::from_iter(substrings.map(|s| match s {
229-
None => Value::Undefined,
230-
Some(s) => AvmString::new(activation.gc(), s).into(),
231-
}));
232-
233-
(storage, matched.start())
234-
}
235-
None => return Ok(Value::Null),
222+
let matched = match re.exec(text) {
223+
Some(matched) => matched,
224+
None => return Ok(Value::Null)
236225
};
237226

227+
let substrings = matched
228+
.groups()
229+
.map(|range| range.map(|r| WString::from(&text[r])));
230+
231+
let storage = ArrayStorage::from_iter(substrings.map(|s| match s {
232+
None => Value::Undefined,
233+
Some(s) => AvmString::new(activation.gc(), s).into(),
234+
}));
235+
238236
let object = ArrayObject::from_storage(activation, storage);
239237

238+
for (name, range) in matched.named_groups() {
239+
if let Some(range) = range {
240+
let substring = AvmString::new(activation.gc(), &text[range]);
241+
object.set_string_property_local(AvmString::new_utf8(activation.gc(), name), substring.into(), activation)?;
242+
}
243+
}
244+
240245
object.set_string_property_local(
241246
istr!("index"),
242-
Value::Number(index as f64),
247+
Value::Number(matched.start() as f64),
243248
activation,
244249
)?;
245250

core/src/avm2/regexp.rs

+1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ impl<'gc> RegExp<'gc> {
100100
icase: self.flags.contains(RegExpFlags::IGNORE_CASE),
101101
multiline: self.flags.contains(RegExpFlags::MULTILINE),
102102
dot_all: self.flags.contains(RegExpFlags::DOTALL),
103+
extended: self.flags.contains(RegExpFlags::EXTENDED),
103104
no_opt: false,
104105
unicode: false,
105106
unicode_sets: false,

0 commit comments

Comments
 (0)