From bf32a5b9bff19423a8ace13591b92e1e60391d42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=BF=E8=B1=AA?= <504595380@qq.com> Date: Sat, 21 Oct 2023 14:10:35 +0800 Subject: [PATCH 1/2] Fix Array.join when the array contains itself --- boa_engine/src/builtins/array/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/boa_engine/src/builtins/array/mod.rs b/boa_engine/src/builtins/array/mod.rs index 8c3f3867071..05b7abc775e 100644 --- a/boa_engine/src/builtins/array/mod.rs +++ b/boa_engine/src/builtins/array/mod.rs @@ -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)? From 3c6556ac876b22f0d1ed2c8e10f1824f7094954b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=BF=E8=B1=AA?= <504595380@qq.com> Date: Sat, 21 Oct 2023 14:50:21 +0800 Subject: [PATCH 2/2] add test --- boa_engine/src/builtins/array/tests.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/boa_engine/src/builtins/array/tests.rs b/boa_engine/src/builtins/array/tests.rs index d14b610e394..595f4d333c5 100644 --- a/boa_engine/src/builtins/array/tests.rs +++ b/boa_engine/src/builtins/array/tests.rs @@ -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!(",,")), ]); }