diff --git a/ecmascript/js_array.cpp b/ecmascript/js_array.cpp index 87f951d481..6ef5c2bf9b 100644 --- a/ecmascript/js_array.cpp +++ b/ecmascript/js_array.cpp @@ -115,10 +115,6 @@ JSTaggedValue JSArray::ArraySpeciesCreate(JSThread *thread, const JSHandle constructor(thread, JSTaggedValue::Undefined()); if (isArray) { // Let C be Get(originalArray, "constructor"). - auto *hclass = originalArray->GetJSHClass(); - if (hclass->IsJSArray() && !hclass->HasConstructor()) { - return JSArray::ArrayCreate(thread, length, ArrayMode::LITERAL).GetTaggedValue(); - } JSHandle constructorKey = globalConst->GetHandledConstructorString(); constructor = JSTaggedValue::GetProperty(thread, originalValue, constructorKey).GetValue(); // ReturnIfAbrupt(C). diff --git a/ecmascript/js_stable_array.cpp b/ecmascript/js_stable_array.cpp index 16794a868f..8cda441a31 100644 --- a/ecmascript/js_stable_array.cpp +++ b/ecmascript/js_stable_array.cpp @@ -379,7 +379,17 @@ JSTaggedValue JSStableArray::HandleFindLastIndexOfStable(JSThread *thread, JSHan while (k >= 0) { // Elements of thisObjHandle may change. array.Update(thisObjHandle->GetElements()); - kValue.Update(array->Get(k)); + JSTaggedValue val = array->Get(k); + if (val.IsHole()) { + auto res = JSArray::FastGetPropertyByValue(thread, thisObjVal, k).GetTaggedValue(); + if (res.IsHole()) { + kValue.Update(JSTaggedValue::Undefined()); + } else { + kValue.Update(res); + } + } else { + kValue.Update(val); + } EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, callbackFnHandle, thisArgHandle, undefined, argsLength); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); diff --git a/test/moduletest/BUILD.gn b/test/moduletest/BUILD.gn index 929b7f5d7a..3d26fcc2cf 100644 --- a/test/moduletest/BUILD.gn +++ b/test/moduletest/BUILD.gn @@ -20,7 +20,9 @@ group("ark_js_moduletest") { "array", "arrayfindlast", "arrayflat", + "arrayflatmap", "arrayfindindex", + "arrayfindlastindex", "arrayforeach", "arrayjoin", "arraypop", @@ -167,6 +169,8 @@ group("ark_asm_test") { "array", "arrayfindlast", "arrayflat", + "arrayflatmap", + "arrayfindlastindex", "arrayfindindex", "arrayforeach", "arrayjoin", @@ -292,6 +296,8 @@ group("ark_asm_single_step_test") { "arrayfindindex", "arrayfindlast", "arrayflat", + "arrayflatmap", + "arrayfindlastindex", "arrayforeach", "arrayjoin", "arraypop", diff --git a/test/moduletest/arrayfindlastindex/BUILD.gn b/test/moduletest/arrayfindlastindex/BUILD.gn new file mode 100644 index 0000000000..5415623086 --- /dev/null +++ b/test/moduletest/arrayfindlastindex/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("arrayfindlastindex") { + deps = [] +} diff --git a/test/moduletest/arrayfindlastindex/arrayfindlastindex.js b/test/moduletest/arrayfindlastindex/arrayfindlastindex.js new file mode 100644 index 0000000000..70ae0c7d6c --- /dev/null +++ b/test/moduletest/arrayfindlastindex/arrayfindlastindex.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:arrayfindIndex + * @tc.desc:test Array.findlastIndex + * @tc.type: FUNC + * @tc.require: issueI8FBM3 + */ + +(function() { + var a = [0, 1,,3]; + var index = a.findLastIndex(function(val){ + return val === undefined; + }); + print(index); +})(); diff --git a/test/moduletest/arrayfindlastindex/expect_output.txt b/test/moduletest/arrayfindlastindex/expect_output.txt new file mode 100644 index 0000000000..40fa087d42 --- /dev/null +++ b/test/moduletest/arrayfindlastindex/expect_output.txt @@ -0,0 +1,14 @@ +# 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 diff --git a/test/moduletest/arrayflat/BUILD.gn b/test/moduletest/arrayflat/BUILD.gn index 25a1c114e3..504879ce72 100644 --- a/test/moduletest/arrayflat/BUILD.gn +++ b/test/moduletest/arrayflat/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. +# 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 diff --git a/test/moduletest/arrayflat/arrayflat.js b/test/moduletest/arrayflat/arrayflat.js index 6c13a9459c..ad8dc59334 100644 --- a/test/moduletest/arrayflat/arrayflat.js +++ b/test/moduletest/arrayflat/arrayflat.js @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * 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 @@ -17,7 +17,18 @@ * @tc.name:async * @tc.desc:test async function * @tc.type: FUNC - * @tc.require: issueI5NO8G + * @tc.require: issueI5NO8G issueI8FBM3 */ const input = [1, [2], [[3]]]; print(input.flat(undefined)); + +{ + class MyArray extends Array { + static get [Symbol.species]() { + return this; + } + } + const wannabe = new MyArray(); + const flattened = wannabe.flat(Infinity); + print(flattened instanceof MyArray); +} diff --git a/test/moduletest/arrayflat/expect_output.txt b/test/moduletest/arrayflat/expect_output.txt index 386be34897..53aae57749 100644 --- a/test/moduletest/arrayflat/expect_output.txt +++ b/test/moduletest/arrayflat/expect_output.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. +# 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 @@ -12,3 +12,4 @@ # limitations under the License. 1,2,3 +true diff --git a/test/moduletest/arrayflatmap/BUILD.gn b/test/moduletest/arrayflatmap/BUILD.gn new file mode 100644 index 0000000000..1bcef0c2c3 --- /dev/null +++ b/test/moduletest/arrayflatmap/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("arrayflatmap") { + deps = [] +} diff --git a/test/moduletest/arrayflatmap/arrayflatmap.js b/test/moduletest/arrayflatmap/arrayflatmap.js new file mode 100644 index 0000000000..9a27ec63b4 --- /dev/null +++ b/test/moduletest/arrayflatmap/arrayflatmap.js @@ -0,0 +1,31 @@ +/* + * 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:array.flatmap + * @tc.type: FUNC + * @tc.require:issueI8FBM3 + */ +{ + class MyArray extends Array { + static get [Symbol.species]() { + return this; + } + } + const wannabe = new MyArray(); + const result = wannabe.flatMap(x => [x, x]); + print(result instanceof MyArray);//t +} diff --git a/test/moduletest/arrayflatmap/expect_output.txt b/test/moduletest/arrayflatmap/expect_output.txt new file mode 100644 index 0000000000..ce415d321a --- /dev/null +++ b/test/moduletest/arrayflatmap/expect_output.txt @@ -0,0 +1,14 @@ +# 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. + +true