diff --git a/ecmascript/stubs/runtime_stubs-inl.h b/ecmascript/stubs/runtime_stubs-inl.h index 372e10f775..7fcf9e5021 100644 --- a/ecmascript/stubs/runtime_stubs-inl.h +++ b/ecmascript/stubs/runtime_stubs-inl.h @@ -443,6 +443,20 @@ JSTaggedValue RuntimeStubs::RuntimeStArraySpread(JSThread *thread, const JSHandl dstArray->SetElements(thread, dstElements); dstArray->SetArrayLength(thread, length); TaggedArray::CopyTaggedArrayElement(thread, srcElements, dstElements, length); + for (uint32_t i = 0; i < length; i++) { + JSTaggedValue reg = srcElements->Get(thread, i); + if (reg.IsHole()) { + JSTaggedValue reg2 = JSArray::FastGetPropertyByValue(thread, src, i).GetTaggedValue(); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + if (reg2.IsHole()) { + dstElements->Set(thread, i, JSTaggedValue::Undefined()); + } else { + dstElements->Set(thread, i, reg2); + } + } else { + dstElements->Set(thread, i, reg); + } + } return JSTaggedValue(length); } diff --git a/test/moduletest/BUILD.gn b/test/moduletest/BUILD.gn index d251202364..3cef51d864 100644 --- a/test/moduletest/BUILD.gn +++ b/test/moduletest/BUILD.gn @@ -30,6 +30,7 @@ group("ark_js_moduletest") { "arraytospliced", "arraywith", "arraysort", + "arrayspread", "arrayprotochange", "arrayshift", "arrayslice", @@ -183,6 +184,7 @@ group("ark_asm_test") { "arrayjoin", "arraypop", "arraysort", + "arrayspread", "arrayprotochange", "arrayshift", "arrayslice", @@ -317,6 +319,7 @@ group("ark_asm_single_step_test") { "arrayprotochange", "arrayshift", "arrayslice", + "arrayspread", "asmstackoverflow", "assignproxy", "async", diff --git a/test/moduletest/arrayspread/BUILD.gn b/test/moduletest/arrayspread/BUILD.gn new file mode 100644 index 0000000000..2624d84215 --- /dev/null +++ b/test/moduletest/arrayspread/BUILD.gn @@ -0,0 +1,18 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//arkcompiler/ets_runtime/test/test_helper.gni") + +host_moduletest_action("arrayspread") { + deps = [] +} diff --git a/test/moduletest/arrayspread/arrayspread.js b/test/moduletest/arrayspread/arrayspread.js new file mode 100644 index 0000000000..f26542bc88 --- /dev/null +++ b/test/moduletest/arrayspread/arrayspread.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * @tc.name:async + * @tc.desc:test array spread + * @tc.type: FUNC + * @tc.require: issues/I8J3HT + */ + +var a = [, 2]; +print([...a]); +print([...a].hasOwnProperty(0)); +function foo0() { return arguments.hasOwnProperty(0); } +print(foo0(...a)); +a.__proto__.push(2); +print([...a]); \ No newline at end of file diff --git a/test/moduletest/arrayspread/expect_output.txt b/test/moduletest/arrayspread/expect_output.txt new file mode 100644 index 0000000000..7850661872 --- /dev/null +++ b/test/moduletest/arrayspread/expect_output.txt @@ -0,0 +1,17 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +,2 +true +true +2,2