Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix remaining ES5 built-ins/RegExp tests #2957

Merged
merged 1 commit into from
May 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions boa_engine/src/builtins/regexp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,8 @@ impl RegExp {

// 11. Let matchSucceeded be 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
if last_index > length {
// i. If global is true or sticky is true, then
Expand All @@ -914,9 +915,7 @@ impl RegExp {
.into())
}
};
let r = matcher
.find_from(input.to_std_string_escaped().as_str(), last_byte_index)
.next();
let r = matcher.find_from(&lossy_input, last_byte_index).next();

match r {
// c. If r is failure, then
Expand All @@ -937,7 +936,7 @@ impl RegExp {
Some(m) => {
// c. If r is failure, then
#[allow(clippy::if_not_else)]
if m.start() as u64 != last_index {
if m.start() != last_byte_index {
// i. If sticky is true, then
if sticky {
// 1. Perform ? Set(R, "lastIndex", +0𝔽, true).
Expand All @@ -953,15 +952,14 @@ impl RegExp {
} else {
//i. Assert: r is a State.
//ii. Set matchSucceeded to true.
break m;
break (m, last_byte_index);
}
}
}
};

// 13. Let e be r's endIndex value.
let mut e = match_value.end();
let lossy_input = input.to_std_string_escaped();

// 14. If fullUnicode is true, then
// TODO: disabled for now until we have UTF-16 support
Expand Down Expand Up @@ -994,15 +992,15 @@ impl RegExp {
let a = Array::array_create(n + 1, None, context)?;

// 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");

// 21. Perform ! CreateDataPropertyOrThrow(A, "input", S).
a.create_data_property_or_throw(utf16!("input"), input.clone(), context)
.expect("this CreateDataPropertyOrThrow call must not fail");

// 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).
a.create_data_property_or_throw(0, matched_substr, context)
Expand Down