Skip to content
Open
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
21 changes: 14 additions & 7 deletions core/engine/src/builtins/string/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1470,6 +1470,7 @@ impl String {
// 2. If regexp is neither undefined nor null, then
let regexp = args.get_or_undefined(0);
if !regexp.is_null_or_undefined() {
if regexp.is_object() {
// a. Let matcher be ? GetMethod(regexp, @@match).
let matcher = regexp.get_method(JsSymbol::r#match(), context)?;
// b. If matcher is not undefined, then
Expand All @@ -1478,7 +1479,7 @@ impl String {
return matcher.call(regexp, std::slice::from_ref(o), context);
}
}

}
// 3. Let S be ? ToString(O).
let s = o.to_string(context)?;

Expand Down Expand Up @@ -1915,12 +1916,14 @@ impl String {

// 2. If separator is neither undefined nor null, then
if !separator.is_null_or_undefined() {
// a. Let splitter be ? GetMethod(separator, @@split).
let splitter = separator.get_method(JsSymbol::split(), context)?;
// b. If splitter is not undefined, then
if let Some(splitter) = splitter {
// i. Return ? Call(splitter, separator, « O, limit »).
return splitter.call(separator, &[this.clone(), limit.clone()], context);
if let Some(separator_obj) = separator.as_object() {
Copy link
Copy Markdown
Member

@jedel1043 jedel1043 Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kind of unrelated, but now that you're touching this part of the code, can you change this to use let chains and &&s?
Something like if !separator.blah() && let Some(separator_obj) = blah

Also kind of applies to the rest of the added lines since I see that a lot of them are just two nested ifs.

// a. Let splitter be ? GetMethod(separator, @@split).
let splitter = separator_obj.get_method(JsSymbol::split(), context)?;
// b. If splitter is not undefined, then
if let Some(splitter) = splitter {
// i. Return ? Call(splitter, separator, « O, limit »).
return splitter.call(separator, &[this.clone(), limit.clone()], context);
}
}
}

Expand Down Expand Up @@ -2053,6 +2056,7 @@ impl String {
// 2. If regexp is neither undefined nor null, then
let regexp = args.get_or_undefined(0);
if !regexp.is_null_or_undefined() {
if regexp.is_object() {
// a. Let isRegExp be ? IsRegExp(regexp).
// b. If isRegExp is true, then
if let Some(regexp) = RegExp::is_reg_exp(regexp, context)? {
Expand All @@ -2078,6 +2082,7 @@ impl String {
return matcher.call(regexp, std::slice::from_ref(o), context);
}
}
}

// 3. Let S be ? ToString(O).
let s = o.to_string(context)?;
Expand Down Expand Up @@ -2195,6 +2200,7 @@ impl String {
// 2. If regexp is neither undefined nor null, then
let regexp = args.get_or_undefined(0);
if !regexp.is_null_or_undefined() {
if regexp.is_object() {
// a. Let searcher be ? GetMethod(regexp, @@search).
let searcher = regexp.get_method(JsSymbol::search(), context)?;
// b. If searcher is not undefined, then
Expand All @@ -2203,6 +2209,7 @@ impl String {
return searcher.call(regexp, std::slice::from_ref(o), context);
}
}
}

// 3. Let string be ? ToString(O).
let string = o.to_string(context)?;
Expand Down
Loading