Skip to content

Commit

Permalink
fix(boa): match and regexp construct fixes (#1374)
Browse files Browse the repository at this point in the history
  • Loading branch information
neeldug authored Jul 27, 2021
1 parent f429c16 commit f93145c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
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

0 comments on commit f93145c

Please sign in to comment.