Browse Source

Fix remaining ES5 `built-ins/RegExp` tests (#2957)

pull/2958/head
Haled Odat 2 years ago committed by GitHub
parent
commit
57ba979415
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      boa_engine/src/builtins/regexp/mod.rs

16
boa_engine/src/builtins/regexp/mod.rs

@ -890,7 +890,8 @@ impl RegExp {
// 11. Let matchSucceeded be false. // 11. Let matchSucceeded be false.
// 12. Repeat, while matchSucceeded is false, // 12. Repeat, while matchSucceeded is false,
let match_value = loop { let lossy_input = input.to_std_string_escaped();
let (match_value, last_byte_index) = loop {
// a. If lastIndex > length, then // a. If lastIndex > length, then
if last_index > length { if last_index > length {
// i. If global is true or sticky is true, then // i. If global is true or sticky is true, then
@ -914,9 +915,7 @@ impl RegExp {
.into()) .into())
} }
}; };
let r = matcher let r = matcher.find_from(&lossy_input, last_byte_index).next();
.find_from(input.to_std_string_escaped().as_str(), last_byte_index)
.next();
match r { match r {
// c. If r is failure, then // c. If r is failure, then
@ -937,7 +936,7 @@ impl RegExp {
Some(m) => { Some(m) => {
// c. If r is failure, then // c. If r is failure, then
#[allow(clippy::if_not_else)] #[allow(clippy::if_not_else)]
if m.start() as u64 != last_index { if m.start() != last_byte_index {
// i. If sticky is true, then // i. If sticky is true, then
if sticky { if sticky {
// 1. Perform ? Set(R, "lastIndex", +0𝔽, true). // 1. Perform ? Set(R, "lastIndex", +0𝔽, true).
@ -953,7 +952,7 @@ impl RegExp {
} else { } else {
//i. Assert: r is a State. //i. Assert: r is a State.
//ii. Set matchSucceeded to true. //ii. Set matchSucceeded to true.
break m; break (m, last_byte_index);
} }
} }
} }
@ -961,7 +960,6 @@ impl RegExp {
// 13. Let e be r's endIndex value. // 13. Let e be r's endIndex value.
let mut e = match_value.end(); let mut e = match_value.end();
let lossy_input = input.to_std_string_escaped();
// 14. If fullUnicode is true, then // 14. If fullUnicode is true, then
// TODO: disabled for now until we have UTF-16 support // TODO: disabled for now until we have UTF-16 support
@ -994,7 +992,7 @@ impl RegExp {
let a = Array::array_create(n + 1, None, context)?; let a = Array::array_create(n + 1, None, context)?;
// 20. Perform ! CreateDataPropertyOrThrow(A, "index", 𝔽(lastIndex)). // 20. Perform ! CreateDataPropertyOrThrow(A, "index", 𝔽(lastIndex)).
a.create_data_property_or_throw(utf16!("index"), match_value.start(), context) a.create_data_property_or_throw(utf16!("index"), last_index, context)
.expect("this CreateDataPropertyOrThrow call must not fail"); .expect("this CreateDataPropertyOrThrow call must not fail");
// 21. Perform ! CreateDataPropertyOrThrow(A, "input", S). // 21. Perform ! CreateDataPropertyOrThrow(A, "input", S).
@ -1002,7 +1000,7 @@ impl RegExp {
.expect("this CreateDataPropertyOrThrow call must not fail"); .expect("this CreateDataPropertyOrThrow call must not fail");
// 22. Let matchedSubstr be the substring of S from lastIndex to e. // 22. Let matchedSubstr be the substring of S from lastIndex to e.
let matched_substr = js_string!(&lossy_input[last_index as usize..e]); let matched_substr = js_string!(&lossy_input[last_byte_index..e]);
// 23. Perform ! CreateDataPropertyOrThrow(A, "0", matchedSubstr). // 23. Perform ! CreateDataPropertyOrThrow(A, "0", matchedSubstr).
a.create_data_property_or_throw(0, matched_substr, context) a.create_data_property_or_throw(0, matched_substr, context)

Loading…
Cancel
Save