Browse Source

Fix Array.join when the array contains itself (#3406)

* Fix Array.join when the array contains itself

* add test
pull/3409/head
阿豪 1 year ago committed by GitHub
parent
commit
caac9049c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      boa_engine/src/builtins/array/mod.rs
  2. 1
      boa_engine/src/builtins/array/tests.rs

4
boa_engine/src/builtins/array/mod.rs

@ -1000,8 +1000,8 @@ impl Array {
} }
// b. Let element be ? Get(O, ! ToString(𝔽(k))). // b. Let element be ? Get(O, ! ToString(𝔽(k))).
let element = o.get(k, context)?; 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). // 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() { let next = if element.is_null_or_undefined() || &element == this {
js_string!() js_string!()
} else { } else {
element.to_string(context)? element.to_string(context)?

1
boa_engine/src/builtins/array/tests.rs

@ -77,6 +77,7 @@ fn join() {
TestAction::assert_eq("[].join('.')", js_string!()), TestAction::assert_eq("[].join('.')", js_string!()),
TestAction::assert_eq("['a'].join('.')", js_string!("a")), TestAction::assert_eq("['a'].join('.')", js_string!("a")),
TestAction::assert_eq("['a', 'b', 'c'].join('.')", js_string!("a.b.c")), 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!(",,")),
]); ]);
} }

Loading…
Cancel
Save