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(boa): match and regexp construct fixes #1374

Merged
merged 5 commits into from
Jul 27, 2021
Merged
Show file tree
Hide file tree
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
18 changes: 9 additions & 9 deletions boa/src/builtins/regexp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,26 +211,26 @@ impl RegExp {
let arg = args.get(0).ok_or_else(Value::undefined)?;

let (regex_body, mut regex_flags) = match arg {
Value::String(ref body) => {
// first argument is a string -> use it as regex pattern
(
body.to_string().into_boxed_str(),
String::new().into_boxed_str(),
)
}
Value::Undefined => (
String::new().into_boxed_str(),
String::new().into_boxed_str(),
),
Value::Object(ref obj) => {
let obj = obj.borrow();
if let Some(regex) = obj.as_regexp() {
// first argument is another `RegExp` object, so copy its pattern and flags
(regex.original_source.clone(), regex.original_flags.clone())
} else {
(
String::new().into_boxed_str(),
arg.to_string(ctx)?.to_string().into_boxed_str(),
String::new().into_boxed_str(),
)
}
}
_ => return Err(Value::undefined()),
_ => (
arg.to_string(ctx)?.to_string().into_boxed_str(),
String::new().into_boxed_str(),
),
};
// if a second argument is given and it's a string, use it as flags
if let Some(Value::String(flags)) = args.get(1) {
Expand Down
7 changes: 3 additions & 4 deletions boa/src/builtins/string/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -872,12 +872,11 @@ impl String {
// a. Let matcher be ? GetMethod(regexp, @@match).
// b. If matcher is not undefined, then
if let Some(matcher) = regexp
.as_object()
.unwrap_or_default()
.get_method(context, "match")?
.to_object(context)?
.get_method(context, WellKnownSymbols::match_())?
{
// i. Return ? Call(matcher, regexp, « O »).
return matcher.call(&regexp, &[object.clone()], context);
return matcher.call(&regexp, &[this.clone()], context);
}
}

Expand Down