Skip to content

Commit

Permalink
Fix Array.join when the array contains itself (#3406)
Browse files Browse the repository at this point in the history
* Fix Array.join when the array contains itself

* add test
  • Loading branch information
ahaoboy authored Oct 21, 2023
1 parent 26d14a8 commit caac904
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
4 changes: 2 additions & 2 deletions boa_engine/src/builtins/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1000,8 +1000,8 @@ impl Array {
}
// b. Let element be ? Get(O, ! ToString(𝔽(k))).
let element = o.get(k, context)?;
// c. If element is undefined or null, let next be the empty String; otherwise, let next be ? ToString(element).
let next = if element.is_null_or_undefined() {
// c. If element is undefined, null or the array itself, let next be the empty String; otherwise, let next be ? ToString(element).
let next = if element.is_null_or_undefined() || &element == this {
js_string!()
} else {
element.to_string(context)?
Expand Down
1 change: 1 addition & 0 deletions boa_engine/src/builtins/array/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ fn join() {
TestAction::assert_eq("[].join('.')", js_string!()),
TestAction::assert_eq("['a'].join('.')", js_string!("a")),
TestAction::assert_eq("['a', 'b', 'c'].join('.')", js_string!("a.b.c")),
TestAction::assert_eq("let a=[];a[0]=a;a[1]=a;a[2]=a;a.join()", js_string!(",,")),
]);
}

Expand Down

0 comments on commit caac904

Please sign in to comment.