diff --git a/core/engine/src/builtins/string/mod.rs b/core/engine/src/builtins/string/mod.rs index b166085003e..3d1647e3e21 100644 --- a/core/engine/src/builtins/string/mod.rs +++ b/core/engine/src/builtins/string/mod.rs @@ -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 @@ -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)?; @@ -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() { + // 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); + } } } @@ -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)? { @@ -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)?; @@ -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 @@ -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)?;