Skip to content

Commit

Permalink
Fix RegExp constructor return value when pattern is a regexp (#2880)
Browse files Browse the repository at this point in the history
When `RegExp` constructor is called with a regexp it should return the same regexp, if `NewTarget`'s constructor is the same.
  • Loading branch information
HalidOdat committed Apr 29, 2023
1 parent d49656d commit c738b50
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion boa_engine/src/builtins/regexp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,20 @@ impl BuiltInConstructor for RegExp {
// 3. Else, let newTarget be NewTarget.
if new_target.is_undefined() {
// a. Let newTarget be the active function object.
let new_target = context
.vm
.active_function
.clone()
.map_or(JsValue::undefined(), JsValue::new);

// b. If patternIsRegExp is true and flags is undefined, then
if let Some(pattern) = pattern_is_regexp {
if flags.is_undefined() {
// i. Let patternConstructor be ? Get(pattern, "constructor").
let pattern_constructor = pattern.get(CONSTRUCTOR, context)?;

// ii. If SameValue(newTarget, patternConstructor) is true, return pattern.
if JsValue::same_value(new_target, &pattern_constructor) {
if JsValue::same_value(&new_target, &pattern_constructor) {
return Ok(pattern.clone().into());
}
}
Expand Down

0 comments on commit c738b50

Please sign in to comment.