From caac9049c40f7361ede282cf358d3c5981e5d6db 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 15:25:18 +0800 Subject: [PATCH] Fix Array.join when the array contains itself (#3406) * Fix Array.join when the array contains itself * add test --- boa_engine/src/builtins/array/mod.rs | 4 ++-- boa_engine/src/builtins/array/tests.rs | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/boa_engine/src/builtins/array/mod.rs b/boa_engine/src/builtins/array/mod.rs index 8c3f386707..05b7abc775 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)? diff --git a/boa_engine/src/builtins/array/tests.rs b/boa_engine/src/builtins/array/tests.rs index d14b610e39..595f4d333c 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!(",,")), ]); }