Browse Source

fix(boa): match and regexp construct fixes (#1374)

pull/1438/head
neeldug 3 years ago committed by GitHub
parent
commit
f93145c0bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      boa/src/builtins/regexp/mod.rs
  2. 7
      boa/src/builtins/string/mod.rs

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

@ -211,13 +211,10 @@ 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(),
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() {
@ -225,12 +222,15 @@ impl RegExp {
(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) {

7
boa/src/builtins/string/mod.rs

@ -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);
}
}

Loading…
Cancel
Save